MCPcopy Create free account
hub / github.com/copernet/copernicus / TestBlockEncodeAndDecode

Function TestBlockEncodeAndDecode

model/block/block_test.go:11–28  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestBlockEncodeAndDecode(t *testing.T) {
12 rawBlockBytes, err := hex.DecodeString(rawBlock)
13 if err != nil {
14 t.Error("block decode string error:", err)
15 }
16 bk := NewBlock()
17 err = bk.Decode(bytes.NewReader(rawBlockBytes))
18 if err != nil {
19 t.Error("block decode error:", err)
20 }
21
22 buf := bytes.NewBuffer(nil)
23 bk.Encode(buf)
24
25 if !bytes.Equal(buf.Bytes(), rawBlockBytes) {
26 t.Error("block decode or encode error")
27 }
28}
29
30var rawBlock = "00000020d2d497201d88978b326a12f04f609a6f1f1425ae63c46c8ac72a200000000000dd241423caab3" +
31 "a32cdcd498a0762293787c3db01710812b901af822e2b019c5410afe05affff001d70baa7f70d0100000001000000000" +

Callers

nothing calls this directly

Calls 6

DecodeMethod · 0.95
EncodeMethod · 0.95
NewBlockFunction · 0.85
ErrorMethod · 0.45
EqualMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected