|
1 | 1 | // Copyright 2021 ChainSafe Systems (ON)
|
2 | 2 | // SPDX-License-Identifier: LGPL-3.0-only
|
3 | 3 |
|
4 |
| -//go:build integration |
5 |
| - |
6 | 4 | package babe
|
7 | 5 |
|
8 | 6 | import (
|
9 | 7 | "fmt"
|
| 8 | + provisioner "github.com/ChainSafe/gossamer/dot/parachain/provisioner/messages" |
| 9 | + parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" |
| 10 | + "go.uber.org/mock/gomock" |
10 | 11 | "testing"
|
11 | 12 | "time"
|
12 | 13 |
|
@@ -35,6 +36,14 @@ var AuthorOnEverySlotBABEConfig = &types.BabeConfiguration{
|
35 | 36 | SecondarySlots: 0,
|
36 | 37 | }
|
37 | 38 |
|
| 39 | +type mockOverseerMessenger struct { |
| 40 | + ch chan any |
| 41 | +} |
| 42 | + |
| 43 | +func (m mockOverseerMessenger) OverseerChannel() chan<- any { |
| 44 | + return m.ch |
| 45 | +} |
| 46 | + |
38 | 47 | func TestService_SlotDuration(t *testing.T) {
|
39 | 48 | duration, err := time.ParseDuration("1000ms")
|
40 | 49 | require.NoError(t, err)
|
@@ -182,7 +191,32 @@ func TestService_HandleSlotWithLaggingSlot(t *testing.T) {
|
182 | 191 | preRuntimeDigest,
|
183 | 192 | )
|
184 | 193 |
|
185 |
| - block, err := builder.buildBlock(&genesisHeader, slot, rt) |
| 194 | + ctrl := gomock.NewController(t) |
| 195 | + bs := NewMockBlockState(ctrl) |
| 196 | + bs.EXPECT().GetHeader(gomock.Any()).Return(&types.Header{ |
| 197 | + ParentHash: emptyHash, |
| 198 | + Number: 0, |
| 199 | + }, nil) |
| 200 | + |
| 201 | + ovChan := make(chan any) |
| 202 | + go func() { |
| 203 | + ovMsg := <-ovChan |
| 204 | + waitForActivation, ok := ovMsg.(parachaintypes.WaitForActivation) |
| 205 | + require.True(t, ok) |
| 206 | + waitForActivation.ResponseCh <- nil |
| 207 | + |
| 208 | + ovMsg = <-ovChan |
| 209 | + provisionerInherentReq, ok := ovMsg.(provisioner.RequestInherentData) |
| 210 | + require.True(t, ok) |
| 211 | + // Provide valid inherent data with required bitfields and heads |
| 212 | + provisionerInherentReq.ProvisionerInherentData <- provisioner.ProvisionerInherentData{ |
| 213 | + Bitfields: []parachaintypes.CheckedSignedAvailabilityBitfield{}, |
| 214 | + BackedCandidates: []parachaintypes.BackedCandidate{}, |
| 215 | + Disputes: []parachaintypes.DisputeStatementSet{}, |
| 216 | + } |
| 217 | + }() |
| 218 | + |
| 219 | + block, err := builder.buildBlock(&genesisHeader, slot, rt, bs, mockOverseerMessenger{ch: ovChan}) |
186 | 220 | require.NoError(t, err)
|
187 | 221 |
|
188 | 222 | fmt.Println(epochDescriptor.startSlot)
|
@@ -255,7 +289,10 @@ func TestService_HandleSlotWithSameSlot(t *testing.T) {
|
255 | 289 | preRuntimeDigest,
|
256 | 290 | )
|
257 | 291 |
|
258 |
| - block, err := builder.buildBlock(&genesisHeader, slot, runtime) |
| 292 | + ctrl := gomock.NewController(t) |
| 293 | + bs := NewMockBlockState(ctrl) |
| 294 | + |
| 295 | + block, err := builder.buildBlock(&genesisHeader, slot, runtime, bs, mockOverseerMessenger{ch: make(chan any)}) |
259 | 296 | require.NoError(t, err)
|
260 | 297 |
|
261 | 298 | // Create new non authority service
|
|
0 commit comments