forked from hyperledger-archives/burrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamino_codec_test.go
82 lines (76 loc) · 2.09 KB
/
amino_codec_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package txs
import (
"testing"
"github.com/hyperledger/burrow/acm"
"github.com/hyperledger/burrow/crypto"
"github.com/hyperledger/burrow/txs/payload"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestAminoEncodeTxDecodeTx(t *testing.T) {
codec := NewAminoCodec()
inputAddress := crypto.Address{1, 2, 3, 4, 5}
outputAddress := crypto.Address{5, 4, 3, 2, 1}
amount := uint64(2)
sequence := uint64(3)
tx := &payload.SendTx{
Inputs: []*payload.TxInput{{
Address: inputAddress,
Amount: amount,
Sequence: sequence,
}},
Outputs: []*payload.TxOutput{{
Address: outputAddress,
Amount: amount,
}},
}
txEnv := Enclose(chainID, tx)
txBytes, err := codec.EncodeTx(txEnv)
if err != nil {
t.Fatal(err)
}
txEnvOut, err := codec.DecodeTx(txBytes)
assert.NoError(t, err, "DecodeTx error")
assert.Equal(t, txEnv, txEnvOut)
}
func TestAminoEncodeTxDecodeTx_CallTx(t *testing.T) {
codec := NewAminoCodec()
inputAccount := acm.GeneratePrivateAccountFromSecret("fooo")
amount := uint64(2)
sequence := uint64(3)
tx := &payload.CallTx{
Input: &payload.TxInput{
Address: inputAccount.Address(),
Amount: amount,
Sequence: sequence,
},
GasLimit: 233,
Fee: 2,
Address: nil,
Data: []byte("code"),
}
txEnv := Enclose(chainID, tx)
require.NoError(t, txEnv.Sign(inputAccount))
txBytes, err := codec.EncodeTx(txEnv)
if err != nil {
t.Fatal(err)
}
txEnvOut, err := codec.DecodeTx(txBytes)
assert.NoError(t, err, "DecodeTx error")
assert.Equal(t, txEnv, txEnvOut)
}
func TestAminoTxEnvelope(t *testing.T) {
codec := NewAminoCodec()
privAccFrom := acm.GeneratePrivateAccountFromSecret("foo")
privAccTo := acm.GeneratePrivateAccountFromSecret("bar")
toAddress := privAccTo.Address()
txEnv := Enclose("testChain", payload.NewCallTxWithSequence(privAccFrom.PublicKey(), &toAddress,
[]byte{3, 4, 5, 5}, 343, 2323, 12, 3))
err := txEnv.Sign(privAccFrom)
require.NoError(t, err)
bs, err := codec.EncodeTx(txEnv)
require.NoError(t, err)
txEnvOut, err := codec.DecodeTx(bs)
require.NoError(t, err)
assert.Equal(t, txEnv, txEnvOut)
}