-
Notifications
You must be signed in to change notification settings - Fork 3
Add reasonable test coverage #20
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
80d5707
Add unit tests for lib.ts utility functions
pkoch c0b03c1
Add modalities tests with cross-check against TDEDisbursement.sol
pkoch 25d4be9
Extract findPendingRows into tdePending.ts and add tests
pkoch dc1ffb5
Add unit tests for loadDisbursementCsv
pkoch df91fd2
Add tests for isDelegatedTo and isExecutionRevert
pkoch 384f860
Add tests for abiItemSignature and checkAbiAgainstArtifact
pkoch f0fe437
Extract buildExpectedEntries from cca.ts and add tests
pkoch bc142dc
Add paginatedGetEvents tests with mock fetcher
pkoch cdde105
Address self-critique issues in test suite
pkoch 3db83e2
Self-review
pkoch 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { describe, it } from "node:test"; | ||
| import { abiItemSignature, checkAbiAgainstArtifact } from "./abiChecker.js"; | ||
|
|
||
| describe("abiItemSignature", () => { | ||
| it("returns function signature for function items", () => { | ||
| const item = { | ||
| type: "function", | ||
| name: "transfer", | ||
| inputs: [ | ||
| { name: "to", type: "address" }, | ||
| { name: "amount", type: "uint256" }, | ||
| ], | ||
| outputs: [{ name: "", type: "bool" }], | ||
| }; | ||
| assert.equal(abiItemSignature(item), "transfer(address,uint256)"); | ||
| }); | ||
|
|
||
| it("returns event signature for event items", () => { | ||
| const item = { | ||
| type: "event", | ||
| name: "Transfer", | ||
| inputs: [ | ||
| { name: "from", type: "address", indexed: true }, | ||
| { name: "to", type: "address", indexed: true }, | ||
| { name: "value", type: "uint256", indexed: false }, | ||
| ], | ||
| }; | ||
| assert.equal(abiItemSignature(item), "Transfer(address,address,uint256)"); | ||
| }); | ||
|
|
||
| it("returns JSON for other types", () => { | ||
| const item = { type: "error", name: "Unauthorized" }; | ||
| assert.equal(abiItemSignature(item), JSON.stringify(item)); | ||
| }); | ||
| }); | ||
|
|
||
| describe("checkAbiAgainstArtifact", () => { | ||
| const transferFn = { | ||
| type: "function" as const, | ||
| name: "transfer" as const, | ||
| inputs: [ | ||
| { name: "to", type: "address" }, | ||
| { name: "amount", type: "uint256" }, | ||
| ], | ||
| outputs: [{ name: "", type: "bool" }], | ||
| }; | ||
|
|
||
| const approvalEvent = { | ||
| type: "event" as const, | ||
| name: "Approval" as const, | ||
| inputs: [ | ||
| { name: "owner", type: "address", indexed: true }, | ||
| { name: "spender", type: "address", indexed: true }, | ||
| { name: "value", type: "uint256", indexed: false }, | ||
| ], | ||
| }; | ||
|
|
||
| it("passes when static ABI is a subset of artifact", () => { | ||
| const staticAbi = [transferFn]; | ||
| const artifact = { abi: [transferFn, approvalEvent] }; | ||
| assert.doesNotThrow(() => checkAbiAgainstArtifact(staticAbi, artifact)); | ||
| }); | ||
|
|
||
| it("passes when both sides match exactly", () => { | ||
| const staticAbi = [transferFn, approvalEvent]; | ||
| const artifact = { abi: [transferFn, approvalEvent] }; | ||
| assert.doesNotThrow(() => checkAbiAgainstArtifact(staticAbi, artifact)); | ||
| }); | ||
|
|
||
| it("throws when a name is missing from artifact", () => { | ||
| const staticAbi = [transferFn]; | ||
| const artifact = { abi: [approvalEvent] }; | ||
| assert.throws( | ||
| () => checkAbiAgainstArtifact(staticAbi, artifact), | ||
| /artifact missing function:transfer/, | ||
| ); | ||
| }); | ||
|
|
||
| it("throws when signatures differ (same name, different params)", () => { | ||
| const staticAbi = [transferFn]; | ||
| const differentTransfer = { | ||
| ...transferFn, | ||
| inputs: [{ name: "to", type: "address" }], | ||
| }; | ||
| const artifact = { abi: [differentTransfer] }; | ||
| assert.throws( | ||
| () => checkAbiAgainstArtifact(staticAbi, artifact), | ||
| /signature differs/, | ||
| ); | ||
| }); | ||
|
|
||
| it("skips entries without a name", () => { | ||
| const staticAbi = [{ type: "constructor" as const }]; | ||
| const artifact = { abi: [] }; | ||
| assert.doesNotThrow(() => checkAbiAgainstArtifact(staticAbi, artifact)); | ||
| }); | ||
| }); |
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,60 @@ | ||
| import assert from "node:assert/strict"; | ||
| import { describe, it } from "node:test"; | ||
| import type { Address } from "viem"; | ||
| import { isDelegatedTo, isExecutionRevert } from "./batch.js"; | ||
|
|
||
| describe("isDelegatedTo", () => { | ||
| const TARGET = "0xaAaAaAaaAaAaAaaAaAAAAAAAAaaaAaAaAaaAaaAa" as Address; | ||
| const DELEGATED_CODE = `0xef0100${TARGET.slice(2).toLowerCase()}`; | ||
|
|
||
| it("returns true for correctly formatted delegation code", () => { | ||
| assert.equal(isDelegatedTo(DELEGATED_CODE, TARGET), true); | ||
| }); | ||
|
|
||
| it("returns false for undefined code", () => { | ||
| assert.equal(isDelegatedTo(undefined, TARGET), false); | ||
| }); | ||
|
|
||
| it("returns false for empty code", () => { | ||
| assert.equal(isDelegatedTo("0x", TARGET), false); | ||
| }); | ||
|
|
||
| it("returns false when code has wrong prefix", () => { | ||
| assert.equal(isDelegatedTo(`0xdeadbeef${TARGET.slice(2)}`, TARGET), false); | ||
| }); | ||
|
|
||
| it("returns false when address does not match", () => { | ||
| const OTHER = "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" as Address; | ||
| assert.equal(isDelegatedTo(DELEGATED_CODE, OTHER), false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("isExecutionRevert", () => { | ||
| it('matches "execution reverted"', () => { | ||
| assert.equal(isExecutionRevert(new Error("execution reverted")), true); | ||
| }); | ||
|
|
||
| it('matches "reverted"', () => { | ||
| assert.equal(isExecutionRevert(new Error("Transaction reverted without a reason")), true); | ||
| }); | ||
|
|
||
| it('matches "exceeds block gas limit"', () => { | ||
| assert.equal(isExecutionRevert(new Error("exceeds block gas limit")), true); | ||
| }); | ||
|
|
||
| it("matches ContractFunctionRevertedError by constructor name", () => { | ||
| class ContractFunctionRevertedError extends Error {} | ||
| assert.equal(isExecutionRevert(new ContractFunctionRevertedError("fail")), true); | ||
| }); | ||
|
|
||
| it("returns false for non-Error values", () => { | ||
| assert.equal(isExecutionRevert("string error"), false); | ||
| assert.equal(isExecutionRevert(42), false); | ||
| assert.equal(isExecutionRevert(null), false); | ||
| }); | ||
|
|
||
| it("returns false for unrelated error messages", () => { | ||
| assert.equal(isExecutionRevert(new Error("network timeout")), false); | ||
| assert.equal(isExecutionRevert(new Error("rate limited")), false); | ||
| }); | ||
| }); |
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
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.