diff options
author | Christoph Jentzsch <jentzsch.software@gmail.com> | 2014-11-06 01:30:38 +0800 |
---|---|---|
committer | Christoph Jentzsch <jentzsch.software@gmail.com> | 2014-11-06 01:30:38 +0800 |
commit | 6b6bb65eb8bdca8754d334510fc6938ff4b1ef5c (patch) | |
tree | d2775998cd0051a5e53a4f7528be3487667a77c6 /TestHelper.cpp | |
parent | 26f4637205d91ba6bb3db4b70b51d9e8b2b41b8e (diff) | |
download | dexon-solidity-6b6bb65eb8bdca8754d334510fc6938ff4b1ef5c.tar.gz dexon-solidity-6b6bb65eb8bdca8754d334510fc6938ff4b1ef5c.tar.zst dexon-solidity-6b6bb65eb8bdca8754d334510fc6938ff4b1ef5c.zip |
Update transactions, style fix
Diffstat (limited to 'TestHelper.cpp')
-rw-r--r-- | TestHelper.cpp | 61 |
1 files changed, 27 insertions, 34 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp index 68fdd748..277c3351 100644 --- a/TestHelper.cpp +++ b/TestHelper.cpp @@ -65,7 +65,7 @@ void connectClients(Client& c1, Client& c2) namespace test { -ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller):m_TestObject(_o) +ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller): m_TestObject(_o) { importEnv(_o["env"].get_obj()); importState(_o["pre"].get_obj(), m_statePre); @@ -79,12 +79,12 @@ ImportTest::ImportTest(json_spirit::mObject& _o, bool isFiller):m_TestObject(_o) void ImportTest::importEnv(json_spirit::mObject& _o) { - assert(_o.count("previousHash") > 0); - assert(_o.count("currentGasLimit") > 0); - assert(_o.count("currentDifficulty") > 0); - assert(_o.count("currentTimestamp") > 0); - assert(_o.count("currentCoinbase") > 0); - assert(_o.count("currentNumber") > 0); + 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); m_environment.previousBlock.hash = h256(_o["previousHash"].get_str()); m_environment.currentBlock.number = toInt(_o["currentNumber"]); @@ -103,10 +103,10 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state) { json_spirit::mObject o = i.second.get_obj(); - assert(o.count("balance") > 0); - assert(o.count("nonce") > 0); - assert(o.count("storage") > 0); - assert(o.count("code") > 0); + BOOST_REQUIRE(o.count("balance") > 0); + BOOST_REQUIRE(o.count("nonce") > 0); + BOOST_REQUIRE(o.count("storage") > 0); + BOOST_REQUIRE(o.count("code") > 0); Address address = Address(i.first); @@ -115,8 +115,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state) bytes code = importCode(o); - toInt(o["nonce"]); - if (toHex(code).size()) + if (code.size()) { _state.m_cache[address] = Account(toInt(o["balance"]), Account::ContractConception); i.second.get_obj()["code"] = "0x" + toHex(code); //preperation for export @@ -134,23 +133,17 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state) void ImportTest::importTransaction(json_spirit::mObject& _o) { - assert(_o.count("nonce")> 0); - assert(_o.count("gasPrice") > 0); - assert(_o.count("gasLimit") > 0); - assert(_o.count("to") > 0); - assert(_o.count("value") > 0); - assert(_o.count("secretKey") > 0); - assert(_o.count("data") > 0); - - m_transaction.nonce = toInt(_o["nonce"]); - m_transaction.gasPrice = toInt(_o["gasPrice"]); - m_transaction.gas = toInt(_o["gasLimit"]); - m_transaction.receiveAddress = Address(_o["to"].get_str()); - m_transaction.type = m_transaction.receiveAddress ? Transaction::MessageCall : Transaction::ContractCreation; - m_transaction.value = toInt(_o["value"]); - Secret secretKey = Secret(_o["secretKey"].get_str()); - m_transaction.sign(secretKey); - m_transaction.data = importData(_o); + BOOST_REQUIRE(_o.count("nonce")> 0); + BOOST_REQUIRE(_o.count("gasPrice") > 0); + BOOST_REQUIRE(_o.count("gasLimit") > 0); + BOOST_REQUIRE(_o.count("to") > 0); + BOOST_REQUIRE(_o.count("value") > 0); + BOOST_REQUIRE(_o.count("secretKey") > 0); + BOOST_REQUIRE(_o.count("data") > 0); + + m_transaction = _o["to"].get_str().empty() ? + Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str())) : + Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), Address(_o["to"].get_str()), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str())); } void ImportTest::exportTest(bytes _output, State& _statePost) @@ -210,7 +203,7 @@ byte toByte(json_spirit::mValue const& _v) return 0; } -bytes importData(json_spirit::mObject & _o) +bytes importData(json_spirit::mObject& _o) { bytes data; if (_o["data"].type() == json_spirit::str_type) @@ -225,7 +218,7 @@ bytes importData(json_spirit::mObject & _o) return data; } -bytes importCode(json_spirit::mObject & _o) +bytes importCode(json_spirit::mObject& _o) { bytes code; if (_o["code"].type() == json_spirit::str_type) @@ -238,11 +231,11 @@ bytes importCode(json_spirit::mObject & _o) code.clear(); for (auto const& j: _o["code"].get_array()) code.push_back(toByte(j)); - } + } return code; } -void checkOutput(bytes const& _output, json_spirit::mObject & _o) +void checkOutput(bytes const& _output, json_spirit::mObject& _o) { int j = 0; if (_o["out"].type() == json_spirit::array_type) |