Fix failed tests

pull/55/head
kourin 2 years ago
parent 7b7ac4a629
commit 368025c938
  1. 11
      core/consensus_test.go
  2. 18
      core/helpers_test.go
  3. 71
      core/ibft_test.go
  4. 6
      core/mock_test.go
  5. 10
      core/rapid_test.go

@ -40,7 +40,7 @@ func buildBasicPreprepareMessage(
PreprepareData: &proto.PrePrepareMessage{
Proposal: &proto.ProposedBlock{
EthereumBlock: ethereumBlock,
Round: 0, //TODO:
Round: view.Round,
},
Certificate: certificate,
ProposalHash: proposalHash,
@ -260,7 +260,6 @@ func TestConsensus_ValidFlow(t *testing.T) {
// Make sure the inserted blocks match what node 0 proposed
for _, block := range insertedBlocks {
// TODO: @Yoshiki, change upon changing the InsertBlock
assert.True(t, bytes.Equal(block, correctRoundMessage.proposal.GetEthereumBlock()))
}
}
@ -329,13 +328,7 @@ func TestConsensus_InvalidBlock(t *testing.T) {
// Make sure the proposal hash matches
backend.isValidProposalHashFn = func(proposal *proto.ProposedBlock, proposalHash []byte) bool {
return true
// TODO:
//if bytes.Equal(proposal, proposals[0]) {
// return bytes.Equal(proposalHash, proposalHashes[0])
//}
//return bytes.Equal(proposalHash, proposalHashes[1])
return bytes.Equal(proposal.EthereumBlock, proposals[1]) && bytes.Equal(proposalHash, proposalHashes[1])
}
// Make sure the preprepare message is built correctly

@ -20,7 +20,7 @@ var (
)
func isValidProposal(newProposal []byte) bool {
return bytes.Equal(newProposal, validProposal)
return bytes.Equal(newProposal, validEthereumBlock)
}
func buildValidEthereumBlock(_ uint64) []byte {
@ -28,15 +28,13 @@ func buildValidEthereumBlock(_ uint64) []byte {
}
func isValidProposalHash(proposal *proto.ProposedBlock, proposalHash []byte) bool {
return true
// TODO:
//return bytes.Equal(
// proposal,
// validProposal,
//) && bytes.Equal(
// proposalHash,
// validProposalHash,
//)
return bytes.Equal(
proposal.EthereumBlock,
validEthereumBlock,
) && bytes.Equal(
proposalHash,
validProposalHash,
)
}
type node struct {

@ -19,12 +19,11 @@ func proposalMatches(proposal *proto.ProposedBlock, message *proto.Message) bool
return false
}
return true
preprepareData, _ := message.Payload.(*proto.Message_PreprepareData)
//TODO:
//preprepareData, _ := message.Payload.(*proto.Message_PreprepareData)
//extractedProposal := preprepareData.PreprepareData.Proposal
//return bytes.Equal(proposal, extractedProposal)
extractedProposal := preprepareData.PreprepareData.Proposal
return bytes.Equal(proposal.EthereumBlock, extractedProposal.EthereumBlock)
}
func prepareHashMatches(prepareHash []byte, message *proto.Message) bool {
@ -258,7 +257,7 @@ func TestRunNewRound_Proposer(t *testing.T) {
PreprepareData: &proto.PrePrepareMessage{
Proposal: &proto.ProposedBlock{
EthereumBlock: ethereumBlock,
Round: 0, // TODO:
Round: view.Round,
},
Certificate: certificate,
},
@ -293,8 +292,10 @@ func TestRunNewRound_Proposer(t *testing.T) {
assert.Equal(t, multicastedProposal, i.state.proposalMessage)
// Make sure the accepted proposal matches what was built
//TODO:
assert.True(t, proposalMatches(&proto.ProposedBlock{}, multicastedProposal))
assert.True(t, proposalMatches(&proto.ProposedBlock{
EthereumBlock: newEthereumBlock,
Round: 0,
}, multicastedProposal))
},
)
@ -419,7 +420,7 @@ func TestRunNewRound_Proposer(t *testing.T) {
lastPreparedProposedBlock := &proto.ProposedBlock{
EthereumBlock: []byte("dummy block"),
Round: 0, //TODO: check
Round: 0,
}
quorum := uint64(4)
@ -512,7 +513,7 @@ func TestRunNewRound_Proposer(t *testing.T) {
PreprepareData: &proto.PrePrepareMessage{
Proposal: &proto.ProposedBlock{
EthereumBlock: ethereumBlock,
Round: 0, // TODO:
Round: 0,
},
ProposalHash: correctRoundMessage.hash,
Certificate: certificate,
@ -1061,7 +1062,7 @@ func TestRunCommit(t *testing.T) {
assert.Equal(t, fin, i.state.name)
// Make sure the inserted proposal was the one present
assert.Equal(t, insertedProposal, correctRoundMessage.proposal)
assert.Equal(t, insertedProposal, correctRoundMessage.proposal.EthereumBlock)
// Make sure the inserted committed seals were correct
assert.Equal(t, insertedCommittedSeals, committedSeals)
@ -1339,7 +1340,10 @@ func TestIBFT_FutureProposal(t *testing.T) {
Type: proto.MessageType_PREPREPARE,
Payload: &proto.Message_PreprepareData{
PreprepareData: &proto.PrePrepareMessage{
Proposal: correctRoundMessage.proposal,
Proposal: &proto.ProposedBlock{
EthereumBlock: correctRoundMessage.proposal.EthereumBlock,
Round: testCase.proposalView.Round,
},
ProposalHash: correctRoundMessage.hash,
Certificate: &proto.RoundChangeCertificate{
RoundChangeMessages: testCase.roundChangeMessages,
@ -1362,10 +1366,8 @@ func TestIBFT_FutureProposal(t *testing.T) {
return nodeID
},
isValidProposalHashFn: func(p *proto.ProposedBlock, hash []byte) bool {
return true
//TODO: Implement
//return bytes.Equal(hash, correctRoundMessage.hash) &&
// bytes.Equal(p, correctRoundMessage.proposal)
return bytes.Equal(hash, correctRoundMessage.hash) &&
bytes.Equal(p.EthereumBlock, correctRoundMessage.proposal.EthereumBlock)
},
hasQuorumFn: defaultHasQuorumFn(quorum),
}
@ -1423,7 +1425,11 @@ func TestIBFT_FutureProposal(t *testing.T) {
}
assert.Equal(t, testCase.notifyRound, receivedProposalEvent.round)
assert.Equal(t, correctRoundMessage.proposal, messages.ExtractProposal(receivedProposalEvent.proposalMessage))
assert.Equal(
t,
messages.ExtractProposal(validProposal),
messages.ExtractProposal(receivedProposalEvent.proposalMessage),
)
})
}
}
@ -1837,7 +1843,11 @@ func TestIBFT_ValidateProposal(t *testing.T) {
View: baseView,
Type: proto.MessageType_PREPREPARE,
Payload: &proto.Message_PreprepareData{
PreprepareData: &proto.PrePrepareMessage{},
PreprepareData: &proto.PrePrepareMessage{
Proposal: &proto.ProposedBlock{
Round: baseView.Round,
},
},
},
}
@ -1870,7 +1880,11 @@ func TestIBFT_ValidateProposal(t *testing.T) {
View: baseView,
Type: proto.MessageType_PREPREPARE,
Payload: &proto.Message_PreprepareData{
PreprepareData: &proto.PrePrepareMessage{},
PreprepareData: &proto.PrePrepareMessage{
Proposal: &proto.ProposedBlock{
Round: baseView.Round,
},
},
},
}
@ -1903,7 +1917,11 @@ func TestIBFT_ValidateProposal(t *testing.T) {
View: baseView,
Type: proto.MessageType_PREPREPARE,
Payload: &proto.Message_PreprepareData{
PreprepareData: &proto.PrePrepareMessage{},
PreprepareData: &proto.PrePrepareMessage{
Proposal: &proto.ProposedBlock{
Round: baseView.Round,
},
},
},
}
@ -1935,6 +1953,9 @@ func TestIBFT_ValidateProposal(t *testing.T) {
Payload: &proto.Message_PreprepareData{
PreprepareData: &proto.PrePrepareMessage{
Certificate: nil,
Proposal: &proto.ProposedBlock{
Round: baseView.Round,
},
},
},
}
@ -1972,6 +1993,9 @@ func TestIBFT_ValidateProposal(t *testing.T) {
Certificate: &proto.RoundChangeCertificate{
RoundChangeMessages: generateMessages(quorum-1, proto.MessageType_ROUND_CHANGE),
},
Proposal: &proto.ProposedBlock{
Round: baseView.Round,
},
},
},
}
@ -2015,6 +2039,9 @@ func TestIBFT_ValidateProposal(t *testing.T) {
Type: proto.MessageType_PREPREPARE,
Payload: &proto.Message_PreprepareData{
PreprepareData: &proto.PrePrepareMessage{
Proposal: &proto.ProposedBlock{
Round: baseView.Round,
},
Certificate: &proto.RoundChangeCertificate{
RoundChangeMessages: generateMessages(quorum, proto.MessageType_ROUND_CHANGE),
},
@ -2058,6 +2085,9 @@ func TestIBFT_ValidateProposal(t *testing.T) {
Certificate: &proto.RoundChangeCertificate{
RoundChangeMessages: generateMessages(quorum, proto.MessageType_ROUND_CHANGE),
},
Proposal: &proto.ProposedBlock{
Round: baseView.Round,
},
},
},
}
@ -2176,7 +2206,6 @@ func TestIBFT_RunSequence_NewProposal(t *testing.T) {
defer cancelFn()
var (
//TODO:
proposal = &proto.ProposedBlock{}
round = uint64(10)
height = uint64(1)

@ -19,7 +19,7 @@ var (
correctRoundMessage = roundMessage{
proposal: &proto.ProposedBlock{
EthereumBlock: validEthereumBlock,
Round: 0, // TODO: correctRound
Round: 0,
},
hash: []byte("proposal hash"),
seal: []byte("seal"),
@ -27,8 +27,8 @@ var (
badRoundMessage = roundMessage{
proposal: &proto.ProposedBlock{
EthereumBlock: []byte("bad"), // TODO: invalidEthereumBlock
Round: 100, // TODO: incorrectRound
EthereumBlock: []byte("bad"),
Round: 100,
},
hash: []byte("bad proposal hash"),
seal: []byte("bad seal"),

@ -255,16 +255,14 @@ func TestProperty(t *testing.T) {
backend.isValidBlockFn = func(ethereumBlock []byte) bool {
message := setup.getEvent(nodeIndex).getMessage(nodeIndex)
return bytes.Equal(ethereumBlock, message.proposal.EthereumBlock) //TODO: Double-check
return bytes.Equal(ethereumBlock, message.proposal.EthereumBlock)
}
// Make sure the proposal hash matches
backend.isValidProposalHashFn = func(p *proto.ProposedBlock, ph []byte) bool {
message := setup.getEvent(nodeIndex).getMessage(nodeIndex)
return true
//TODO: Impl
//message := setup.getEvent(nodeIndex).getMessage(nodeIndex)
// return bytes.Equal(p, message.proposal) && bytes.Equal(ph, message.hash)
return bytes.Equal(p.EthereumBlock, message.proposal.EthereumBlock) && bytes.Equal(ph, message.hash)
}
// Make sure the preprepare message is built correctly
@ -368,7 +366,7 @@ func TestProperty(t *testing.T) {
// Make sure inserted block value is correct
for _, val := range proposalMap {
assert.Equal(t, correctRoundMessage.proposal, val)
assert.Equal(t, correctRoundMessage.proposal.EthereumBlock, val)
}
} else {
// There should not be inserted blocks in bad nodes

Loading…
Cancel
Save