-
Notifications
You must be signed in to change notification settings - Fork 6
Feat/happy path(claimer) in validator-cli #396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ad77cf4
feat: claimer
371e8d0
feat: happy path tests
7173b75
feat: claimer tests
240f5f7
feat: cli path tests
a25b473
feat: increased test coverage
cfa2e02
chore: outscoped claim fetch
105a50a
fix: verifySnapshot time flag
edce69c
fix: happy path logs
3f78877
chore: env.dist update
4eb9b3c
feat: multi network support
06220dd
chore: refactor for networks
84ab53f
feat(validator): devent network support
5b0740a
chore(validator): refactor for network support
2e67ae2
chore(validator): update subgraph query for multi network
af153e1
chore(validator): type params & refactor
2316c21
chore(validator): update tests for refactor
88deca7
chore(validator): remove old watcher
bedb92c
fix(validator): existence check
d85dd2d
chore(validator): udpdate rpc in env example
3b3d905
chore(validator): add custom error
f1bb940
chore: merge and resolve dev
54fbed2
chore(validator): pm2 bump & removed web3 dep
66c1fc6
chore(validator): add no claim required log
410a068
fix(validator): claimable epoch calculation fix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,234 @@ | ||
import { ethers } from "ethers"; | ||
import { checkAndClaim, CheckAndClaimParams } from "./claimer"; | ||
import { ClaimHonestState } from "../utils/claim"; | ||
import { Network } from "../consts/bridgeRoutes"; | ||
|
||
describe("claimer", () => { | ||
const NETWORK = Network.DEVNET; | ||
let veaOutbox: any; | ||
let veaInbox: any; | ||
let veaInboxProvider: any; | ||
let veaOutboxProvider: any; | ||
let emitter: any; | ||
let mockClaim: any; | ||
let mockGetLatestClaimedEpoch: any; | ||
let mockGetTransactionHandler: any; | ||
let mockDeps: CheckAndClaimParams; | ||
|
||
let mockTransactionHandler: any; | ||
const mockTransactions = { | ||
claimTxn: "0x111", | ||
withdrawClaimDepositTxn: "0x222", | ||
startVerificationTxn: "0x333", | ||
verifySnapshotTxn: "0x444", | ||
devnetAdvanceStateTxn: "0x555", | ||
}; | ||
beforeEach(() => { | ||
mockClaim = { | ||
stateRoot: "0x1234", | ||
claimer: "0xFa00D29d378EDC57AA1006946F0fc6230a5E3288", | ||
timestampClaimed: 1234, | ||
timestampVerification: 0, | ||
blocknumberVerification: 0, | ||
honest: 0, | ||
challenger: ethers.ZeroAddress, | ||
}; | ||
veaInbox = { | ||
snapshots: jest.fn().mockResolvedValue(mockClaim.stateRoot), | ||
}; | ||
|
||
veaOutbox = { | ||
stateRoot: jest.fn().mockResolvedValue(mockClaim.stateRoot), | ||
}; | ||
veaOutboxProvider = { | ||
getBlock: jest.fn().mockResolvedValue({ number: 0, timestamp: 110 }), | ||
}; | ||
emitter = { | ||
emit: jest.fn(), | ||
}; | ||
|
||
mockGetLatestClaimedEpoch = jest.fn(); | ||
mockGetTransactionHandler = jest.fn().mockReturnValue(function DummyTransactionHandler(params: any) { | ||
// Return an object that matches our expected transaction handler. | ||
return mockTransactionHandler; | ||
}); | ||
mockDeps = { | ||
chainId: 0, | ||
claim: mockClaim, | ||
network: NETWORK, | ||
epoch: 10, | ||
epochPeriod: 10, | ||
veaInbox, | ||
veaInboxProvider, | ||
veaOutboxProvider, | ||
veaOutbox, | ||
transactionHandler: null, | ||
emitter, | ||
fetchLatestClaimedEpoch: mockGetLatestClaimedEpoch, | ||
now: 110000, // (epoch+ 1) * epochPeriod * 1000 for claimable epoch | ||
}; | ||
|
||
mockTransactionHandler = { | ||
withdrawClaimDeposit: jest.fn().mockImplementation(() => { | ||
mockTransactionHandler.transactions.withdrawClaimDepositTxn = mockTransactions.withdrawClaimDepositTxn; | ||
return Promise.resolve(); | ||
}), | ||
makeClaim: jest.fn().mockImplementation(() => { | ||
mockTransactionHandler.transactions.claimTxn = mockTransactions.claimTxn; | ||
return Promise.resolve(); | ||
}), | ||
startVerification: jest.fn().mockImplementation(() => { | ||
mockTransactionHandler.transactions.startVerificationTxn = mockTransactions.startVerificationTxn; | ||
return Promise.resolve(); | ||
}), | ||
verifySnapshot: jest.fn().mockImplementation(() => { | ||
mockTransactionHandler.transactions.verifySnapshotTxn = mockTransactions.verifySnapshotTxn; | ||
return Promise.resolve(); | ||
}), | ||
transactions: { | ||
claimTxn: "0x0", | ||
withdrawClaimDepositTxn: "0x0", | ||
startVerificationTxn: "0x0", | ||
verifySnapshotTxn: "0x0", | ||
}, | ||
}; | ||
}); | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
describe("checkAndClaim", () => { | ||
beforeEach(() => { | ||
mockTransactionHandler = { | ||
withdrawClaimDeposit: jest.fn().mockImplementation(() => { | ||
mockTransactionHandler.transactions.withdrawClaimDepositTxn = mockTransactions.withdrawClaimDepositTxn; | ||
return Promise.resolve(); | ||
}), | ||
makeClaim: jest.fn().mockImplementation(() => { | ||
mockTransactionHandler.transactions.claimTxn = mockTransactions.claimTxn; | ||
return Promise.resolve(); | ||
}), | ||
startVerification: jest.fn().mockImplementation(() => { | ||
mockTransactionHandler.transactions.startVerificationTxn = mockTransactions.startVerificationTxn; | ||
return Promise.resolve(); | ||
}), | ||
verifySnapshot: jest.fn().mockImplementation(() => { | ||
mockTransactionHandler.transactions.verifySnapshotTxn = mockTransactions.verifySnapshotTxn; | ||
return Promise.resolve(); | ||
}), | ||
devnetAdvanceState: jest.fn().mockImplementation(() => { | ||
mockTransactionHandler.transactions.devnetAdvanceStateTxn = mockTransactions.devnetAdvanceStateTxn; | ||
return Promise.resolve(); | ||
}), | ||
transactions: { | ||
claimTxn: "0x0", | ||
withdrawClaimDepositTxn: "0x0", | ||
startVerificationTxn: "0x0", | ||
verifySnapshotTxn: "0x0", | ||
}, | ||
}; | ||
mockGetTransactionHandler = jest.fn().mockReturnValue(function DummyTransactionHandler(param: any) { | ||
return mockTransactionHandler; | ||
}); | ||
mockDeps.fetchTransactionHandler = mockGetTransactionHandler; | ||
}); | ||
it("should return null if no claim is made for a passed epoch", async () => { | ||
mockDeps.epoch = 7; // claimable epoch - 3 | ||
mockDeps.claim = null; | ||
|
||
mockDeps.fetchTransactionHandler = mockGetTransactionHandler; | ||
const result = await checkAndClaim(mockDeps); | ||
expect(result).toBeNull(); | ||
}); | ||
it("should return null if no snapshot is saved on the inbox for a claimable epoch", async () => { | ||
veaInbox.snapshots = jest.fn().mockResolvedValue(ethers.ZeroHash); | ||
mockGetLatestClaimedEpoch = jest.fn().mockResolvedValue({ | ||
challenged: false, | ||
stateroot: "0x1111", | ||
}); | ||
mockDeps.claim = null; | ||
mockDeps.fetchLatestClaimedEpoch = mockGetLatestClaimedEpoch; | ||
const result = await checkAndClaim(mockDeps); | ||
expect(result).toBeNull(); | ||
}); | ||
it("should return null if there are no new messages in the inbox", async () => { | ||
veaInbox.snapshots = jest.fn().mockResolvedValue(mockClaim.stateRoot); | ||
mockGetLatestClaimedEpoch = jest.fn().mockResolvedValue({ | ||
challenged: false, | ||
stateroot: "0x1111", | ||
}); | ||
mockDeps.claim = null; | ||
mockDeps.fetchLatestClaimedEpoch = mockGetLatestClaimedEpoch; | ||
const result = await checkAndClaim(mockDeps); | ||
expect(result).toBeNull(); | ||
}); | ||
describe("devnet", () => { | ||
beforeEach(() => { | ||
mockDeps.network = Network.DEVNET; | ||
}); | ||
it("should make a valid claim and advance state", async () => { | ||
veaInbox.snapshots = jest.fn().mockResolvedValue("0x7890"); | ||
mockGetLatestClaimedEpoch = jest.fn().mockResolvedValue({ | ||
challenged: false, | ||
stateroot: mockClaim.stateRoot, | ||
}); | ||
mockDeps.transactionHandler = mockTransactionHandler; | ||
mockDeps.fetchLatestClaimedEpoch = mockGetLatestClaimedEpoch; | ||
mockDeps.claim = null; | ||
mockDeps.veaInbox = veaInbox; | ||
const result = await checkAndClaim(mockDeps); | ||
expect(result.transactions.devnetAdvanceStateTxn).toBe(mockTransactions.devnetAdvanceStateTxn); | ||
}); | ||
}); | ||
describe("testnet", () => { | ||
beforeEach(() => { | ||
mockDeps.network = Network.TESTNET; | ||
}); | ||
it("should make a valid claim if no claim is made", async () => { | ||
veaInbox.snapshots = jest.fn().mockResolvedValue("0x7890"); | ||
mockGetLatestClaimedEpoch = jest.fn().mockResolvedValue({ | ||
challenged: false, | ||
stateroot: mockClaim.stateRoot, | ||
}); | ||
mockDeps.transactionHandler = mockTransactionHandler; | ||
mockDeps.fetchLatestClaimedEpoch = mockGetLatestClaimedEpoch; | ||
mockDeps.claim = null; | ||
mockDeps.veaInbox = veaInbox; | ||
const result = await checkAndClaim(mockDeps); | ||
expect(result.transactions.claimTxn).toBe(mockTransactions.claimTxn); | ||
}); | ||
it("should make a valid claim if last claim was challenged", async () => { | ||
veaInbox.snapshots = jest.fn().mockResolvedValue(mockClaim.stateRoot); | ||
mockGetLatestClaimedEpoch = jest.fn().mockResolvedValue({ | ||
challenged: true, | ||
stateroot: mockClaim.stateRoot, | ||
}); | ||
mockDeps.transactionHandler = mockTransactionHandler; | ||
mockDeps.fetchLatestClaimedEpoch = mockGetLatestClaimedEpoch; | ||
mockDeps.claim = null; | ||
mockDeps.veaInbox = veaInbox; | ||
const result = await checkAndClaim(mockDeps); | ||
expect(result.transactions.claimTxn).toEqual(mockTransactions.claimTxn); | ||
}); | ||
it("should withdraw claim deposit if claimer is honest", async () => { | ||
mockDeps.transactionHandler = mockTransactionHandler; | ||
mockClaim.honest = ClaimHonestState.CLAIMER; | ||
const result = await checkAndClaim(mockDeps); | ||
expect(result.transactions.withdrawClaimDepositTxn).toEqual(mockTransactions.withdrawClaimDepositTxn); | ||
}); | ||
it("should start verification if verification is not started", async () => { | ||
mockDeps.transactionHandler = mockTransactionHandler; | ||
mockClaim.honest = ClaimHonestState.NONE; | ||
const result = await checkAndClaim(mockDeps); | ||
expect(result.transactions.startVerificationTxn).toEqual(mockTransactions.startVerificationTxn); | ||
}); | ||
it("should verify snapshot if verification is started", async () => { | ||
mockDeps.transactionHandler = mockTransactionHandler; | ||
mockClaim.honest = ClaimHonestState.NONE; | ||
mockClaim.timestampVerification = 1234; | ||
mockDeps.claim = mockClaim; | ||
const result = await checkAndClaim(mockDeps); | ||
expect(result.transactions.verifySnapshotTxn).toEqual(mockTransactions.verifySnapshotTxn); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove duplicate RPC URL configuration.
The Arbitrum RPC URL is defined twice:
RPC_ARB_SEPOLIA=https://sepolia-rollup.arbitrum.io/rpc
RPC_ARB=https://sepolia-rollup.arbitrum.io/rpc
This could lead to confusion. Consider removing one of them or clearly documenting the difference if both are needed.
Also applies to: 4-4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will use a single RPC var for both networks on a chain 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mani99brar Great! Using a single RPC variable per chain is a good simplification that will make the configuration more maintainable. This is a change from your previous approach where you had separate variables for devnet and testnet/mainnet usage, but it should make the codebase cleaner and reduce potential confusion. Let me know if you need any help with implementing this change.
✏️ Learnings added
🧠 Learnings used