@@ -20,13 +20,13 @@ module voteBookkeeperTest {
2020 lastEmitted' = lastEmitted,
2121 }
2222
23- action initWith(round: Round, totalWeight: Weight): bool = all {
24- bookkeeper' = { height: 10, currentRound: round, totalWeight: totalWeight, rounds: Map() },
23+ action initWith(totalWeight: Weight): bool = all {
24+ bookkeeper' = { height: 10, totalWeight: totalWeight, rounds: Map() },
2525 lastEmitted' = { round: -1, name: "", value: "null" },
2626 }
2727
28- action applyVoteAction(vote: Vote, weight: Weight): bool =
29- val result = applyVote(bookkeeper, vote, weight)
28+ action applyVoteAction(vote: Vote, weight: Weight, currentRound: Round ): bool =
29+ val result = applyVote(bookkeeper, vote, weight, currentRound )
3030 all {
3131 bookkeeper' = result.bookkeeper,
3232 lastEmitted' = result.event,
@@ -44,100 +44,100 @@ module voteBookkeeperTest {
4444 // all messages are received in order. We assume three validators in the validator set wtih 60%, 30% and 10%
4545 // each of the total voting power
4646 run synchronousConsensusTest =
47- initWith(1, 100)
48- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 60))
47+ initWith(100)
48+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 60, 1 ))
4949 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
50- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "john"}, 10))
50+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "john"}, 10, 1 ))
5151 .then(_assert(lastEmitted == {round: 1, name: "PolkaValue", value: "proposal"}))
52- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "bob"}, 30))
52+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "bob"}, 30, 1 ))
5353 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
54- .then(applyVoteAction({typ: "Precommit", round: 1, value: "proposal", address: "bob"}, 30))
54+ .then(applyVoteAction({typ: "Precommit", round: 1, value: "proposal", address: "bob"}, 30, 1 ))
5555 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
56- .then(applyVoteAction({typ: "Precommit", round: 1, value: "proposal", address: "john"}, 10))
56+ .then(applyVoteAction({typ: "Precommit", round: 1, value: "proposal", address: "john"}, 10, 1 ))
5757 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
58- .then(applyVoteAction({typ: "Precommit", round: 1, value: "proposal", address: "alice"}, 60))
58+ .then(applyVoteAction({typ: "Precommit", round: 1, value: "proposal", address: "alice"}, 60, 1 ))
5959 .then(_assert(lastEmitted == {round: 1, name: "PrecommitValue", value: "proposal"}))
6060
6161 // Reaching PolkaAny
6262 run polkaAnyTest =
63- initWith(1, 100)
64- .then(applyVoteAction({typ: "Prevote", round: 1, value: "val1", address: "alice"}, 60))
63+ initWith(100)
64+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "val1", address: "alice"}, 60, 1 ))
6565 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
66- .then(applyVoteAction({typ: "Prevote", round: 1, value: "nil", address: "john"}, 10))
66+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "nil", address: "john"}, 10, 1 ))
6767 .then(_assert(lastEmitted == {round: 1, name: "PolkaAny", value: "null"}))
6868
6969 // Reaching PolkaNil
7070 run polkaNilTest =
71- initWith(1, 100)
72- .then(applyVoteAction({typ: "Prevote", round: 1, value: "nil", address: "alice"}, 60))
71+ initWith(100)
72+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "nil", address: "alice"}, 60, 1 ))
7373 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
74- .then(applyVoteAction({typ: "Prevote", round: 1, value: "nil", address: "john"}, 10))
74+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "nil", address: "john"}, 10, 1 ))
7575 .then(_assert(lastEmitted == {round: 1, name: "PolkaNil", value: "null"}))
7676
7777 // Reaching Skip via n+1 threshold with prevotes from two validators at a future round
7878 run skipSmallQuorumAllPrevotesTest =
79- initWith(1, 100)
80- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 60))
79+ initWith(100)
80+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 60, 1 ))
8181 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
82- .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 10))
82+ .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 10, 1 ))
8383 .then(_assert(lastEmitted == {round: 2, name: "None", value: "null"}))
84- .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "bob"}, 30))
84+ .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "bob"}, 30, 1 ))
8585 .then(_assert(lastEmitted == {round: 2, name: "Skip", value: "null"}))
8686
8787 // Cannot reach Skip via f+1 threshold with one prevote and one precommit from the same validator at a future round
8888 run noSkipSmallQuorumMixedVotesSameValTest =
89- initWith(1, 90)
90- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 10))
89+ initWith(90)
90+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 10, 1 ))
9191 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
92- .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 20))
92+ .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 20, 1 ))
9393 .then(_assert(lastEmitted == {round: 2, name: "None", value: "null"}))
94- .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "john"}, 20))
94+ .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "john"}, 20, 1 ))
9595 .then(_assert(lastEmitted != {round: 2, name: "Skip", value: "null"}))
9696
9797 // Reaching Skip via f+1 threshold with one prevote and one precommit from two validators at a future round
9898 run skipSmallQuorumMixedVotesTwoValsTest =
99- initWith(1, 80)
100- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 50))
99+ initWith(80)
100+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 50, 1 ))
101101 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
102- .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 10))
102+ .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 10, 1 ))
103103 .then(_assert(lastEmitted == {round: 2, name: "None", value: "null"}))
104- .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "bob"}, 20))
104+ .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "bob"}, 20, 1 ))
105105 .then(_assert(lastEmitted == {round: 2, name: "Skip", value: "null"}))
106106
107107 // Reaching Skip via 2f+1 threshold with a single prevote from a single validator at a future round
108108 run skipQuorumSinglePrevoteTest =
109- initWith(1, 100)
110- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 10))
109+ initWith(100)
110+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 10, 1 ))
111111 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
112- .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 60))
112+ .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 60, 1 ))
113113 .then(_assert(lastEmitted == {round: 2, name: "Skip", value: "null"}))
114114
115115 // Reaching Skip via 2f+1 threshold with a single precommit from a single validator at a future round
116116 run skipQuorumSinglePrecommitTest =
117- initWith(1, 100)
118- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 10))
117+ initWith(100)
118+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 10, 1 ))
119119 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
120- .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "john"}, 60))
120+ .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "john"}, 60, 1 ))
121121 .then(_assert(lastEmitted == {round: 2, name: "Skip", value: "null"}))
122122
123123 // Cannot reach Skip via 2f+1 threshold with one prevote and one precommit from the same validator at a future round
124124 run noSkipQuorumMixedVotesSameValTest =
125- initWith(1, 100)
126- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 10))
125+ initWith(100)
126+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 10, 1 ))
127127 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
128- .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 30))
128+ .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 30, 1 ))
129129 .then(_assert(lastEmitted == {round: 2, name: "None", value: "null"}))
130- .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "john"}, 30))
130+ .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "john"}, 30, 1 ))
131131 .then(_assert(lastEmitted != {round: 2, name: "Skip", value: "null"}))
132132
133133 // Reaching Skip via 2f+1 threshold with one prevote and one precommit from two validators at a future round
134134 run skipQuorumMixedVotesTwoValsTest =
135- initWith(1, 80)
136- .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 20))
135+ initWith(80)
136+ .then(applyVoteAction({typ: "Prevote", round: 1, value: "proposal", address: "alice"}, 20, 1 ))
137137 .then(_assert(lastEmitted == {round: 1, name: "None", value: "null"}))
138- .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 10))
138+ .then(applyVoteAction({typ: "Prevote", round: 2, value: "proposal", address: "john"}, 10, 1 ))
139139 .then(_assert(lastEmitted == {round: 2, name: "None", value: "null"}))
140- .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "bob"}, 50))
140+ .then(applyVoteAction({typ: "Precommit", round: 2, value: "proposal", address: "bob"}, 50, 1 ))
141141 .then(_assert(lastEmitted == {round: 2, name: "Skip", value: "null"}))
142142
143143}
0 commit comments