-
Notifications
You must be signed in to change notification settings - Fork 12
/
storage_settings.go
128 lines (102 loc) · 4.46 KB
/
storage_settings.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package testsuite
import (
"context"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/iota-core/pkg/testsuite/mock"
iotago "github.com/iotaledger/iota.go/v4"
)
func (t *TestSuite) AssertSnapshotImported(imported bool, nodes ...*mock.Node) {
mustNodes(nodes)
for _, node := range nodes {
t.Eventually(func() error {
if imported != node.Protocol.Engines.Main.Get().Storage.Settings().IsSnapshotImported() {
return ierrors.Errorf("AssertSnapshotImported: %s: expected %v, got %v", node.Name, imported, node.Protocol.Engines.Main.Get().Storage.Settings().IsSnapshotImported())
}
return nil
})
}
}
func (t *TestSuite) AssertProtocolParameters(parameters iotago.ProtocolParameters, nodes ...*mock.Node) {
mustNodes(nodes)
for _, node := range nodes {
t.Eventually(func() error {
if !parameters.Equals(node.Protocol.CommittedAPI().ProtocolParameters()) {
return ierrors.Errorf("AssertProtocolParameters: %s: expected %s, got %s", node.Name, parameters, node.Protocol.CommittedAPI().ProtocolParameters())
}
return nil
})
}
}
func (t *TestSuite) AssertLatestCommitment(commitment *iotago.Commitment, nodes ...*mock.Node) {
mustNodes(nodes)
for _, node := range nodes {
t.Eventually(func() error {
if !commitment.Equals(node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment()) {
return ierrors.Errorf("AssertLatestCommitment: %s: expected %s, got %s", node.Name, commitment, node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Commitment())
}
return nil
})
}
}
func (t *TestSuite) AssertCommitmentSlotIndexExists(slot iotago.SlotIndex, clients ...mock.Client) {
for _, client := range clients {
t.Eventually(func() error {
latestCommitment, err := client.CommitmentByID(context.Background(), iotago.EmptyCommitmentID)
if err != nil {
return ierrors.Errorf("AssertCommitmentSlotIndexExists: error loading latest commitment: %w", err)
}
if latestCommitment.Slot < slot {
return ierrors.Errorf("AssertCommitmentSlotIndexExists: commitment with at least %v not found in settings.LatestCommitment()", slot)
}
cm, err := client.CommitmentBySlot(context.Background(), slot)
if err != nil {
return ierrors.Errorf("AssertCommitmentSlotIndexExists: expected %v, got error %v", slot, err)
}
if cm == nil {
return ierrors.Errorf("AssertCommitmentSlotIndexExists: commitment at index %v not found", slot)
}
return nil
})
}
}
func (t *TestSuite) AssertLatestCommitmentSlotIndex(slot iotago.SlotIndex, nodes ...*mock.Node) {
mustNodes(nodes)
for _, node := range nodes {
t.Eventually(func() error {
latestCommittedSlotSettings := node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().Slot()
if slot != latestCommittedSlotSettings {
return ierrors.Errorf("AssertLatestCommitmentSlotIndex: %s: expected %v, got %v in settings", node.Name, slot, latestCommittedSlotSettings)
}
latestCommittedSlotSyncManager := node.Protocol.Engines.Main.Get().SyncManager.LatestCommitment().Slot()
if slot != latestCommittedSlotSyncManager {
return ierrors.Errorf("AssertLatestCommitmentSlotIndex: %s: expected %v, got %v in sync manager", node.Name, slot, latestCommittedSlotSyncManager)
}
return nil
})
}
}
func (t *TestSuite) AssertLatestCommitmentCumulativeWeight(cw uint64, nodes ...*mock.Node) {
mustNodes(nodes)
for _, node := range nodes {
t.Eventually(func() error {
if cw != node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().CumulativeWeight() {
return ierrors.Errorf("AssertLatestCommitmentCumulativeWeight: %s: expected %v, got %v", node.Name, cw, node.Protocol.Engines.Main.Get().Storage.Settings().LatestCommitment().CumulativeWeight())
}
return nil
})
}
}
func (t *TestSuite) AssertLatestFinalizedSlot(slot iotago.SlotIndex, nodes ...*mock.Node) {
mustNodes(nodes)
for _, node := range nodes {
t.Eventually(func() error {
if slot != node.Protocol.Engines.Main.Get().Storage.Settings().LatestFinalizedSlot() {
return ierrors.Errorf("AssertLatestFinalizedSlot: %s: expected %d, got %d from settings", node.Name, slot, node.Protocol.Engines.Main.Get().Storage.Settings().LatestFinalizedSlot())
}
if slot != node.Protocol.Engines.Main.Get().SyncManager.LatestFinalizedSlot() {
return ierrors.Errorf("AssertLatestFinalizedSlot: %s: expected %d, got %d from SyncManager", node.Name, slot, node.Protocol.Engines.Main.Get().SyncManager.LatestFinalizedSlot())
}
return nil
})
}
}