Skip to content

Commit

Permalink
Description of polybft test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemanja0x committed Oct 24, 2022
1 parent 3fc575a commit 118a591
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions consensus/polybft/consensus_runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func TestConsensusRuntime_GetVotes(t *testing.T) {
for i := 0; i < int(votesCount); i++ {
validator := validatorAccounts.getValidator(validatorIds[i])
signature, err := validator.mustSign(hash.Bytes()).Marshal()
require.NoError(t, err)

_, err = state.insertMessageVote(epoch, hash.Bytes(),
&MessageSignature{
Expand Down
9 changes: 6 additions & 3 deletions consensus/polybft/polybft_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
"github.com/stretchr/testify/require"
)

// the test initializes polybft and chain mock (map of headers) after wihch a new header is verified
// firstly, two invalid situation of header verifications are triggered (missing Committed field and invalid validators for ParentCommitted)
// afterwards, valid inclusion into the block chain is checked
// and at the end there is a situation when header is already a part of blockchain
func TestPolybft_VerifyHeader(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -67,7 +71,7 @@ func TestPolybft_VerifyHeader(t *testing.T) {
}
header.ComputeHash()

// add header from 1 to 9 to map
// add headers from 1 to 9 to map (blockchain imitation)
headersMap.addHeader(header)
}

Expand Down Expand Up @@ -98,7 +102,6 @@ func TestPolybft_VerifyHeader(t *testing.T) {
currentExtra := &Extra{Validators: currentDelta, Parent: parentCommitted}
currentHeader := &types.Header{
Number: polyBftConfig.EpochSize + 1,
ExtraData: append(make([]byte, signer.IstanbulExtraVanity), currentExtra.MarshalRLPTo(nil)...),
ParentHash: parentHeader.Hash,
Timestamp: parentHeader.Timestamp + 1,
MixHash: PolyMixDigest,
Expand Down Expand Up @@ -140,7 +143,7 @@ func TestPolybft_VerifyHeader(t *testing.T) {
assert.NoError(t, polybft.validatorsCache.storeSnapshot(1, validatorSetCurrent))
assert.ErrorContains(t, polybft.VerifyHeader(currentHeader), "failed to verify signatures for parent of block")

// clean validators cache again and set valid snapsots
// clean validators cache again and set valid snapshots
polybft.validatorsCache = newValidatorsSnapshotCache(hclog.NewNullLogger(), newTestState(t), polyBftConfig.EpochSize, blockchainMock)
assert.NoError(t, polybft.validatorsCache.storeSnapshot(0, validatorSetParent))
assert.NoError(t, polybft.validatorsCache.storeSnapshot(1, validatorSetCurrent))
Expand Down

0 comments on commit 118a591

Please sign in to comment.