23 #include <boost/filesystem/operations.hpp> 24 #include <boost/test/unit_test.hpp> 25 #include <boost/filesystem.hpp> 48 m_path(
boost::filesystem::temp_directory_path().string() +
"/" +
toString(
chrono::system_clock::now().time_since_epoch().
count()) +
"-" +
FixedHash<4>::random().hex()),
54 sealer()->onSealGenerated([&](
bytes const& sealedHeader){
55 sealed = sealedHeader;
66 sealer()->generateSeal(_block.
info());
79 cnote <<
"Importing sealed: " <<
sha3(sealed);
81 m_bc.import(_block.
blockData(), m_stateDB);
85 void import(
Block const& _block)
87 m_bc.import(_block.blockData(), m_stateDB);
94 m_bc.insert(_block.
blockData(), &receipts);
95 assert(m_bc.isKnown(bi.hash(),
false));
116 ret.push_back(i.toHash<
h256>());
120 if (r[1].
size() == 32)
133 while (!todo.empty())
135 h256 h = todo.back();
140 cnote <<
" More: " << s;
145 for (
auto const&
d: data)
154 BasicAuthority::init();
155 BasicAuthority::init();
166 Block block = tcFull.bc().genesisBlock(tcFull.db());
170 block.sync(tcFull.bc());
173 cnote <<
"First seal and import";
174 tcFull.sealAndImport(block);
177 cnote <<
"Insert into light";
178 tcLight.insert(block, tcFull.bc());
181 cnote <<
"Syncing light state";
182 syncStateTrie(&block.blockData(), tcFull.db(), tcLight.db());
187 cnote <<
"Prep block";
188 block.sync(tcFull.bc());
189 cnote << block.state();
190 while (
utcTime() < block.info().timestamp())
191 this_thread::sleep_for(chrono::milliseconds(100));
196 cnote <<
"Execute transaction";
197 block.execute(tcFull.bc().lastHashes(), t);
198 cnote << block.state();
201 cnote <<
"Seal and import";
202 tcFull.sealAndImport(block);
203 cnote <<
"Import into light";
204 tcLight.import(block);
206 cnote << tcFull.bc();
207 cnote << tcLight.bc();
208 block.sync(tcFull.bc());
210 cnote << block.state();
211 cnote << tcFull.bc().dumpDatabase();
212 cnote << tcLight.bc().dumpDatabase();
213 BOOST_REQUIRE_EQUAL(tcFull.bc().dumpDatabase(), tcLight.bc().dumpDatabase());
bytes const & blockData() const
Get the complete current block, including valid nonce.
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::string toHex(T const &_data, int _w=2, HexPrefix _prefix=HexPrefix::DontAdd)
h256s subs(bytesConstRef _node)
Implements the blockchain database.
bytes rlp(_T _t)
Export a single item in RLP format, returning a byte array.
uint64_t utcTime()
Get the current time in seconds since the epoch in UTC.
Simple class that represents a "key pair".
BlockReceipts receipts(h256 const &_hash) const
Get the transactions' receipts of a block (or the most recent mined if none given).
SealEngineFace * sealer() const
SecureFixedHash< 32 > Secret
void commitToSeal(BlockChain const &_bc, bytes const &_extraData={})
Prepares the current state for mining.
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
void syncStateTrie(bytesConstRef _block, OverlayDB const &_dbSource, OverlayDB &_dbDest)
Secret const & secret() const
std::string toString(string32 const &_s)
Make normal string from fixed-length string.
void sealAndImport(Block &_block)
Model of an Ethereum state, essentially a facade for the trie.
std::string lookup(h256 const &_h) const
Active model of a block within the block chain.
_N toHash(int _flags=Strict) const
FixedHash< T > const & makeInsecure() const
void insert(Block const &_block, BlockChain const &_bcSource)
std::vector< byte > bytes
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
bytes asBytes(std::string const &_b)
Converts a string to a byte array containing the string's (byte) data.
bool sealBlock(bytes const &_header)
Pass in a properly sealed header matching this block.
void insert(h256 const &_h, bytesConstRef _v)
Encodes a transaction, ready to be exported to or freshly imported from RLP.
Address toAddress(Public const &_public)
Convert a public key to address.
bytes rlpList()
Export a list of items in RLP format, returning a byte array.
Address const & address() const
Retrieve the associated address of the public key.
int g_logVerbosity
The logging system's current verbosity.
void setAuthor(Address const &_id)
Set the author address for any transactions we do and rewards we get.
#define BOOST_FIXTURE_TEST_SUITE(a, b)
uint8_t const size_t const size
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
#define BOOST_AUTO_TEST_SUITE_END()
std::vector< h256 > h256s
BOOST_AUTO_TEST_CASE(bcBasicInsert)
Class for interpreting Recursive Linear-Prefix Data.
std::string const c_genesisInfoTestBasicAuthority
BlockHeader const & info() const
Get the header information on the present block.
TestClient(Secret const &_authority)
Helper functions to work with json::spirit and test files.