aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCJentzsch <jentzsch.software@gmail.com>2015-01-09 17:58:32 +0800
committerCJentzsch <jentzsch.software@gmail.com>2015-01-09 17:58:32 +0800
commit203005e2b77e0fbaa2cb8003fc85a784628c1866 (patch)
treec09cc8bf29b6d94b443436d8f6bd139da7d9266b
parent90cdc52ae788d24e79800bf44473f3c8c087c1f4 (diff)
downloaddexon-solidity-203005e2b77e0fbaa2cb8003fc85a784628c1866.tar.gz
dexon-solidity-203005e2b77e0fbaa2cb8003fc85a784628c1866.tar.zst
dexon-solidity-203005e2b77e0fbaa2cb8003fc85a784628c1866.zip
add blockhash test fo vm tests
-rw-r--r--TestHelper.cpp8
-rw-r--r--TestHelper.h1
-rw-r--r--state.cpp10
-rw-r--r--vm.cpp3
-rw-r--r--vmBlockInfoTestFiller.json56
5 files changed, 67 insertions, 11 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp
index ea848c7c..ff330d60 100644
--- a/TestHelper.cpp
+++ b/TestHelper.cpp
@@ -489,4 +489,12 @@ void processCommandLineOptions()
}
}
+LastHashes lastHashes(u256 _currentBlockNumber)
+{
+ LastHashes ret;
+ for (u256 i = 1; i <= 256 && i <= _currentBlockNumber; ++i)
+ ret.push_back(sha3(toString(_currentBlockNumber - i)));
+ return ret;
+}
+
} } // namespaces
diff --git a/TestHelper.h b/TestHelper.h
index 20328c91..85017c84 100644
--- a/TestHelper.h
+++ b/TestHelper.h
@@ -77,6 +77,7 @@ void executeTests(const std::string& _name, const std::string& _testPathAppendix
std::string getTestPath();
void userDefinedTest(std::string testTypeFlag, std::function<void(json_spirit::mValue&, bool)> doTests);
void processCommandLineOptions();
+eth::LastHashes lastHashes(u256 _currentBlockNumber);
template<typename mapType>
void checkAddresses(mapType& _expectedAddrs, mapType& _resultAddrs)
diff --git a/state.cpp b/state.cpp
index db8350e4..6da18e70 100644
--- a/state.cpp
+++ b/state.cpp
@@ -39,16 +39,6 @@ using namespace dev::eth;
namespace dev { namespace test {
-LastHashes lastHashes(u256 _currentBlockNumber)
-{
- LastHashes ret;
- for (u256 i = 1; i <= 256 && i <= _currentBlockNumber; ++i)
- ret.push_back(sha3(toString(_currentBlockNumber - i)));
- return ret;
-}
-
-
-
void doStateTests(json_spirit::mValue& v, bool _fillin)
{
processCommandLineOptions();
diff --git a/vm.cpp b/vm.cpp
index 18bf5797..6ae95f25 100644
--- a/vm.cpp
+++ b/vm.cpp
@@ -33,7 +33,7 @@ using namespace dev::eth;
using namespace dev::test;
FakeExtVM::FakeExtVM(eth::BlockInfo const& _previousBlock, eth::BlockInfo const& _currentBlock, unsigned _depth): /// TODO: XXX: remove the default argument & fix.
- ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), _previousBlock, _currentBlock, LastHashes(), _depth) {}
+ ExtVMFace(Address(), Address(), Address(), 0, 1, bytesConstRef(), bytes(), _previousBlock, _currentBlock, test::lastHashes(_currentBlock.number), _depth) {}
h160 FakeExtVM::create(u256 _endowment, u256& io_gas, bytesConstRef _init, OnOpFunc const&)
{
@@ -117,6 +117,7 @@ void FakeExtVM::importEnv(mObject& _o)
previousBlock.hash = h256(_o["previousHash"].get_str());
currentBlock.number = toInt(_o["currentNumber"]);
+ lastHashes = test::lastHashes(currentBlock.number);
currentBlock.gasLimit = toInt(_o["currentGasLimit"]);
currentBlock.difficulty = toInt(_o["currentDifficulty"]);
currentBlock.timestamp = toInt(_o["currentTimestamp"]);
diff --git a/vmBlockInfoTestFiller.json b/vmBlockInfoTestFiller.json
index 15c27017..89862947 100644
--- a/vmBlockInfoTestFiller.json
+++ b/vmBlockInfoTestFiller.json
@@ -111,6 +111,62 @@
}
},
+ "blockhashInRange": {
+ "env" : {
+ "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+ "currentNumber" : "257",
+ "currentGasLimit" : "1000000",
+ "currentDifficulty" : "256",
+ "currentTimestamp" : 1,
+ "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+ },
+ "pre" : {
+ "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+ "balance" : "1000000000000000000",
+ "nonce" : 0,
+ "code" : "{ [[ 0 ]] (BLOCKHASH 1) [[ 1 ]] (BLOCKHASH 2) [[ 2 ]] (BLOCKHASH 256) }",
+ "storage": {}
+ }
+ },
+ "exec" : {
+ "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+ "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+ "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+ "value" : "1000000000000000000",
+ "data" : "",
+ "gasPrice" : "100000000000000",
+ "gas" : "10000"
+ }
+ },
+
+ "blockhashOutOfRange": {
+ "env" : {
+ "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",
+ "currentNumber" : "257",
+ "currentGasLimit" : "1000000",
+ "currentDifficulty" : "256",
+ "currentTimestamp" : 1,
+ "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba"
+ },
+ "pre" : {
+ "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6" : {
+ "balance" : "1000000000000000000",
+ "nonce" : 0,
+ "code" : "{ [[ 0 ]] (BLOCKHASH 0) [[ 1 ]] (BLOCKHASH 257) [[ 2 ]] (BLOCKHASH 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) }",
+ "storage": {}
+ }
+ },
+ "exec" : {
+ "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6",
+ "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+ "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681",
+ "value" : "1000000000000000000",
+ "data" : "",
+ "gasPrice" : "100000000000000",
+ "gas" : "10000"
+ }
+ },
+
"coinbase": {
"env" : {
"previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6",