/
future_pre_prepare_after_change_round.go
80 lines (68 loc) · 3.26 KB
/
future_pre_prepare_after_change_round.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
package changeround
import (
ibft2 "github.com/bloxapp/ssv/ibft/instance"
"github.com/bloxapp/ssv/ibft/instance/spectesting"
"github.com/bloxapp/ssv/ibft/leader/constant"
"github.com/bloxapp/ssv/ibft/proto"
"github.com/bloxapp/ssv/network"
"github.com/stretchr/testify/require"
"testing"
)
// FuturePrePrepareAfterChangeRound tests handling a pre-prepare msgs received before a change round happened
type FuturePrePrepareAfterChangeRound struct {
instance *ibft2.Instance
inputValue []byte
lambda []byte
}
// Name returns test name
func (test *FuturePrePrepareAfterChangeRound) Name() string {
return "pre-prepare -> change round quorum -> should send prepare msg"
}
// Prepare prepares the test
func (test *FuturePrePrepareAfterChangeRound) Prepare(t *testing.T) {
test.lambda = []byte{1, 2, 3, 4}
test.inputValue = spectesting.TestInputValue()
test.instance = spectesting.TestIBFTInstance(t, test.lambda)
test.instance.LeaderSelector = &constant.Constant{LeaderIndex: 1}
test.instance.State().Round.Set(1)
// load messages to queue
for _, msg := range test.MessagesSequence(t) {
test.instance.MsgQueue.AddMessage(&network.Message{
SignedMessage: msg,
Type: network.NetworkMsg_IBFTType,
})
}
}
// MessagesSequence includes all test messages
func (test *FuturePrePrepareAfterChangeRound) MessagesSequence(t *testing.T) []*proto.SignedMessage {
return []*proto.SignedMessage{
spectesting.PrePrepareMsg(t, spectesting.TestSKs()[1], test.lambda, test.inputValue, 2, 2),
spectesting.ChangeRoundMsg(t, spectesting.TestSKs()[0], test.lambda, 2, 1),
spectesting.ChangeRoundMsg(t, spectesting.TestSKs()[1], test.lambda, 2, 2),
spectesting.ChangeRoundMsg(t, spectesting.TestSKs()[2], test.lambda, 2, 3),
spectesting.ChangeRoundMsg(t, spectesting.TestSKs()[3], test.lambda, 2, 4),
spectesting.PrepareMsg(t, spectesting.TestSKs()[0], test.lambda, test.inputValue, 2, 1),
spectesting.PrepareMsg(t, spectesting.TestSKs()[1], test.lambda, test.inputValue, 2, 2),
spectesting.PrepareMsg(t, spectesting.TestSKs()[2], test.lambda, test.inputValue, 2, 3),
}
}
// Run runs the test
func (test *FuturePrePrepareAfterChangeRound) Run(t *testing.T) {
// future pre-prepare
spectesting.RequireReturnedTrueNoError(t, test.instance.ProcessMessage)
// change round
spectesting.SimulateTimeout(test.instance, 2)
require.EqualValues(t, proto.RoundState_ChangeRound, test.instance.State().Stage.Get())
spectesting.RequireReturnedTrueNoError(t, test.instance.ProcessMessage)
require.EqualValues(t, proto.RoundState_ChangeRound, test.instance.State().Stage.Get())
spectesting.RequireReturnedTrueNoError(t, test.instance.ProcessMessage)
require.EqualValues(t, proto.RoundState_ChangeRound, test.instance.State().Stage.Get())
spectesting.RequireReturnedTrueNoError(t, test.instance.ProcessMessage)
spectesting.RequireReturnedTrueNoError(t, test.instance.ProcessMessage)
require.EqualValues(t, proto.RoundState_PrePrepare, test.instance.State().Stage.Get())
// process prepare msgs
spectesting.RequireReturnedTrueNoError(t, test.instance.ProcessMessage)
spectesting.RequireReturnedTrueNoError(t, test.instance.ProcessMessage)
spectesting.RequireReturnedTrueNoError(t, test.instance.ProcessMessage)
require.EqualValues(t, proto.RoundState_Prepare, test.instance.State().Stage.Get())
}