mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Latest tests-related refactoring & improvments.
This commit is contained in:
parent
0b6763ddc1
commit
d737f6df42
5
trie.cpp
5
trie.cpp
@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(trie_tests)
|
|||||||
cnote << "Testing Trie...";
|
cnote << "Testing Trie...";
|
||||||
js::mValue v;
|
js::mValue v;
|
||||||
string s = asString(contents("../../../tests/trietest.json"));
|
string s = asString(contents("../../../tests/trietest.json"));
|
||||||
BOOST_REQUIRE_MESSAGE( s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
||||||
js::read_string(s, v);
|
js::read_string(s, v);
|
||||||
for (auto& i: v.get_obj())
|
for (auto& i: v.get_obj())
|
||||||
{
|
{
|
||||||
@ -60,6 +60,7 @@ BOOST_AUTO_TEST_CASE(trie_tests)
|
|||||||
vector<pair<string, string>> ss;
|
vector<pair<string, string>> ss;
|
||||||
for (auto& i: o["in"].get_obj())
|
for (auto& i: o["in"].get_obj())
|
||||||
ss.push_back(make_pair(i.first, i.second.get_str()));
|
ss.push_back(make_pair(i.first, i.second.get_str()));
|
||||||
|
cnote << ss;
|
||||||
for (unsigned j = 0; j < eth::test::fac((unsigned)ss.size()); ++j)
|
for (unsigned j = 0; j < eth::test::fac((unsigned)ss.size()); ++j)
|
||||||
{
|
{
|
||||||
next_permutation(ss.begin(), ss.end());
|
next_permutation(ss.begin(), ss.end());
|
||||||
@ -74,7 +75,7 @@ BOOST_AUTO_TEST_CASE(trie_tests)
|
|||||||
BOOST_REQUIRE(t.check(true));
|
BOOST_REQUIRE(t.check(true));
|
||||||
}
|
}
|
||||||
BOOST_REQUIRE(!o["root"].is_null());
|
BOOST_REQUIRE(!o["root"].is_null());
|
||||||
BOOST_CHECK(o["root"].get_str() == toHex(t.root().asArray()) );
|
BOOST_CHECK_EQUAL(o["root"].get_str(), toHex(t.root().asArray()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
102
vm.cpp
102
vm.cpp
@ -128,48 +128,6 @@ public:
|
|||||||
set(myAddress, _myBalance, _myNonce, _storage, get<3>(addresses[myAddress]));
|
set(myAddress, _myBalance, _myNonce, _storage, get<3>(addresses[myAddress]));
|
||||||
}
|
}
|
||||||
|
|
||||||
mObject exportEnv()
|
|
||||||
{
|
|
||||||
mObject ret;
|
|
||||||
ret["previousHash"] = toString(previousBlock.hash);
|
|
||||||
push(ret, "currentDifficulty", currentBlock.difficulty);
|
|
||||||
push(ret, "currentTimestamp", currentBlock.timestamp);
|
|
||||||
ret["currentCoinbase"] = toString(currentBlock.coinbaseAddress);
|
|
||||||
push(ret, "currentNumber", currentBlock.number);
|
|
||||||
push(ret, "currentGasLimit", currentBlock.gasLimit);
|
|
||||||
|
|
||||||
mArray c;
|
|
||||||
for (auto const& i: code)
|
|
||||||
push(c, i);
|
|
||||||
ret["code"] = c;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void importEnv(mObject& _o)
|
|
||||||
{
|
|
||||||
BOOST_REQUIRE(_o.count("previousHash") > 0);
|
|
||||||
BOOST_REQUIRE(_o.count("currentGasLimit") > 0);
|
|
||||||
BOOST_REQUIRE(_o.count("currentDifficulty") > 0);
|
|
||||||
BOOST_REQUIRE(_o.count("currentTimestamp") > 0);
|
|
||||||
BOOST_REQUIRE(_o.count("currentCoinbase") > 0);
|
|
||||||
BOOST_REQUIRE(_o.count("currentNumber") > 0);
|
|
||||||
|
|
||||||
previousBlock.hash = h256(_o["previousHash"].get_str());
|
|
||||||
currentBlock.number = toInt(_o["currentNumber"]);
|
|
||||||
currentBlock.gasLimit = toInt(_o["currentGasLimit"]);
|
|
||||||
currentBlock.difficulty = toInt(_o["currentDifficulty"]);
|
|
||||||
currentBlock.timestamp = toInt(_o["currentTimestamp"]);
|
|
||||||
currentBlock.coinbaseAddress = Address(_o["currentCoinbase"].get_str());
|
|
||||||
|
|
||||||
thisTxCode.clear();
|
|
||||||
if (_o["code"].type() == str_type)
|
|
||||||
thisTxCode = compileLLL(_o["code"].get_str());
|
|
||||||
else
|
|
||||||
for (auto const& j: _o["code"].get_array())
|
|
||||||
thisTxCode.push_back(toByte(j));
|
|
||||||
code = &thisTxCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
static u256 toInt(mValue const& _v)
|
static u256 toInt(mValue const& _v)
|
||||||
{
|
{
|
||||||
switch (_v.type())
|
switch (_v.type())
|
||||||
@ -212,6 +170,35 @@ public:
|
|||||||
a.push_back(toString(_v));
|
a.push_back(toString(_v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mObject exportEnv()
|
||||||
|
{
|
||||||
|
mObject ret;
|
||||||
|
ret["previousHash"] = toString(previousBlock.hash);
|
||||||
|
push(ret, "currentDifficulty", currentBlock.difficulty);
|
||||||
|
push(ret, "currentTimestamp", currentBlock.timestamp);
|
||||||
|
ret["currentCoinbase"] = toString(currentBlock.coinbaseAddress);
|
||||||
|
push(ret, "currentNumber", currentBlock.number);
|
||||||
|
push(ret, "currentGasLimit", currentBlock.gasLimit);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void importEnv(mObject& _o)
|
||||||
|
{
|
||||||
|
BOOST_REQUIRE(_o.count("previousHash") > 0);
|
||||||
|
BOOST_REQUIRE(_o.count("currentGasLimit") > 0);
|
||||||
|
BOOST_REQUIRE(_o.count("currentDifficulty") > 0);
|
||||||
|
BOOST_REQUIRE(_o.count("currentTimestamp") > 0);
|
||||||
|
BOOST_REQUIRE(_o.count("currentCoinbase") > 0);
|
||||||
|
BOOST_REQUIRE(_o.count("currentNumber") > 0);
|
||||||
|
|
||||||
|
previousBlock.hash = h256(_o["previousHash"].get_str());
|
||||||
|
currentBlock.number = toInt(_o["currentNumber"]);
|
||||||
|
currentBlock.gasLimit = toInt(_o["currentGasLimit"]);
|
||||||
|
currentBlock.difficulty = toInt(_o["currentDifficulty"]);
|
||||||
|
currentBlock.timestamp = toInt(_o["currentTimestamp"]);
|
||||||
|
currentBlock.coinbaseAddress = Address(_o["currentCoinbase"].get_str());
|
||||||
|
}
|
||||||
|
|
||||||
mObject exportState()
|
mObject exportState()
|
||||||
{
|
{
|
||||||
mObject ret;
|
mObject ret;
|
||||||
@ -301,6 +288,10 @@ public:
|
|||||||
for (auto const& i: data)
|
for (auto const& i: data)
|
||||||
push(d, i);
|
push(d, i);
|
||||||
ret["data"] = d;
|
ret["data"] = d;
|
||||||
|
mArray c;
|
||||||
|
for (auto const& i: code)
|
||||||
|
push(c, i);
|
||||||
|
ret["code"] = c;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -321,6 +312,16 @@ public:
|
|||||||
gasPrice = toInt(_o["gasPrice"]);
|
gasPrice = toInt(_o["gasPrice"]);
|
||||||
gas = toInt(_o["gas"]);
|
gas = toInt(_o["gas"]);
|
||||||
|
|
||||||
|
thisTxCode.clear();
|
||||||
|
code = &thisTxCode;
|
||||||
|
if (_o["code"].type() == str_type)
|
||||||
|
thisTxCode = compileLLL(_o["code"].get_str());
|
||||||
|
else if (_o["code"].type() == array_type)
|
||||||
|
for (auto const& j: _o["code"].get_array())
|
||||||
|
thisTxCode.push_back(toByte(j));
|
||||||
|
else
|
||||||
|
code.reset();
|
||||||
|
|
||||||
thisTxData.clear();
|
thisTxData.clear();
|
||||||
if (_o["data"].type() == str_type)
|
if (_o["data"].type() == str_type)
|
||||||
thisTxData = fromHex(_o["data"].get_str());
|
thisTxData = fromHex(_o["data"].get_str());
|
||||||
@ -396,15 +397,15 @@ void doTests(json_spirit::mValue& v, bool _fillin)
|
|||||||
if (_fillin)
|
if (_fillin)
|
||||||
o["pre"] = mValue(fev.exportState());
|
o["pre"] = mValue(fev.exportState());
|
||||||
|
|
||||||
bytes output;
|
fev.importExec(o["exec"].get_obj());
|
||||||
for (auto i: o["exec"].get_array())
|
if (!fev.code)
|
||||||
{
|
fev.code = &get<3>(fev.addresses.at(fev.myAddress));
|
||||||
fev.importExec(i.get_obj());
|
|
||||||
vm.reset(fev.gas);
|
vm.reset(fev.gas);
|
||||||
output = vm.go(fev).toBytes();
|
bytes output = vm.go(fev).toBytes();
|
||||||
}
|
|
||||||
if (_fillin)
|
if (_fillin)
|
||||||
{
|
{
|
||||||
|
o["exec"] = mValue(fev.exportExec());
|
||||||
o["post"] = mValue(fev.exportState());
|
o["post"] = mValue(fev.exportState());
|
||||||
o["callcreates"] = fev.exportCallCreates();
|
o["callcreates"] = fev.exportCallCreates();
|
||||||
mArray df;
|
mArray df;
|
||||||
@ -479,12 +480,11 @@ BOOST_AUTO_TEST_CASE(vm_tests)
|
|||||||
eth::test::doTests(v, true);
|
eth::test::doTests(v, true);
|
||||||
writeFile("../../../tests/vmtests.json", asBytes(json_spirit::write_string(v, true)));
|
writeFile("../../../tests/vmtests.json", asBytes(json_spirit::write_string(v, true)));
|
||||||
}
|
}
|
||||||
catch( std::exception& e)
|
catch (std::exception const& e)
|
||||||
{
|
{
|
||||||
BOOST_ERROR("Failed VM Test with Exception: " << e.what());
|
BOOST_ERROR("Failed VM Test with Exception: " << e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cnote << "Testing VM...";
|
cnote << "Testing VM...";
|
||||||
@ -494,7 +494,7 @@ BOOST_AUTO_TEST_CASE(vm_tests)
|
|||||||
json_spirit::read_string(s, v);
|
json_spirit::read_string(s, v);
|
||||||
eth::test::doTests(v, false);
|
eth::test::doTests(v, false);
|
||||||
}
|
}
|
||||||
catch( std::exception& e)
|
catch (std::exception const& e)
|
||||||
{
|
{
|
||||||
BOOST_ERROR("Failed VM Test with Exception: " << e.what());
|
BOOST_ERROR("Failed VM Test with Exception: " << e.what());
|
||||||
}
|
}
|
||||||
|
27
vmtests.json
27
vmtests.json
@ -6,8 +6,7 @@
|
|||||||
"currentGasLimit" : "1000000",
|
"currentGasLimit" : "1000000",
|
||||||
"currentDifficulty" : "256",
|
"currentDifficulty" : "256",
|
||||||
"currentTimestamp" : 1,
|
"currentTimestamp" : 1,
|
||||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
|
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||||
"code" : "(suicide (caller))"
|
|
||||||
},
|
},
|
||||||
"pre" : {
|
"pre" : {
|
||||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||||
@ -17,8 +16,7 @@
|
|||||||
"storage": {}
|
"storage": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exec" : [
|
"exec" : {
|
||||||
{
|
|
||||||
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
||||||
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||||
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||||
@ -27,7 +25,6 @@
|
|||||||
"gasPrice" : "100000000000000",
|
"gasPrice" : "100000000000000",
|
||||||
"gas" : "10000"
|
"gas" : "10000"
|
||||||
}
|
}
|
||||||
]
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"arith": {
|
"arith": {
|
||||||
@ -37,8 +34,7 @@
|
|||||||
"currentGasLimit" : "1000000",
|
"currentGasLimit" : "1000000",
|
||||||
"currentDifficulty" : "256",
|
"currentDifficulty" : "256",
|
||||||
"currentTimestamp" : 1,
|
"currentTimestamp" : 1,
|
||||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
|
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||||
"code" : "{ (call (- (gas) 200) (caller) (+ 2 2 (* 4 4 4) (/ 2 2) (% 3 2) (- 8 2 2)) 0 0 0 0) }"
|
|
||||||
},
|
},
|
||||||
"pre" : {
|
"pre" : {
|
||||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||||
@ -48,8 +44,7 @@
|
|||||||
"storage": {}
|
"storage": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exec" : [
|
"exec" : {
|
||||||
{
|
|
||||||
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
||||||
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||||
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||||
@ -58,7 +53,6 @@
|
|||||||
"gasPrice" : "100000000000000",
|
"gasPrice" : "100000000000000",
|
||||||
"gas" : "10000"
|
"gas" : "10000"
|
||||||
}
|
}
|
||||||
]
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"boolean": {
|
"boolean": {
|
||||||
@ -68,8 +62,7 @@
|
|||||||
"currentGasLimit" : "1000000",
|
"currentGasLimit" : "1000000",
|
||||||
"currentDifficulty" : "256",
|
"currentDifficulty" : "256",
|
||||||
"currentTimestamp" : 1,
|
"currentTimestamp" : 1,
|
||||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
|
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||||
"code" : "(seq (when (and 1 1) (call (- (gas) 200) (caller) 2 0 0 0 0)) (when (and 1 0) (call (- (gas) 200) (caller) 3 0 0 0 0)) (when (and 0 1) (call (- (gas) 200) (caller) 4 0 0 0 0)) (when (and 0 0) (call (- (gas) 200) (caller) 5 0 0 0 0)) (when (or 1 1) (call (- (gas) 200) (caller) 12 0 0 0 0)) (when (or 1 0) (call (- (gas) 200) (caller) 13 0 0 0 0)) (when (or 0 1) (call (- (gas) 200) (caller) 14 0 0 0 0)) (when (or 0 0) (call (- (gas) 200) (caller) 15 0 0 0 0)) )"
|
|
||||||
},
|
},
|
||||||
"pre" : {
|
"pre" : {
|
||||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||||
@ -79,8 +72,7 @@
|
|||||||
"storage": {}
|
"storage": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exec" : [
|
"exec" : {
|
||||||
{
|
|
||||||
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
||||||
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||||
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||||
@ -89,7 +81,6 @@
|
|||||||
"gasPrice" : "100000000000000",
|
"gasPrice" : "100000000000000",
|
||||||
"gas" : "10000"
|
"gas" : "10000"
|
||||||
}
|
}
|
||||||
]
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"mktx": {
|
"mktx": {
|
||||||
@ -99,8 +90,7 @@
|
|||||||
"currentGasLimit" : "1000000",
|
"currentGasLimit" : "1000000",
|
||||||
"currentDifficulty" : "256",
|
"currentDifficulty" : "256",
|
||||||
"currentTimestamp" : 1,
|
"currentTimestamp" : 1,
|
||||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
|
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||||
"code" : "(call (- (gas) 200) (caller) 500000000000000000 0 0 0 0)"
|
|
||||||
},
|
},
|
||||||
"pre" : {
|
"pre" : {
|
||||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||||
@ -110,7 +100,7 @@
|
|||||||
"storage": {}
|
"storage": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exec" : [
|
"exec" :
|
||||||
{
|
{
|
||||||
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
||||||
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||||
@ -120,6 +110,5 @@
|
|||||||
"gas" : "10000",
|
"gas" : "10000",
|
||||||
"data" : ""
|
"data" : ""
|
||||||
}
|
}
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user