-
Notifications
You must be signed in to change notification settings - Fork 884
/
testing.go
68 lines (58 loc) · 1.91 KB
/
testing.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
package nodebuilder
import (
"context"
"net"
"testing"
"time"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/stretchr/testify/require"
"go.uber.org/fx"
"github.com/celestiaorg/celestia-app/app"
"github.com/celestiaorg/celestia-app/app/encoding"
apptypes "github.com/celestiaorg/celestia-app/x/payment/types"
"github.com/celestiaorg/celestia-node/core"
"github.com/celestiaorg/celestia-node/nodebuilder/node"
"github.com/celestiaorg/celestia-node/nodebuilder/state"
"github.com/celestiaorg/celestia-node/params"
)
// MockStore provides mock in memory Store for testing purposes.
func MockStore(t *testing.T, cfg *Config) Store {
t.Helper()
store := NewMemStore()
err := store.PutConfig(cfg)
require.NoError(t, err)
return store
}
func TestNode(t *testing.T, tp node.Type, opts ...fx.Option) *Node {
return TestNodeWithConfig(t, tp, DefaultConfig(tp), opts...)
}
func TestNodeWithConfig(t *testing.T, tp node.Type, cfg *Config, opts ...fx.Option) *Node {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
t.Cleanup(cancel)
store := MockStore(t, cfg)
_, _, coreCfg := core.StartTestKVApp(ctx, t)
endpoint, err := core.GetEndpoint(coreCfg)
require.NoError(t, err)
ip, port, err := net.SplitHostPort(endpoint)
require.NoError(t, err)
cfg.Core.IP = ip
cfg.Core.RPCPort = port
cfg.RPC.Port = "0"
opts = append(opts,
WithNetwork(params.Private),
state.WithKeyringSigner(TestKeyringSigner(t)),
)
nd, err := New(tp, store, opts...)
require.NoError(t, err)
return nd
}
func TestKeyringSigner(t *testing.T) *apptypes.KeyringSigner {
encConf := encoding.MakeConfig(app.ModuleEncodingRegisters...)
ring := keyring.NewInMemory(encConf.Codec)
signer := apptypes.NewKeyringSigner(ring, "", string(params.Private))
_, _, err := signer.NewMnemonic("test_celes", keyring.English, "",
"", hd.Secp256k1)
require.NoError(t, err)
return signer
}