Skip to content

Commit

Permalink
refactor: Only test receive, fallback funcs when available
Browse files Browse the repository at this point in the history
Previously runs all the time, which is currently okay with the current
single testing contract that includes both functions. This conditionally
adds these test cases if the respective functions exist so we can test
additional contract behavior that may not have these functions and may
produce a different error.
  • Loading branch information
drklee3 committed Oct 9, 2024
1 parent cd15cde commit 0f248d2
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions tests/e2e-evm/test/abi_disabled.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,33 @@ describe("ABI_DisabledTests", function () {
value: bigint;
data: Hex;
}
const testCases: testCase[] = [
{ name: "zero value transfer", value: 0n, data: "0x" },
{ name: "value transfer", value: 1n, data: "0x" },
{ name: "invalid function selector", value: 0n, data: "0x010203" },
{ name: "invalid function selector with value", value: 1n, data: "0x010203" },
{ name: "non-matching function selector", value: 0n, data: toFunctionSelector("does_not_exist()") },
{ name: "non-matching function selector with value", value: 1n, data: toFunctionSelector("does_not_exist()") },
{
name: "non-matching function selector with extra data",
value: 0n,
data: concat([toFunctionSelector("does_not_exist()"), "0x01"]),
},
{
name: "non-matching function selector with value and extra data",
value: 1n,
data: concat([toFunctionSelector("does_not_exist()"), "0x01"]),
},
];
const testCases: testCase[] = [];

if (receiveFunction) {
testCases.push(
{ name: "zero value transfer", value: 0n, data: "0x" },
{ name: "value transfer", value: 1n, data: "0x" },
);
}

if (fallbackFunction) {
testCases.push(
{ name: "invalid function selector", value: 0n, data: "0x010203" },
{ name: "invalid function selector with value", value: 1n, data: "0x010203" },
{ name: "non-matching function selector", value: 0n, data: toFunctionSelector("does_not_exist()") },
{ name: "non-matching function selector with value", value: 1n, data: toFunctionSelector("does_not_exist()") },
{
name: "non-matching function selector with extra data",
value: 0n,
data: concat([toFunctionSelector("does_not_exist()"), "0x01"]),
},
{
name: "non-matching function selector with value and extra data",
value: 1n,
data: concat([toFunctionSelector("does_not_exist()"), "0x01"]),
},
);
}

for (const funcDesc of abi) {
if (funcDesc.type !== "function") {
Expand Down

0 comments on commit 0f248d2

Please sign in to comment.