Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 1d52744

Browse files
committed
Fix: fixed test
1 parent 7f24d25 commit 1d52744

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

pkg/protocol/engine/consensus/blockgadget/gadget_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ func TestBlockGadget(t *testing.T) {
3232
tf.Events.BlockPreConfirmed.Hook(checkOrder(&expectedPreConfirmationOrder, "pre-confirmation"))
3333
tf.Events.BlockConfirmed.Hook(checkOrder(&expectedConfirmationOrder, "confirmation"))
3434

35-
tf.SeatManager.AddRandomAccount("A")
36-
tf.SeatManager.AddRandomAccount("B")
35+
tf.SeatManager.AddRandomAccounts("A", "B")
3736

3837
tf.SeatManager.SetOnline("A")
3938
tf.SeatManager.SetOnline("B")

pkg/protocol/engine/tipmanager/tests/testframework.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,22 @@ func (t *TestFramework) Validator(alias string) iotago.AccountID {
6767
return t.manualPOA.AccountID(alias)
6868
}
6969

70-
func (t *TestFramework) AddValidator(alias string) {
71-
t.manualPOA.AddRandomAccount(alias)
70+
func (t *TestFramework) AddValidators(aliases ...string) {
71+
t.manualPOA.AddRandomAccounts(aliases...)
7272

73-
seat, exists := t.manualPOA.GetSeat(alias)
74-
if !exists {
75-
panic("seat does not exist")
76-
}
73+
for _, alias := range aliases {
74+
seat, exists := t.manualPOA.GetSeat(alias)
75+
if !exists {
76+
panic("seat does not exist")
77+
}
7778

78-
t.Instance.AddSeat(seat)
79+
t.Instance.AddSeat(seat)
80+
}
7981
}
8082

8183
func (t *TestFramework) AddBlock(alias string) tipmanager.TipMetadata {
8284
t.tipMetadataByAlias[alias] = t.Instance.AddBlock(t.Block(alias))
85+
t.tipMetadataByAlias[alias].ID().RegisterAlias(alias)
8386

8487
return t.tipMetadataByAlias[alias]
8588
}

pkg/protocol/engine/tipmanager/tests/tipmanager_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func Test_Orphanage(t *testing.T) {
6262
func Test_ValidationTips(t *testing.T) {
6363
tf := NewTestFramework(t)
6464

65+
tf.AddValidators("validatorA", "validatorB")
66+
6567
{
6668
tf.CreateBasicBlock("1", map[iotago.ParentsType][]string{
6769
iotago.StrongParentType: {"Genesis"},
@@ -78,8 +80,6 @@ func Test_ValidationTips(t *testing.T) {
7880

7981
// Add validation tip for validatorA.
8082
{
81-
tf.AddValidator("validatorA")
82-
8383
tf.CreateValidationBlock("3", map[iotago.ParentsType][]string{
8484
iotago.StrongParentType: {"2"},
8585
}, func(blockBuilder *builder.ValidationBlockBuilder) {
@@ -94,8 +94,6 @@ func Test_ValidationTips(t *testing.T) {
9494

9595
// Add validation tip for validatorB.
9696
{
97-
tf.AddValidator("validatorB")
98-
9997
tf.CreateValidationBlock("4", map[iotago.ParentsType][]string{
10098
iotago.StrongParentType: {"1"},
10199
}, func(blockBuilder *builder.ValidationBlockBuilder) {

pkg/protocol/sybilprotection/seatmanager/mock/mockseatmanager.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,32 @@ func NewManualPOAProvider() module.Provider[*engine.Engine, seatmanager.SeatMana
5858
})
5959
}
6060

61-
func (m *ManualPOA) AddRandomAccount(alias string) iotago.AccountID {
62-
id := iotago.AccountID(tpkg.Rand32ByteArray())
63-
id.RegisterAlias(alias)
64-
if err := m.accounts.Set(id, &account.Pool{ // We don't care about pools with PoA, but need to set something to avoid division by zero errors.
65-
PoolStake: 1,
66-
ValidatorStake: 1,
67-
FixedCost: 1,
68-
}); err != nil {
69-
panic(err)
70-
}
61+
func (m *ManualPOA) AddRandomAccounts(aliases ...string) (accountIDs []iotago.AccountID) {
62+
accountIDs = make([]iotago.AccountID, len(aliases))
63+
64+
for i, alias := range aliases {
65+
id := iotago.AccountID(tpkg.Rand32ByteArray())
66+
id.RegisterAlias(alias)
67+
if err := m.accounts.Set(id, &account.Pool{ // We don't care about pools with PoA, but need to set something to avoid division by zero errors.
68+
PoolStake: 1,
69+
ValidatorStake: 1,
70+
FixedCost: 1,
71+
}); err != nil {
72+
panic(err)
73+
}
7174

72-
m.aliases.Set(alias, id)
75+
m.aliases.Set(alias, id)
76+
77+
accountIDs[i] = id
78+
}
7379

7480
m.committee = m.accounts.SeatedAccounts(m.accounts.IDs()...)
7581

7682
if err := m.committeeStore.Store(0, m.accounts); err != nil {
7783
panic(err)
7884
}
7985

80-
return id
86+
return accountIDs
8187
}
8288

8389
func (m *ManualPOA) AddAccount(id iotago.AccountID, alias string) iotago.AccountID {

0 commit comments

Comments
 (0)