Update transactions, style fix

This commit is contained in:
Christoph Jentzsch 2014-11-05 18:30:38 +01:00
parent 26f4637205
commit 6b6bb65eb8
5 changed files with 34 additions and 84 deletions

View File

@ -65,7 +65,7 @@ void connectClients(Client& c1, Client& c2)
namespace test 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()); importEnv(_o["env"].get_obj());
importState(_o["pre"].get_obj(), m_statePre); 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) void ImportTest::importEnv(json_spirit::mObject& _o)
{ {
assert(_o.count("previousHash") > 0); BOOST_REQUIRE(_o.count("previousHash") > 0);
assert(_o.count("currentGasLimit") > 0); BOOST_REQUIRE(_o.count("currentGasLimit") > 0);
assert(_o.count("currentDifficulty") > 0); BOOST_REQUIRE(_o.count("currentDifficulty") > 0);
assert(_o.count("currentTimestamp") > 0); BOOST_REQUIRE(_o.count("currentTimestamp") > 0);
assert(_o.count("currentCoinbase") > 0); BOOST_REQUIRE(_o.count("currentCoinbase") > 0);
assert(_o.count("currentNumber") > 0); BOOST_REQUIRE(_o.count("currentNumber") > 0);
m_environment.previousBlock.hash = h256(_o["previousHash"].get_str()); m_environment.previousBlock.hash = h256(_o["previousHash"].get_str());
m_environment.currentBlock.number = toInt(_o["currentNumber"]); 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(); json_spirit::mObject o = i.second.get_obj();
assert(o.count("balance") > 0); BOOST_REQUIRE(o.count("balance") > 0);
assert(o.count("nonce") > 0); BOOST_REQUIRE(o.count("nonce") > 0);
assert(o.count("storage") > 0); BOOST_REQUIRE(o.count("storage") > 0);
assert(o.count("code") > 0); BOOST_REQUIRE(o.count("code") > 0);
Address address = Address(i.first); Address address = Address(i.first);
@ -115,8 +115,7 @@ void ImportTest::importState(json_spirit::mObject& _o, State& _state)
bytes code = importCode(o); bytes code = importCode(o);
toInt(o["nonce"]); if (code.size())
if (toHex(code).size())
{ {
_state.m_cache[address] = Account(toInt(o["balance"]), Account::ContractConception); _state.m_cache[address] = Account(toInt(o["balance"]), Account::ContractConception);
i.second.get_obj()["code"] = "0x" + toHex(code); //preperation for export 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) void ImportTest::importTransaction(json_spirit::mObject& _o)
{ {
assert(_o.count("nonce")> 0); BOOST_REQUIRE(_o.count("nonce")> 0);
assert(_o.count("gasPrice") > 0); BOOST_REQUIRE(_o.count("gasPrice") > 0);
assert(_o.count("gasLimit") > 0); BOOST_REQUIRE(_o.count("gasLimit") > 0);
assert(_o.count("to") > 0); BOOST_REQUIRE(_o.count("to") > 0);
assert(_o.count("value") > 0); BOOST_REQUIRE(_o.count("value") > 0);
assert(_o.count("secretKey") > 0); BOOST_REQUIRE(_o.count("secretKey") > 0);
assert(_o.count("data") > 0); BOOST_REQUIRE(_o.count("data") > 0);
m_transaction.nonce = toInt(_o["nonce"]); m_transaction = _o["to"].get_str().empty() ?
m_transaction.gasPrice = toInt(_o["gasPrice"]); Transaction(toInt(_o["value"]), toInt(_o["gasPrice"]), toInt(_o["gasLimit"]), importData(_o), toInt(_o["nonce"]), Secret(_o["secretKey"].get_str())) :
m_transaction.gas = toInt(_o["gasLimit"]); 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()));
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);
} }
void ImportTest::exportTest(bytes _output, State& _statePost) void ImportTest::exportTest(bytes _output, State& _statePost)
@ -210,7 +203,7 @@ byte toByte(json_spirit::mValue const& _v)
return 0; return 0;
} }
bytes importData(json_spirit::mObject & _o) bytes importData(json_spirit::mObject& _o)
{ {
bytes data; bytes data;
if (_o["data"].type() == json_spirit::str_type) if (_o["data"].type() == json_spirit::str_type)
@ -225,7 +218,7 @@ bytes importData(json_spirit::mObject & _o)
return data; return data;
} }
bytes importCode(json_spirit::mObject & _o) bytes importCode(json_spirit::mObject& _o)
{ {
bytes code; bytes code;
if (_o["code"].type() == json_spirit::str_type) if (_o["code"].type() == json_spirit::str_type)
@ -238,11 +231,11 @@ bytes importCode(json_spirit::mObject & _o)
code.clear(); code.clear();
for (auto const& j: _o["code"].get_array()) for (auto const& j: _o["code"].get_array())
code.push_back(toByte(j)); code.push_back(toByte(j));
} }
return code; return code;
} }
void checkOutput(bytes const& _output, json_spirit::mObject & _o) void checkOutput(bytes const& _output, json_spirit::mObject& _o)
{ {
int j = 0; int j = 0;
if (_o["out"].type() == json_spirit::array_type) if (_o["out"].type() == json_spirit::array_type)

View File

@ -121,10 +121,10 @@ BOOST_AUTO_TEST_CASE(stExample)
dev::test::executeTests("stExample", "/StateTests", dev::test::doStateTests); dev::test::executeTests("stExample", "/StateTests", dev::test::doStateTests);
} }
//BOOST_AUTO_TEST_CASE(stSystemOperationsTest) BOOST_AUTO_TEST_CASE(stSystemOperationsTest)
//{ {
// dev::test::executeStateTests("stSystemOperationsTest"); dev::test::executeTests("stSystemOperationsTest", "/StateTests", dev::test::doStateTests);
//} }
BOOST_AUTO_TEST_CASE(tmp) BOOST_AUTO_TEST_CASE(tmp)
{ {

View File

@ -65,12 +65,7 @@ int stateTest()
// Inject a transaction to transfer funds from miner to me. // Inject a transaction to transfer funds from miner to me.
bytes tx; bytes tx;
{ {
Transaction t; Transaction t(1000, 0, 0, me.address(), bytes(), s.transactionsFrom(myMiner.address()), myMiner.secret());
t.nonce = s.transactionsFrom(myMiner.address());
t.value = 1000; // 1e3 wei.
t.type = eth::Transaction::MessageCall;
t.receiveAddress = me.address();
t.sign(myMiner.secret());
assert(t.sender() == myMiner.address()); assert(t.sender() == myMiner.address());
tx = t.rlp(); tx = t.rlp();
} }

14
vm.cpp
View File

@ -232,8 +232,8 @@ void FakeExtVM::importCallCreates(mArray& _callcreates)
BOOST_REQUIRE(tx.count("destination") > 0); BOOST_REQUIRE(tx.count("destination") > 0);
BOOST_REQUIRE(tx.count("gasLimit") > 0); BOOST_REQUIRE(tx.count("gasLimit") > 0);
Transaction t = tx["destination"].get_str().empty() ? Transaction t = tx["destination"].get_str().empty() ?
Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), data) : Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), data.toBytes()) :
Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), data); Transaction(toInt(tx["value"]), 0, toInt(tx["gasLimit"]), Address(tx["destination"].get_str()), data.toBytes());
callcreates.push_back(t); callcreates.push_back(t);
} }
} }
@ -423,16 +423,6 @@ BOOST_AUTO_TEST_CASE(vmPushDupSwapTest)
dev::test::executeTests("vmPushDupSwapTest", "/VMTests", dev::test::doVMTests); dev::test::executeTests("vmPushDupSwapTest", "/VMTests", dev::test::doVMTests);
} }
BOOST_AUTO_TEST_CASE(vmNamecoin)
{
dev::test::executeTests("vmNamecoin", "/VMTests", dev::test::doVMTests);
}
//BOOST_AUTO_TEST_CASE(vmSystemOperationsTest)
//{
// dev::test::executeTests("vmSystemOperationsTest", "/VMTests", dev::test::doVMTests);
//}
BOOST_AUTO_TEST_CASE(userDefinedFile) BOOST_AUTO_TEST_CASE(userDefinedFile)
{ {
if (boost::unit_test::framework::master_test_suite().argc == 2) if (boost::unit_test::framework::master_test_suite().argc == 2)

View File

@ -167,7 +167,7 @@
} }
}, },
"sha3_4": { "sha3_5": {
"env" : { "env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6", "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
"currentNumber" : "0", "currentNumber" : "0",
@ -194,32 +194,4 @@
"gas" : "10000" "gas" : "10000"
} }
}, },
// "sha3_5": {
// "env" : {
// "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
// "currentNumber" : "0",
// "currentGasLimit" : "1000000",
// "currentDifficulty" : "256",
// "currentTimestamp" : 1,
// "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
// },
// "pre" : {
// "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
// "balance" : "1000000000000000000",
// "nonce" : 0,
// "code" : "{ [[ 0 ]] (SHA3 100 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)}",
// "storage": {}
// }
// },
// "exec" : {
// "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
// "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
// "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
// "value" : "1000000000000000000",
// "data" : "",
// "gasPrice" : "100000000000000",
// "gas" : "10000"
// }
// }
} }