forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_state_summary.go
52 lines (40 loc) · 973 Bytes
/
test_state_summary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package block
import (
"context"
"errors"
"testing"
"github.com/stretchr/testify/require"
"github.com/MetalBlockchain/metalgo/ids"
)
var (
_ StateSummary = (*TestStateSummary)(nil)
errAccept = errors.New("unexpectedly called Accept")
)
type TestStateSummary struct {
IDV ids.ID
HeightV uint64
BytesV []byte
T *testing.T
CantAccept bool
AcceptF func(context.Context) (StateSyncMode, error)
}
func (s *TestStateSummary) ID() ids.ID {
return s.IDV
}
func (s *TestStateSummary) Height() uint64 {
return s.HeightV
}
func (s *TestStateSummary) Bytes() []byte {
return s.BytesV
}
func (s *TestStateSummary) Accept(ctx context.Context) (StateSyncMode, error) {
if s.AcceptF != nil {
return s.AcceptF(ctx)
}
if s.CantAccept && s.T != nil {
require.FailNow(s.T, errAccept.Error())
}
return StateSyncSkipped, errAccept
}