|
| 1 | +const tape = require('tape') |
| 2 | +const { zeroAddress } = require('ethereumjs-util') |
| 3 | +const EEI = require('../../../dist/evm/eei').default |
| 4 | +const StateManager = require('../../../dist/state/stateManager').default |
| 5 | +const Account = require('@ethereumjs/account').default |
| 6 | + |
| 7 | +const ZeroAddress = Buffer.from("0000000000000000000000000000000000000000", 'hex') |
| 8 | + |
| 9 | +tape('EEI', t => { |
| 10 | + |
| 11 | + t.test('should return false on non-existing accounts', async st => { |
| 12 | + const eei = new EEI(undefined, new StateManager()) // create a dummy EEI (no VM, no EVM, etc.) |
| 13 | + st.notOk(await eei.accountExists(ZeroAddress)) |
| 14 | + st.ok(await eei.isAccountEmpty(ZeroAddress)) |
| 15 | + st.end() |
| 16 | + }) |
| 17 | + |
| 18 | + |
| 19 | + t.test('should return false on non-existing accounts which once existed in state but are now gone', async st => { |
| 20 | + const eei = new EEI(undefined, new StateManager()) // create a dummy EEI (no VM, no EVM, etc.) |
| 21 | + // create empty account |
| 22 | + await eei._state.putAccount(ZeroAddress, new Account()) |
| 23 | + st.ok(await eei.accountExists(ZeroAddress)) |
| 24 | + st.ok(await eei.isAccountEmpty(ZeroAddress)) |
| 25 | + // now put a non-empty account |
| 26 | + await eei._state.putAccount(ZeroAddress, new Account({nonce: '0x01', balance: '0x01'})) |
| 27 | + st.ok(await eei.accountExists(ZeroAddress)) |
| 28 | + st.notOk(await eei.isAccountEmpty(ZeroAddress)) |
| 29 | + st.end() |
| 30 | + }) |
| 31 | + |
| 32 | + t.test('should return true on existing accounts', async st => { |
| 33 | + const eei = new EEI(undefined, new StateManager()) // create a dummy EEI (no VM, no EVM, etc.) |
| 34 | + // create empty account |
| 35 | + await eei._state.putAccount(ZeroAddress, new Account()) |
| 36 | + st.ok(await eei.accountExists(ZeroAddress)) // sanity check: account exists before we delete it |
| 37 | + st.ok(await eei.isAccountEmpty(ZeroAddress)) // it is obviously empty |
| 38 | + await eei._state.deleteAccount(ZeroAddress) // delete the account |
| 39 | + st.notOk(await eei.accountExists(ZeroAddress)) // account should not exist |
| 40 | + st.ok(await eei.isAccountEmpty(ZeroAddress)) // account is empty |
| 41 | + st.end() |
| 42 | + }) |
| 43 | + |
| 44 | +}) |
0 commit comments