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

Function TestTransactionResultJSON

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

Source from the content-addressed store, hash-verified

291}
292
293func TestTransactionResultJSON(t *testing.T) {
294 // pre-define a test message
295 sig := &Signature{
296 PublicKey: newTestPublicKeyBytes(t),
297 Signature: newTestPublicKeyBytes(t),
298 }
299 // pre-define an any for testing
300 a, e := NewAny(sig)
301 require.NoError(t, e)
302 // pre-define a transaction
303 expected := &TxResult{
304 Sender: newTestAddressBytes(t),
305 Recipient: newTestAddressBytes(t),
306 MessageType: testMessageName,
307 Height: 1,
308 Index: 2,
309 Transaction: &Transaction{
310 MessageType: testMessageName,
311 Msg: a,
312 Signature: sig,
313 Time: uint64(time.Now().UnixMicro()),
314 Fee: 1,
315 Memo: "memo",
316 },
317 TxHash: crypto.HashString([]byte("hash")),
318 }
319 // convert structure to json bytes
320 gotBytes, err := json.Marshal(expected)
321 require.NoError(t, err)
322 // convert bytes to structure
323 got := new(TxResult)
324 // unmarshal into bytes
325 require.NoError(t, json.Unmarshal(gotBytes, got))
326 // hardcode time as we lose precision upon conversion
327 got.Transaction.Time = expected.Transaction.Time
328 // compare got vs expected
329 require.EqualExportedValues(t, expected, got)
330}
331
332func TestSignatureJSON(t *testing.T) {
333 // pre-define a signature

Callers

nothing calls this directly

Calls 6

HashStringFunction · 0.92
NewAnyFunction · 0.85
newTestPublicKeyBytesFunction · 0.70
newTestAddressBytesFunction · 0.70
MarshalMethod · 0.65
UnmarshalMethod · 0.65

Tested by

no test coverage detected