@@ -5,18 +5,20 @@ import (
55
66 "github.com/iotaledger/iota-core/pkg/protocol/engine/tipmanager"
77 iotago "github.com/iotaledger/iota.go/v4"
8+ "github.com/iotaledger/iota.go/v4/builder"
9+ "github.com/iotaledger/iota.go/v4/tpkg"
810)
911
1012func TestTipManager (t * testing.T ) {
1113 tf := NewTestFramework (t )
1214
13- tf .CreateBlock ("Bernd" , map [iotago.ParentsType ][]string {
15+ tf .CreateBasicBlock ("Bernd" , map [iotago.ParentsType ][]string {
1416 iotago .StrongParentType : {"Genesis" },
1517 })
16- tf .CreateBlock ("Bernd1" , map [iotago.ParentsType ][]string {
18+ tf .CreateBasicBlock ("Bernd1" , map [iotago.ParentsType ][]string {
1719 iotago .StrongParentType : {"Bernd" },
1820 })
19- tf .CreateBlock ("Bernd1.1" , map [iotago.ParentsType ][]string {
21+ tf .CreateBasicBlock ("Bernd1.1" , map [iotago.ParentsType ][]string {
2022 iotago .StrongParentType : {"Bernd" },
2123 })
2224
@@ -33,13 +35,13 @@ func TestTipManager(t *testing.T) {
3335func Test_Orphanage (t * testing.T ) {
3436 tf := NewTestFramework (t )
3537
36- tf .CreateBlock ("A" , map [iotago.ParentsType ][]string {
38+ tf .CreateBasicBlock ("A" , map [iotago.ParentsType ][]string {
3739 iotago .StrongParentType : {"Genesis" },
3840 })
39- tf .CreateBlock ("B" , map [iotago.ParentsType ][]string {
41+ tf .CreateBasicBlock ("B" , map [iotago.ParentsType ][]string {
4042 iotago .StrongParentType : {"Genesis" },
4143 })
42- tf .CreateBlock ("C" , map [iotago.ParentsType ][]string {
44+ tf .CreateBasicBlock ("C" , map [iotago.ParentsType ][]string {
4345 iotago .StrongParentType : {"A" , "B" },
4446 })
4547
@@ -56,3 +58,108 @@ func Test_Orphanage(t *testing.T) {
5658 blockB .LivenessThresholdReached ().Trigger ()
5759 tf .RequireStrongTips ("A" )
5860}
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