-
Notifications
You must be signed in to change notification settings - Fork 122
/
test_user.go
84 lines (73 loc) · 2.27 KB
/
test_user.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
83
84
package interchaintest
import (
"context"
"fmt"
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"cosmossdk.io/math"
"github.com/strangelove-ventures/interchaintest/v8/dockerutil"
"github.com/strangelove-ventures/interchaintest/v8/ibc"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
)
// GetAndFundTestUserWithMnemonic restores a user using the given mnemonic
// and funds it with the native chain denom.
// The caller should wait for some blocks to complete before the funds will be accessible.
func GetAndFundTestUserWithMnemonic(
ctx context.Context,
keyNamePrefix, mnemonic string,
amount math.Int,
chain ibc.Chain,
) (ibc.Wallet, error) {
chainCfg := chain.Config()
keyName := fmt.Sprintf("%s-%s-%s", keyNamePrefix, chainCfg.ChainID, dockerutil.RandLowerCaseLetterString(3))
user, err := chain.BuildWallet(ctx, keyName, mnemonic)
if err != nil {
return nil, fmt.Errorf("failed to get source user wallet: %w", err)
}
err = chain.SendFunds(ctx, FaucetAccountKeyName, ibc.WalletAmount{
Address: user.FormattedAddress(),
Amount: amount,
Denom: chainCfg.Denom,
})
if err != nil {
return nil, fmt.Errorf("failed to get funds from faucet: %w", err)
}
// If this chain is an instance of Penumbra we need to initialize a new pclientd instance for the
// newly created test user account.
err = CreatePenumbraClient(ctx, chain, keyName)
if err != nil {
return nil, err
}
return user, nil
}
// GetAndFundTestUsers generates and funds chain users with the native chain denom.
// The caller should wait for some blocks to complete before the funds will be accessible.
func GetAndFundTestUsers(
t *testing.T,
ctx context.Context,
keyNamePrefix string,
amount math.Int,
chains ...ibc.Chain,
) []ibc.Wallet {
t.Helper()
users := make([]ibc.Wallet, len(chains))
var eg errgroup.Group
for i, chain := range chains {
eg.Go(func() error {
user, err := GetAndFundTestUserWithMnemonic(ctx, keyNamePrefix, "", amount, chain)
if err != nil {
return err
}
users[i] = user
return nil
})
}
require.NoError(t, eg.Wait())
// TODO(nix 05-17-2022): Map with generics once using go 1.18
chainHeights := make([]testutil.ChainHeighter, len(chains))
for i := range chains {
chainHeights[i] = chains[i]
}
return users
}