Skip to content

Commit 6b913a8

Browse files
decofefgimenez
andcommitted
fix(test): extract helper contracts to separate files
The invariant-tests workflow injects wrapper functions before every '^}$' line in the test file. With helpers inline, the wrappers got injected into helper contracts too. Moved GasTestStorage, TIP1016Storage, and GasLeftChecker to test/helpers/. Co-Authored-By: Federico Gimenez <70376+fgimenez@users.noreply.github.com>
1 parent 93fdd00 commit 6b913a8

4 files changed

Lines changed: 64 additions & 66 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity >=0.8.13 <0.9.0;
3+
4+
/// @title GasTestStorage - Contract for testing SSTORE gas costs
5+
contract GasTestStorage {
6+
7+
mapping(bytes32 => uint256) private _storage;
8+
9+
function storeValue(bytes32 slot, uint256 value) external {
10+
_storage[slot] = value;
11+
}
12+
13+
function storeMultiple(bytes32[] calldata slots) external {
14+
for (uint256 i = 0; i < slots.length; i++) {
15+
_storage[slots[i]] = 1;
16+
}
17+
}
18+
19+
function getValue(bytes32 slot) external view returns (uint256) {
20+
return _storage[slot];
21+
}
22+
23+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity >=0.8.13 <0.9.0;
3+
4+
/// @title TIP1016Storage - Contract for testing TIP-1016 gas semantics
5+
contract TIP1016Storage {
6+
7+
mapping(bytes32 => uint256) private _storage;
8+
9+
function storeValue(bytes32 slot, uint256 value) external {
10+
_storage[slot] = value;
11+
}
12+
13+
function storeMultiple(bytes32[] calldata slots) external {
14+
for (uint256 i = 0; i < slots.length; i++) {
15+
_storage[slots[i]] = 1;
16+
}
17+
}
18+
19+
function storeAndClear(bytes32 slot, uint256 value) external {
20+
_storage[slot] = value;
21+
_storage[slot] = 0;
22+
}
23+
24+
function getValue(bytes32 slot) external view returns (uint256) {
25+
return _storage[slot];
26+
}
27+
28+
}
29+
30+
/// @title GasLeftChecker - Contract that records gasleft() for RES1 testing
31+
contract GasLeftChecker {
32+
33+
uint256 public lastGasLeft;
34+
35+
function checkGasLeft() external {
36+
lastGasLeft = gasleft();
37+
}
38+
39+
}

tips/ref-impls/test/invariants/GasPricing.t.sol

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,12 @@ import { Test } from "forge-std/Test.sol";
66
import { ITIP20 } from "../../src/interfaces/ITIP20.sol";
77
import { InvariantBase } from "../helpers/InvariantBase.sol";
88
import { Counter, InitcodeHelper, SimpleStorage } from "../helpers/TestContracts.sol";
9+
import { GasTestStorage } from "../helpers/GasTestStorage.sol";
910
import { TxBuilder } from "../helpers/TxBuilder.sol";
1011

1112
import { VmExecuteTransaction, VmRlp } from "tempo-std/StdVm.sol";
1213
import { LegacyTransaction, LegacyTransactionLib } from "tempo-std/tx/LegacyTransactionLib.sol";
1314

14-
/*//////////////////////////////////////////////////////////////
15-
HELPER CONTRACTS
16-
//////////////////////////////////////////////////////////////*/
17-
18-
/// @title GasTestStorage - Contract for testing SSTORE gas costs
19-
contract GasTestStorage {
20-
21-
mapping(bytes32 => uint256) private _storage;
22-
23-
function storeValue(bytes32 slot, uint256 value) external {
24-
_storage[slot] = value;
25-
}
26-
27-
function storeMultiple(bytes32[] calldata slots) external {
28-
for (uint256 i = 0; i < slots.length; i++) {
29-
_storage[slots[i]] = 1;
30-
}
31-
}
32-
33-
function getValue(bytes32 slot) external view returns (uint256) {
34-
return _storage[slot];
35-
}
36-
37-
}
38-
3915
/// @title TIP-1000 / TIP-1016 Gas Pricing Invariant Tests
4016
/// @notice Fuzz-based invariant tests for Tempo's state creation gas costs
4117
/// @dev Tests gas pricing invariants at the EVM opcode level using vmExec.executeTransaction()

tips/ref-impls/test/invariants/TIP1016.t.sol

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,12 @@ import { Test } from "forge-std/Test.sol";
66
import { ITIP20 } from "../../src/interfaces/ITIP20.sol";
77
import { InvariantBase } from "../helpers/InvariantBase.sol";
88
import { Counter, InitcodeHelper, SimpleStorage } from "../helpers/TestContracts.sol";
9+
import { TIP1016Storage, GasLeftChecker } from "../helpers/TIP1016Helpers.sol";
910
import { TxBuilder } from "../helpers/TxBuilder.sol";
1011

1112
import { VmExecuteTransaction, VmRlp } from "tempo-std/StdVm.sol";
1213
import { LegacyTransaction, LegacyTransactionLib } from "tempo-std/tx/LegacyTransactionLib.sol";
1314

14-
/*//////////////////////////////////////////////////////////////
15-
HELPER CONTRACTS
16-
//////////////////////////////////////////////////////////////*/
17-
18-
/// @title TIP1016Storage - Contract for testing TIP-1016 gas semantics
19-
contract TIP1016Storage {
20-
21-
mapping(bytes32 => uint256) private _storage;
22-
23-
function storeValue(bytes32 slot, uint256 value) external {
24-
_storage[slot] = value;
25-
}
26-
27-
function storeMultiple(bytes32[] calldata slots) external {
28-
for (uint256 i = 0; i < slots.length; i++) {
29-
_storage[slots[i]] = 1;
30-
}
31-
}
32-
33-
function storeAndClear(bytes32 slot, uint256 value) external {
34-
_storage[slot] = value;
35-
_storage[slot] = 0;
36-
}
37-
38-
function getValue(bytes32 slot) external view returns (uint256) {
39-
return _storage[slot];
40-
}
41-
42-
}
43-
44-
/// @title GasLeftChecker - Contract that records gasleft() for RES1 testing
45-
contract GasLeftChecker {
46-
47-
uint256 public lastGasLeft;
48-
49-
function checkGasLeft() external {
50-
lastGasLeft = gasleft();
51-
}
52-
53-
}
54-
5515
/// @title TIP-1016 State Gas Exemption Invariant Tests
5616
/// @notice Fuzz-based invariant tests for TIP-1016's gas dimension split, reservoir model,
5717
/// block accounting, and refund semantics

0 commit comments

Comments
 (0)