// (c) 2019-2020, Ava Labs, Inc. All rights reserved. // See the file LICENSE for licensing terms. package spdagvm import ( "bytes" "math" "testing" "github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/utils/wrappers" ) func TestInputPayment(t *testing.T) { txID := ids.NewID([32]byte{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, }) b := Builder{ NetworkID: 0, ChainID: ids.Empty, } input := b.NewInputPayment( /*sourceID=*/ txID, /*sourceIndex=*/ 9, /*amount=*/ 123456789, /*sigs=*/ []*Sig{b.NewSig(7)}, ) c := Codec{} p := wrappers.Packer{MaxSize: math.MaxInt32} c.marshalInput(input, &p) if p.Errored() { t.Fatal(p.Err) } inputBytes := p.Bytes expected := []byte{ // input type: 0x00, 0x00, 0x00, 0x00, // txID 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, // output index: 0x00, 0x00, 0x00, 0x09, // amount: 0x00, 0x00, 0x00, 0x00, 0x07, 0x5b, 0xcd, 0x15, // number of signatures: 0x00, 0x00, 0x00, 0x01, // signature index[0]: 0x00, 0x00, 0x00, 0x07, } if !bytes.Equal(inputBytes, expected) { t.Fatalf("Codec.marshalInput returned:\n0x%x\nExpected:\n0x%x", inputBytes, expected) } }