From 604b862c5403f071a66ae78ea7636e3c2a801710 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 29 Oct 2023 13:12:20 +0000 Subject: [PATCH] Add corresponding wallet for each validator node --- pkg/tests/accounts_test.go | 6 +-- pkg/tests/booker_test.go | 10 ++-- pkg/tests/committee_rotation_test.go | 23 +++++----- pkg/tests/loss_of_acceptance_test.go | 6 +-- pkg/tests/protocol_engine_switching_test.go | 2 +- pkg/tests/protocol_startup_test.go | 2 +- pkg/tests/upgrade_signaling_test.go | 2 +- pkg/testsuite/mock/node.go | 8 ++-- pkg/testsuite/mock/utils.go | 2 +- pkg/testsuite/mock/wallet.go | 12 +++-- pkg/testsuite/mock/wallet_transactions.go | 3 ++ pkg/testsuite/snapshotcreator/options.go | 11 +++-- .../snapshotcreator/snapshotcreator.go | 5 +- pkg/testsuite/testsuite.go | 46 ++++++++++++++----- pkg/testsuite/testsuite_issue_blocks.go | 7 ++- tools/genesis-snapshot/main.go | 4 +- tools/genesis-snapshot/presets/presets.go | 4 +- 17 files changed, 92 insertions(+), 61 deletions(-) diff --git a/pkg/tests/accounts_test.go b/pkg/tests/accounts_test.go index f81b996d5..99886583d 100644 --- a/pkg/tests/accounts_test.go +++ b/pkg/tests/accounts_test.go @@ -50,7 +50,7 @@ func Test_TransitionAndDestroyAccount(t *testing.T) { // add a non-validator node to the network. This will not add any accounts to the snapshot. _ = ts.AddNode("node2") // add a default block issuer to the network. This will add another block issuer account to the snapshot. - wallet := ts.AddWallet("default", node1, iotago.MaxBlockIssuanceCredits/2) + wallet := ts.AddGenesisWallet("default", node1, iotago.MaxBlockIssuanceCredits/2) ts.Run(true) @@ -177,7 +177,7 @@ func Test_StakeDelegateAndDelayedClaim(t *testing.T) { // add a non-validator node to the network. This will not add any accounts to the snapshot. _ = ts.AddNode("node2") // add a default block issuer to the network. This will add another block issuer account to the snapshot. - wallet := ts.AddWallet("default", node1, iotago.MaxBlockIssuanceCredits/2) + wallet := ts.AddGenesisWallet("default", node1, iotago.MaxBlockIssuanceCredits/2) ts.Run(true) @@ -352,7 +352,7 @@ func Test_ImplicitAccounts(t *testing.T) { // add a non-validator node to the network. This will not add any accounts to the snapshot. _ = ts.AddNode("node2") // add a default block issuer to the network. This will add another block issuer account to the snapshot. - wallet := ts.AddWallet("default", node1, iotago.MaxBlockIssuanceCredits/2) + wallet := ts.AddGenesisWallet("default", node1, iotago.MaxBlockIssuanceCredits/2) ts.Run(true) diff --git a/pkg/tests/booker_test.go b/pkg/tests/booker_test.go index 4e05b94fa..8a9e2e576 100644 --- a/pkg/tests/booker_test.go +++ b/pkg/tests/booker_test.go @@ -18,7 +18,7 @@ func Test_IssuingTransactionsOutOfOrder(t *testing.T) { defer ts.Shutdown() node1 := ts.AddValidatorNode("node1") - wallet := ts.AddWallet("default", node1) + wallet := ts.AddGenesisWallet("default", node1) ts.Run(true, map[string][]options.Option[protocol.Protocol]{}) tx1 := wallet.CreateBasicOutputsEquallyFromInputs("tx1", 1, "Genesis:0") @@ -54,7 +54,7 @@ func Test_DoubleSpend(t *testing.T) { node1 := ts.AddValidatorNode("node1") node2 := ts.AddValidatorNode("node2") - wallet := ts.AddWallet("default", node1) + wallet := ts.AddGenesisWallet("default", node1) ts.Run(true, map[string][]options.Option[protocol.Protocol]{}) @@ -124,7 +124,7 @@ func Test_MultipleAttachments(t *testing.T) { nodeA := ts.AddValidatorNode("nodeA") nodeB := ts.AddValidatorNode("nodeB") - wallet := ts.AddWallet("default", nodeA) + wallet := ts.AddGenesisWallet("default", nodeA) ts.Run(true, map[string][]options.Option[protocol.Protocol]{}) @@ -246,7 +246,7 @@ func Test_SpendRejectedCommittedRace(t *testing.T) { node1 := ts.AddValidatorNode("node1") node2 := ts.AddValidatorNode("node2") - wallet := ts.AddWallet("default", node1) + wallet := ts.AddGenesisWallet("default", node1) ts.Run(true, map[string][]options.Option[protocol.Protocol]{}) @@ -515,7 +515,7 @@ func Test_SpendPendingCommittedRace(t *testing.T) { node1 := ts.AddValidatorNode("node1") node2 := ts.AddValidatorNode("node2") - wallet := ts.AddWallet("default", node1) + wallet := ts.AddGenesisWallet("default", node1) ts.Run(true, map[string][]options.Option[protocol.Protocol]{}) diff --git a/pkg/tests/committee_rotation_test.go b/pkg/tests/committee_rotation_test.go index 56b4f397d..375a3c98f 100644 --- a/pkg/tests/committee_rotation_test.go +++ b/pkg/tests/committee_rotation_test.go @@ -5,10 +5,10 @@ import ( "github.com/iotaledger/hive.go/runtime/options" "github.com/iotaledger/iota-core/pkg/protocol" - "github.com/iotaledger/iota-core/pkg/protocol/snapshotcreator" "github.com/iotaledger/iota-core/pkg/protocol/sybilprotection/seatmanager/topstakers" "github.com/iotaledger/iota-core/pkg/protocol/sybilprotection/sybilprotectionv1" "github.com/iotaledger/iota-core/pkg/testsuite" + "github.com/iotaledger/iota-core/pkg/testsuite/snapshotcreator" iotago "github.com/iotaledger/iota.go/v4" ) @@ -38,12 +38,13 @@ func Test_TopStakersRotation(t *testing.T) { ) defer ts.Shutdown() - ts.AddValidatorNode("node1", 1_000_006) + node1 := ts.AddValidatorNode("node1", 1_000_006) ts.AddValidatorNode("node2", 1_000_005) ts.AddValidatorNode("node3", 1_000_004) ts.AddValidatorNode("node4", 1_000_003) ts.AddValidatorNode("node5", 1_000_002) ts.AddValidatorNode("node6", 1_000_001) + ts.AddGenesisWallet("default", node1) nodeOptions := make(map[string][]options.Option[protocol.Protocol]) @@ -77,24 +78,24 @@ func Test_TopStakersRotation(t *testing.T) { ts.IssueBlocksAtSlots("wave-1:", []iotago.SlotIndex{1, 2, 3, 4}, 4, "Genesis", ts.Nodes(), true, nil) - ts.IssueCandidacyAnnouncementInSlot("node1-candidacy:1", 4, "wave-1:4.3", ts.Node("node1")) - ts.IssueCandidacyAnnouncementInSlot("node4-candidacy:1", 5, "node1-candidacy:1", ts.Node("node4")) + ts.IssueCandidacyAnnouncementInSlot("node1-candidacy:1", 4, "wave-1:4.3", ts.Wallet("node1")) + ts.IssueCandidacyAnnouncementInSlot("node4-candidacy:1", 5, "node1-candidacy:1", ts.Wallet("node4")) ts.IssueBlocksAtSlots("wave-2:", []iotago.SlotIndex{5, 6, 7, 8, 9}, 4, "node4-candidacy:1", ts.Nodes(), true, nil) - ts.IssueCandidacyAnnouncementInSlot("node4-candidacy:2", 9, "wave-2:9.3", ts.Node("node4")) - ts.IssueCandidacyAnnouncementInSlot("node5-candidacy:1", 9, "node4-candidacy:2", ts.Node("node5")) + ts.IssueCandidacyAnnouncementInSlot("node4-candidacy:2", 9, "wave-2:9.3", ts.Wallet("node4")) + ts.IssueCandidacyAnnouncementInSlot("node5-candidacy:1", 9, "node4-candidacy:2", ts.Wallet("node5")) // This candidacy should be considered as it's announced at the last possible slot. - ts.IssueCandidacyAnnouncementInSlot("node6-candidacy:1", 10, "node5-candidacy:1", ts.Node("node6")) + ts.IssueCandidacyAnnouncementInSlot("node6-candidacy:1", 10, "node5-candidacy:1", ts.Wallet("node6")) ts.IssueBlocksAtSlots("wave-3:", []iotago.SlotIndex{10}, 4, "node6-candidacy:1", ts.Nodes(), true, nil) // Those candidacies should not be considered as they're issued after EpochNearingThreshold (slot 10). - ts.IssueCandidacyAnnouncementInSlot("node2-candidacy:1", 11, "wave-3:10.3", ts.Node("node2")) - ts.IssueCandidacyAnnouncementInSlot("node3-candidacy:1", 11, "node2-candidacy:1", ts.Node("node3")) - ts.IssueCandidacyAnnouncementInSlot("node4-candidacy:3", 11, "node3-candidacy:1", ts.Node("node3")) - ts.IssueCandidacyAnnouncementInSlot("node5-candidacy:2", 11, "node4-candidacy:3", ts.Node("node3")) + ts.IssueCandidacyAnnouncementInSlot("node2-candidacy:1", 11, "wave-3:10.3", ts.Wallet("node2")) + ts.IssueCandidacyAnnouncementInSlot("node3-candidacy:1", 11, "node2-candidacy:1", ts.Wallet("node3")) + ts.IssueCandidacyAnnouncementInSlot("node4-candidacy:3", 11, "node3-candidacy:1", ts.Wallet("node3")) + ts.IssueCandidacyAnnouncementInSlot("node5-candidacy:2", 11, "node4-candidacy:3", ts.Wallet("node3")) // Assert that only candidates that issued before slot 11 are considered. ts.AssertSybilProtectionCandidates(1, []iotago.AccountID{ diff --git a/pkg/tests/loss_of_acceptance_test.go b/pkg/tests/loss_of_acceptance_test.go index 160f57482..a8bb02537 100644 --- a/pkg/tests/loss_of_acceptance_test.go +++ b/pkg/tests/loss_of_acceptance_test.go @@ -33,7 +33,7 @@ func TestLossOfAcceptanceFromGenesis(t *testing.T) { defer ts.Shutdown() node0 := ts.AddValidatorNode("node0") - ts.AddWallet("default", node0) + ts.AddGenesisWallet("default", node0) ts.AddValidatorNode("node1") ts.AddNode("node2") @@ -118,7 +118,7 @@ func TestLossOfAcceptanceFromSnapshot(t *testing.T) { defer ts.Shutdown() node0 := ts.AddValidatorNode("node0") - ts.AddWallet("default", node0) + ts.AddGenesisWallet("default", node0) ts.AddValidatorNode("node1") node2 := ts.AddNode("node2") @@ -212,7 +212,7 @@ func TestLossOfAcceptanceWithRestartFromDisk(t *testing.T) { defer ts.Shutdown() node0 := ts.AddValidatorNode("node0") - ts.AddWallet("default", node0) + ts.AddGenesisWallet("default", node0) ts.AddValidatorNode("node1") node2 := ts.AddNode("node2") diff --git a/pkg/tests/protocol_engine_switching_test.go b/pkg/tests/protocol_engine_switching_test.go index e5a61698f..aa6bf7834 100644 --- a/pkg/tests/protocol_engine_switching_test.go +++ b/pkg/tests/protocol_engine_switching_test.go @@ -56,7 +56,7 @@ func TestProtocol_EngineSwitching(t *testing.T) { node6 := ts.AddValidatorNode("node6") node7 := ts.AddValidatorNode("node7") node8 := ts.AddNode("node8") - ts.AddWallet("default", node0, iotago.MaxBlockIssuanceCredits/2) + ts.AddGenesisWallet("default", node0, iotago.MaxBlockIssuanceCredits/2) const expectedCommittedSlotAfterPartitionMerge = 19 nodesP1 := []*mock.Node{node0, node1, node2, node3, node4, node5} diff --git a/pkg/tests/protocol_startup_test.go b/pkg/tests/protocol_startup_test.go index 5ba4f4960..11b6672d1 100644 --- a/pkg/tests/protocol_startup_test.go +++ b/pkg/tests/protocol_startup_test.go @@ -141,7 +141,7 @@ func Test_StartNodeFromSnapshotAndDisk(t *testing.T) { nodeA := ts.AddValidatorNode("nodeA") nodeB := ts.AddValidatorNode("nodeB") ts.AddNode("nodeC") - ts.AddWallet("default", nodeA, iotago.MaxBlockIssuanceCredits/2) + ts.AddGenesisWallet("default", nodeA, iotago.MaxBlockIssuanceCredits/2) nodeOptions := []options.Option[protocol.Protocol]{ protocol.WithStorageOptions( diff --git a/pkg/tests/upgrade_signaling_test.go b/pkg/tests/upgrade_signaling_test.go index ae80157a0..8f5ed29f3 100644 --- a/pkg/tests/upgrade_signaling_test.go +++ b/pkg/tests/upgrade_signaling_test.go @@ -114,7 +114,7 @@ func Test_Upgrade_Signaling(t *testing.T) { ts.AddValidatorNode("nodeD") ts.AddNode("nodeE") ts.AddNode("nodeF") - wallet := ts.AddWallet("default", nodeA, iotago.MaxBlockIssuanceCredits/2) + wallet := ts.AddGenesisWallet("default", nodeA, iotago.MaxBlockIssuanceCredits/2) ts.Run(true, map[string][]options.Option[protocol.Protocol]{ "nodeA": nodeOptionsWithoutV5, diff --git a/pkg/testsuite/mock/node.go b/pkg/testsuite/mock/node.go index 36112ad13..061730ff9 100644 --- a/pkg/testsuite/mock/node.go +++ b/pkg/testsuite/mock/node.go @@ -48,8 +48,9 @@ func UnregisterIDAliases() { type Node struct { Testing *testing.T - Name string - Validator *BlockIssuer + Name string + Validator *BlockIssuer + KeyManager *KeyManager ctx context.Context ctxCancel context.CancelFunc @@ -95,7 +96,8 @@ func NewNode(t *testing.T, net *Network, partition string, name string, validato Name: name, - Validator: validatorBlockIssuer, + Validator: validatorBlockIssuer, + KeyManager: keyManager, PeerID: peerID, diff --git a/pkg/testsuite/mock/utils.go b/pkg/testsuite/mock/utils.go index 9fb8d20f1..f7cc8adcd 100644 --- a/pkg/testsuite/mock/utils.go +++ b/pkg/testsuite/mock/utils.go @@ -64,7 +64,7 @@ func WithAccountInput(input *utxoledger.Output, governorTransition bool) options func WithAllotments(allotments iotago.Allotments) options.Option[builder.TransactionBuilder] { return func(txBuilder *builder.TransactionBuilder) { for _, allotment := range allotments { - txBuilder.IncreaseAllotment(allotment.AccountID, allotment.Value) + txBuilder.IncreaseAllotment(allotment.AccountID, allotment.Mana) } } } diff --git a/pkg/testsuite/mock/wallet.go b/pkg/testsuite/mock/wallet.go index e8608aab3..b161ed1af 100644 --- a/pkg/testsuite/mock/wallet.go +++ b/pkg/testsuite/mock/wallet.go @@ -31,12 +31,14 @@ type Wallet struct { transactions map[string]*iotago.Transaction } -func NewWallet(t *testing.T, name string, node *Node, seed ...[]byte) *Wallet { - if len(seed) == 0 { +func NewWallet(t *testing.T, name string, node *Node, keyManager ...*KeyManager) *Wallet { + var km *KeyManager + if len(keyManager) == 0 { randomSeed := tpkg.RandEd25519Seed() - seed = append(seed, randomSeed[:]) + km = NewKeyManager(randomSeed[:], 0) + } else { + km = keyManager[0] } - keyManager := NewKeyManager(seed[0], 0) return &Wallet{ Testing: t, @@ -44,7 +46,7 @@ func NewWallet(t *testing.T, name string, node *Node, seed ...[]byte) *Wallet { Node: node, outputs: make(map[string]*utxoledger.Output), transactions: make(map[string]*iotago.Transaction), - keyManager: keyManager, + keyManager: km, } } diff --git a/pkg/testsuite/mock/wallet_transactions.go b/pkg/testsuite/mock/wallet_transactions.go index af58856a5..6b3481046 100644 --- a/pkg/testsuite/mock/wallet_transactions.go +++ b/pkg/testsuite/mock/wallet_transactions.go @@ -333,6 +333,9 @@ func (w *Wallet) createSignedTransactionWithOptions(transactionName string, opts addrSigner := w.AddressSigner() signedTransaction, err := options.Apply(txBuilder, opts).Build(addrSigner) + // register the outputs in the wallet + w.registerOutputs(transactionName, signedTransaction.Transaction) + return signedTransaction, err } diff --git a/pkg/testsuite/snapshotcreator/options.go b/pkg/testsuite/snapshotcreator/options.go index 74d986fe4..85aa1f439 100644 --- a/pkg/testsuite/snapshotcreator/options.go +++ b/pkg/testsuite/snapshotcreator/options.go @@ -8,6 +8,7 @@ import ( ledger1 "github.com/iotaledger/iota-core/pkg/protocol/engine/ledger/ledger" "github.com/iotaledger/iota-core/pkg/protocol/sybilprotection/seatmanager" "github.com/iotaledger/iota-core/pkg/protocol/sybilprotection/seatmanager/poa" + "github.com/iotaledger/iota-core/pkg/testsuite/mock" iotago "github.com/iotaledger/iota.go/v4" ) @@ -22,8 +23,8 @@ type Options struct { // RootBlocks define the initial blocks to which new blocks can attach to. RootBlocks map[iotago.BlockID]iotago.CommitmentID - // GenesisSeed defines the seed used to generate keypair that can spend Genesis outputs. - GenesisSeed []byte + // GenesisKeyManager defines the key manager used to generate keypair that can spend Genesis outputs. + GenesisKeyManager *mock.KeyManager // Accounts defines the accounts that are created in the ledger as part of the Genesis. Accounts []AccountDetails @@ -83,10 +84,10 @@ func WithRootBlocks(rootBlocks map[iotago.BlockID]iotago.CommitmentID) options.O } } -// WithGenesisSeed defines the seed used to generate keypair that can spend Genesis outputs. -func WithGenesisSeed(genesisSeed []byte) options.Option[Options] { +// WithGenesisKeyManager defines the seed used to generate keypair that can spend Genesis outputs. +func WithGenesisKeyManager(keyManager *mock.KeyManager) options.Option[Options] { return func(m *Options) { - m.GenesisSeed = genesisSeed + m.GenesisKeyManager = keyManager } } diff --git a/pkg/testsuite/snapshotcreator/snapshotcreator.go b/pkg/testsuite/snapshotcreator/snapshotcreator.go index f2040d79d..f0d3ee8a0 100644 --- a/pkg/testsuite/snapshotcreator/snapshotcreator.go +++ b/pkg/testsuite/snapshotcreator/snapshotcreator.go @@ -133,7 +133,7 @@ func CreateSnapshot(opts ...options.Option[Options]) error { }, iotago.BaseToken(0)) var genesisTransactionOutputs iotago.TxEssenceOutputs - genesisOutput, err := createGenesisOutput(api, opt.ProtocolParameters.TokenSupply()-totalAccountAmount-totalBasicOutputAmount, opt.GenesisSeed) + genesisOutput, err := createGenesisOutput(api, opt.ProtocolParameters.TokenSupply()-totalAccountAmount-totalBasicOutputAmount, opt.GenesisKeyManager) if err != nil { return ierrors.Wrap(err, "failed to create genesis outputs") } @@ -187,9 +187,8 @@ func CreateSnapshot(opts ...options.Option[Options]) error { return engineInstance.WriteSnapshot(opt.FilePath) } -func createGenesisOutput(api iotago.API, genesisTokenAmount iotago.BaseToken, genesisSeed []byte) (iotago.Output, error) { +func createGenesisOutput(api iotago.API, genesisTokenAmount iotago.BaseToken, genesisKeyManager *mock.KeyManager) (iotago.Output, error) { if genesisTokenAmount > 0 { - genesisKeyManager := mock.NewKeyManager(genesisSeed, 0) output := createOutput(genesisKeyManager.Address(iotago.AddressEd25519), genesisTokenAmount, iotago.Mana(genesisTokenAmount)) if _, err := api.StorageScoreStructure().CoversMinDeposit(output, genesisTokenAmount); err != nil { diff --git a/pkg/testsuite/testsuite.go b/pkg/testsuite/testsuite.go index d4323e9a4..794702d79 100644 --- a/pkg/testsuite/testsuite.go +++ b/pkg/testsuite/testsuite.go @@ -51,14 +51,15 @@ type TestSuite struct { uniqueBlockTimeCounter atomic.Int64 automaticTransactionIssuingCounters shrinkingmap.ShrinkingMap[string, int] mutex syncutils.RWMutex - genesisSeed [32]byte + genesisKeyManager *mock.KeyManager } func NewTestSuite(testingT *testing.T, opts ...options.Option[TestSuite]) *TestSuite { + genesisSeed := tpkg.RandEd25519Seed() return options.Apply(&TestSuite{ Testing: testingT, fakeTesting: &testing.T{}, - genesisSeed: tpkg.RandEd25519Seed(), + genesisKeyManager: mock.NewKeyManager(genesisSeed[:], 0), network: mock.NewNetwork(), Directory: utils.NewDirectory(testingT.TempDir()), nodes: orderedmap.New[string, *mock.Node](), @@ -248,6 +249,18 @@ func (t *TestSuite) Node(name string) *mock.Node { return node } +func (t *TestSuite) Wallet(name string) *mock.Wallet { + t.mutex.RLock() + defer t.mutex.RUnlock() + + wallet, exist := t.wallets.Get(name) + if !exist { + panic(fmt.Sprintf("wallet %s does not exist", name)) + } + + return wallet +} + func (t *TestSuite) Nodes(names ...string) []*mock.Node { if len(names) == 0 { t.mutex.RLock() @@ -342,7 +355,11 @@ func (t *TestSuite) AddValidatorNodeToPartition(name string, partition string, o } func (t *TestSuite) AddValidatorNode(name string, optAmount ...iotago.BaseToken) *mock.Node { - return t.addNodeToPartition(name, mock.NetworkMainPartition, true, optAmount...) + node := t.addNodeToPartition(name, mock.NetworkMainPartition, true, optAmount...) + // create a wallet for each validator node which uses the validator account as a block issuer + t.addWallet(name, node, node.Validator.AccountID, node.KeyManager) + + return node } func (t *TestSuite) AddNodeToPartition(name string, partition string, optAmount ...iotago.BaseToken) *mock.Node { @@ -357,12 +374,10 @@ func (t *TestSuite) RemoveNode(name string) { t.nodes.Delete(name) } -// AddWallet adds a wallet to the test suite with a block issuer in the genesis snapshot and access to the genesis seed. +// AddGenesisWallet adds a wallet to the test suite with a block issuer in the genesis snapshot and access to the genesis seed. // If no block issuance credits are provided, the wallet will be assigned half of the maximum block issuance credits. -func (t *TestSuite) AddWallet(name string, node *mock.Node, blockIssuanceCredits ...iotago.BlockIssuanceCredits) *mock.Wallet { - newWallet := mock.NewWallet(t.Testing, name, node, t.genesisSeed[:]) - newWallet.SetBlockIssuer(iotago.EmptyAccountID) - t.wallets.Set(name, newWallet) +func (t *TestSuite) AddGenesisWallet(name string, node *mock.Node, blockIssuanceCredits ...iotago.BlockIssuanceCredits) *mock.Wallet { + newWallet := t.addWallet(name, node, iotago.EmptyAccountID, t.genesisKeyManager) var bic iotago.BlockIssuanceCredits if len(blockIssuanceCredits) == 0 { bic = iotago.MaxBlockIssuanceCredits / 2 @@ -384,6 +399,14 @@ func (t *TestSuite) AddWallet(name string, node *mock.Node, blockIssuanceCredits return newWallet } +func (t *TestSuite) addWallet(name string, node *mock.Node, accountID iotago.AccountID, keyManager *mock.KeyManager) *mock.Wallet { + newWallet := mock.NewWallet(t.Testing, name, node, keyManager) + newWallet.SetBlockIssuer(accountID) + t.wallets.Set(name, newWallet) + + return newWallet +} + func (t *TestSuite) DefaultWallet() *mock.Wallet { defaultWallet, exists := t.wallets.Get("default") if !exists { @@ -399,11 +422,10 @@ func (t *TestSuite) Run(failOnBlockFiltered bool, nodesOptions ...map[string][]o // Create accounts for any block issuer nodes added before starting the network. if t.optsAccounts != nil { - keyManager := mock.NewKeyManager(t.genesisSeed[:], 0) t.optsSnapshotOptions = append(t.optsSnapshotOptions, snapshotcreator.WithAccounts(lo.Map(t.optsAccounts, func(accountDetails snapshotcreator.AccountDetails) snapshotcreator.AccountDetails { - // if no custom address is assigned to the account, assign an address generated from GenesisSeed + // if no custom address is assigned to the account, assign an address generated from GenesisKeyManager if accountDetails.Address == nil { - accountDetails.Address = keyManager.Address(iotago.AddressEd25519) + accountDetails.Address = t.genesisKeyManager.Address(iotago.AddressEd25519) } if accountDetails.AccountID.Empty() { @@ -420,7 +442,7 @@ func (t *TestSuite) Run(failOnBlockFiltered bool, nodesOptions ...map[string][]o })...)) } - err := snapshotcreator.CreateSnapshot(append([]options.Option[snapshotcreator.Options]{snapshotcreator.WithGenesisSeed(t.genesisSeed[:])}, t.optsSnapshotOptions...)...) + err := snapshotcreator.CreateSnapshot(append([]options.Option[snapshotcreator.Options]{snapshotcreator.WithGenesisKeyManager(t.genesisKeyManager)}, t.optsSnapshotOptions...)...) if err != nil { panic(fmt.Sprintf("failed to create snapshot: %s", err)) } diff --git a/pkg/testsuite/testsuite_issue_blocks.go b/pkg/testsuite/testsuite_issue_blocks.go index 38ce7ed98..982f4a714 100644 --- a/pkg/testsuite/testsuite_issue_blocks.go +++ b/pkg/testsuite/testsuite_issue_blocks.go @@ -158,15 +158,14 @@ func (t *TestSuite) IssueValidationBlock(blockName string, node *mock.Node, bloc return block } -func (t *TestSuite) IssueCandidacyAnnouncementInSlot(alias string, slot iotago.SlotIndex, parentsPrefixAlias string, node *mock.Node, issuingOptions ...options.Option[mock.BlockHeaderParams]) *blocks.Block { +func (t *TestSuite) IssueCandidacyAnnouncementInSlot(alias string, slot iotago.SlotIndex, parentsPrefixAlias string, wallet *mock.Wallet, issuingOptions ...options.Option[mock.BlockHeaderParams]) *blocks.Block { timeProvider := t.API.TimeProvider() issuingTime := timeProvider.SlotStartTime(slot).Add(time.Duration(t.uniqueBlockTimeCounter.Add(1))) - require.Truef(t.Testing, issuingTime.Before(time.Now()), "node: %s: issued block (%s, slot: %d) is in the current (%s, slot: %d) or future slot", node.Name, issuingTime, slot, time.Now(), timeProvider.SlotFromTime(time.Now())) + require.Truef(t.Testing, issuingTime.Before(time.Now()), "wallet: %s: issued block (%s, slot: %d) is in the current (%s, slot: %d) or future slot", wallet.Name, issuingTime, slot, time.Now(), timeProvider.SlotFromTime(time.Now())) return t.IssuePayloadWithOptions( alias, - node.Validator, - node, + wallet, &iotago.CandidacyAnnouncement{}, append(issuingOptions, mock.WithStrongParents(t.BlockIDsWithPrefix(parentsPrefixAlias)...), diff --git a/tools/genesis-snapshot/main.go b/tools/genesis-snapshot/main.go index 2623fc938..63d303a83 100644 --- a/tools/genesis-snapshot/main.go +++ b/tools/genesis-snapshot/main.go @@ -8,6 +8,7 @@ import ( "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/runtime/options" + "github.com/iotaledger/iota-core/pkg/testsuite/mock" "github.com/iotaledger/iota-core/pkg/testsuite/snapshotcreator" "github.com/iotaledger/iota-core/tools/genesis-snapshot/presets" ) @@ -49,7 +50,8 @@ func parseFlags() (opt []options.Option[snapshotcreator.Options], conf string) { if err != nil { log.Fatal(ierrors.Errorf("failed to decode base58 seed, using the default one: %w", err)) } - opt = append(opt, snapshotcreator.WithGenesisSeed(genesisSeed)) + keyManager := mock.NewKeyManager(genesisSeed[:], 0) + opt = append(opt, snapshotcreator.WithGenesisKeyManager(keyManager)) } return opt, *config diff --git a/tools/genesis-snapshot/presets/presets.go b/tools/genesis-snapshot/presets/presets.go index 373a52929..8157c81e2 100644 --- a/tools/genesis-snapshot/presets/presets.go +++ b/tools/genesis-snapshot/presets/presets.go @@ -171,11 +171,11 @@ var Feature = []options.Option[snapshotcreator.Options]{ */ AccountID: blake2b.Sum256(lo.PanicOnErr(hexutil.DecodeHex("0x670a1a20ddb02a6cec53ec3196bc7d5bd26df2f5a6ca90b5fffd71364f104b25"))), Address: iotago.Ed25519AddressFromPubKey(lo.PanicOnErr(hexutil.DecodeHex("0x670a1a20ddb02a6cec53ec3196bc7d5bd26df2f5a6ca90b5fffd71364f104b25"))), - Amount: testsuite.MinIssuerAccountAmount, + Amount: mock.MinIssuerAccountAmount, IssuerKey: iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(lo.PanicOnErr(hexutil.DecodeHex("0x670a1a20ddb02a6cec53ec3196bc7d5bd26df2f5a6ca90b5fffd71364f104b25")))), ExpirySlot: iotago.MaxSlotIndex, BlockIssuanceCredits: iotago.MaxBlockIssuanceCredits / 4, - Mana: iotago.Mana(testsuite.MinIssuerAccountAmount), + Mana: iotago.Mana(mock.MinIssuerAccountAmount), }, ), snapshotcreator.WithBasicOutputs(