Skip to content

Commit

Permalink
clean up and keep secondary test for now
Browse files Browse the repository at this point in the history
  • Loading branch information
jimjbrettj committed Feb 16, 2023
1 parent aaf3dd4 commit 32a7c81
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/babe/epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func (b *Service) initiateEpoch(epoch uint64) (*epochData, error) {
// by checking when we will be able to produce block 1.
// note that this assumes there will only be one producer of block 1
if bestBlockHeader.Hash() == b.blockState.GenesisHash() {

startSlot, err = b.getFirstAuthoringSlot(epoch, epochData)
if err != nil {
return nil, fmt.Errorf("cannot get first authoring slot: %w", err)
Expand Down
47 changes: 47 additions & 0 deletions lib/babe/verify_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package babe
import (
"errors"
"fmt"
"github.com/ChainSafe/gossamer/lib/common"
"testing"
"time"

Expand Down Expand Up @@ -152,6 +153,52 @@ func TestVerificationManager_OnDisabled_DuplicateDigest(t *testing.T) {
require.Equal(t, ErrAuthorityAlreadyDisabled, err)
}

// TODO Rather than test error, test happy path #3060
func TestVerificationManager_VerifyBlock_Secondary(t *testing.T) {
genesis, genesisTrie, genesisHeader := newWestendDevGenesisWithTrieAndHeader(t)
babeService := createTestService(t, ServiceConfig{}, genesis, genesisTrie, genesisHeader, nil, true)
vm := NewVerificationManager(babeService.blockState, babeService.epochState)

secondaryDigest := createSecondaryVRFPreDigest(t, keyring.Alice().(*sr25519.Keypair),
0, uint64(0), uint64(0), Randomness{})
babeDigest := types.NewBabeDigest()
err := babeDigest.Set(secondaryDigest)
require.NoError(t, err)

encodedBabeDigest, err := scale.Marshal(babeDigest)
require.NoError(t, err)

// create pre-digest
preDigest := &types.PreRuntimeDigest{
ConsensusEngineID: types.BabeEngineID,
Data: encodedBabeDigest,
}

// create new block header
const number uint = 1
digest := types.NewDigest()
err = digest.Add(*preDigest)
require.NoError(t, err)

// create seal and add to digest
seal := &types.SealDigest{
ConsensusEngineID: types.BabeEngineID,
Data: []byte{0},
}
require.NoError(t, err)

err = digest.Add(*seal)
require.NoError(t, err)

header := types.NewHeader(common.Hash{}, common.Hash{}, common.Hash{}, number, digest)
block := types.Block{
Header: *header,
Body: nil,
}
err = vm.VerifyBlock(&block.Header)
require.EqualError(t, err, "failed to verify pre-runtime digest: block producer is not in authority set")
}

func TestVerificationManager_VerifyBlock_CurrentEpoch(t *testing.T) {
genesis, genesisTrie, genesisHeader := newWestendDevGenesisWithTrieAndHeader(t)
babeService := createTestService(t, ServiceConfig{}, genesis, genesisTrie, genesisHeader, nil, false)
Expand Down

0 comments on commit 32a7c81

Please sign in to comment.