@ -35,7 +35,7 @@ using namespace dev::test;
FakeExtVM : : FakeExtVM ( eth : : BlockInfo const & _previousBlock , eth : : BlockInfo const & _currentBlock , unsigned _depth ) : /// TODO: XXX: remove the default argument & fix.
ExtVMFace ( Address ( ) , Address ( ) , Address ( ) , 0 , 1 , bytesConstRef ( ) , bytesConstRef ( ) , _previousBlock , _currentBlock , _depth ) { }
h160 FakeExtVM : : create ( u256 _endowment , u256 * _gas , bytesConstRef _init , OnOpFunc )
h160 FakeExtVM : : create ( u256 _endowment , u256 * _gas , bytesConstRef _init , OnOpFunc const & )
{
Transaction t ;
t . value = _endowment ;
@ -45,7 +45,7 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun
m_s . noteSending ( myAddress ) ;
m_ms . internal . resize ( m_ms . internal . size ( ) + 1 ) ;
auto ret = m_s . create ( myAddress , _endowment , gasPrice , _gas , _init , origin , & suicides , & m_ms ? & ( m_ms . internal . back ( ) ) : nullptr , OnOpFunc ( ) , 1 ) ;
auto ret = m_s . create ( myAddress , _endowment , gasPrice , _gas , _init , origin , & suicides , & m_ms ? & ( m_ms . internal . back ( ) ) : nullptr , { } , 1 ) ;
if ( ! m_ms . internal . back ( ) . from )
m_ms . internal . pop_back ( ) ;
@ -61,7 +61,7 @@ h160 FakeExtVM::create(u256 _endowment, u256* _gas, bytesConstRef _init, OnOpFun
return ret ;
}
bool FakeExtVM : : call ( Address _receiveAddress , u256 _value , bytesConstRef _data , u256 * _gas , bytesRef _out , OnOpFunc , Address _myAddressOverride = Address ( ) , Address _codeAddressOverride = Address ( ) )
bool FakeExtVM : : call ( Address _receiveAddress , u256 _value , bytesConstRef _data , u256 * _gas , bytesRef _out , OnOpFunc const & , Address _myAddressOverride , Address _codeAddressOverride )
{
u256 contractgas = 0xffff ;
@ -91,7 +91,7 @@ bool FakeExtVM::call(Address _receiveAddress, u256 _value, bytesConstRef _data,
if ( ! m_s . addresses ( ) . count ( myAddress ) )
{
m_ms . internal . resize ( m_ms . internal . size ( ) + 1 ) ;
auto na = m_s . createNewAddress ( myAddress , myAddress , balance ( myAddress ) , gasPrice , & contractgas , init , origin , & suicides , & m_ms ? & ( m_ms . internal . back ( ) ) : nullptr , OnOpFunc ( ) , 1 ) ;
auto na = m_s . createNewAddress ( myAddress , myAddress , balance ( myAddress ) , gasPrice , & contractgas , init , origin , & suicides , & m_ms ? & ( m_ms . internal . back ( ) ) : nullptr , { } , 1 ) ;
if ( ! m_ms . internal . back ( ) . from )
m_ms . internal . pop_back ( ) ;
if ( na ! = myAddress )
@ -512,12 +512,10 @@ void doTests(json_spirit::mValue& v, bool _fillin)
}
bytes output ;
u256 gas ;
VM vm ( fev . gas ) ;
try
{
VM vm ( fev . gas ) ;
output = vm . go ( fev ) . toVector ( ) ;
gas = vm . gas ( ) ; // Get the remaining gas
}
catch ( Exception const & _e )
{
@ -554,7 +552,7 @@ void doTests(json_spirit::mValue& v, bool _fillin)
o [ " post " ] = mValue ( fev . exportState ( ) ) ;
o [ " callcreates " ] = fev . exportCallCreates ( ) ;
o [ " out " ] = " 0x " + toHex ( output ) ;
fev . push ( o , " gas " , gas ) ;
fev . push ( o , " gas " , vm . gas ( ) ) ;
}
else
{
@ -578,8 +576,44 @@ void doTests(json_spirit::mValue& v, bool _fillin)
else
BOOST_CHECK ( output = = fromHex ( o [ " out " ] . get_str ( ) ) ) ;
BOOST_CHECK ( test . toInt ( o [ " gas " ] ) = = gas ) ;
BOOST_CHECK ( test . addresses = = fev . addresses ) ;
BOOST_CHECK_EQUAL ( test . toInt ( o [ " gas " ] ) , vm . gas ( ) ) ;
auto & expectedAddrs = test . addresses ;
auto & resultAddrs = fev . addresses ;
for ( auto & & expectedPair : expectedAddrs )
{
auto & expectedAddr = expectedPair . first ;
auto resultAddrIt = resultAddrs . find ( expectedAddr ) ;
if ( resultAddrIt = = resultAddrs . end ( ) )
BOOST_ERROR ( " Missing expected address " < < expectedAddr ) ;
else
{
auto & expectedState = expectedPair . second ;
auto & resultState = resultAddrIt - > second ;
BOOST_CHECK_MESSAGE ( std : : get < 0 > ( expectedState ) = = std : : get < 0 > ( resultState ) , expectedAddr < < " : incorrect balance " < < std : : get < 0 > ( resultState ) < < " , expected " < < std : : get < 0 > ( expectedState ) ) ;
BOOST_CHECK_MESSAGE ( std : : get < 1 > ( expectedState ) = = std : : get < 1 > ( resultState ) , expectedAddr < < " : incorrect txCount " < < std : : get < 1 > ( resultState ) < < " , expected " < < std : : get < 1 > ( expectedState ) ) ;
BOOST_CHECK_MESSAGE ( std : : get < 3 > ( expectedState ) = = std : : get < 3 > ( resultState ) , expectedAddr < < " : incorrect code " ) ;
auto & & expectedStore = std : : get < 2 > ( expectedState ) ;
auto & & resultStore = std : : get < 2 > ( resultState ) ;
for ( auto & & expectedStorePair : expectedStore )
{
auto & expectedStoreKey = expectedStorePair . first ;
auto resultStoreIt = resultStore . find ( expectedStoreKey ) ;
if ( resultStoreIt = = resultStore . end ( ) )
BOOST_ERROR ( expectedAddr < < " : missing store key " < < expectedStoreKey ) ;
else
{
auto & expectedStoreValue = expectedStorePair . second ;
auto & resultStoreValue = resultStoreIt - > second ;
BOOST_CHECK_MESSAGE ( expectedStoreValue = = resultStoreValue , expectedAddr < < " : store[ " < < expectedStoreKey < < " ] = " < < resultStoreValue < < " , expected " < < expectedStoreValue ) ;
}
}
}
}
BOOST_CHECK ( test . addresses = = fev . addresses ) ; // Just to make sure nothing missed
BOOST_CHECK ( test . callcreates = = fev . callcreates ) ;
}
}
@ -621,11 +655,13 @@ void executeTests(const string& _name)
if ( ptestPath = = NULL )
{
cnote < < " could not find environment variable ETHEREUM_TEST_PATH \n " ;
testPath = " ../../../tests/vmtests " ;
testPath = " ../../../tests " ;
}
else
testPath = ptestPath ;
testPath + = " /vmtests " ;
# ifdef FILL_TESTS
try
{
@ -654,7 +690,7 @@ void executeTests(const string& _name)
cnote < < " Testing VM... " < < _name ;
json_spirit : : mValue v ;
string s = asString ( contents ( testPath + " / " + _name + " .json " ) ) ;
BOOST_REQUIRE_MESSAGE ( s . length ( ) > 0 , " Contents of " + _name + " .json is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path? " ) ;
BOOST_REQUIRE_MESSAGE ( s . length ( ) > 0 , " Contents of " + testPath + " / " + _name + " .json is empty. Have you cloned the 'tests' repo branch develop and set ETHEREUM_TEST_PATH to its path? " ) ;
json_spirit : : read_string ( s , v ) ;
dev : : test : : doTests ( v , false ) ;
}