MCPcopy Create free account
hub / github.com/chain/txvm / TestGetBlock

Function TestGetBlock

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

GetBlockMethod · 0.95
HeightMethod · 0.95
NewFunction · 0.92
EmptyFunction · 0.92
FatalErrFunction · 0.92
DeepEqualFunction · 0.92
ApplyBlockMethod · 0.80
NewChainFunction · 0.70
SaveBlockMethod · 0.65
SaveSnapshotMethod · 0.65

Tested by

no test coverage detected