1111 std/ [tables, sets],
1212 stew/ byteutils,
1313 unittest2,
14+ eth/ common/ times,
1415 ../ execution_chain/ evm/ async_evm,
1516 ./ async_evm_test_backend
1617
2526 TestAccount =
2627 tuple [balance: string , nonce: string , code: string , storage: TestStorage ]
2728
29+ TestBlockNumber = string
30+ TestBlockHash = string
31+ TestBlockHashes = Table [TestBlockNumber , TestBlockHash ]
32+
2833 TestTxArgs = tuple [to: string , input: string ]
2934
30- TestResult = tuple [output: string , accessList: Table [TestAddress , TestStorageKeys ]]
35+ TestAccessList = Table [TestAddress , TestStorageKeys ]
36+ TestResult = tuple [output: string , accessList: TestAccessList ]
3137
3238 TestCase =
3339 tuple [
3440 preState: Table [TestAddress , TestAccount ],
41+ blockHashes: TestBlockHashes ,
3542 blockNumber: string ,
3643 txArgs: TestTxArgs ,
3744 expected: TestResult ,
3845 ]
3946
4047const
41- emptyStorage = default (Table [string , string ])
42- emptyStorageKeys = default (HashSet [string ])
48+ emptyStorage = default (TestStorage )
49+ emptyStorageKeys = default (TestStorageKeys )
50+ emptyAccessList = default (TestAccessList )
51+ emptyBlockHashes = default (TestBlockHashes )
4352
4453const testCases: seq [TestCase ] =
4554 @ [
55+ # Block hash test which executes bytecode compiled from the following solidity:
56+ #
57+ # pragma solidity >=0.8.30 <0.9.0;
58+ #
59+ # contract BlockHashContract {
60+ # function getBlockHash() public view returns(bytes32) {
61+ # return blockhash(block.number - 10);
62+ # }
63+ # }
64+ (
65+ preState: {
66+ " 0x358aa13c52544eccef6b0add0f801012adad5ee3" : (
67+ balance: " 0x" ,
68+ nonce: " 0x" ,
69+ code:
70+ " 0x6080604052348015600e575f5ffd5b50600436106026575f3560e01c80639663f88f14602a575b5f5ffd5b60306044565b604051603b9190606c565b60405180910390f35b5f600a436050919060b9565b40905090565b5f819050919050565b6066816056565b82525050565b5f602082019050607d5f830184605f565b92915050565b5f819050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f60c1826083565b915060ca836083565b925082820390508181111560df5760de608c565b5b9291505056fea26469706673582212205d02238b0582fce570b72434d696e873371bf590e00d5deed50555a523df0e8764736f6c634300081e0033" ,
71+ storage: emptyStorage,
72+ ),
73+ }.toTable,
74+ blockHashes: {
75+ " 0x015EE5A0" : " 0x536174697366792056616c756573207468726f75676820467269656e64736869" ,
76+ }.toTable,
77+ blockNumber: " 0x015EE5A9" ,
78+ txArgs: (to: " 0x358aa13c52544eccef6b0add0f801012adad5ee3" , input: " 0x9663f88f" ),
79+ expected: (
80+ output: " 0x536174697366792056616c756573207468726f75676820467269656e64736869" ,
81+ accessList: {
82+ " 0x358aa13c52544eccef6b0add0f801012adad5ee3" : emptyStorageKeys,
83+ }.toTable,
84+ )
85+ ),
4686 # Test state from mainnet contract 0x1a875Da9e86506999A2931400475C34c27185Dd1 at block 700_000
4787 (
4888 preState: {
@@ -61,6 +101,7 @@ const testCases: seq[TestCase] =
61101 storage: emptyStorage,
62102 ),
63103 }.toTable,
104+ blockHashes: emptyBlockHashes,
64105 blockNumber: " 0x0AAE60" ,
65106 txArgs: (to: " 0x1a875da9e86506999a2931400475c34c27185dd1" , input: " 0x" ),
66107 expected: (
@@ -95,6 +136,7 @@ const testCases: seq[TestCase] =
95136 }.toTable,
96137 )
97138 }.toTable,
139+ blockHashes: emptyBlockHashes,
98140 blockNumber: " 0x0F4240" ,
99141 txArgs: (
100142 to: " 0x6e38a457c722c6011b2dfa06d49240e797844d66" ,
@@ -133,6 +175,9 @@ proc setupTestEvmState(testCase: TestCase): TestEvmState =
133175 for k, v in acc.storage:
134176 testState.setStorage (address, k.hexToUInt256 (), v.hexToUInt256 ())
135177
178+ for number, blockHash in testCase.blockHashes:
179+ testState.setBlockHash (number.hexToUInt256 ().truncate (BlockNumber ), Hash32 .fromHex (blockHash))
180+
136181 return testState
137182
138183suite " Async EVM" :
@@ -143,6 +188,7 @@ suite "Async EVM":
143188 evm = AsyncEvm .init (testState.toAsyncEvmStateBackend ())
144189 header = Header (
145190 number: testCase.blockNumber.hexToUInt256 ().truncate (uint64 ),
191+ timestamp: 1_746_612_312 .EthTime , # pragueTime: Opt.some(1_746_612_311.EthTime)
146192 gasLimit: EVM_CALL_GAS_CAP ,
147193 )
148194 tx = TransactionArgs (
@@ -161,6 +207,7 @@ suite "Async EVM":
161207 evm = AsyncEvm .init (testState.toAsyncEvmStateBackend ())
162208 header = Header (
163209 number: testCase.blockNumber.hexToUInt256 ().truncate (uint64 ),
210+ timestamp: 1_746_612_312 .EthTime , # pragueTime: Opt.some(1_746_612_311.EthTime)
164211 gasLimit: EVM_CALL_GAS_CAP ,
165212 )
166213 tx = TransactionArgs (
@@ -179,6 +226,7 @@ suite "Async EVM":
179226 evm = AsyncEvm .init (testState.toAsyncEvmStateBackend ())
180227 header = Header (
181228 number: testCase.blockNumber.hexToUInt256 ().truncate (uint64 ),
229+ timestamp: 1_746_612_312 .EthTime , # pragueTime: Opt.some(1_746_612_311.EthTime)
182230 gasLimit: EVM_CALL_GAS_CAP ,
183231 )
184232 tx = TransactionArgs (
@@ -214,6 +262,7 @@ suite "Async EVM":
214262 evm = AsyncEvm .init (testState.toAsyncEvmStateBackend ())
215263 header = Header (
216264 number: testCase.blockNumber.hexToUInt256 ().truncate (uint64 ),
265+ timestamp: 1_746_612_312 .EthTime , # pragueTime: Opt.some(1_746_612_311.EthTime)
217266 gasLimit: EVM_CALL_GAS_CAP ,
218267 )
219268 tx = TransactionArgs (
@@ -249,6 +298,7 @@ suite "Async EVM":
249298 evm = AsyncEvm .init (testState.toAsyncEvmStateBackend ())
250299 header = Header (
251300 number: testCase.blockNumber.hexToUInt256 ().truncate (uint64 ),
301+ timestamp: 1_746_612_312 .EthTime , # pragueTime: Opt.some(1_746_612_311.EthTime)
252302 gasLimit: EVM_CALL_GAS_CAP ,
253303 )
254304 tx = TransactionArgs (
@@ -268,6 +318,7 @@ suite "Async EVM":
268318 evm = AsyncEvm .init (testState.toAsyncEvmStateBackend ())
269319 header = Header (
270320 number: testCase.blockNumber.hexToUInt256 ().truncate (uint64 ),
321+ timestamp: 1_746_612_312 .EthTime , # pragueTime: Opt.some(1_746_612_311.EthTime)
271322 gasLimit: EVM_CALL_GAS_CAP ,
272323 )
273324 tx = TransactionArgs (
@@ -289,6 +340,7 @@ suite "Async EVM":
289340 evm = AsyncEvm .init (testState.toAsyncEvmStateBackend ())
290341 header = Header (
291342 number: testCase.blockNumber.hexToUInt256 ().truncate (uint64 ),
343+ timestamp: 1_746_612_312 .EthTime , # pragueTime: Opt.some(1_746_612_311.EthTime)
292344 gasLimit: EVM_CALL_GAS_CAP ,
293345 )
294346 tx = TransactionArgs (
0 commit comments