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

Function TestHashReadFrom

protocol/bc/hash_test.go:137–162  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

135}
136
137func TestHashReadFrom(t *testing.T) {
138 cases := []struct {
139 buf []byte
140 want Hash
141 wantErr bool
142 }{{
143 buf: []byte("short"),
144 wantErr: true,
145 }, {
146 buf: mustDecodeHex("0100000000000000000000000000000000000000000000000000000000000000"),
147 want: NewHash([32]byte{1}),
148 }}
149
150 for _, c := range cases {
151 var buf bytes.Buffer
152 buf.Write(c.buf[:])
153 var got Hash
154 _, err := got.ReadFrom(&buf)
155 if err != nil && !c.wantErr {
156 t.Errorf("ReadFrom(%x) error = %v want nil", c.buf, err)
157 }
158 if got != c.want {
159 t.Errorf("ReadFrom(%x) = %x want %x", c.buf, got.Bytes(), c.want.Bytes())
160 }
161 }
162}
163
164func TestHashIsZero(t *testing.T) {
165 var hash *Hash

Callers

nothing calls this directly

Calls 5

ReadFromMethod · 0.95
BytesMethod · 0.95
NewHashFunction · 0.85
mustDecodeHexFunction · 0.70
WriteMethod · 0.45

Tested by

no test coverage detected