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

Function TestGetBlock

core/rpc_test.go:14–47  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func 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}

Callers

nothing calls this directly

Calls 5

getBlockRPCMethod · 0.95
ErrorMethod · 0.45
WriteToMethod · 0.45
EqualMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected