|
1 |
| -import { Address } from '@ethereumjs/util' |
| 1 | +import { Address, equalsBytes, hexToBytes, setLengthLeft, unpadBytes } from '@ethereumjs/util' |
2 | 2 | import { assert, describe, it } from 'vitest'
|
3 | 3 |
|
| 4 | +import { EVM } from '../src/index.js' |
4 | 5 | import { TransientStorage } from '../src/transientStorage.js'
|
5 | 6 |
|
6 | 7 | describe('Transient Storage', () => {
|
@@ -176,4 +177,38 @@ describe('Transient Storage', () => {
|
176 | 177 | transientStorage.revert()
|
177 | 178 | assert.deepEqual(transientStorage.get(address, key), value1)
|
178 | 179 | })
|
| 180 | + |
| 181 | + it('should cleanup after a message create', async () => { |
| 182 | + const evm = await EVM.create() |
| 183 | + // PUSH 1 PUSH 1 TSTORE |
| 184 | + const code = hexToBytes('0x600160015D') |
| 185 | + const keyBuf = setLengthLeft(new Uint8Array([1]), 32) |
| 186 | + const result = await evm.runCall({ |
| 187 | + data: code, |
| 188 | + gasLimit: BigInt(100_000), |
| 189 | + }) |
| 190 | + const created = result.createdAddress! |
| 191 | + const stored = evm.transientStorage.get(created, keyBuf) |
| 192 | + assert.ok( |
| 193 | + equalsBytes(unpadBytes(stored), new Uint8Array()), |
| 194 | + 'Transient storage has been cleared' |
| 195 | + ) |
| 196 | + }) |
| 197 | + |
| 198 | + it('should cleanup after a message call', async () => { |
| 199 | + const evm = await EVM.create() |
| 200 | + const contractAddress = Address.zero() |
| 201 | + // PUSH 1 PUSH 1 TSTORE |
| 202 | + const code = hexToBytes('0x600160015D') |
| 203 | + await evm.stateManager.putContractCode(contractAddress, code) |
| 204 | + const keyBuf = setLengthLeft(new Uint8Array([1]), 32) |
| 205 | + await evm.runCall({ |
| 206 | + gasLimit: BigInt(100_000), |
| 207 | + }) |
| 208 | + const stored = evm.transientStorage.get(contractAddress, keyBuf) |
| 209 | + assert.ok( |
| 210 | + equalsBytes(unpadBytes(stored), new Uint8Array()), |
| 211 | + 'Transient storage has been cleared' |
| 212 | + ) |
| 213 | + }) |
179 | 214 | })
|
0 commit comments