Fix setup_chains to use state block instead of legacy blocks. (#4188)

Fix issue where functions were not using the specified source account and were directly using the dev genesis account.
This commit is contained in:
clemahieu 2023-03-20 19:58:28 +00:00 committed by GitHub
commit 6c10b9f705
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 21 deletions

View file

@ -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 ();
@ -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 ();
@ -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 ();
@ -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 ();
@ -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;
}
}

View file

@ -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
@ -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);
}
}