Skip to content

Commit

Permalink
Merge pull request #448 from iotaledger/feat/wallet-centric-testing
Browse files Browse the repository at this point in the history
Wallet-centric account testing
  • Loading branch information
cyberphysic4l authored Oct 29, 2023
2 parents c6155f9 + 604b862 commit e226f5f
Show file tree
Hide file tree
Showing 26 changed files with 1,367 additions and 1,208 deletions.
422 changes: 240 additions & 182 deletions pkg/tests/accounts_test.go

Large diffs are not rendered by default.

198 changes: 104 additions & 94 deletions pkg/tests/booker_test.go

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions pkg/tests/committee_rotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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{
Expand Down
6 changes: 3 additions & 3 deletions pkg/tests/loss_of_acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func TestLossOfAcceptanceFromGenesis(t *testing.T) {
)
defer ts.Shutdown()

ts.AddBasicBlockIssuer("default")
node0 := ts.AddValidatorNode("node0")
ts.AddGenesisWallet("default", node0)
ts.AddValidatorNode("node1")
ts.AddNode("node2")

Expand Down Expand Up @@ -117,8 +117,8 @@ func TestLossOfAcceptanceFromSnapshot(t *testing.T) {
)
defer ts.Shutdown()

ts.AddBasicBlockIssuer("default")
node0 := ts.AddValidatorNode("node0")
ts.AddGenesisWallet("default", node0)
ts.AddValidatorNode("node1")
node2 := ts.AddNode("node2")

Expand Down Expand Up @@ -211,8 +211,8 @@ func TestLossOfAcceptanceWithRestartFromDisk(t *testing.T) {
)
defer ts.Shutdown()

ts.AddBasicBlockIssuer("default")
node0 := ts.AddValidatorNode("node0")
ts.AddGenesisWallet("default", node0)
ts.AddValidatorNode("node1")
node2 := ts.AddNode("node2")

Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/protocol_engine_switching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestProtocol_EngineSwitching(t *testing.T) {
node6 := ts.AddValidatorNode("node6")
node7 := ts.AddValidatorNode("node7")
node8 := ts.AddNode("node8")
ts.AddBasicBlockIssuer("default", iotago.MaxBlockIssuanceCredits/2)
ts.AddGenesisWallet("default", node0, iotago.MaxBlockIssuanceCredits/2)

const expectedCommittedSlotAfterPartitionMerge = 19
nodesP1 := []*mock.Node{node0, node1, node2, node3, node4, node5}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tests/protocol_startup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func Test_StartNodeFromSnapshotAndDisk(t *testing.T) {
nodeA := ts.AddValidatorNode("nodeA")
nodeB := ts.AddValidatorNode("nodeB")
ts.AddNode("nodeC")
ts.AddBasicBlockIssuer("default", iotago.MaxBlockIssuanceCredits/2)
ts.AddGenesisWallet("default", nodeA, iotago.MaxBlockIssuanceCredits/2)

nodeOptions := []options.Option[protocol.Protocol]{
protocol.WithStorageOptions(
Expand Down
21 changes: 11 additions & 10 deletions pkg/tests/upgrade_signaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/iotaledger/iota-core/pkg/storage"
"github.com/iotaledger/iota-core/pkg/storage/permanent"
"github.com/iotaledger/iota-core/pkg/testsuite"
"github.com/iotaledger/iota-core/pkg/testsuite/mock"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)
Expand Down Expand Up @@ -107,13 +108,13 @@ func Test_Upgrade_Signaling(t *testing.T) {
),
)

ts.AddValidatorNode("nodeA")
nodeA := ts.AddValidatorNode("nodeA")
ts.AddValidatorNode("nodeB")
ts.AddValidatorNode("nodeC")
ts.AddValidatorNode("nodeD")
ts.AddNode("nodeE")
ts.AddNode("nodeF")
ts.AddBasicBlockIssuer("default", iotago.MaxBlockIssuanceCredits/2)
wallet := ts.AddGenesisWallet("default", nodeA, iotago.MaxBlockIssuanceCredits/2)

ts.Run(true, map[string][]options.Option[protocol.Protocol]{
"nodeA": nodeOptionsWithoutV5,
Expand All @@ -135,19 +136,19 @@ func Test_Upgrade_Signaling(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
OutputID: ts.AccountOutput("Genesis:1").OutputID(),
BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeA").Validator.PublicKey))),
ValidatorStake: testsuite.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount,
DelegationStake: 0,
FixedCost: 0,
StakeEndEpoch: iotago.MaxEpochIndex,
LatestSupportedProtocolVersionAndHash: model.VersionAndHash{},
}, ts.Nodes()...)

ts.AssertAccountData(&accounts.AccountData{
ID: ts.DefaultBasicBlockIssuer().AccountID,
ID: wallet.BlockIssuer.AccountID,
Credits: &accounts.BlockIssuanceCredits{Value: iotago.MaxBlockIssuanceCredits / 2, UpdateTime: 0},
ExpirySlot: iotago.MaxSlotIndex,
OutputID: ts.AccountOutput("Genesis:5").OutputID(),
BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.DefaultBasicBlockIssuer().PublicKey))),
BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(wallet.BlockIssuer.PublicKey))),
ValidatorStake: 0,
DelegationStake: 0,
FixedCost: 0,
Expand All @@ -169,7 +170,7 @@ func Test_Upgrade_Signaling(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
OutputID: ts.AccountOutput("Genesis:1").OutputID(),
BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeA").Validator.PublicKey))),
ValidatorStake: testsuite.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount,
DelegationStake: 0,
FixedCost: 0,
StakeEndEpoch: iotago.MaxEpochIndex,
Expand All @@ -182,7 +183,7 @@ func Test_Upgrade_Signaling(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
OutputID: ts.AccountOutput("Genesis:4").OutputID(),
BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeD").Validator.PublicKey))),
ValidatorStake: testsuite.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount,
DelegationStake: 0,
FixedCost: 0,
StakeEndEpoch: iotago.MaxEpochIndex,
Expand All @@ -203,7 +204,7 @@ func Test_Upgrade_Signaling(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
OutputID: ts.AccountOutput("Genesis:1").OutputID(),
BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeA").Validator.PublicKey))),
ValidatorStake: testsuite.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount,
DelegationStake: 0,
FixedCost: 0,
StakeEndEpoch: iotago.MaxEpochIndex,
Expand Down Expand Up @@ -368,7 +369,7 @@ func Test_Upgrade_Signaling(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
OutputID: ts.AccountOutput("Genesis:1").OutputID(),
BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeA").Validator.PublicKey))),
ValidatorStake: testsuite.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount,
DelegationStake: 0,
FixedCost: 0,
StakeEndEpoch: iotago.MaxEpochIndex,
Expand All @@ -381,7 +382,7 @@ func Test_Upgrade_Signaling(t *testing.T) {
ExpirySlot: iotago.MaxSlotIndex,
OutputID: ts.AccountOutput("Genesis:4").OutputID(),
BlockIssuerKeys: iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(ed25519.PublicKey(ts.Node("nodeD").Validator.PublicKey))),
ValidatorStake: testsuite.MinValidatorAccountAmount,
ValidatorStake: mock.MinValidatorAccountAmount,
DelegationStake: 0,
FixedCost: 0,
StakeEndEpoch: iotago.MaxEpochIndex,
Expand Down
2 changes: 1 addition & 1 deletion pkg/testsuite/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (t *TestSuite) AssertBlocksInCacheConflicts(blockConflicts map[*blocks.Bloc
return ierrors.Errorf("AssertBlocksInCacheConflicts: %s: block %s is root block", node.Name, blockFromCache.ID())
}

expectedConflictIDs := ds.NewSet(lo.Map(conflictAliases, t.TransactionFramework.TransactionID)...)
expectedConflictIDs := ds.NewSet(lo.Map(conflictAliases, t.DefaultWallet().TransactionID)...)
actualConflictIDs := blockFromCache.ConflictIDs()

if expectedConflictIDs.Size() != actualConflictIDs.Size() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/testsuite/conflicts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func (t *TestSuite) AssertConflictsInCacheAcceptanceState(expectedConflictAliase
for _, node := range nodes {
for _, conflictAlias := range expectedConflictAliases {
t.Eventually(func() error {
acceptanceState := node.Protocol.MainEngineInstance().Ledger.ConflictDAG().AcceptanceState(ds.NewSet(t.TransactionFramework.TransactionID(conflictAlias)))
acceptanceState := node.Protocol.MainEngineInstance().Ledger.ConflictDAG().AcceptanceState(ds.NewSet(t.DefaultWallet().TransactionID(conflictAlias)))

if acceptanceState != expectedState {
return ierrors.Errorf("assertTransactionsInCacheWithFunc: %s: conflict %s is %s, but expected %s", node.Name, conflictAlias, acceptanceState, expectedState)
Expand Down
25 changes: 15 additions & 10 deletions pkg/testsuite/mock/blockissuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"golang.org/x/crypto/blake2b"

"github.com/iotaledger/hive.go/core/safemath"
hiveEd25519 "github.com/iotaledger/hive.go/crypto/ed25519"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/hive.go/runtime/event"
Expand Down Expand Up @@ -45,28 +46,28 @@ type BlockIssuer struct {
Name string
Validator bool

AccountID iotago.AccountID
OutputID iotago.OutputID
PublicKey ed25519.PublicKey
privateKey ed25519.PrivateKey

events *Events

workerPool *workerpool.WorkerPool

privateKey ed25519.PrivateKey
PublicKey ed25519.PublicKey
AccountID iotago.AccountID

optsTipSelectionTimeout time.Duration
optsTipSelectionRetryInterval time.Duration
// optsIncompleteBlockAccepted defines whether the node allows filling in incomplete block and issuing it for user.
optsIncompleteBlockAccepted bool
optsRateSetterEnabled bool
}

func NewBlockIssuer(t *testing.T, name string, validator bool, opts ...options.Option[BlockIssuer]) *BlockIssuer {
pub, priv, err := ed25519.GenerateKey(nil)
if err != nil {
panic(err)
}
func NewBlockIssuer(t *testing.T, name string, keyManager *KeyManager, accountID iotago.AccountID, validator bool, opts ...options.Option[BlockIssuer]) *BlockIssuer {
priv, pub := keyManager.KeyPair()

accountID := iotago.AccountID(blake2b.Sum256(pub))
if accountID == iotago.EmptyAccountID {
accountID = iotago.AccountID(blake2b.Sum256(pub))
}
accountID.RegisterAlias(name)

return options.Apply(&BlockIssuer{
Expand All @@ -85,6 +86,10 @@ func NewBlockIssuer(t *testing.T, name string, validator bool, opts ...options.O
}, opts)
}

func (i *BlockIssuer) BlockIssuerKeys() iotago.BlockIssuerKeys {
return iotago.NewBlockIssuerKeys(iotago.Ed25519PublicKeyBlockIssuerKeyFromPublicKey(hiveEd25519.PublicKey(i.PublicKey)))
}

// Shutdown shuts down the block issuer.
func (i *BlockIssuer) Shutdown() {
i.workerPool.Shutdown()
Expand Down
Loading

0 comments on commit e226f5f

Please sign in to comment.