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...";
|
||||
js::mValue v;
|
||||
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);
|
||||
for (auto& i: v.get_obj())
|
||||
{
|
||||
@ -60,6 +60,7 @@ BOOST_AUTO_TEST_CASE(trie_tests)
|
||||
vector<pair<string, string>> ss;
|
||||
for (auto& i: o["in"].get_obj())
|
||||
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)
|
||||
{
|
||||
next_permutation(ss.begin(), ss.end());
|
||||
@ -74,7 +75,7 @@ BOOST_AUTO_TEST_CASE(trie_tests)
|
||||
BOOST_REQUIRE(t.check(true));
|
||||
}
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
104
vm.cpp
104
vm.cpp
@ -128,48 +128,6 @@ public:
|
||||
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)
|
||||
{
|
||||
switch (_v.type())
|
||||
@ -212,6 +170,35 @@ public:
|
||||
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 ret;
|
||||
@ -301,6 +288,10 @@ public:
|
||||
for (auto const& i: data)
|
||||
push(d, i);
|
||||
ret["data"] = d;
|
||||
mArray c;
|
||||
for (auto const& i: code)
|
||||
push(c, i);
|
||||
ret["code"] = c;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -321,6 +312,16 @@ public:
|
||||
gasPrice = toInt(_o["gasPrice"]);
|
||||
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();
|
||||
if (_o["data"].type() == str_type)
|
||||
thisTxData = fromHex(_o["data"].get_str());
|
||||
@ -396,15 +397,15 @@ void doTests(json_spirit::mValue& v, bool _fillin)
|
||||
if (_fillin)
|
||||
o["pre"] = mValue(fev.exportState());
|
||||
|
||||
bytes output;
|
||||
for (auto i: o["exec"].get_array())
|
||||
{
|
||||
fev.importExec(i.get_obj());
|
||||
vm.reset(fev.gas);
|
||||
output = vm.go(fev).toBytes();
|
||||
}
|
||||
fev.importExec(o["exec"].get_obj());
|
||||
if (!fev.code)
|
||||
fev.code = &get<3>(fev.addresses.at(fev.myAddress));
|
||||
vm.reset(fev.gas);
|
||||
bytes output = vm.go(fev).toBytes();
|
||||
|
||||
if (_fillin)
|
||||
{
|
||||
o["exec"] = mValue(fev.exportExec());
|
||||
o["post"] = mValue(fev.exportState());
|
||||
o["callcreates"] = fev.exportCallCreates();
|
||||
mArray df;
|
||||
@ -479,12 +480,11 @@ BOOST_AUTO_TEST_CASE(vm_tests)
|
||||
eth::test::doTests(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());
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
cnote << "Testing VM...";
|
||||
@ -494,7 +494,7 @@ BOOST_AUTO_TEST_CASE(vm_tests)
|
||||
json_spirit::read_string(s, v);
|
||||
eth::test::doTests(v, false);
|
||||
}
|
||||
catch( std::exception& e)
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
BOOST_ERROR("Failed VM Test with Exception: " << e.what());
|
||||
}
|
||||
|
31
vmtests.json
31
vmtests.json
@ -6,8 +6,7 @@
|
||||
"currentGasLimit" : "1000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
|
||||
"code" : "(suicide (caller))"
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
@ -17,8 +16,7 @@
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"exec" : [
|
||||
{
|
||||
"exec" : {
|
||||
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
||||
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||
@ -27,7 +25,6 @@
|
||||
"gasPrice" : "100000000000000",
|
||||
"gas" : "10000"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"arith": {
|
||||
@ -37,8 +34,7 @@
|
||||
"currentGasLimit" : "1000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
|
||||
"code" : "{ (call (- (gas) 200) (caller) (+ 2 2 (* 4 4 4) (/ 2 2) (% 3 2) (- 8 2 2)) 0 0 0 0) }"
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
@ -48,9 +44,8 @@
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"exec" : [
|
||||
{
|
||||
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
||||
"exec" : {
|
||||
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
||||
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||
"value" : "1000000000000000000",
|
||||
@ -58,7 +53,6 @@
|
||||
"gasPrice" : "100000000000000",
|
||||
"gas" : "10000"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"boolean": {
|
||||
@ -68,8 +62,7 @@
|
||||
"currentGasLimit" : "1000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"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)) )"
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
@ -78,9 +71,8 @@
|
||||
"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)) )",
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"exec" : [
|
||||
{
|
||||
},
|
||||
"exec" : {
|
||||
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
||||
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||
"caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||
@ -89,7 +81,6 @@
|
||||
"gasPrice" : "100000000000000",
|
||||
"gas" : "10000"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"mktx": {
|
||||
@ -99,8 +90,7 @@
|
||||
"currentGasLimit" : "1000000",
|
||||
"currentDifficulty" : "256",
|
||||
"currentTimestamp" : 1,
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba",
|
||||
"code" : "(call (- (gas) 200) (caller) 500000000000000000 0 0 0 0)"
|
||||
"currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
|
||||
},
|
||||
"pre" : {
|
||||
"0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
|
||||
@ -110,7 +100,7 @@
|
||||
"storage": {}
|
||||
}
|
||||
},
|
||||
"exec" : [
|
||||
"exec" :
|
||||
{
|
||||
"address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
|
||||
"origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
|
||||
@ -120,6 +110,5 @@
|
||||
"gas" : "10000",
|
||||
"data" : ""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user