MCPcopy Index your code
hub / github.com/chain/Core / TestGetBlock

Function TestGetBlock

protocol/block_test.go:16–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestGetBlock(t *testing.T) {
17 ctx := context.Background()
18
19 b1 := &legacy.Block{BlockHeader: legacy.BlockHeader{Height: 1}}
20 noBlocks := memstore.New()
21 oneBlock := memstore.New()
22 oneBlock.SaveBlock(ctx, b1)
23 oneBlock.SaveSnapshot(ctx, 1, state.Empty())
24
25 cases := []struct {
26 store Store
27 want *legacy.Block
28 wantErr bool
29 }{
30 {noBlocks, nil, true},
31 {oneBlock, b1, false},
32 }
33
34 for _, test := range cases {
35 c, err := NewChain(ctx, b1.Hash(), test.store, nil)
36 if err != nil {
37 testutil.FatalErr(t, err)
38 }
39 got, gotErr := c.GetBlock(ctx, c.Height())
40 if !testutil.DeepEqual(got, test.want) {
41 t.Errorf("got latest = %+v want %+v", got, test.want)
42 }
43 if (gotErr != nil) != test.wantErr {
44 t.Errorf("got latest err = %q want err?: %t", gotErr, test.wantErr)
45 }
46 }
47}
48
49func TestNoTimeTravel(t *testing.T) {
50 ctx := context.Background()

Callers

nothing calls this directly

Calls 6

GetBlockMethod · 0.95
HeightMethod · 0.95
NewChainFunction · 0.70
SaveBlockMethod · 0.65
SaveSnapshotMethod · 0.65
HashMethod · 0.45

Tested by

no test coverage detected