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

Function TestEmptyVarstring31

encoding/blockchain/blockchain_test.go:164–184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestEmptyVarstring31(t *testing.T) {
165 s := []byte{}
166 b := new(bytes.Buffer)
167 _, err := WriteVarstr31(b, s)
168 if err != nil {
169 t.Fatal(err)
170 }
171 want := []byte{0x00}
172 if !bytes.Equal(b.Bytes(), want) {
173 t.Errorf("got %x, want %x", b.Bytes(), want)
174 }
175
176 s, err = ReadVarstr31(NewReader(want))
177 if err != nil {
178 t.Fatal(err)
179 }
180 want = nil // we deliberately return nil for empty strings to avoid unnecessary byteslice allocation
181 if !bytes.Equal(s, want) {
182 t.Errorf("got %x, expected %x", s, want)
183 }
184}
185
186// TestTooLongVarstring31 tests decoding a varstring31 with a leading
187// length too long to fit in memory. Reading such a varstring31 should

Callers

nothing calls this directly

Calls 5

WriteVarstr31Function · 0.85
ReadVarstr31Function · 0.85
NewReaderFunction · 0.85
EqualMethod · 0.45
BytesMethod · 0.45

Tested by

no test coverage detected