github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/txs/payload/payload_test.go (about) 1 package payload 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/hyperledger/burrow/crypto" 8 "github.com/hyperledger/burrow/encoding" 9 "github.com/stretchr/testify/assert" 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestCustomTypes(t *testing.T) { 14 address := crypto.Address{1, 2, 3} 15 callTx := &CallTx{ 16 Input: &TxInput{ 17 Address: crypto.Address{1, 2}, 18 Amount: 2, 19 Sequence: 0, 20 }, 21 Address: &address, 22 } 23 bs, err := encoding.Encode(callTx) 24 require.NoError(t, err) 25 callTxOut := new(CallTx) 26 err = encoding.Decode(bs, callTxOut) 27 require.NoError(t, err) 28 assert.Equal(t, jsonString(t, callTx), jsonString(t, callTxOut)) 29 } 30 31 func jsonString(t testing.TB, conf interface{}) string { 32 bs, err := json.MarshalIndent(conf, "", " ") 33 require.NoError(t, err, "must be able to convert interface to string for comparison") 34 return string(bs) 35 }