Skip to content

Commit

Permalink
tests(dot/digest) add tests to digest block import handler (#3329)
Browse files Browse the repository at this point in the history
  • Loading branch information
EclesioMeloJunior authored Jun 21, 2023
1 parent a3b3d48 commit 8d76664
Show file tree
Hide file tree
Showing 2 changed files with 415 additions and 7 deletions.
22 changes: 15 additions & 7 deletions dot/digest/block_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ func NewBlockImportHandler(epochState EpochState, grandpaState GrandpaState) *Bl
func (h *BlockImportHandler) Handle(importedBlockHeader *types.Header) error {
err := h.handleDigests(importedBlockHeader)
if err != nil {
return fmt.Errorf("while handling digests: %w", err)
return fmt.Errorf("handling digests: %w", err)
}

// TODO: move to core handleBlock
// https://github.com/ChainSafe/gossamer/issues/3330
err = h.grandpaState.ApplyForcedChanges(importedBlockHeader)
if err != nil {
return fmt.Errorf("while apply forced changes: %s", err)
return fmt.Errorf("applying forced changes: %w", err)
}

return nil
Expand All @@ -53,7 +53,7 @@ func (h *BlockImportHandler) handleDigests(header *types.Header) error {
digest := consensusDigests[i]
err := h.handleConsensusDigest(&digest, header)
if err != nil {
logger.Errorf("cannot handle consensus digest: %w", err)
return fmt.Errorf("consensus digests: %w", err)
}
}

Expand All @@ -66,21 +66,29 @@ func (h *BlockImportHandler) handleConsensusDigest(d *types.ConsensusDigest, hea
data := types.NewGrandpaConsensusDigest()
err := scale.Unmarshal(d.Data, &data)
if err != nil {
return err
return fmt.Errorf("unmarshaling grandpa consensus digest: %w", err)
}

return h.grandpaState.HandleGRANDPADigest(header, data)
err = h.grandpaState.HandleGRANDPADigest(header, data)
if err != nil {
return fmt.Errorf("handling grandpa digest: %w", err)
}
case types.BabeEngineID:
data := types.NewBabeConsensusDigest()
err := scale.Unmarshal(d.Data, &data)
if err != nil {
return err
return fmt.Errorf("unmarshaling babe consensus digest: %w", err)
}

return h.epochState.HandleBABEDigest(header, data)
err = h.epochState.HandleBABEDigest(header, data)
if err != nil {
return fmt.Errorf("handling babe digest: %w", err)
}
default:
return fmt.Errorf("%w: 0x%x", ErrUnknownConsensusEngineID, d.ConsensusEngineID.ToBytes())
}

return nil
}

// toConsensusDigests converts a slice of scale.VaryingDataType to a slice of types.ConsensusDigest.
Expand Down
Loading

0 comments on commit 8d76664

Please # to comment.