| 14 | ) |
| 15 | |
| 16 | func 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 | |
| 49 | func TestNoTimeTravel(t *testing.T) { |
| 50 | ctx := context.Background() |