提交 c059de75 编写于 作者: A Andrianto Lie

Add additional test case for 1972

上级 124c62d0
......@@ -89,8 +89,11 @@ namespace eosio { namespace testing {
uint32_t expiration = DEFAULT_EXPIRATION_DELTA,
uint32_t delay_sec = 0)const;
void create_accounts( vector<account_name> names, bool multisig = false ) {
for( auto n : names ) create_account(n, config::system_account_name, multisig );
vector<transaction_trace> create_accounts( vector<account_name> names, bool multisig = false ) {
vector<transaction_trace> traces;
traces.reserve(names.size());
for( auto n : names ) traces.emplace_back(create_account(n, config::system_account_name, multisig ));
return traces;
}
void push_genesis_block();
......@@ -105,7 +108,7 @@ namespace eosio { namespace testing {
void delete_authority( account_name account, permission_name perm, const vector<permission_level>& auths, const vector<private_key_type>& keys );
void delete_authority( account_name account, permission_name perm );
void create_account( account_name name, account_name creator = config::system_account_name, bool multisig = false );
transaction_trace create_account( account_name name, account_name creator = config::system_account_name, bool multisig = false );
transaction_trace push_reqauth( account_name from, const vector<permission_level>& auths, const vector<private_key_type>& keys );
transaction_trace push_reqauth(account_name from, string role, bool multi_sig = false);
......
......@@ -131,7 +131,7 @@ namespace eosio { namespace testing {
}
void base_tester::create_account( account_name a, account_name creator, bool multisig ) {
transaction_trace base_tester::create_account( account_name a, account_name creator, bool multisig ) {
signed_transaction trx;
set_transaction_headers(trx);
......@@ -154,7 +154,7 @@ namespace eosio { namespace testing {
set_transaction_headers(trx);
trx.sign( get_private_key( creator, "active" ), chain_id_type() );
push_transaction( trx );
return push_transaction( trx );
}
transaction_trace base_tester::push_transaction( packed_transaction& trx, uint32_t skip_flag ) { try {
......
......@@ -956,4 +956,49 @@ BOOST_AUTO_TEST_CASE(get_required_keys)
} FC_LOG_AND_RETHROW() }
// Test transaction_mroot matches with the specification in Github #1972 https://github.com/EOSIO/eos/issues/1972
// Which is a root of a Merkle tree over commitments for each region processed in the block ordered in ascending region id order.
// Commitment for each region is a merkle tree over commitments for each shard inside the cycle of that region.
// Commitment for the shard itself is a merkle tree over the transactions commitments inside that shard.
// The transaction commitment is digest of the concentanation of region_id, cycle_index, shard_index, tx_index,
// transaction_receipt and packed_trx_digest (if the tx is an input tx, which doesn't include implicit/ deferred tx)
BOOST_AUTO_TEST_CASE(transaction_mroot)
{ try {
validating_tester chain;
// Finalize current block (which has set contract transaction for eosio)
chain.produce_block();
// any transaction will do
vector<transaction_trace> traces = chain.create_accounts({"test1", "test2", "test3"});
// Calculate expected tx roots
vector<digest_type> tx_roots;
for( uint64_t tx_index = 0; tx_index < traces.size(); tx_index++ ) {
const auto& tx = traces[tx_index];
digest_type::encoder enc;
// region_id, cycle_index, shard_index, tx_index, transaction_receipt and packed_trx_digest (if the tx is an input tx)
fc::raw::pack( enc, tx.region_id );
fc::raw::pack( enc, tx.cycle_index );
fc::raw::pack( enc, tx.shard_index );
fc::raw::pack( enc, tx_index );
fc::raw::pack( enc, *static_cast<const transaction_receipt*>(&tx) );
if( tx.packed_trx_digest.valid() ) fc::raw::pack( enc, *tx.packed_trx_digest );
tx_roots.emplace_back(enc.result());
}
auto expected_shard_tx_root = merkle(tx_roots);
// Hardcoded on_block tx_root, since there's no easy way to calculate the tx_root with current interface
auto on_block_tx_root = digest_type("aa63d366cc2ef41746bb150258d1c0662c8133469f785425cb996dbe2a227086");
// There is only 1 region, 2 cycle, 1 shard in first cycle, 1 shard in second cycle
auto expected_tx_mroot = merkle({on_block_tx_root, expected_shard_tx_root});
// Compare with head block tx mroot
chain.produce_block();
auto head_block_tx_mroot = chain.control->head_block_header().transaction_mroot;
BOOST_TEST(expected_tx_mroot.str() == head_block_tx_mroot.str());
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册