Skip to content

Commit

Permalink
split TestPlayerRetainsReceivedValidatedAtPP from TestPlayerRetainsRe…
Browse files Browse the repository at this point in the history
…ceivedValidatedAt
  • Loading branch information
cce committed Mar 7, 2023
1 parent 3bbba0b commit c7ea113
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions agreement/player_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3244,6 +3244,36 @@ func TestPlayerRetainsReceivedValidatedAt(t *testing.T) {
pWhite, pM, helper := setupP(t, r-1, p, soft)
pP, pV := helper.MakeRandomProposalPayload(t, r-1)

// send voteVerified message
vVote := helper.MakeVerifiedVote(t, 0, r-1, p, propose, *pV)
inMsg := messageEvent{T: voteVerified, Input: message{Vote: vVote, UnauthenticatedVote: vVote.u()}}
err, panicErr := pM.transition(inMsg)
require.NoError(t, err)
require.NoError(t, panicErr)

// send payloadPresent message
m := message{UnauthenticatedProposal: pP.u()}
inMsg = messageEvent{T: payloadPresent, Input: m}
inMsg = inMsg.AttachReceivedAt(time.Second)
err, panicErr = pM.transition(inMsg)
require.NoError(t, err)
require.NoError(t, panicErr)

assertCorrectReceivedAtSet(t, pWhite, pM, helper, r, p, pP, pV, m)
}

// test that ReceivedAt and ValidateAt timing information are retained in proposalStore
// when the payloadPresent (as part of the CompoundMessage encoding used by PP messages)
// and payloadVerified events are processed, and that both timings
// are available when the ensureAction is called for the block.
func TestPlayerRetainsReceivedValidatedAtPP(t *testing.T) {
partitiontest.PartitionTest(t)

const r = round(20239)
const p = period(1001)
pWhite, pM, helper := setupP(t, r-1, p, soft)
pP, pV := helper.MakeRandomProposalPayload(t, r-1)

// create a PP message for an arbitrary proposal/payload similar to setupCompoundMessage
vVote := helper.MakeVerifiedVote(t, 0, r-1, p, propose, *pV)
voteMsg := message{Vote: vVote, UnauthenticatedVote: vVote.u()}
Expand All @@ -3265,15 +3295,20 @@ func TestPlayerRetainsReceivedValidatedAt(t *testing.T) {
require.NoError(t, err)
require.NoError(t, panicErr)

assertCorrectReceivedAtSet(t, pWhite, pM, helper, r, p, pP, pV, proposalMsg)
}

func assertCorrectReceivedAtSet(t *testing.T, pWhite *player, pM ioAutomata, helper *voteMakerHelper,
r round, p period, pP *proposal, pV *proposalValue, proposalMsg message) {
// make sure payload verify requests
verifyEvent = ev(cryptoAction{T: verifyPayload, M: proposalMsg})
verifyEvent := ev(cryptoAction{T: verifyPayload, M: proposalMsg})
tr := pM.getTrace()
require.Truef(t, tr.Contains(verifyEvent), "Player should verify payload: %s", tr.String())

// payloadVerified
inMsg = messageEvent{T: payloadVerified, Input: message{Proposal: *pP}, Proto: ConsensusVersionView{Version: protocol.ConsensusCurrentVersion}}
inMsg := messageEvent{T: payloadVerified, Input: message{Proposal: *pP}, Proto: ConsensusVersionView{Version: protocol.ConsensusCurrentVersion}}
inMsg = inMsg.AttachValidatedAt(2 * time.Second) // call AttachValidatedAt like demux would
err, panicErr = pM.transition(inMsg)
err, panicErr := pM.transition(inMsg)
require.NoError(t, err)
require.NoError(t, panicErr)

Expand Down

0 comments on commit c7ea113

Please sign in to comment.