MCPcopy Create free account
hub / github.com/chain/txvm / TestBlockMarshal

Function TestBlockMarshal

protocol/bc/block_test.go:102–129  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

100}
101
102func TestBlockMarshal(t *testing.T) {
103 block := testBlock()
104
105 blockBytes, err := block.Bytes()
106 if err != nil {
107 t.Fatal(err)
108 }
109
110 wantBytes := []byte(hex.EncodeToString(blockBytes))
111 gotBytes, err := block.MarshalText()
112 if err != nil {
113 t.Fatal(err)
114 }
115
116 if !bytes.Equal(gotBytes, wantBytes) {
117 t.Errorf("MarshalText(%v):\ngot: %x\n\twant: %x", block, gotBytes, wantBytes)
118 }
119
120 gotBlock := new(Block)
121 err = gotBlock.UnmarshalText(wantBytes)
122 if err != nil {
123 t.Fatal(err)
124 }
125
126 if !testutil.DeepEqual(gotBlock, block) {
127 t.Errorf("UnmarshalText(%x):\ngot: %v\n\twant: %v", wantBytes, gotBlock, block)
128 }
129}
130
131func TestBlockScan(t *testing.T) {
132 block := testBlock()

Callers

nothing calls this directly

Calls 6

DeepEqualFunction · 0.92
testBlockFunction · 0.85
EqualMethod · 0.80
BytesMethod · 0.45
MarshalTextMethod · 0.45
UnmarshalTextMethod · 0.45

Tested by

no test coverage detected