MCPcopy
hub / github.com/canopy-network/canopy / TestGetHash

Function TestGetHash

lib/tx_test.go:164–191  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

162}
163
164func TestGetHash(t *testing.T) {
165 // pre-define a test message
166 sig := &Signature{
167 PublicKey: newTestPublicKeyBytes(t),
168 Signature: newTestPublicKeyBytes(t),
169 }
170 // pre-define an any for testing
171 a, e := NewAny(sig)
172 require.NoError(t, e)
173 // pre-define a transaction
174 tx := &Transaction{
175 MessageType: testMessageName,
176 Msg: a,
177 Signature: sig,
178 Time: uint64(time.Now().UnixMicro()),
179 Fee: 1,
180 Memo: "memo",
181 }
182 // calculate expected
183 bz, err := Marshal(tx)
184 require.NoError(t, err)
185 expected := crypto.Hash(bz)
186 // execute function call
187 got, err := tx.GetHash()
188 require.NoError(t, err)
189 // compare got vs expected
190 require.Equal(t, expected, got)
191}
192
193func TestGetSignBytes(t *testing.T) {
194 // pre-define a test message

Callers

nothing calls this directly

Calls 6

GetHashMethod · 0.95
HashFunction · 0.92
NewAnyFunction · 0.85
EqualMethod · 0.80
newTestPublicKeyBytesFunction · 0.70
MarshalFunction · 0.70

Tested by

no test coverage detected