diff options
author | Gav Wood <i@gavwood.com> | 2014-06-28 03:39:46 +0800 |
---|---|---|
committer | Gav Wood <i@gavwood.com> | 2014-06-28 03:39:46 +0800 |
commit | d737f6df42f98c42d98d7bd4bad8a8c96e61d5a1 (patch) | |
tree | fccd73433f1d920e2e87cc28d6b2ad6407cd0d2a /vm.cpp | |
parent | 0b6763ddc15bc9a6311d1378a704f69cd4cbd976 (diff) | |
download | dexon-solidity-d737f6df42f98c42d98d7bd4bad8a8c96e61d5a1.tar dexon-solidity-d737f6df42f98c42d98d7bd4bad8a8c96e61d5a1.tar.gz dexon-solidity-d737f6df42f98c42d98d7bd4bad8a8c96e61d5a1.tar.bz2 dexon-solidity-d737f6df42f98c42d98d7bd4bad8a8c96e61d5a1.tar.lz dexon-solidity-d737f6df42f98c42d98d7bd4bad8a8c96e61d5a1.tar.xz dexon-solidity-d737f6df42f98c42d98d7bd4bad8a8c96e61d5a1.tar.zst dexon-solidity-d737f6df42f98c42d98d7bd4bad8a8c96e61d5a1.zip |
Latest tests-related refactoring & improvments.
Diffstat (limited to 'vm.cpp')
-rw-r--r-- | vm.cpp | 104 |
1 files changed, 52 insertions, 52 deletions
@@ -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()); } |