-
Notifications
You must be signed in to change notification settings - Fork 37
/
setup.go
183 lines (152 loc) · 5.4 KB
/
setup.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package tests
import (
"testing"
"github.com/cosmos/cosmos-sdk/codec"
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/store"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
porttypes "github.com/cosmos/ibc-go/v6/modules/core/05-port/types"
"github.com/golang/mock/gomock"
"github.com/peggyjv/sommelier/v7/x/axelarcork"
"github.com/peggyjv/sommelier/v7/x/axelarcork/keeper"
"github.com/peggyjv/sommelier/v7/x/axelarcork/tests/mocks"
"github.com/peggyjv/sommelier/v7/x/axelarcork/types"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmdb "github.com/tendermint/tm-db"
)
var TestGMPAccount = authtypes.NewModuleAddress("test-gmp-account")
// DefaultParams returns default oracle parameters
func TestParams() types.Params {
return types.Params{
IbcChannel: "channel-2",
IbcPort: "axelar",
GmpAccount: TestGMPAccount.String(),
ExecutorAccount: "test-executor-account",
TimeoutDuration: 100,
}
}
func NewTestSetup(t *testing.T, ctl *gomock.Controller) *Setup {
t.Helper()
initializer := newInitializer()
accountKeeperMock := mocks.NewMockAccountKeeper(ctl)
bankKeeperMock := mocks.NewMockBankKeeper(ctl)
transferKeeperMock := mocks.NewMockTransferKeeper(ctl)
stakingKeeper := mocks.NewMockStakingKeeper(ctl)
distributionKeeperMock := mocks.NewMockDistributionKeeper(ctl)
ibcModuleMock := mocks.NewMockIBCModule(ctl)
ics4WrapperMock := mocks.NewMockICS4Wrapper(ctl)
gravityKeeper := mocks.NewMockGravityKeeper(ctl)
pubsubKeeper := mocks.NewMockPubsubKeeper(ctl)
paramsKeeper := initializer.paramsKeeper()
acKeeper := initializer.axelarcorkKeeper(
paramsKeeper, accountKeeperMock, bankKeeperMock, stakingKeeper, transferKeeperMock, distributionKeeperMock,
ics4WrapperMock, gravityKeeper, pubsubKeeper)
require.NoError(t, initializer.StateStore.LoadLatestVersion())
acKeeper.SetParams(initializer.Ctx, TestParams())
//acKeeper.SetChainConfiguration()
return &Setup{
Initializer: initializer,
Keepers: &testKeepers{
ParamsKeeper: ¶msKeeper,
AxelarCorkKeeper: acKeeper,
},
Mocks: &testMocks{
AccountKeeperMock: accountKeeperMock,
BankKeeperMock: bankKeeperMock,
TransferKeeperMock: transferKeeperMock,
DistributionKeeperMock: distributionKeeperMock,
IBCModuleMock: ibcModuleMock,
ICS4WrapperMock: ics4WrapperMock,
},
AxelarCorkMiddleware: initializer.axelarMiddleware(ibcModuleMock, acKeeper),
}
}
type Setup struct {
Initializer initializer
Keepers *testKeepers
Mocks *testMocks
AxelarCorkMiddleware axelarcork.IBCMiddleware
}
type testKeepers struct {
ParamsKeeper *paramskeeper.Keeper
AxelarCorkKeeper *keeper.Keeper
}
type testMocks struct {
AccountKeeperMock *mocks.MockAccountKeeper
BankKeeperMock *mocks.MockBankKeeper
TransferKeeperMock *mocks.MockTransferKeeper
DistributionKeeperMock *mocks.MockDistributionKeeper
IBCModuleMock *mocks.MockIBCModule
ICS4WrapperMock *mocks.MockICS4Wrapper
}
type initializer struct {
DB *tmdb.MemDB
StateStore store.CommitMultiStore
Ctx sdk.Context
Marshaler codec.Codec
Amino *codec.LegacyAmino
}
// Create an initializer with in memory database and default codecs
func newInitializer() initializer {
logger := log.TestingLogger()
logger.Debug("initializing test setup")
db := tmdb.NewMemDB()
stateStore := store.NewCommitMultiStore(db)
ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, logger)
interfaceRegistry := cdctypes.NewInterfaceRegistry()
amino := codec.NewLegacyAmino()
marshaler := codec.NewProtoCodec(interfaceRegistry)
return initializer{
DB: db,
StateStore: stateStore,
Ctx: ctx,
Marshaler: marshaler,
Amino: amino,
}
}
func (i initializer) paramsKeeper() paramskeeper.Keeper {
storeKey := sdk.NewKVStoreKey(paramstypes.StoreKey)
transientStoreKey := sdk.NewTransientStoreKey(paramstypes.TStoreKey)
i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB)
i.StateStore.MountStoreWithDB(transientStoreKey, storetypes.StoreTypeTransient, i.DB)
paramsKeeper := paramskeeper.NewKeeper(i.Marshaler, i.Amino, storeKey, transientStoreKey)
return paramsKeeper
}
func (i initializer) axelarcorkKeeper(
paramsKeeper paramskeeper.Keeper,
accountKeeper types.AccountKeeper,
bankKeeper types.BankKeeper,
stakingKeeper types.StakingKeeper,
transferKeeper types.TransferKeeper,
distributionKeeper types.DistributionKeeper,
ics4Wrapper porttypes.ICS4Wrapper,
gravityKeeper types.GravityKeeper,
pubsubKeeper types.PubsubKeeper,
) *keeper.Keeper {
storeKey := sdk.NewKVStoreKey(types.StoreKey)
i.StateStore.MountStoreWithDB(storeKey, storetypes.StoreTypeIAVL, i.DB)
subspace := paramsKeeper.Subspace(types.ModuleName)
routerKeeper := keeper.NewKeeper(
i.Marshaler,
storeKey,
subspace,
accountKeeper,
bankKeeper,
stakingKeeper,
transferKeeper,
distributionKeeper,
ics4Wrapper,
gravityKeeper,
pubsubKeeper,
)
return &routerKeeper
}
func (i initializer) axelarMiddleware(app porttypes.IBCModule, k *keeper.Keeper) axelarcork.IBCMiddleware {
return axelarcork.NewIBCMiddleware(k, app)
}