-
Notifications
You must be signed in to change notification settings - Fork 8
/
faucet.go
53 lines (46 loc) · 1.64 KB
/
faucet.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
package ibctesting
import (
"cosmossdk.io/math"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"
"github.com/terpnetwork/terp-core/app"
)
// Fund an address with the given amount in default denom
func (chain *TestChain) Fund(addr sdk.AccAddress, amount math.Int) {
require.NoError(chain.t, chain.sendMsgs(&banktypes.MsgSend{
FromAddress: chain.SenderAccount.GetAddress().String(),
ToAddress: addr.String(),
Amount: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, amount)),
}))
}
// SendNonDefaultSenderMsgs delivers a transaction through the application. It returns the result and error if one
// occurred.
func (chain *TestChain) SendNonDefaultSenderMsgs(senderPrivKey cryptotypes.PrivKey, msgs ...sdk.Msg) (*sdk.Result, error) {
require.NotEqual(chain.t, chain.SenderPrivKey, senderPrivKey, "use SendMsgs method")
// ensure the chain has the latest time
chain.Coordinator.UpdateTimeForChain(chain)
addr := sdk.AccAddress(senderPrivKey.PubKey().Address().Bytes())
account := chain.App.AccountKeeper.GetAccount(chain.GetContext(), addr)
require.NotNil(chain.t, account)
_, r, err := app.SignAndDeliverWithoutCommit(
chain.t,
chain.TxConfig,
chain.App.BaseApp,
chain.GetContext().BlockHeader(),
msgs,
chain.ChainID,
[]uint64{account.GetAccountNumber()},
[]uint64{account.GetSequence()},
senderPrivKey,
)
// SignAndDeliverWithoutCommit calls app.Commit()
chain.NextBlock()
chain.Coordinator.IncrementTime()
if err != nil {
return r, err
}
chain.CaptureIBCEvents(r)
return r, nil
}