-
Notifications
You must be signed in to change notification settings - Fork 15
/
transactions_test.go
60 lines (49 loc) · 1.48 KB
/
transactions_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
package aptos
import (
"github.com/aptos-labs/aptos-go-sdk/bcs"
"github.com/stretchr/testify/assert"
"testing"
)
func TestRawTransactionSign(t *testing.T) {
sender, err := NewEd25519Account()
assert.NoError(t, err)
receiver, err := NewEd25519Account()
assert.NoError(t, err)
dest := receiver.Address
sn := uint64(1)
amount := uint64(10_000)
payload, err := CoinTransferPayload(nil, dest, amount)
assert.NoError(t, err)
txn := RawTransaction{
Sender: sender.Address,
SequenceNumber: sn + 1,
Payload: TransactionPayload{Payload: payload},
MaxGasAmount: 1000,
GasUnitPrice: 2000,
ExpirationTimestampSeconds: 1714158778,
ChainId: 4,
}
signedTxn, err := txn.SignedTransaction(sender)
assert.NoError(t, err)
_, ok := signedTxn.Authenticator.Auth.(*Ed25519TransactionAuthenticator)
assert.True(t, ok)
assert.NoError(t, signedTxn.Verify())
// Serialize, Deserialize, Serialize
// out1 and out3 should be the same
txn1Bytes, err := bcs.Serialize(&txn)
assert.NoError(t, err)
txn2 := RawTransaction{}
err = bcs.Deserialize(&txn2, txn1Bytes)
assert.NoError(t, err)
txn2Bytes, err := bcs.Serialize(&txn2)
assert.NoError(t, err)
assert.Equal(t, txn1Bytes, txn2Bytes)
assert.Equal(t, txn, txn2)
}
func TestTPMarshal(t *testing.T) {
var wat TransactionPayload
var ser bcs.Serializer
wat.MarshalBCS(&ser)
// without a payload, it should fail
assert.Error(t, ser.Error())
}