22pragma solidity ^ 0.8.13 ;
33
44import "forge-std/Test.sol " ;
5+ import "geas-ffi/Geas.sol " ;
56import "../src/Contract.sol " ;
67
78address constant addr = 0x000000000000000000000000000000000000aaaa ;
@@ -18,40 +19,37 @@ function hash_idx() view returns (bytes32) {
1819}
1920
2021contract ContractTest is Test {
21- address unit;
22-
2322 function setUp () public {
24- vm.etch(addr, hex"@bytecode@");
25- unit = addr;
23+ vm.etch (addr, Geas.compile ("src/execution_hash/main.eas " ));
2624 }
2725
2826 // testRead verifies the contract returns the expected execution hash.
2927 function testExecRead () public {
3028 // Store hash at expected indexes.
31- vm.store(unit , hash_idx(), hash);
29+ vm.store (addr , hash_idx (), hash);
3230
3331 // Read hash associated with current timestamp.
34- (bool ret, bytes memory data) = unit .call(bytes.concat(lastBlockNumber()));
32+ (bool ret , bytes memory data ) = addr .call (bytes .concat (lastBlockNumber ()));
3533 assertTrue (ret);
3634 assertEq (data, bytes .concat (hash));
3735 }
3836
3937 function testReadBadCalldataSize () public {
4038 // Store hash at expected indexes.
41- vm.store(unit , hash_idx(), hash);
39+ vm.store (addr , hash_idx (), hash);
4240
4341 // Call with 0 byte arguement.
44- (bool ret, bytes memory data) = unit .call(hex"");
42+ (bool ret , bytes memory data ) = addr .call (hex "" );
4543 assertFalse (ret);
4644 assertEq (data, hex "" );
4745
4846 // Call with 31 byte arguement.
49- (ret, data) = unit .call(hex"00000000000000000000000000000000000000000000000000000000001337");
47+ (ret, data) = addr .call (hex "00000000000000000000000000000000000000000000000000000000001337 " );
5048 assertFalse (ret);
5149 assertEq (data, hex "" );
5250
5351 // Call with 33 byte arguement.
54- (ret, data) = unit .call(hex"000000000000000000000000000000000000000000000000000000000000001337");
52+ (ret, data) = addr .call (hex "000000000000000000000000000000000000000000000000000000000000001337 " );
5553 assertFalse (ret);
5654 assertEq (data, hex "" );
5755 }
@@ -62,25 +60,25 @@ contract ContractTest is Test {
6260 uint256 number = block .number -1 ;
6361
6462 // Store hash at expected indexes.
65- vm.store(unit , hash_idx(), hash);
63+ vm.store (addr , hash_idx (), hash);
6664
6765 // Request current block.
68- (bool ret, bytes memory data) = unit .call(bytes.concat(bytes32(block.number)));
66+ (bool ret , bytes memory data ) = addr .call (bytes .concat (bytes32 (block .number )));
6967 assertFalse (ret);
7068 assertEq (data, hex "" );
7169
7270 // Wrap around buflen once forward.
73- (ret, data) = unit .call(bytes.concat(bytes32(number+buflen)));
71+ (ret, data) = addr .call (bytes .concat (bytes32 (number+ buflen)));
7472 assertFalse (ret);
7573 assertEq (data, hex "" );
7674
7775 // Wrap around buflen once backward.
78- (ret, data) = unit .call(bytes.concat(bytes32(number-buflen)));
76+ (ret, data) = addr .call (bytes .concat (bytes32 (number- buflen)));
7977 assertFalse (ret);
8078 assertEq (data, hex "" );
8179
8280 // Block number zero should fail.
83- (ret, data) = unit .call(bytes.concat(bytes32(0)));
81+ (ret, data) = addr .call (bytes .concat (bytes32 (0 )));
8482 assertFalse (ret);
8583 assertEq (data, hex "" );
8684 }
@@ -89,12 +87,12 @@ contract ContractTest is Test {
8987 function testUpdate () public {
9088 // Simulate pre-block call to set hash.
9189 vm.prank (sysaddr);
92- (bool ret, bytes memory data) = unit .call(bytes.concat(hash));
90+ (bool ret , bytes memory data ) = addr .call (bytes .concat (hash));
9391 assertTrue (ret);
9492 assertEq (data, hex "" );
9593
9694 // Verify hash.
97- bytes32 got = vm.load(unit , hash_idx());
95+ bytes32 got = vm.load (addr , hash_idx ());
9896 assertEq (got, hash);
9997 }
10098
@@ -110,13 +108,13 @@ contract ContractTest is Test {
110108
111109 // Simulate pre-block call to set hash.
112110 vm.prank (sysaddr);
113- (bool ret, bytes memory data) = unit .call(bytes.concat(pbbr));
111+ (bool ret , bytes memory data ) = addr .call (bytes .concat (pbbr));
114112 assertTrue (ret);
115113 assertEq (data, hex "" );
116114
117115 // Call contract as normal account to get exeuction hash associated
118116 // with current timestamp.
119- (ret, data) = unit .call(bytes.concat(lastBlockNumber()));
117+ (ret, data) = addr .call (bytes .concat (lastBlockNumber ()));
120118 assertTrue (ret);
121119 assertEq (data, bytes .concat (pbbr));
122120
@@ -136,7 +134,7 @@ contract ContractTest is Test {
136134 for (uint256 i = 0 ; i < buflen; i += 1 ) {
137135 bytes32 pbbr = bytes32 (i* 1337 );
138136 vm.prank (sysaddr);
139- (bool ret, bytes memory data) = unit .call(bytes.concat(pbbr));
137+ (bool ret , bytes memory data ) = addr .call (bytes .concat (pbbr));
140138 assertTrue (ret);
141139 assertEq (data, hex "" );
142140 if (i+1 < buflen) {
@@ -152,7 +150,7 @@ contract ContractTest is Test {
152150 // Attempt to read all values in same block context.
153151 for (uint256 i = 0 ; i < buflen; i += 1 ) {
154152 bytes32 num = bytes32 (uint256 (base+ i));
155- (bool ret, bytes memory got) = unit .call(bytes.concat(num));
153+ (bool ret , bytes memory got ) = addr .call (bytes .concat (num));
156154 assertTrue (ret);
157155 assertEq (got, bytes .concat (bytes32 (i* 1337 )));
158156 }
0 commit comments