-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const tape = require('tape') | ||
const BN = require('bn.js') | ||
const Common = require('ethereumjs-common').default | ||
const VM = require('../../../dist/index').default | ||
const PStateManager = require('../../../dist/state/promisified').default | ||
const { ERROR } = require('../../../dist/exceptions') | ||
const { createAccount } = require('../utils') | ||
|
||
const testCases = [ | ||
{ chain: 'mainnet', hardfork: 'istanbul', selfbalance: '0xf1' }, | ||
{ chain: 'mainnet', hardfork: 'constantinople', err: ERROR.INVALID_OPCODE } | ||
] | ||
|
||
// SELFBALANCE PUSH8 0x00 MSTORE8 PUSH8 0x01 PUSH8 0x00 RETURN | ||
const code = ['47', '60', '00', '53', '60', '01', '60', '00', 'f3'] | ||
tape('Istanbul: EIP-1884: SELFBALANCE', async (t) => { | ||
const addr = Buffer.from('00000000000000000000000000000000000000ff', 'hex') | ||
const runCodeArgs = { | ||
code: Buffer.from(code.join(''), 'hex'), | ||
gasLimit: new BN(0xffff), | ||
address: addr | ||
} | ||
|
||
for (const testCase of testCases) { | ||
const common = new Common(testCase.chain, testCase.hardfork) | ||
const vm = new VM({ common }) | ||
const state = new PStateManager(vm.stateManager) | ||
const account = createAccount('00', testCase.selfbalance) | ||
await state.putAccount(addr, account) | ||
try { | ||
const res = await vm.runCode(runCodeArgs) | ||
if (testCase.err) { | ||
t.equal(res.exceptionError.error, testCase.err) | ||
} else { | ||
t.assert(res.exceptionError === undefined) | ||
t.assert(new BN(Buffer.from(testCase.selfbalance.slice(2), 'hex')).eq(new BN(res.returnValue))) | ||
} | ||
} catch (e) { | ||
t.fail(e.message) | ||
} | ||
} | ||
|
||
t.end() | ||
}) |