Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add work check for ledger::process () in Debug mode #1939

Merged
merged 3 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions nano/core_test/block_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,8 @@ TEST (block_store, upgrade_v2_v3)
store.initialize (transaction, genesis);
nano::stat stats;
nano::ledger ledger (store, stats);
nano::change_block change (hash, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::change_block change (hash, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (hash));
change_hash = change.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, change).code);
ASSERT_EQ (0, ledger.weight (transaction, nano::test_genesis_key.pub));
Expand Down Expand Up @@ -890,7 +891,8 @@ TEST (block_store, upgrade_v4_v5)
nano::account_info info;
ASSERT_FALSE (store.account_get (transaction, nano::test_genesis_key.pub, info));
nano::keypair key0;
nano::send_block block0 (info.head, key0.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::send_block block0 (info.head, key0.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (info.head));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block0).code);
hash = block0.hash ();
auto original (store.block_get (transaction, info.head));
Expand Down Expand Up @@ -1211,7 +1213,8 @@ TEST (block_store, upgrade_sideband_two_blocks)
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis);
nano::state_block block (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::state_block block (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
hash2 = block.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block).code);
write_legacy_sideband (store, transaction, *genesis.open, hash2, store.open_blocks);
Expand Down Expand Up @@ -1250,10 +1253,11 @@ TEST (block_store, upgrade_sideband_two_accounts)
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis);
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
hash2 = block1.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block1).code);
nano::state_block block2 (key.pub, 0, nano::test_genesis_key.pub, nano::Gxrb_ratio, hash2, key.prv, key.pub, 0);
nano::state_block block2 (key.pub, 0, nano::test_genesis_key.pub, nano::Gxrb_ratio, hash2, key.prv, key.pub, pool.generate (key.pub));
hash3 = block2.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block2).code);
write_legacy_sideband (store, transaction, *genesis.open, hash2, store.open_blocks);
Expand Down Expand Up @@ -1294,7 +1298,8 @@ TEST (block_store, insert_after_legacy)
store.version_put (transaction, 11);
store.initialize (transaction, genesis);
write_legacy_sideband (store, transaction, *genesis.open, 0, store.open_blocks);
nano::state_block block (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::state_block block (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block).code);
}

Expand All @@ -1321,6 +1326,7 @@ TEST (block_store, upgrade_sideband_epoch)
nano::genesis genesis;
nano::block_hash hash2;
auto path (nano::unique_path ());
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
{
nano::logger_mt logger;
nano::mdb_store store (error, logger, path);
Expand All @@ -1330,7 +1336,7 @@ TEST (block_store, upgrade_sideband_epoch)
auto transaction (store.tx_begin_write ());
store.version_put (transaction, 11);
store.initialize (transaction, genesis);
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount, 42, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block block1 (nano::test_genesis_key.pub, genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount, 42, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
hash2 = block1.hash ();
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block1).code);
ASSERT_EQ (nano::epoch::epoch_1, store.block_version (transaction, hash2));
Expand All @@ -1349,7 +1355,7 @@ TEST (block_store, upgrade_sideband_epoch)
nano::block_sideband sideband;
auto block1 (store.block_get (transaction, hash2, &sideband));
ASSERT_NE (0, sideband.height);
nano::state_block block2 (nano::test_genesis_key.pub, hash2, nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block block2 (nano::test_genesis_key.pub, hash2, nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (hash2));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, block2).code);
ASSERT_EQ (nano::epoch::epoch_1, store.block_version (transaction, block2.hash ()));
}
Expand All @@ -1370,29 +1376,30 @@ TEST (block_store, sideband_height)
ledger.epoch_signer = epoch_key.pub;
auto transaction (store.tx_begin_write ());
store.initialize (transaction, genesis);
nano::send_block send (genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::work_pool pool (std::numeric_limits<unsigned>::max ());
nano::send_block send (genesis.hash (), nano::test_genesis_key.pub, nano::genesis_amount - nano::Gxrb_ratio, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (genesis.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, send).code);
nano::receive_block receive (send.hash (), send.hash (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::receive_block receive (send.hash (), send.hash (), nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (send.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, receive).code);
nano::change_block change (receive.hash (), 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::change_block change (receive.hash (), 0, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (receive.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, change).code);
nano::state_block state_send1 (nano::test_genesis_key.pub, change.hash (), 0, nano::genesis_amount - nano::Gxrb_ratio, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block state_send1 (nano::test_genesis_key.pub, change.hash (), 0, nano::genesis_amount - nano::Gxrb_ratio, key1.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (change.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_send1).code);
nano::state_block state_send2 (nano::test_genesis_key.pub, state_send1.hash (), 0, nano::genesis_amount - 2 * nano::Gxrb_ratio, key2.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block state_send2 (nano::test_genesis_key.pub, state_send1.hash (), 0, nano::genesis_amount - 2 * nano::Gxrb_ratio, key2.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (state_send1.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_send2).code);
nano::state_block state_send3 (nano::test_genesis_key.pub, state_send2.hash (), 0, nano::genesis_amount - 3 * nano::Gxrb_ratio, key3.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, 0);
nano::state_block state_send3 (nano::test_genesis_key.pub, state_send2.hash (), 0, nano::genesis_amount - 3 * nano::Gxrb_ratio, key3.pub, nano::test_genesis_key.prv, nano::test_genesis_key.pub, pool.generate (state_send2.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_send3).code);
nano::state_block state_open (key1.pub, 0, 0, nano::Gxrb_ratio, state_send1.hash (), key1.prv, key1.pub, 0);
nano::state_block state_open (key1.pub, 0, 0, nano::Gxrb_ratio, state_send1.hash (), key1.prv, key1.pub, pool.generate (key1.pub));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_open).code);
nano::state_block epoch (key1.pub, state_open.hash (), 0, nano::Gxrb_ratio, ledger.epoch_link, epoch_key.prv, epoch_key.pub, 0);
nano::state_block epoch (key1.pub, state_open.hash (), 0, nano::Gxrb_ratio, ledger.epoch_link, epoch_key.prv, epoch_key.pub, pool.generate (state_open.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, epoch).code);
ASSERT_EQ (nano::epoch::epoch_1, store.block_version (transaction, epoch.hash ()));
nano::state_block epoch_open (key2.pub, 0, 0, 0, ledger.epoch_link, epoch_key.prv, epoch_key.pub, 0);
nano::state_block epoch_open (key2.pub, 0, 0, 0, ledger.epoch_link, epoch_key.prv, epoch_key.pub, pool.generate (key2.pub));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, epoch_open).code);
ASSERT_EQ (nano::epoch::epoch_1, store.block_version (transaction, epoch_open.hash ()));
nano::state_block state_receive (key2.pub, epoch_open.hash (), 0, nano::Gxrb_ratio, state_send2.hash (), key2.prv, key2.pub, 0);
nano::state_block state_receive (key2.pub, epoch_open.hash (), 0, nano::Gxrb_ratio, state_send2.hash (), key2.prv, key2.pub, pool.generate (epoch_open.hash ()));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, state_receive).code);
nano::open_block open (state_send3.hash (), nano::test_genesis_key.pub, key3.pub, key3.prv, key3.pub, 0);
nano::open_block open (state_send3.hash (), nano::test_genesis_key.pub, key3.pub, key3.prv, key3.pub, pool.generate (key3.pub));
ASSERT_EQ (nano::process_result::progress, ledger.process (transaction, open).code);
nano::block_sideband sideband1;
auto block1 (store.block_get (transaction, genesis.hash (), &sideband1));
Expand Down
Loading