Skip to content

Commit

Permalink
Fix setup_chains to use state block instead of legacy blocks. (#4188)
Browse files Browse the repository at this point in the history
Fix issue where functions were not using the specified source account and were directly using the dev genesis account.
  • Loading branch information
clemahieu committed Mar 20, 2023
1 parent e8ddd83 commit 6c10b9f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
46 changes: 28 additions & 18 deletions nano/test_common/chains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ nano::block_list_t nano::test::setup_chain (nano::test::system & system, nano::n

balance -= 1;
auto send = builder
.send ()
.state ()
.account (target.pub)
.previous (latest)
.destination (throwaway.pub)
.representative (throwaway.pub)
.balance (balance)
.link (throwaway.pub)
.sign (target.prv, target.pub)
.work (*system.work.generate (latest))
.build_shared ();
Expand Down Expand Up @@ -53,19 +55,23 @@ std::vector<std::pair<nano::account, nano::block_list_t>> nano::test::setup_chai

balance -= block_count * 2; // Send enough to later create `block_count` blocks
auto send = builder
.send ()
.state ()
.account (source.pub)
.previous (latest)
.destination (key.pub)
.representative (source.pub)
.balance (balance)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.link (key.pub)
.sign (source.prv, source.pub)
.work (*system.work.generate (latest))
.build_shared ();

auto open = builder
.open ()
.source (send->hash ())
.representative (key.pub)
.state ()
.account (key.pub)
.previous (0)
.representative (key.pub)
.balance (block_count * 2)
.link (send->hash ())
.sign (key.prv, key.pub)
.work (*system.work.generate (key.pub))
.build_shared ();
Expand Down Expand Up @@ -107,12 +113,12 @@ nano::block_list_t nano::test::setup_independent_blocks (nano::test::system & sy
balance -= 1;
auto send = builder
.state ()
.account (nano::dev::genesis_key.pub)
.account (source.pub)
.previous (latest)
.representative (nano::dev::genesis_key.pub)
.representative (source.pub)
.balance (balance)
.link (key.pub)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.sign (source.prv, source.pub)
.work (*system.work.generate (latest))
.build_shared ();

Expand Down Expand Up @@ -151,19 +157,23 @@ nano::keypair nano::test::setup_rep (nano::test::system & system, nano::node & n
nano::block_builder builder;

auto send = builder
.send ()
.state ()
.account (source.pub)
.previous (latest)
.destination (key.pub)
.representative (source.pub)
.balance (balance - amount)
.sign (nano::dev::genesis_key.prv, nano::dev::genesis_key.pub)
.link (key.pub)
.sign (source.prv, source.pub)
.work (*system.work.generate (latest))
.build_shared ();

auto open = builder
.open ()
.source (send->hash ())
.representative (key.pub)
.state ()
.account (key.pub)
.previous (0)
.representative (key.pub)
.balance (amount)
.link (send->hash ())
.sign (key.prv, key.pub)
.work (*system.work.generate (key.pub))
.build_shared ();
Expand All @@ -173,4 +183,4 @@ nano::keypair nano::test::setup_rep (nano::test::system & system, nano::node & n
EXPECT_TIMELY (5s, nano::test::confirmed (node, { send, open }));

return key;
}
}
6 changes: 3 additions & 3 deletions nano/test_common/chains.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
namespace nano::test
{
/**
* Creates `count` random 1 raw send blocks in a `target` account chain
* Creates `count` random 1 raw send blocks in a `source` account chain
* @returns created blocks
*/
nano::block_list_t setup_chain (nano::test::system & system, nano::node & node, int count, nano::keypair target = nano::dev::genesis_key, bool confirm = true);
nano::block_list_t setup_chain (nano::test::system & system, nano::node & node, int count, nano::keypair source = nano::dev::genesis_key, bool confirm = true);

/**
* Creates `chain_count` account chains, each with `block_count` 1 raw random send blocks, all accounts are seeded from `source` account
Expand All @@ -37,4 +37,4 @@ nano::block_list_t setup_independent_blocks (nano::test::system & system, nano::
* @return created representative
*/
nano::keypair setup_rep (nano::test::system & system, nano::node & node, nano::uint128_t amount, nano::keypair source = nano::dev::genesis_key);
}
}

0 comments on commit 6c10b9f

Please sign in to comment.