@@ -5,18 +5,20 @@ import (
5
5
6
6
"github.com/iotaledger/iota-core/pkg/protocol/engine/tipmanager"
7
7
iotago "github.com/iotaledger/iota.go/v4"
8
+ "github.com/iotaledger/iota.go/v4/builder"
9
+ "github.com/iotaledger/iota.go/v4/tpkg"
8
10
)
9
11
10
12
func TestTipManager (t * testing.T ) {
11
13
tf := NewTestFramework (t )
12
14
13
- tf .CreateBlock ("Bernd" , map [iotago.ParentsType ][]string {
15
+ tf .CreateBasicBlock ("Bernd" , map [iotago.ParentsType ][]string {
14
16
iotago .StrongParentType : {"Genesis" },
15
17
})
16
- tf .CreateBlock ("Bernd1" , map [iotago.ParentsType ][]string {
18
+ tf .CreateBasicBlock ("Bernd1" , map [iotago.ParentsType ][]string {
17
19
iotago .StrongParentType : {"Bernd" },
18
20
})
19
- tf .CreateBlock ("Bernd1.1" , map [iotago.ParentsType ][]string {
21
+ tf .CreateBasicBlock ("Bernd1.1" , map [iotago.ParentsType ][]string {
20
22
iotago .StrongParentType : {"Bernd" },
21
23
})
22
24
@@ -33,13 +35,13 @@ func TestTipManager(t *testing.T) {
33
35
func Test_Orphanage (t * testing.T ) {
34
36
tf := NewTestFramework (t )
35
37
36
- tf .CreateBlock ("A" , map [iotago.ParentsType ][]string {
38
+ tf .CreateBasicBlock ("A" , map [iotago.ParentsType ][]string {
37
39
iotago .StrongParentType : {"Genesis" },
38
40
})
39
- tf .CreateBlock ("B" , map [iotago.ParentsType ][]string {
41
+ tf .CreateBasicBlock ("B" , map [iotago.ParentsType ][]string {
40
42
iotago .StrongParentType : {"Genesis" },
41
43
})
42
- tf .CreateBlock ("C" , map [iotago.ParentsType ][]string {
44
+ tf .CreateBasicBlock ("C" , map [iotago.ParentsType ][]string {
43
45
iotago .StrongParentType : {"A" , "B" },
44
46
})
45
47
@@ -56,3 +58,108 @@ func Test_Orphanage(t *testing.T) {
56
58
blockB .LivenessThresholdReached ().Trigger ()
57
59
tf .RequireStrongTips ("A" )
58
60
}
61
+
62
+ func Test_ValidationTips (t * testing.T ) {
63
+ tf := NewTestFramework (t )
64
+
65
+ tf .AddValidators ("validatorA" , "validatorB" )
66
+
67
+ {
68
+ tf .CreateBasicBlock ("1" , map [iotago.ParentsType ][]string {
69
+ iotago .StrongParentType : {"Genesis" },
70
+ })
71
+ tf .CreateBasicBlock ("2" , map [iotago.ParentsType ][]string {
72
+ iotago .StrongParentType : {"Genesis" },
73
+ })
74
+
75
+ tf .AddBlock ("1" ).TipPool ().Set (tipmanager .StrongTipPool )
76
+ tf .AddBlock ("2" ).TipPool ().Set (tipmanager .StrongTipPool )
77
+
78
+ tf .RequireStrongTips ("1" , "2" )
79
+ }
80
+
81
+ // Add validation tip for validatorA.
82
+ {
83
+ tf .CreateValidationBlock ("3" , map [iotago.ParentsType ][]string {
84
+ iotago .StrongParentType : {"2" },
85
+ }, func (blockBuilder * builder.ValidationBlockBuilder ) {
86
+ blockBuilder .Sign (tf .Validator ("validatorA" ), tpkg .RandEd25519PrivateKey ())
87
+ })
88
+
89
+ tf .AddBlock ("3" ).TipPool ().Set (tipmanager .StrongTipPool )
90
+
91
+ tf .RequireValidationTips ("3" )
92
+ tf .RequireStrongTips ("1" , "3" )
93
+ }
94
+
95
+ // Add validation tip for validatorB.
96
+ {
97
+ tf .CreateValidationBlock ("4" , map [iotago.ParentsType ][]string {
98
+ iotago .StrongParentType : {"1" },
99
+ }, func (blockBuilder * builder.ValidationBlockBuilder ) {
100
+ blockBuilder .Sign (tf .Validator ("validatorB" ), tpkg .RandEd25519PrivateKey ())
101
+ })
102
+
103
+ tf .AddBlock ("4" ).TipPool ().Set (tipmanager .StrongTipPool )
104
+
105
+ tf .RequireValidationTips ("3" , "4" )
106
+ tf .RequireStrongTips ("3" , "4" )
107
+ }
108
+
109
+ // Add basic blocks in the future cone of the validation tips, referencing both existing validation tips.
110
+ {
111
+ tf .CreateBasicBlock ("5" , map [iotago.ParentsType ][]string {
112
+ iotago .StrongParentType : {"3" , "4" },
113
+ })
114
+
115
+ tf .AddBlock ("5" ).TipPool ().Set (tipmanager .StrongTipPool )
116
+
117
+ tf .RequireValidationTips ("5" )
118
+ tf .RequireStrongTips ("5" )
119
+ }
120
+
121
+ // Add basic blocks in the future cone of the validation tips.
122
+ {
123
+ tf .CreateBasicBlock ("6" , map [iotago.ParentsType ][]string {
124
+ iotago .StrongParentType : {"3" },
125
+ })
126
+ tf .CreateBasicBlock ("7" , map [iotago.ParentsType ][]string {
127
+ iotago .StrongParentType : {"4" },
128
+ })
129
+
130
+ tf .AddBlock ("6" ).TipPool ().Set (tipmanager .StrongTipPool )
131
+ tf .AddBlock ("7" ).TipPool ().Set (tipmanager .StrongTipPool )
132
+
133
+ tf .RequireValidationTips ("5" , "6" , "7" )
134
+ tf .RequireStrongTips ("5" , "6" , "7" )
135
+ }
136
+
137
+ // A newer validation block replaces the previous validation tip of that validator.
138
+ {
139
+ tf .CreateValidationBlock ("8" , map [iotago.ParentsType ][]string {
140
+ iotago .StrongParentType : {"6" },
141
+ }, func (blockBuilder * builder.ValidationBlockBuilder ) {
142
+ blockBuilder .Sign (tf .Validator ("validatorB" ), tpkg .RandEd25519PrivateKey ())
143
+ })
144
+
145
+ tf .AddBlock ("8" ).TipPool ().Set (tipmanager .StrongTipPool )
146
+
147
+ tf .RequireValidationTips ("5" , "8" )
148
+ tf .RequireStrongTips ("5" , "7" , "8" )
149
+ }
150
+
151
+ // A newer validation block (with parallel past cone) still becomes a validation tip and overwrites
152
+ // the previous validation tip of that validator.
153
+ {
154
+ tf .CreateValidationBlock ("9" , map [iotago.ParentsType ][]string {
155
+ iotago .StrongParentType : {"Genesis" },
156
+ }, func (blockBuilder * builder.ValidationBlockBuilder ) {
157
+ blockBuilder .Sign (tf .Validator ("validatorA" ), tpkg .RandEd25519PrivateKey ())
158
+ })
159
+
160
+ tf .AddBlock ("9" ).TipPool ().Set (tipmanager .StrongTipPool )
161
+
162
+ tf .RequireValidationTips ("8" , "9" )
163
+ tf .RequireStrongTips ("5" , "7" , "8" , "9" )
164
+ }
165
+ }
0 commit comments