(t *testing.T)
| 20 | ) |
| 21 | |
| 22 | func 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 | |
| 57 | func TestNoTimeTravel(t *testing.T) { |
| 58 | b1 := &bc.Block{UnsignedBlock: &bc.UnsignedBlock{BlockHeader: &bc.BlockHeader{Height: 1, NextPredicate: &bc.Predicate{}}}} |
nothing calls this directly
no test coverage detected