From f3e26d28a260a3a125c65473bce00eeceaaf2478 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 23 Jun 2026 17:01:41 +0000 Subject: [PATCH 1/2] Add optional gasUsed assertion to testrunner output expectations The testrunner JSON output expectation now supports an optional "gasUsed" field. When present, the test fails unless the gas used at that point matches exactly; when absent, gas is ignored. Co-Authored-By: Alex Beregszaszi --- test/testrunner/testrunner.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/testrunner/testrunner.cpp b/test/testrunner/testrunner.cpp index 5c2c8565b..01c0f64e9 100644 --- a/test/testrunner/testrunner.cpp +++ b/test/testrunner/testrunner.cpp @@ -196,6 +196,17 @@ int main(int argc, char** argv) continue; } } + if (test["output"].contains("gasUsed")) + { + auto expectedGasUsed = test["output"]["gasUsed"].get(); + if (u256(expectedGasUsed) != gasUsed) + { + reportFailure("Expected gasUsed " + expectedGasUsed + " but got " + gasUsed.str()); + resultRecorder.record(filename, "Expected different constructor gasUsed.", gasUsed.str(), expectedGasUsed, gasUsed, gasUsedForDeposit); + hasTestFailure = true; + continue; + } + } resultRecorder.record(filename, "Passed.", toHex(output), test["output"].value("returndata", std::string("")), gasUsed, gasUsedForDeposit); } else @@ -248,6 +259,17 @@ int main(int argc, char** argv) hasTestFailure = true; continue; } + if (test["output"].contains("gasUsed")) + { + auto expectedGasUsed = test["output"]["gasUsed"].get(); + if (u256(expectedGasUsed) != gasUsed) + { + reportFailure("Expected gasUsed " + expectedGasUsed + " but got " + gasUsed.str()); + resultRecorder.record(filename, "Expected different gasUsed.", gasUsed.str(), expectedGasUsed, gasUsed, gasUsedForDeposit); + hasTestFailure = true; + continue; + } + } resultRecorder.record(filename, "Passed.", toHex(output), expectedOutput, gasUsed, gasUsedForDeposit); } } From aa54a82b0758749f4b1455d63522ecf541aac4ee Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 23 Jun 2026 19:10:17 +0200 Subject: [PATCH 2/2] Add gas expectation to certain 'heavy' tests --- test/examples/dispatch/concat.json | 3 ++- test/examples/dispatch/deposit.json | 3 ++- test/examples/dispatch/miniERC20.json | 3 ++- test/examples/dispatch/slices.json | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test/examples/dispatch/concat.json b/test/examples/dispatch/concat.json index 322a6d9e1..54b95dc69 100644 --- a/test/examples/dispatch/concat.json +++ b/test/examples/dispatch/concat.json @@ -248,7 +248,8 @@ "kind": "call", "output": { "returndata": "00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000048111111111111111111111111111111111111111111111111111111111111111100000000000000003333333333333333333333333333333333333333333333333333333333333333000000000000000000000000000000000000000000000000", - "status": "success" + "status": "success", + "gasUsed": "24265" } } ] diff --git a/test/examples/dispatch/deposit.json b/test/examples/dispatch/deposit.json index 137c5e2aa..6f6aeda47 100644 --- a/test/examples/dispatch/deposit.json +++ b/test/examples/dispatch/deposit.json @@ -141,7 +141,8 @@ "kind": "call", "output": { "returndata": "", - "status": "success" + "status": "success", + "gasUsed": "80087" } }, diff --git a/test/examples/dispatch/miniERC20.json b/test/examples/dispatch/miniERC20.json index 20c52b2ae..9905807ee 100644 --- a/test/examples/dispatch/miniERC20.json +++ b/test/examples/dispatch/miniERC20.json @@ -20,7 +20,8 @@ "kind": "call", "output": { "returndata": "0000000000000000000000000000000000000000000000000000000000000001", - "status": "success" + "status": "success", + "gasUsed": "53538" } }, { diff --git a/test/examples/dispatch/slices.json b/test/examples/dispatch/slices.json index 7eb707709..71befbdcb 100644 --- a/test/examples/dispatch/slices.json +++ b/test/examples/dispatch/slices.json @@ -416,7 +416,8 @@ "kind": "call", "output": { "returndata": "52775448d69df653edbf6877861761433014544bd8871f69c9aed6eed947b46f", - "status": "success" + "status": "success", + "gasUsed": "24584" } } ]