Skip to content

Commit

Permalink
refactor: Optional expected storage for STATICCALL
Browse files Browse the repository at this point in the history
STATICCALL is expected to revert for storage tests, so having a
expected storage owner is misleading. This makes it optional so we can
show in the test cases that there is no expected storage.
  • Loading branch information
drklee3 committed Oct 25, 2024
1 parent 428d6c2 commit 83ab338
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions tests/e2e-evm/test/message_call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,11 @@ describe("Message calls", () => {
interface valueTestCase {
name: string;
type: CallType;
wantRevertReason?: string;
// msg.value for the parent
giveParentValue: bigint;
// Call value for the child, only applicable for call, callcode
giveChildCallValue?: bigint;
wantRevertReason?: string;
// Expected msg.value for the child
wantChildMsgValue: (txValue: bigint) => bigint;
}
Expand Down Expand Up @@ -387,7 +387,7 @@ describe("Message calls", () => {
name: string;
callType: CallType;
wantRevert?: boolean;
wantStorageContract: (ctx: TestContext<"StorageBasic">) => Address;
wantStorageContract?: (ctx: TestContext<"StorageBasic">) => Address;
}

const testCases: storageTestCase[] = [
Expand All @@ -412,8 +412,7 @@ describe("Message calls", () => {
name: "staticcall storage not allowed",
callType: "staticcall",
wantRevert: true,
// Storage in caller contract
wantStorageContract: (ctx) => ctx.lowLevelCaller.address,
// No expected storage due to revert
},
];

Expand Down Expand Up @@ -452,6 +451,10 @@ describe("Message calls", () => {
await publicClient.call(txData);
}

if (!tc.wantStorageContract) {
expect.fail("expected storage contract set");
}

const txHash = await walletClient.sendTransaction(txData);
const txReceipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
expect(txReceipt.status).to.equal("success");
Expand All @@ -474,16 +477,16 @@ describe("Message calls", () => {
});
}

// Mock contracts & precompiles need to implement these interfaces. These
// ABIs will be used to test the message call behavior.
const contextInspectorAbi = hre.artifacts.readArtifactSync("ContextInspector").abi;
const storageBasicAbi = hre.artifacts.readArtifactSync("StorageBasic").abi;

// Test context and storage for mock contracts as a baseline check
describe("Mock", () => {
let contextInspectorMock: GetContractReturnType<ArtifactsMap["ContextInspectorMock"]["abi"]>;
let storageBasicMock: GetContractReturnType<ArtifactsMap["StorageBasicMock"]["abi"]>;

// Mock contracts & precompiles need to implement these interfaces. These
// ABIs will be used to test the message call behavior.
const contextInspectorAbi = hre.artifacts.readArtifactSync("ContextInspector").abi;
const storageBasicAbi = hre.artifacts.readArtifactSync("StorageBasic").abi;

before("deploy mock contracts", async function () {
contextInspectorMock = await hre.viem.deployContract("ContextInspectorMock");
storageBasicMock = await hre.viem.deployContract("StorageBasicMock");
Expand Down

0 comments on commit 83ab338

Please sign in to comment.