aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGav Wood <i@gavwood.com>2015-07-21 01:39:09 +0800
committerGav Wood <i@gavwood.com>2015-07-21 01:39:09 +0800
commit262643f5612f59741df8a0e0d5f7c187788e7bc5 (patch)
tree95fea969a077f7cc0b0fe5d98b7d646c28b9eeaa
parent8e4517a015b1f5d5068233505d4e6ee2c8359521 (diff)
parent189b298ae1522c02aeb0fbab035682ad9294d788 (diff)
downloaddexon-solidity-262643f5612f59741df8a0e0d5f7c187788e7bc5.tar.gz
dexon-solidity-262643f5612f59741df8a0e0d5f7c187788e7bc5.tar.zst
dexon-solidity-262643f5612f59741df8a0e0d5f7c187788e7bc5.zip
Merge branch 'whizz' into develop
-rw-r--r--TestHelper.cpp98
-rw-r--r--TestHelper.h19
-rw-r--r--libsolidity/solidityExecutionFramework.h6
3 files changed, 91 insertions, 32 deletions
diff --git a/TestHelper.cpp b/TestHelper.cpp
index f49ed1e0..aec72285 100644
--- a/TestHelper.cpp
+++ b/TestHelper.cpp
@@ -23,6 +23,7 @@
#include <thread>
#include <chrono>
+#include <libethcore/EthashAux.h>
#include <libethereum/Client.h>
#include <liblll/Compiler.h>
#include <libevm/VMFactory.h>
@@ -62,32 +63,23 @@ void connectClients(Client& c1, Client& c2)
void mine(State& s, BlockChain const& _bc)
{
+ std::unique_ptr<SealEngineFace> sealer(Ethash::createSealEngine());
s.commitToMine(_bc);
- GenericFarm<ProofOfWork> f;
- bool completed = false;
- f.onSolutionFound([&](ProofOfWork::Solution sol)
- {
- return completed = s.completeMine<ProofOfWork>(sol);
- });
- f.setWork(s.info());
- f.startCPU();
- while (!completed)
- this_thread::sleep_for(chrono::milliseconds(20));
+ Notified<bytes> sealed;
+ sealer->onSealGenerated([&](bytes const& sealedHeader){ sealed = sealedHeader; });
+ sealer->generateSeal(s.info());
+ sealed.waitNot({});
+ s.sealBlock(sealed);
}
-void mine(BlockInfo& _bi)
+void mine(Ethash::BlockHeader& _bi)
{
- GenericFarm<ProofOfWork> f;
- bool completed = false;
- f.onSolutionFound([&](ProofOfWork::Solution sol)
- {
- ProofOfWork::assignResult(sol, _bi);
- return completed = true;
- });
- f.setWork(_bi);
- f.startCPU();
- while (!completed)
- this_thread::sleep_for(chrono::milliseconds(20));
+ std::unique_ptr<SealEngineFace> sealer(Ethash::createSealEngine());
+ Notified<bytes> sealed;
+ sealer->onSealGenerated([&](bytes const& sealedHeader){ sealed = sealedHeader; });
+ sealer->generateSeal(_bi);
+ sealed.waitNot({});
+ _bi = Ethash::BlockHeader(sealed);
}
}
@@ -151,13 +143,24 @@ void ImportTest::importEnv(json_spirit::mObject& _o)
assert(_o.count("currentCoinbase") > 0);
assert(_o.count("currentNumber") > 0);
- m_environment.currentBlock.parentHash = h256(_o["previousHash"].get_str());
- m_environment.currentBlock.number = toInt(_o["currentNumber"]);
- m_environment.currentBlock.gasLimit = toInt(_o["currentGasLimit"]);
- m_environment.currentBlock.difficulty = toInt(_o["currentDifficulty"]);
- m_environment.currentBlock.timestamp = toInt(_o["currentTimestamp"]);
- m_environment.currentBlock.coinbaseAddress = Address(_o["currentCoinbase"].get_str());
-
+ RLPStream rlpStream;
+ rlpStream.appendList(BlockInfo::BasicFields);
+
+ rlpStream << h256(_o["previousHash"].get_str());
+ rlpStream << EmptyListSHA3;
+ rlpStream << Address(_o["currentCoinbase"].get_str());
+ rlpStream << h256(); // stateRoot
+ rlpStream << EmptyTrie; // transactionTrie
+ rlpStream << EmptyTrie; // receiptTrie
+ rlpStream << LogBloom(); // bloom
+ rlpStream << toInt(_o["currentDifficulty"]);
+ rlpStream << toInt(_o["currentNumber"]);
+ rlpStream << toInt(_o["currentGasLimit"]);
+ rlpStream << 0; //gasUsed
+ rlpStream << toInt(_o["currentTimestamp"]);
+ rlpStream << std::string(); //extra data
+
+ m_environment.currentBlock = BlockInfo(rlpStream.out(), CheckEverything, h256{}, HeaderData);
m_statePre.m_previousBlock = m_environment.previousBlock;
m_statePre.m_currentBlock = m_environment.currentBlock;
}
@@ -817,6 +820,43 @@ LastHashes lastHashes(u256 _currentBlockNumber)
return ret;
}
+dev::eth::Ethash::BlockHeader constructHeader(
+ h256 const& _parentHash,
+ h256 const& _sha3Uncles,
+ Address const& _coinbaseAddress,
+ h256 const& _stateRoot,
+ h256 const& _transactionsRoot,
+ h256 const& _receiptsRoot,
+ dev::eth::LogBloom const& _logBloom,
+ u256 const& _difficulty,
+ u256 const& _number,
+ u256 const& _gasLimit,
+ u256 const& _gasUsed,
+ u256 const& _timestamp,
+ bytes const& _extraData)
+{
+ RLPStream rlpStream;
+ rlpStream.appendList(Ethash::BlockHeader::Fields);
+
+ rlpStream << _parentHash << _sha3Uncles << _coinbaseAddress << _stateRoot << _transactionsRoot << _receiptsRoot << _logBloom
+ << _difficulty << _number << _gasLimit << _gasUsed << _timestamp << _extraData << h256{} << Nonce{};
+
+ return Ethash::BlockHeader(rlpStream.out());
+}
+
+void updateEthashSeal(dev::eth::Ethash::BlockHeader& _header, h256 const& _mixHash, dev::eth::Nonce const& _nonce)
+{
+ RLPStream source;
+ _header.streamRLP(source);
+ RLP sourceRlp(source.out());
+ RLPStream header;
+ header.appendList(Ethash::BlockHeader::Fields);
+ for (size_t i = 0; i < BlockInfo::BasicFields; i++)
+ header << sourceRlp[i];
+
+ header << _mixHash << _nonce;
+ _header = Ethash::BlockHeader(header.out());
+}
namespace
{
diff --git a/TestHelper.h b/TestHelper.h
index 4ac59e91..73553549 100644
--- a/TestHelper.h
+++ b/TestHelper.h
@@ -27,6 +27,7 @@
#include <boost/filesystem.hpp>
#include "JsonSpiritHeaders.h"
+#include <libethcore/Ethash.h>
#include <libethereum/State.h>
#include <libevm/ExtVMFace.h>
#include <libtestutils/Common.h>
@@ -62,7 +63,7 @@ class State;
void mine(Client& c, int numBlocks);
void connectClients(Client& c1, Client& c2);
void mine(State& _s, BlockChain const& _bc);
-void mine(BlockInfo& _bi);
+void mine(Ethash::BlockHeader& _bi);
}
@@ -175,7 +176,21 @@ void checkOutput(bytes const& _output, json_spirit::mObject& _o);
void checkStorage(std::map<u256, u256> _expectedStore, std::map<u256, u256> _resultStore, Address _expectedAddr);
void checkLog(eth::LogEntries _resultLogs, eth::LogEntries _expectedLogs);
void checkCallCreates(eth::Transactions _resultCallCreates, eth::Transactions _expectedCallCreates);
-
+dev::eth::Ethash::BlockHeader constructHeader(
+ h256 const& _parentHash,
+ h256 const& _sha3Uncles,
+ Address const& _coinbaseAddress,
+ h256 const& _stateRoot,
+ h256 const& _transactionsRoot,
+ h256 const& _receiptsRoot,
+ dev::eth::LogBloom const& _logBloom,
+ u256 const& _difficulty,
+ u256 const& _number,
+ u256 const& _gasLimit,
+ u256 const& _gasUsed,
+ u256 const& _timestamp,
+ bytes const& _extraData);
+void updateEthashSeal(dev::eth::Ethash::BlockHeader& _header, h256 const& _mixHash, dev::eth::Nonce const& _nonce);
void executeTests(const std::string& _name, const std::string& _testPathAppendix, const boost::filesystem::path _pathToFiller, std::function<void(json_spirit::mValue&, bool)> doTests);
void userDefinedTest(std::function<void(json_spirit::mValue&, bool)> doTests);
RLPStream createRLPStreamFromTransactionFields(json_spirit::mObject& _tObj);
diff --git a/libsolidity/solidityExecutionFramework.h b/libsolidity/solidityExecutionFramework.h
index f4dbbcb9..0e863701 100644
--- a/libsolidity/solidityExecutionFramework.h
+++ b/libsolidity/solidityExecutionFramework.h
@@ -41,7 +41,11 @@ namespace test
class ExecutionFramework
{
public:
- ExecutionFramework() { g_logVerbosity = 0; }
+ ExecutionFramework()
+ {
+ g_logVerbosity = 0;
+ m_state.resetCurrent();
+ }
bytes const& compileAndRunWithoutCheck(
std::string const& _sourceCode,