-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
164 lines (131 loc) · 5.94 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
package integration
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/suite"
dbm "github.com/cometbft/cometbft-db"
"github.com/cometbft/cometbft/libs/log"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
rsconsumer "github.com/celinium-network/restaking_protocol/app/consumer"
rscoordinator "github.com/celinium-network/restaking_protocol/app/coordinator"
restakingtypes "github.com/celinium-network/restaking_protocol/x/restaking/types"
)
type SetupRestakingCoordinator func(t *testing.T) (
coord *ibctesting.Coordinator,
RestakingCoordinatorChain *ibctesting.TestChain,
RestakingCoordinatorApp *rscoordinator.App,
)
type SetupRestakingConsumer func(*testing.T, *ibctesting.Coordinator, int) (
*ibctesting.TestChain,
*rsconsumer.App,
)
type IntegrationTestSuite struct {
suite.Suite
coordinator *ibctesting.Coordinator
setupRestakingCoordinator SetupRestakingCoordinator
setupRestakingConsumer SetupRestakingConsumer
rsCoordinatorChain *ibctesting.TestChain
rsCoordinatorApp *rscoordinator.App
rsConsumerChain *ibctesting.TestChain
rsConsumerApp *rsconsumer.App
path *ibctesting.Path
transferPath *ibctesting.Path
}
func NewIntegrationTestSuite() *IntegrationTestSuite {
suite := new(IntegrationTestSuite)
suite.setupRestakingCoordinator = func(t *testing.T) (
*ibctesting.Coordinator,
*ibctesting.TestChain,
*rscoordinator.App,
) {
t.Helper()
ibctesting.DefaultTestingAppInit = func() (ibctesting.TestingApp, map[string]json.RawMessage) {
db := dbm.NewMemDB()
encCdc := rscoordinator.MakeEncodingConfig()
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[flags.FlagHome] = rscoordinator.DefaultNodeHome
appOptions[server.FlagInvCheckPeriod] = false
app := rscoordinator.New(log.NewNopLogger(), db, nil, true, nil, "", 0, encCdc, appOptions)
genesisState := rscoordinator.NewDefaultGenesisState(encCdc.Marshaler)
return app, genesisState
}
coordinator := ibctesting.NewCoordinator(t, 0)
rscoordinatorChain := ibctesting.NewTestChain(t, coordinator, "coordinator")
coordinatorApp, ok := rscoordinatorChain.App.(*rscoordinator.App)
if !ok {
t.Fatal("coordinator chain has mismatch app")
}
ctx := rscoordinatorChain.GetContext()
coordinatorApp.RestakingCoordinatorKeeper.InitGenesis(ctx, nil)
return coordinator, rscoordinatorChain, coordinatorApp
}
suite.setupRestakingConsumer = func(t *testing.T, coordinator *ibctesting.Coordinator, chainIndex int) (
*ibctesting.TestChain,
*rsconsumer.App,
) {
ibctesting.DefaultTestingAppInit = func() (ibctesting.TestingApp, map[string]json.RawMessage) {
db := dbm.NewMemDB()
encCdc := rsconsumer.MakeEncodingConfig()
appOptions := make(simtestutil.AppOptionsMap, 0)
appOptions[flags.FlagHome] = rscoordinator.DefaultNodeHome
appOptions[server.FlagInvCheckPeriod] = false
app := rsconsumer.New(log.NewNopLogger(), db, nil, true, nil, "", 0, encCdc, appOptions)
genesisState := rsconsumer.NewDefaultGenesisState(encCdc.Marshaler)
return app, genesisState
}
chainID := ibctesting.GetChainID(chainIndex)
consumerChian := ibctesting.NewTestChain(t, coordinator, chainID)
consumerApp, ok := consumerChian.App.(*rsconsumer.App)
if !ok {
t.Fatal("consumer chain has mismatch app")
}
ctx := consumerChian.GetContext()
consumerApp.RestakingConsumerKeeper.InitGenesis(ctx, nil)
// TODO the params of coordinator and consumer maybe in different package
consumerApp.MTStakingKeeper.AddMTStakingDenom(ctx, rscoordinator.DefaultBondDenom)
consumerApp.MTStakingKeeper.SetEquivalentNativeCoinMultiplier(ctx, 1, rscoordinator.DefaultBondDenom, sdk.MustNewDecFromStr("1"))
return consumerChian, consumerApp
}
return suite
}
func (s *IntegrationTestSuite) SetupTest() {
s.coordinator, s.rsCoordinatorChain, s.rsCoordinatorApp = s.setupRestakingCoordinator(s.T())
s.rsConsumerChain, s.rsConsumerApp = s.setupRestakingConsumer(s.T(), s.coordinator, 0)
s.path = ibctesting.NewPath(s.rsConsumerChain, s.rsCoordinatorChain)
s.path.EndpointA.ChannelConfig.PortID = restakingtypes.ConsumerPortID
s.path.EndpointB.ChannelConfig.PortID = restakingtypes.CoordinatorPortID
s.path.EndpointA.ChannelConfig.Version = restakingtypes.Version
s.path.EndpointB.ChannelConfig.Version = restakingtypes.Version
s.path.EndpointA.ChannelConfig.Order = channeltypes.ORDERED
s.path.EndpointB.ChannelConfig.Order = channeltypes.ORDERED
s.transferPath = ibctesting.NewPath(s.rsConsumerChain, s.rsCoordinatorChain)
s.transferPath.EndpointA.ChannelConfig.PortID = ibctesting.TransferPort
s.transferPath.EndpointB.ChannelConfig.PortID = ibctesting.TransferPort
s.transferPath.EndpointA.ChannelConfig.Version = ibctransfertypes.Version
s.transferPath.EndpointB.ChannelConfig.Version = ibctransfertypes.Version
}
func getCoordinatorApp(chain *ibctesting.TestChain) *rscoordinator.App {
app := chain.App.(*rscoordinator.App)
return app
}
func getConsumerApp(chain *ibctesting.TestChain) *rsconsumer.App {
app := chain.App.(*rsconsumer.App)
return app
}
// func copyConnectionAndClientToPath(path *ibctesting.Path, pathToCopy *ibctesting.Path) *ibctesting.Path {
// path.EndpointA.ClientID = pathToCopy.EndpointA.ClientID
// path.EndpointB.ClientID = pathToCopy.EndpointB.ClientID
// path.EndpointA.ConnectionID = pathToCopy.EndpointA.ConnectionID
// path.EndpointB.ConnectionID = pathToCopy.EndpointB.ConnectionID
// path.EndpointA.ClientConfig = pathToCopy.EndpointA.ClientConfig
// path.EndpointB.ClientConfig = pathToCopy.EndpointB.ClientConfig
// path.EndpointA.ConnectionConfig = pathToCopy.EndpointA.ConnectionConfig
// path.EndpointB.ConnectionConfig = pathToCopy.EndpointB.ConnectionConfig
// return path
// }