Add tests on base tx

This commit is contained in:
Ethan Frey 2017-05-18 17:22:28 +02:00
parent 6029f5c986
commit 1307064ce5
2 changed files with 55 additions and 1 deletions

View File

@ -31,7 +31,8 @@ const (
func init() {
basecoin.TxMapper.
RegisterImplementation(Raw{}, TypeRaw, ByteRaw).
RegisterImplementation(&Fee{}, TypeFees, ByteFees)
RegisterImplementation(&Fee{}, TypeFees, ByteFees).
RegisterImplementation(&MultiTx{}, TypeMulti, ByteMulti)
}
// Raw just contains bytes that can be hex-ified

53
txs/base_test.go Normal file
View File

@ -0,0 +1,53 @@
package txs
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/go-wire/data"
"github.com/tendermint/basecoin"
"github.com/tendermint/basecoin/types"
)
func TestEncoding(t *testing.T) {
assert := assert.New(t)
require := require.New(t)
raw := NewRaw([]byte{0x34, 0xa7}).Wrap()
raw2 := NewRaw([]byte{0x73, 0x86, 0x22}).Wrap()
coin := types.Coin{Denom: "atom", Amount: 123}
addr := []byte{0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef}
cases := []struct {
Tx basecoin.Tx
}{
{raw},
{NewFee(raw, coin, addr).Wrap()},
{NewMultiTx(raw, raw2).Wrap()},
}
for idx, tc := range cases {
i := strconv.Itoa(idx)
tx := tc.Tx
// test json in and out
js, err := data.ToJSON(tx)
require.Nil(err, i)
var jtx basecoin.Tx
err = data.FromJSON(js, &jtx)
require.Nil(err, i)
assert.Equal(tx, jtx, i)
// test wire in and out
bin, err := data.ToWire(tx)
require.Nil(err, i)
var wtx basecoin.Tx
err = data.FromWire(bin, &wtx)
require.Nil(err, i)
assert.Equal(tx, wtx, i)
}
}