def test_201503112218PYTHON(self): """ Textcase taken from https://github.com/ethereum/tests File: 201503112218PYTHON.json sha256sum: cbd7e0e94cc25d26f381b86d2808304264910c18affd48aad6bbe888929e4207 Code: BLOCKHASH COINBASE """ constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=300, timestamp=2, difficulty= 115792089237316195423570985008687907853269984665640564039457584007913129639935, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('4041') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=1000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 10000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) # This variable might seem redundant in some tests - don't forget it is auto generated # and there are cases in which we need it ;) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) #If test end in exception check it here self.assertTrue(result == 'THROW')
def will_decode_instruction_callback(self, state, pc): TRUE = bytearray((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1)) FALSE = bytearray((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)) #print pc, state.platform.current_vm.instruction #Once this address is reached the challenge is won if pc == 0x4141414141414141414141414141414141414141: func_id = to_constant(state.platform.current_transaction.data[:4]) if func_id == ABI.make_function_id("print(string)"): func_name, args = ABI.parse("print(string)", state.platform.current_transaction.data) raise Return() elif func_id == ABI.make_function_id("terminate(string)"): func_name, args = ABI.parse("terminate(string)", state.platform.current_transaction.data) self.manticore.shutdown() raise Return(TRUE) elif func_id == ABI.make_function_id("assume(bool)"): func_name, args = ABI.parse("assume(bool)", state.platform.current_transaction.data) state.add(args[0]) raise Return(TRUE) elif func_id == ABI.make_function_id("is_symbolic(bytes)"): func_name, args = ABI.parse("is_symbolic(bytes)", state.platform.current_transaction.data) try: arg = to_constant(args[0]) except: raise Return(TRUE) raise Return(FALSE) elif func_id == ABI.make_function_id("is_symbolic(uint256)"): func_name, args = ABI.parse("is_symbolic(uint256)", state.platform.current_transaction.data) try: arg = to_constant(args[0]) except Exception,e: raise Return(TRUE) raise Return(FALSE) elif func_id == ABI.make_function_id("shutdown(string)"): func_name, args = ABI.parse("shutdown(string)", state.platform.current_transaction.data) print "Shutdown", to_constant(args[0]) self.manticore.shutdown() elif func_id == ABI.make_function_id("can_be_true(bool)"): func_name, args = ABI.parse("can_be_true(bool)", state.platform.current_transaction.data) result = solver.can_be_true(state.constraints, args[0] != 0) if result: raise Return(TRUE) raise Return(FALSE) raise Stop()
def test_selfdestruct_decoupled_account_delete(self): source_code = ''' contract C{ function d( ){ selfdestruct(0); } function g() returns(uint) { return 42 ; } } contract D{ C c; constructor () { c = new C(); } function t () returns(uint){ c.d(); return c.g(); } } ''' user_account = self.mevm.create_account(balance=1000) contract_account = self.mevm.solidity_create_contract( source_code, owner=user_account, contract_name='D', gas=9000000) contract_account.t( gas=9000000 ) #this does not return nothing as it may create several states # nothing reverted and we end up with a single state self.assertEqual(self.mevm.count_states(), 1) # Check that calling t() returned a 42 # That is that calling a selfdestructed contract works as the account # is actually deleted at the end of the human tx self.assertEqual( ABI.deserialize( 'uint', to_constant(self.mevm.world.transactions[-1].return_data)), 42)
def test_number(self): ''' Textcase taken from https://github.com/ethereum/tests File: number.json sha256sum: cced67c3cea4a07ce9c4c15107f87a2d6e958cf065791d7c793a260575e9b140 Code: NUMBER PUSH1 0x0 SSTORE ''' constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=1, timestamp=1, difficulty=256, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('43600055') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=100000000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 100000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if e.result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) #Add pos checks for account 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 #check nonce, balance, code self.assertEqual( world.get_nonce(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), 0) self.assertEqual( to_constant( world.get_balance(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6)), 100000000000000000000000) self.assertEqual( world.get_code(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), unhexlify('43600055')) #check storage self.assertEqual( to_constant( world.get_storage_data( 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, 0x00)), 0x01) #check outs self.assertEqual(returndata, unhexlify('')) #check logs data = rlp.encode([ Log(unhexlify('{:040x}'.format(l.address)), l.topics, to_constant(l.memlog)) for l in world.logs ]) self.assertEqual( sha3.keccak_256(data).hexdigest(), '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347') # test used gas self.assertEqual(to_constant(world.current_vm.gas), 79995)
def test_201503110206PYTHON(self): ''' Textcase taken from https://github.com/ethereum/tests File: 201503110206PYTHON.json sha256sum: d02dd686767e9a3f281f4dce40244cbe23a022eae7a3e8cc3dd2e747b889500a Code: BLOCKHASH GASLIMIT BLOCKHASH COINBASE GASLIMIT GASLIMIT DIFFICULTY COINBASE CALLVALUE CODECOPY DUP8 SELFDESTRUCT CALLDATACOPY CALLDATALOAD DIV ADDRESS SSTORE ''' constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=300, timestamp=2, difficulty= 115792089237316195423570985008687907853269984665640564039457584007913129639935, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('4045404145454441343987ff3735043055') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=1000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 10000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if e.result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) #If test end in exception ceck it here self.assertTrue(result in ('THROW'))
def test_201503110346PYTHON_PUSH24(self): ''' Textcase taken from https://github.com/ethereum/tests File: 201503110346PYTHON_PUSH24.json sha256sum: 0f512fa3c9cf0e24e246ca46e8e072745df14f1cdfc8fcf6d201aba5e55f7932 Code: ''' constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=300, timestamp=2, difficulty= 115792089237316195423570985008687907853269984665640564039457584007913129639935, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('7745414245403745f31387900a8d55') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=1000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 10000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if e.result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) #Add pos checks for account 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 #check nonce, balance, code self.assertEqual( world.get_nonce(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), 0) self.assertEqual( to_constant( world.get_balance(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6)), 1000000000000000000) self.assertEqual( world.get_code(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), unhexlify('7745414245403745f31387900a8d55')) #check outs self.assertEqual(returndata, unhexlify('')) #check logs data = rlp.encode([ Log(unhexlify('{:040x}'.format(l.address)), l.topics, to_constant(l.memlog)) for l in world.logs ]) self.assertEqual( sha3.keccak_256(data).hexdigest(), '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347') # test used gas self.assertEqual(to_constant(world.current_vm.gas), 9997)
def test_201503102320PYTHON(self): ''' Textcase taken from https://github.com/ethereum/tests File: 201503102320PYTHON.json sha256sum: 612078317eb4f60643c39c4c0d2ee8e9c0c853ed5188d437d811cba47fe9e26f Code: NUMBER NUMBER TIMESTAMP DIFFICULTY TIMESTAMP DIFFICULTY GASLIMIT GASLIMIT SWAP8 ''' constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=300, timestamp=2, difficulty= 115792089237316195423570985008687907853269984665640564039457584007913129639935, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('434342444244454597') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=1000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 10000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if e.result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) #If test end in exception ceck it here self.assertTrue(result in ('THROW'))
def test_201503110219PYTHON(self): ''' Textcase taken from https://github.com/ethereum/tests File: 201503110219PYTHON.json sha256sum: e153bd49bafe6f1e398ddaeb35a9f0493d823b36c3823908211bf371ec95cb1f Code: BLOCKHASH BLOCKHASH GASLIMIT SWAP2 NUMBER BLOCKHASH COINBASE DIFFICULTY DUP1 SWAP8 MSIZE DUP9 ''' constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=300, timestamp=2, difficulty= 115792089237316195423570985008687907853269984665640564039457584007913129639935, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('4040459143404144809759886d608f') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=1000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 10000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if e.result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) #If test end in exception ceck it here self.assertTrue(result in ('THROW'))
def test_suicide0(self): """ Textcase taken from https://github.com/ethereum/tests File: suicide0.json sha256sum: b6a8903cf90bc139d273b9408ec6aad5832bc94a2f87ee21cc018a4f1aea2fd8 Code: CALLER SELFDESTRUCT """ constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=0, timestamp=1, difficulty=256, coinbase=244687034288125203496486448490407391986876152250, gaslimit=10000000) bytecode = unhexlify('33ff') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=100000000000000000000000, code=bytecode, nonce=0) bytecode = unhexlify('6000355415600957005b60203560003555') world.create_account( address=0xcd1722f3947def4cf144679da39c4c32bdc35681, balance=23, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 100000 gas = 1000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) # This variable might seem redundant in some tests - don't forget it is auto generated # and there are cases in which we need it ;) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) # Add pos checks for account 0xcd1722f3947def4cf144679da39c4c32bdc35681 # check nonce, balance, code self.assertEqual( world.get_nonce(0xcd1722f3947def4cf144679da39c4c32bdc35681), 0) self.assertEqual( to_constant( world.get_balance(0xcd1722f3947def4cf144679da39c4c32bdc35681)), 100000000000000000000023) self.assertEqual( world.get_code(0xcd1722f3947def4cf144679da39c4c32bdc35681), unhexlify('6000355415600957005b60203560003555')) # check outs self.assertEqual(returndata, unhexlify('')) # check logs logs = [ Log(unhexlify('{:040x}'.format(l.address)), l.topics, to_constant(l.memlog)) for l in world.logs ] data = rlp.encode(logs) self.assertEqual( sha3.keccak_256(data).hexdigest(), '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347') # test used gas self.assertEqual(to_constant(world.current_vm.gas), 998)
def test_return2(self): """ Textcase taken from https://github.com/ethereum/tests File: return2.json sha256sum: 25972361a5871003f44467255a656b9e7ba3762a5cfe02b56a0197318d375b9a Code: PUSH1 0x37 PUSH1 0x0 MSTORE8 PUSH1 0x0 MLOAD PUSH1 0x0 SSTORE PUSH1 0x21 PUSH1 0x0 RETURN """ constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=0, timestamp=1, difficulty=256, coinbase=244687034288125203496486448490407391986876152250, gaslimit=10000000) bytecode = unhexlify('603760005360005160005560216000f3') world.create_account( address=0xcd1722f3947def4cf144679da39c4c32bdc35681, balance=23, code=bytecode, nonce=0) address = 0xcd1722f3947def4cf144679da39c4c32bdc35681 price = 0x5af3107a4000 data = unhexlify('aa') caller = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 value = 23 gas = 100000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) # This variable might seem redundant in some tests - don't forget it is auto generated # and there are cases in which we need it ;) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) # Add pos checks for account 0xcd1722f3947def4cf144679da39c4c32bdc35681 # check nonce, balance, code self.assertEqual( world.get_nonce(0xcd1722f3947def4cf144679da39c4c32bdc35681), 0) self.assertEqual( to_constant( world.get_balance(0xcd1722f3947def4cf144679da39c4c32bdc35681)), 23) self.assertEqual( world.get_code(0xcd1722f3947def4cf144679da39c4c32bdc35681), unhexlify('603760005360005160005560216000f3')) #check storage self.assertEqual( to_constant( world.get_storage_data( 0xcd1722f3947def4cf144679da39c4c32bdc35681, 0x00)), 0x3700000000000000000000000000000000000000000000000000000000000000) # check outs self.assertEqual( returndata, unhexlify( '370000000000000000000000000000000000000000000000000000000000000000' )) # check logs logs = [ Log(unhexlify('{:040x}'.format(l.address)), l.topics, to_constant(l.memlog)) for l in world.logs ] data = rlp.encode(logs) self.assertEqual( sha3.keccak_256(data).hexdigest(), '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347') # test used gas self.assertEqual(to_constant(world.current_vm.gas), 79970)
def test_TestNameRegistrator(self): """ Textcase taken from https://github.com/ethereum/tests File: TestNameRegistrator.json sha256sum: dd000f5977416de19410170b8a7acb5060011594fd97c81f307f015cd5bdd51e Code: PUSH1 0x0 CALLDATALOAD SLOAD ISZERO PUSH1 0x9 JUMPI STOP JUMPDEST PUSH1 0x20 CALLDATALOAD PUSH1 0x0 CALLDATALOAD SSTORE """ constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=0, timestamp=1, difficulty=256, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('6000355415600957005b60203560003555') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=100000000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = unhexlify( 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffafffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa' ) caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 100000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) # This variable might seem redundant in some tests - don't forget it is auto generated # and there are cases in which we need it ;) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) # Add pos checks for account 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 # check nonce, balance, code self.assertEqual( world.get_nonce(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), 0) self.assertEqual( to_constant( world.get_balance(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6)), 100000000000000000000000) self.assertEqual( world.get_code(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), unhexlify('6000355415600957005b60203560003555')) #check storage self.assertEqual( to_constant( world.get_storage_data( 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa )), 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa) # check outs self.assertEqual(returndata, unhexlify('')) # check logs logs = [ Log(unhexlify('{:040x}'.format(l.address)), l.topics, to_constant(l.memlog)) for l in world.logs ] data = rlp.encode(logs) self.assertEqual( sha3.keccak_256(data).hexdigest(), '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347') # test used gas self.assertEqual(to_constant(world.current_vm.gas), 79915)
def solve(val): """ Those tests are **auto-generated** and `solve` is used in symbolic tests. So yes, this returns just val; it makes it easier to generate tests like this. """ return to_constant(val)
def test_201503111844PYTHON(self): """ Textcase taken from https://github.com/ethereum/tests File: 201503111844PYTHON.json sha256sum: 75bc0568cd5fe782e030391083658cdcbac61e32d6f0b1bdce9286ee7fd6d75e Code: """ constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=300, timestamp=2, difficulty= 115792089237316195423570985008687907853269984665640564039457584007913129639935, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('65424555') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=1000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 10000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) # This variable might seem redundant in some tests - don't forget it is auto generated # and there are cases in which we need it ;) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) # Add pos checks for account 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 # check nonce, balance, code self.assertEqual( world.get_nonce(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), 0) self.assertEqual( to_constant( world.get_balance(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6)), 1000000000000000000) self.assertEqual( world.get_code(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), unhexlify('65424555')) # check outs self.assertEqual(returndata, unhexlify('')) # check logs logs = [ Log(unhexlify('{:040x}'.format(l.address)), l.topics, to_constant(l.memlog)) for l in world.logs ] data = rlp.encode(logs) self.assertEqual( sha3.keccak_256(data).hexdigest(), '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347') # test used gas self.assertEqual(to_constant(world.current_vm.gas), 9997)
def test_timestamp(self): """ Textcase taken from https://github.com/ethereum/tests File: timestamp.json sha256sum: e0517702c3ba8bc8a593af7dbdb4de4d3ee7a53ae4fffc058776e40c435b20ba Code: TIMESTAMP PUSH1 0x0 SSTORE """ constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=0, timestamp=1, difficulty=256, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('42600055') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=100000000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 100000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) # This variable might seem redundant in some tests - don't forget it is auto generated # and there are cases in which we need it ;) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) # Add pos checks for account 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 # check nonce, balance, code self.assertEqual( world.get_nonce(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), 0) self.assertEqual( to_constant( world.get_balance(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6)), 100000000000000000000000) self.assertEqual( world.get_code(0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6), unhexlify('42600055')) #check storage self.assertEqual( to_constant( world.get_storage_data( 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, 0x00)), 0x01) # check outs self.assertEqual(returndata, unhexlify('')) # check logs logs = [ Log(unhexlify('{:040x}'.format(l.address)), l.topics, to_constant(l.memlog)) for l in world.logs ] data = rlp.encode(logs) self.assertEqual( sha3.keccak_256(data).hexdigest(), '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347') # test used gas self.assertEqual(to_constant(world.current_vm.gas), 79995)
def test_suicide(self): ''' Textcase taken from https://github.com/ethereum/tests File: suicide.json sha256sum: 1aa0a61de3c9576faf6ac4f002626210a5315d3132d032162b2934d304a60c1f Code: CALLER SELFDESTRUCT ''' constraints = ConstraintSet() world = evm.EVMWorld( constraints, blocknumber=0, timestamp=1, difficulty=256, coinbase=244687034288125203496486448490407391986876152250, gaslimit=1000000) bytecode = unhexlify('33ff') world.create_account(address=0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6, balance=100000000000000000000000, code=bytecode, nonce=0) address = 0xf572e5295c57f15886f9b263e2f6d2d6c7b5ec6 price = 0x5af3107a4000 data = '' caller = 0xcd1722f3947def4cf144679da39c4c32bdc35681 value = 1000000000000000000 gas = 100000 # open a fake tx, no funds send world._open_transaction('CALL', address, price, data, caller, value, gas=gas) result = None returndata = b'' try: while True: world.current_vm.execute() except evm.EndTx as e: result = e.result if e.result in ('RETURN', 'REVERT'): returndata = to_constant(e.data) except evm.StartTx as e: self.fail( 'This tests should not initiate an internal tx (no CALLs allowed)' ) #Add pos checks for account 0xcd1722f3947def4cf144679da39c4c32bdc35681 #check nonce, balance, code self.assertEqual( world.get_nonce(0xcd1722f3947def4cf144679da39c4c32bdc35681), 0) self.assertEqual( to_constant( world.get_balance(0xcd1722f3947def4cf144679da39c4c32bdc35681)), 100000000000000000000000) self.assertEqual( world.get_code(0xcd1722f3947def4cf144679da39c4c32bdc35681), unhexlify('')) #check outs self.assertEqual(returndata, unhexlify('')) #check logs data = rlp.encode([ Log(unhexlify('{:040x}'.format(l.address)), l.topics, to_constant(l.memlog)) for l in world.logs ]) self.assertEqual( sha3.keccak_256(data).hexdigest(), '1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347') # test used gas self.assertEqual(to_constant(world.current_vm.gas), 99998)