40 TestTransaction::TestTransaction(
mObject const& _o):
58 m_state.get()->commit(State::CommitBehaviour::KeepEmptyAccounts);
78 for (
auto const& tr: root[1])
80 Transaction tx(tr.data(), CheckTransaction::Everything);
86 for (
auto const& uRLP: root[2])
123 catch (exception
const& _e)
194 block.
sync(blockchain);
201 cnote <<
"Dropped invalid Transactions when mining!";
211 catch (std::exception
const& _e)
219 for (
size_t i = 0; i < validTransactions; i++)
235 for (
unsigned i = 0; i <
m_uncles.size(); ++i)
238 m_uncles[i].blockHeader().streamRLP(uncleRlp);
269 catch (std::exception
const& _e)
283 rlpStream.
appendList(_tObj.count(
"hash") > 0 ? (_tObj.size() - 1) : _tObj.size());
285 if (_tObj.count(
"parentHash"))
288 if (_tObj.count(
"uncleHash"))
291 if (_tObj.count(
"coinbase"))
295 rlpStream << _stateRoot;
296 else if (_tObj.count(
"stateRoot"))
299 if (_tObj.count(
"transactionsTrie"))
302 if (_tObj.count(
"receiptTrie"))
305 if (_tObj.count(
"bloom"))
308 if (_tObj.count(
"difficulty"))
309 rlpStream <<
bigint(_tObj.at(
"difficulty").get_str());
311 if (_tObj.count(
"number"))
312 rlpStream <<
bigint(_tObj.at(
"number").get_str());
314 if (_tObj.count(
"gasLimit"))
315 rlpStream <<
bigint(_tObj.at(
"gasLimit").get_str());
317 if (_tObj.count(
"gasUsed"))
318 rlpStream <<
bigint(_tObj.at(
"gasUsed").get_str());
320 if (_tObj.count(
"timestamp"))
321 rlpStream <<
bigint(_tObj.at(
"timestamp").get_str());
323 if (_tObj.count(
"extraData"))
324 rlpStream <<
fromHex(_tObj.at(
"extraData").get_str());
326 if (_tObj.count(
"mixHash"))
329 if (_tObj.count(
"nonce"))
332 return rlpStream.
out();
362 string exWhat { _e.
what() };
363 string exExpect =
"InvalidTransactionsRoot";
364 BOOST_REQUIRE_MESSAGE(exWhat.find(exExpect) != string::npos,
TestOutputHelper::testName() +
"block import expected another exeption: " + exExpect);
371 BOOST_ERROR(
TestOutputHelper::testName() +
"BlockHeader Verification failed: " << boost::current_exception_diagnostic_information());
380 txList.push_back(txi);
383 for (
unsigned i = 0; i < txList.size(); ++i)
386 txList[i].streamRLP(txrlp);
392 for (
unsigned i = 0; i <
m_uncles.size(); ++i)
395 m_uncles[i].blockHeader().streamRLP(uncleRlp);
422 for (
size_t i = 0; i <
m_uncles.size(); i++)
435 cnote << _ex.
what() <<
"copying block with null state";
452 reset(_genesisBlock);
461 if (!m_blockChain->isKnown(BlockHeader::headerHashFromBlock(_genesisBlock.
bytes())))
464 cdebug <<
"Genesis block not known!";
465 cdebug <<
"This should never happen.";
468 m_lastBlock = m_genesisBlock = _genesisBlock;
478 m_blockChain.get()->import(_block.
bytes(), m_genesisBlock.state().db());
483 this_thread::sleep_for(chrono::milliseconds(100));
489 if (_block.
bytes() == m_blockChain.get()->block())
491 m_lastBlock = _block;
494 OverlayDB const& genesisDB = m_genesisBlock.state().
db();
495 Block block = (m_blockChain.get()->genesisBlock(genesisDB));
496 block.
sync(*m_blockChain.get());
508 vector<TestBlock> validUncles;
509 if (uncles.size() == 0)
514 uncleBlockQueue.
setChain(blockchain);
516 for (
size_t i = 0; i < uncles.size(); i++)
520 uncleBlockQueue.
import(&uncles.at(i).bytes(),
false);
521 this_thread::sleep_for(chrono::seconds(1));
522 validUncles.push_back(uncles.at(i));
526 cnote <<
"error in importing uncle! This produces an invalid block (May be by purpose for testing).";
530 blockchain.
sync(uncleBlockQueue, m_genesisBlock.state().db(), (unsigned)4);
537 txObj[
"data"] =
toHex(_data);
538 txObj[
"gasLimit"] =
toString(_gasLimit);
539 txObj[
"gasPrice"] =
toString(_gasPrice);
541 txObj[
"secretKey"] =
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8";
542 txObj[
"to"] =
"095e7baea6a6c7c4c2dfeb977efac326af552d87";
543 txObj[
"value"] =
"100";
551 ret[
Address(
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b")] =
Account(0, 10000000000);
558 blockObj[
"bloom"] =
"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
559 blockObj[
"coinbase"] =
"0x8888f1f195afa192cfee860698584c030f4c9db1";
560 blockObj[
"difficulty"] =
"131072";
561 blockObj[
"extraData"] =
"0x42";
562 blockObj[
"gasLimit"] =
"3141592";
563 blockObj[
"gasUsed"] =
"0";
564 blockObj[
"mixHash"] =
"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421";
565 blockObj[
"nonce"] =
"0x0102030405060708";
566 blockObj[
"number"] =
"0";
567 blockObj[
"parentHash"] =
"0x0000000000000000000000000000000000000000000000000000000000000000";
568 blockObj[
"receiptTrie"] =
"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421";
569 blockObj[
"stateRoot"] =
"0xf99eb1626cfa6db435c0836235942d7ccaa935f1ae247d3f1c21e495685f903a";
570 blockObj[
"timestamp"] =
"0x54c98c81";
571 blockObj[
"transactionsTrie"] =
"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421";
572 blockObj[
"uncleHash"] =
"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347";
579 blockObj[
"gasLimit"] =
toString(_gasLimit);
582 accountObj[
"balance"] =
"10000000000";
583 accountObj[
"nonce"] =
"1";
584 accountObj[
"code"] =
"";
588 accountMapObj[
"a94f5374fce5edbc8e2a8697c15331677e6ebf0b"] = accountObj;
590 return TestBlock(blockObj, accountMapObj);
BlockHeader m_blockHeader
bytes const & blockData() const
Get the complete current block, including valid nonce.
vector< TestTransaction > m_testTransactions
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
State const & state() const
Get the backing state object.
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
std::pair< TransactionReceipts, bool > sync(BlockChain const &_bc, TransactionQueue &_tq, GasPricer const &_gp, unsigned _msTimeout=100)
Sync our transactions, killing those from the queue that we have and assimilating those that we don't...
std::map< std::string, bool > m_premineUpdate
A queue of Transactions, each stored as RLP.
static AccountMap defaultAccountMap()
ChainOperationParams const & chainParams() const
std::unordered_map< Address, Account > AccountMap
State fromPending(unsigned _i) const
Get the State immediately after the given number of pending transactions have been applied...
bytes genesisBlock() const
Genesis block info.
Implements the blockchain database.
static TestTransaction defaultTransaction(u256 const &_nonce=1, u256 const &_gasPrice=1, u256 const &_gasLimit=50000, bytes const &_data=bytes())
BlockChain const & interface() const
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>> bigint
Models the state of a single Ethereum account.
bytes const & out() const
Read the byte stream.
BlockHeader m_premineHeader
static std::string const & testName()
const char * what() const noexceptoverride
ImportResult import(bytesConstRef _block, bool _isOurs=false)
Import a block into the queue.
h160 Address
An Ethereum address: 20 bytes.
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
static TestBlock defaultGenesisBlock(u256 const &_gasLimit=DefaultBlockGasLimit)
Block genesisBlock(OverlayDB const &_db) const
Get a pre-made genesis State object.
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
BlockHeader const & blockHeader() const
static eth::Network s_sealEngineNetwork
Model of an Ethereum state, essentially a facade for the trie.
OverlayDB const & db() const
TransactionReceipt const & receipt(unsigned _i) const
Get the transaction receipt for the transaction of the given index.
void setState(State const &_state)
void updateNonce(TestBlockChain const &_bc)
bytes rlp(IncludeSignature _sig=WithSignature) const
TransactionQueue m_transactionQueue
Transactions topTransactions(unsigned _limit, h256Hash const &_avoid=h256Hash()) const
Get top transactions from the queue.
Active model of a block within the block chain.
TestBlock const & testGenesis() const
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
static void importState(json_spirit::mObject const &_o, eth::State &_state)
Base class for all exceptions.
vector< TestTransaction > const & testTransactions() const
dev::bytes createBlockRLPFromFields(mObject const &_tObj, h256 const &_stateRoot=h256{})
std::vector< byte > bytes
void clear()
Clear the queue.
BlockHeader constructBlock(mObject const &_o, h256 const &_stateRoot)
Test Block Private.
RLPStream & appendList(size_t _items)
Appends a list.
void populateFrom(TestBlock const &_original)
json_spirit::mObject fillJsonWithState(State const &_state)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
ImportResult import(bytes const &_tx, IfDropped _ik=IfDropped::Ignore)
Verify and add transaction to the queue synchronously.
Encodes a transaction, ready to be exported to or freshly imported from RLP.
mConfig::Object_type mObject
bool addBlock(TestBlock const &_block)
void premineUpdate(BlockHeader &info)
void recalcBlockHeaderBytes()
int g_logVerbosity
The logging system's current verbosity.
void mine(TestBlockChain const &_bc)
void replaceLLLinState(json_spirit::mObject &_o)
void setAuthor(Address const &_id)
Set the author address for any transactions we do and rewards we get.
TransactionQueue const & transactionQueue() const
u256 u256Param(std::string const &_name) const
Convenience method to get an otherParam as a u256 int.
State const & state() const
std::string const & genesisInfo(Network _n)
vector< TestBlock > const & uncles() const
Value_type::String_type write_string(const Value_type &value, bool pretty)
std::unique_ptr< State > m_state
dev::bytes const & bytes() const
static json_spirit::mObject defaultGenesisBlockJson()
void setUncles(vector< TestBlock > const &_uncles)
AccountMap jsonToAccountMap(std::string const &_json, u256 const &_defaultNonce=0, AccountMaskMap *o_mask=nullptr, PrecompiledContractMap *o_precompiled=nullptr)
void setChain(BlockChain const &_bc)
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
void copyStateFrom(State const &_state)
void addTransaction(TestTransaction const &_tr)
std::unique_ptr< TransientDirectory > m_tempDirState
Transaction const & transaction() const
TestBlock & operator=(TestBlock const &_original)
void verify(TestBlockChain const &_bc) const
void reset(TestBlock const &_genesisBlock)
bytes importByteArray(std::string const &_str)
std::tuple< ImportRoute, bool, unsigned > sync(BlockQueue &_bq, OverlayDB const &_stateDB, unsigned _max)
Sync the chain with any incoming blocks.
Address const & beneficiary() const
vector< TestBlock > syncUncles(vector< TestBlock > const &_uncles)
void addUncle(TestBlock const &_uncle)
static void importTransaction(json_spirit::mObject const &_o, eth::Transaction &o_tr)
Class for writing to an RLP bytestream.
temporary directory implementation It creates temporary directory in the given path.
RLPStream & appendRaw(bytesConstRef _rlp, size_t _itemCount=1)
Appends raw (pre-serialised) RLP data. Use with caution.
void mine(Client &c, int numBlocks)
Class for interpreting Recursive Linear-Prefix Data.
Transaction m_transaction
void setBlockHeader(BlockHeader const &_header)
virtual void verify(Strictness _s, BlockHeader const &_bi, BlockHeader const &_parent=BlockHeader(), bytesConstRef _block=bytesConstRef()) const
Don't forget to call Super::verify when subclassing & overriding.
SealEngineFace * sealEngine() const
BlockHeader const & info() const
Get the header information on the present block.
Helper functions to work with json::spirit and test files.
AccountMap const & accountMap() const
vector< TestBlock > m_uncles