(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestGetBlock(t *testing.T) { |
| 15 | _, db := pgtest.NewDB(t, pgtest.SchemaPath) |
| 16 | ctx := context.Background() |
| 17 | store := txdb.NewStore(db) |
| 18 | chain := prottest.NewChain(t, prottest.WithStore(store)) |
| 19 | api := &API{chain: chain, store: store} |
| 20 | |
| 21 | block, err := api.getBlockRPC(ctx, 1) |
| 22 | if err != nil { |
| 23 | t.Fatal(err) |
| 24 | } |
| 25 | if block == nil { |
| 26 | t.Error("expected 1 (initial) block, got none") |
| 27 | } |
| 28 | |
| 29 | newBlock := prottest.MakeBlock(t, chain, nil) |
| 30 | buf := new(bytes.Buffer) |
| 31 | _, err = newBlock.WriteTo(buf) |
| 32 | if err != nil { |
| 33 | t.Fatal(err) |
| 34 | } |
| 35 | |
| 36 | block, err = api.getBlockRPC(ctx, 2) |
| 37 | if err != nil { |
| 38 | testutil.FatalErr(t, err) |
| 39 | } |
| 40 | |
| 41 | if block == nil { |
| 42 | t.Error("expected 1 block, got none") |
| 43 | } |
| 44 | if !bytes.Equal(block, buf.Bytes()) { |
| 45 | t.Errorf("got=%x, want=%s", block, buf.Bytes()) |
| 46 | } |
| 47 | } |
nothing calls this directly
no test coverage detected