aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Kotewicz <marek.kotewicz@gmail.com>2015-03-11 15:33:52 +0800
committerMarek Kotewicz <marek.kotewicz@gmail.com>2015-03-11 15:33:52 +0800
commit68db4681c0ff2a0c724512edac5abe1fb5341444 (patch)
treef5528939cd3d4b1cadc9b409d6d062cb190ea07a
parent57e6fb303dd65212855ea69f2bd25358f0379526 (diff)
parente9db858ccabbdaa90ed721065b7ace48d3e34bd5 (diff)
downloaddexon-solidity-68db4681c0ff2a0c724512edac5abe1fb5341444.tar.gz
dexon-solidity-68db4681c0ff2a0c724512edac5abe1fb5341444.tar.zst
dexon-solidity-68db4681c0ff2a0c724512edac5abe1fb5341444.zip
Merge branch 'develop' into new_jsonrpc
-rw-r--r--TestHelper.cpp41
-rw-r--r--TestHelper.h8
-rw-r--r--bcUncleTestFiller.json18
-rw-r--r--blockchain.cpp14
-rw-r--r--natspec.cpp19
-rw-r--r--vm.cpp64
6 files changed, 89 insertions, 75 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp
index befd571e..9ac64107 100644
--- a/TestHelper.cpp
+++ b/TestHelper.cpp
@@ -181,46 +181,35 @@ void ImportTest::exportTest(bytes const& _output, State const& _statePost)
m_TestObject["logs"] = exportLog(_statePost.pending().size() ? _statePost.log(0) : LogEntries());
// export post state
- json_spirit::mObject postState;
-
- for (auto const& a: _statePost.addresses())
- {
- json_spirit::mObject o;
- o["balance"] = toString(_statePost.balance(a.first));
- o["nonce"] = toString(_statePost.transactionsFrom(a.first));
- {
- json_spirit::mObject store;
- for (auto const& s: _statePost.storage(a.first))
- store["0x"+toHex(toCompactBigEndian(s.first))] = "0x"+toHex(toCompactBigEndian(s.second));
- o["storage"] = store;
- }
- o["code"] = "0x" + toHex(_statePost.code(a.first));
-
- postState[toString(a.first)] = o;
- }
- m_TestObject["post"] = json_spirit::mValue(postState);
+ m_TestObject["post"] = fillJsonWithState(_statePost);
m_TestObject["postStateRoot"] = toHex(_statePost.rootHash().asBytes());
// export pre state
- json_spirit::mObject preState;
+ m_TestObject["pre"] = fillJsonWithState(m_statePre);
+}
+
+json_spirit::mObject fillJsonWithState(State _state)
+{
+ // export pre state
+ json_spirit::mObject oState;
- for (auto const& a: m_statePre.addresses())
+ for (auto const& a: _state.addresses())
{
json_spirit::mObject o;
- o["balance"] = toString(m_statePre.balance(a.first));
- o["nonce"] = toString(m_statePre.transactionsFrom(a.first));
+ o["balance"] = toString(_state.balance(a.first));
+ o["nonce"] = toString(_state.transactionsFrom(a.first));
{
json_spirit::mObject store;
- for (auto const& s: m_statePre.storage(a.first))
+ for (auto const& s: _state.storage(a.first))
store["0x"+toHex(toCompactBigEndian(s.first))] = "0x"+toHex(toCompactBigEndian(s.second));
o["storage"] = store;
}
- o["code"] = "0x" + toHex(m_statePre.code(a.first));
+ o["code"] = "0x" + toHex(_state.code(a.first));
- preState[toString(a.first)] = o;
+ oState[toString(a.first)] = o;
}
- m_TestObject["pre"] = json_spirit::mValue(preState);
+ return oState;
}
u256 toInt(json_spirit::mValue const& _v)
diff --git a/TestHelper.h b/TestHelper.h
index 0f23f945..d378848a 100644
--- a/TestHelper.h
+++ b/TestHelper.h
@@ -117,6 +117,13 @@ private:
json_spirit::mObject& m_TestObject;
};
+class ZeroGasPricer: public eth::GasPricer
+{
+protected:
+ u256 ask(eth::State const&) const override { return 0; }
+ u256 bid(eth::TransactionPriority = eth::TransactionPriority::Medium) const override { return 0; }
+};
+
// helping functions
u256 toInt(json_spirit::mValue const& _v);
byte toByte(json_spirit::mValue const& _v);
@@ -136,6 +143,7 @@ void userDefinedTest(std::string testTypeFlag, std::function<void(json_spirit::m
RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj);
void processCommandLineOptions();
eth::LastHashes lastHashes(u256 _currentBlockNumber);
+json_spirit::mObject fillJsonWithState(eth::State _state);
template<typename mapType>
void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs)
diff --git a/bcUncleTestFiller.json b/bcUncleTestFiller.json
index 639051f2..73d1e548 100644
--- a/bcUncleTestFiller.json
+++ b/bcUncleTestFiller.json
@@ -265,23 +265,7 @@
"uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
},
{
- "bloom" : "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
- "coinbase" : "0000000000000000000000000000000000000000",
- "difficulty" : "131072",
- "extraData" : "0x",
- "gasLimit" : "99902343",
- "gasUsed" : "0",
- "hash" : "9de9879b6a81d1b6c4993c63c90a3c9d1e775f14572694778e828bc64972ae04",
- "mixHash" : "b557f905d29ed0fca99d65d0adcce698dee97cf72a13c7cd8d7a7826b8eee770",
- "nonce" : "18a524c1790fa83b",
- "number" : "2",
- "parentHash" : "6134fc6b5d99ee03c4aab1592640f6f9dcbc850668d75d631aee34989b938fae",
- "receiptTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "seedHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
- "stateRoot" : "ff640b30d613c35dad43e3693329e1b1ee6350f989cf46a288025a1cbfdab9cd",
- "timestamp" : "0x54c98c82",
- "transactionsTrie" : "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
- "uncleHash" : "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"
+ "sameAsPreviousSibling" : "1"
}
]
}
diff --git a/blockchain.cpp b/blockchain.cpp
index 0e1128ef..eca08d09 100644
--- a/blockchain.cpp
+++ b/blockchain.cpp
@@ -52,6 +52,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
ImportTest importer(o["pre"].get_obj());
State state(Address(), OverlayDB(), BaseState::Empty);
importer.importState(o["pre"].get_obj(), state);
+ o["pre"] = fillJsonWithState(state);
state.commit();
if (_fillin)
@@ -87,7 +88,7 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
// get txs
TransactionQueue txs;
- TrivialGasPricer gp;
+ ZeroGasPricer gp;
BOOST_REQUIRE(blObj.count("transactions"));
for (auto const& txObj: blObj["transactions"].get_array())
{
@@ -101,10 +102,18 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
BlockQueue uncleBlockQueue;
mArray aUncleList;
vector<BlockInfo> vBiUncles;
+ mObject uncleHeaderObj_pre;
for (auto const& uHObj: blObj["uncleHeaders"].get_array())
{
mObject uncleHeaderObj = uHObj.get_obj();
+ if (uncleHeaderObj.count("sameAsPreviousSibling"))
+ {
+ writeBlockHeaderToJson(uncleHeaderObj_pre, vBiUncles[vBiUncles.size()-1]);
+ aUncleList.push_back(uncleHeaderObj_pre);
+ vBiUncles.push_back(vBiUncles[vBiUncles.size()-1]);
+ continue;
+ }
BlockInfo uncleBlockFromFields = constructBlock(uncleHeaderObj);
// make uncle header valid
@@ -123,6 +132,8 @@ void doBlockchainTests(json_spirit::mValue& _v, bool _fillin)
cnote << "import uncle in blockQueue";
RLPStream uncle = createFullBlockFromHeader(uncleBlockFromFields);
uncleBlockQueue.import(&uncle.out(), bc);
+
+ uncleHeaderObj_pre = uncleHeaderObj;
}
blObj["uncleHeaders"] = aUncleList;
@@ -579,6 +590,7 @@ void updatePoW(BlockInfo& _bi)
ret = pow.mine(_bi, 10000, true, true); // tie(ret, blockFromFields.nonce)
Ethash::assignResult(ret.second, _bi);
}
+ _bi.hash = _bi.headerHash(WithNonce);
}
void writeBlockHeaderToJson(mObject& _o, const BlockInfo& _bi)
diff --git a/natspec.cpp b/natspec.cpp
index 8ba66041..cdcedca4 100644
--- a/natspec.cpp
+++ b/natspec.cpp
@@ -34,7 +34,7 @@ BOOST_AUTO_TEST_CASE(natspec_eval_function_exists)
// given
NatspecExpressionEvaluator e;
// when
- string result = e.evalExpression("`typeof evaluateExpression`").toStdString();
+ string result = e.evalExpression("`typeof natspec.evaluateExpression`").toStdString();
// then
BOOST_CHECK_EQUAL(result, "function");
}
@@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params)
// given
char const* abi = R"([
{
- "name": "f",
+ "name": "multiply",
"constant": false,
"type": "function",
"inputs": [
@@ -94,7 +94,18 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval_input_params)
]
}
])";
- NatspecExpressionEvaluator e(abi, "'f'", "[4]");
+
+ char const* transaction = R"({
+ "jsonrpc": "2.0",
+ "method": "eth_call",
+ "params": [{
+ "to": "0x8521742d3f456bd237e312d6e30724960f72517a",
+ "data": "0xc6888fa10000000000000000000000000000000000000000000000000000000000000004"
+ }],
+ "id": 6
+ })";
+
+ NatspecExpressionEvaluator e(abi, transaction , "multiply");
// when
string result = e.evalExpression("Will multiply `a` by 7 and return `a * 7`.").toStdString();
// then
@@ -108,7 +119,7 @@ BOOST_AUTO_TEST_CASE(natspec_js_eval_error)
// when
string result = e.evalExpression("`test(`").toStdString();
// then
- BOOST_CHECK_EQUAL(result, "`test(`");
+ BOOST_CHECK_EQUAL(result, "Natspec evaluation failed, wrong input params");
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/vm.cpp b/vm.cpp
index eb7c174e..a39f0005 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -533,33 +533,43 @@ BOOST_AUTO_TEST_CASE(vmPerformanceTest)
}
}
-//BOOST_AUTO_TEST_CASE(vmInputLimitsTest1)
-//{
-// for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
-// {
-// string arg = boost::unit_test::framework::master_test_suite().argv[i];
-// if (arg == "--inputlimits" || arg == "--all")
-// {
-// auto start = chrono::steady_clock::now();
-
-// dev::test::executeTests("vmInputLimitsTest1", "/VMTests", dev::test::doVMTests);
-
-// auto end = chrono::steady_clock::now();
-// auto duration(chrono::duration_cast<chrono::milliseconds>(end - start));
-// cnote << "test duration: " << duration.count() << " milliseconds.\n";
-// }
-// }
-//}
-
-//BOOST_AUTO_TEST_CASE(vmInputLimitsTest2)
-//{
-// for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
-// {
-// string arg = boost::unit_test::framework::master_test_suite().argv[i];
-// if (arg == "--inputlimits" || arg == "--all")
-// dev::test::executeTests("vmInputLimitsTest2", "/VMTests", dev::test::doVMTests);
-// }
-//}
+BOOST_AUTO_TEST_CASE(vmInputLimitsTest1)
+{
+ for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
+ {
+ string arg = boost::unit_test::framework::master_test_suite().argv[i];
+ if (arg == "--inputlimits" || arg == "--all")
+ {
+ auto start = chrono::steady_clock::now();
+
+ dev::test::executeTests("vmInputLimits1", "/VMTests", dev::test::doVMTests);
+
+ auto end = chrono::steady_clock::now();
+ auto duration(chrono::duration_cast<chrono::milliseconds>(end - start));
+ cnote << "test duration: " << duration.count() << " milliseconds.\n";
+ }
+ }
+}
+
+BOOST_AUTO_TEST_CASE(vmInputLimitsTest2)
+{
+ for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
+ {
+ string arg = boost::unit_test::framework::master_test_suite().argv[i];
+ if (arg == "--inputlimits" || arg == "--all")
+ dev::test::executeTests("vmInputLimits2", "/VMTests", dev::test::doVMTests);
+ }
+}
+
+BOOST_AUTO_TEST_CASE(vmInputLimitsLightTest)
+{
+ for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i)
+ {
+ string arg = boost::unit_test::framework::master_test_suite().argv[i];
+ if (arg == "--inputlimits" || arg == "--all")
+ dev::test::executeTests("vmInputLimitsLight", "/VMTests", dev::test::doVMTests);
+ }
+}
BOOST_AUTO_TEST_CASE(vmRandom)
{