MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestHeaderMarshalUnmarshaler

Function TestHeaderMarshalUnmarshaler

types/block_test.go:61–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestHeaderMarshalUnmarshaler(t *testing.T) {
62 block, err := CreateRandomBlock(genesisHash, false)
63
64 if err != nil {
65 t.Fatalf("error occurred: %v", err)
66 }
67
68 origin := &block.SignedHeader.Header
69 enc, err := utils.EncodeMsgPack(origin)
70
71 if err != nil {
72 t.Fatalf("error occurred: %v", err)
73 }
74
75 dec := &Header{}
76 if err = utils.DecodeMsgPack(enc.Bytes(), dec); err != nil {
77 t.Fatalf("error occurred: %v", err)
78 }
79
80 bts1, err := origin.MarshalHash()
81 if err != nil {
82 t.Fatalf("error occurred: %v", err)
83 }
84
85 bts2, err := dec.MarshalHash()
86 if err != nil {
87 t.Fatalf("error occurred: %v", err)
88 }
89
90 if !bytes.Equal(bts1, bts2) {
91 t.Fatal("hash not stable")
92 }
93
94 if !reflect.DeepEqual(origin, dec) {
95 t.Fatalf("values don't match:\n\tv1 = %+v\n\tv2 = %+v", origin, dec)
96 }
97}
98
99func TestSignedHeaderMarshaleUnmarshaler(t *testing.T) {
100 block, err := CreateRandomBlock(genesisHash, false)

Callers

nothing calls this directly

Calls 8

MarshalHashMethod · 0.95
EncodeMsgPackFunction · 0.92
DecodeMsgPackFunction · 0.92
CreateRandomBlockFunction · 0.85
FatalfMethod · 0.80
FatalMethod · 0.80
MarshalHashMethod · 0.65
BytesMethod · 0.45

Tested by

no test coverage detected