-
Notifications
You must be signed in to change notification settings - Fork 3
/
prepare_test.go
73 lines (55 loc) · 1.67 KB
/
prepare_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
package faucet
import (
"testing"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/sdk/bank"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPrepareTransaction(t *testing.T) {
t.Parallel()
var (
fromAddress = crypto.Address{0}
toAddress = crypto.Address{1}
sendAmount = std.NewCoins(std.NewCoin("ugnot", 10))
expectedGasFee = std.NewCoin("gnot", 1)
expectedGasWanted = int64(100)
capturedTx *std.Tx
mockEstimator = &mockEstimator{
estimateGasFeeFn: func() std.Coin {
return expectedGasFee
},
estimateGasWantedFn: func(tx *std.Tx) int64 {
capturedTx = tx
return expectedGasWanted
},
}
)
// Prepare the transaction
cfg := PrepareCfg{
FromAddress: fromAddress,
ToAddress: toAddress,
SendAmount: sendAmount,
}
tx := prepareTransaction(mockEstimator, defaultPrepareTxMessage(cfg))
// Make sure the transaction was created
require.NotNil(t, tx)
// Make sure the transaction is unsigned
assert.Len(t, tx.Signatures, 0)
// Make sure the transaction fee is correct
expectedFee := std.NewFee(expectedGasWanted, expectedGasFee)
assert.Equal(t, expectedFee, tx.Fee)
// Make sure the correct transaction was estimated
assert.Equal(t, tx, capturedTx)
// Make sure there is one message
require.Len(t, tx.Msgs, 1)
msg := tx.Msgs[0]
// Make sure the message is a send message
msgSend, ok := msg.(bank.MsgSend)
require.True(t, ok)
// Make sure the message has valid fields
assert.Equal(t, fromAddress, msgSend.FromAddress)
assert.Equal(t, toAddress, msgSend.ToAddress)
assert.Equal(t, sendAmount, msgSend.Amount)
}