-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.go
63 lines (49 loc) · 2.29 KB
/
channel.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
package integration
import (
"fmt"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
coordapp "github.com/celinium-network/restaking_protocol/app/coordinator"
rscoordinatortypes "github.com/celinium-network/restaking_protocol/x/restaking/coordinator/types"
)
func (s *IntegrationTestSuite) TestChannelInit() {
proposal := CreateConsumerAdditionalProposal(s.path, s.rsConsumerChain)
app := getCoordinatorApp(s.rsCoordinatorChain)
ctx := s.rsCoordinatorChain.GetContext()
app.RestakingCoordinatorKeeper.SetConsumerAdditionProposal(ctx, proposal)
s.SetupRestakingPath()
ctx = s.rsCoordinatorChain.GetContext()
_, found := app.RestakingCoordinatorKeeper.GetConsumerAdditionProposal(ctx, s.rsConsumerChain.ChainID)
s.Require().False(found)
_, found = app.RestakingCoordinatorKeeper.GetConsumerClientID(ctx, s.rsConsumerChain.ChainID)
s.Require().True(found)
}
func (s *IntegrationTestSuite) SetupRestakingPath() {
s.coordinator.SetupConnections(s.path)
err := s.path.EndpointA.ChanOpenInit()
s.Require().NoError(err)
err = s.path.EndpointB.ChanOpenTry()
s.Require().NoError(err)
events := s.ChanOpenAck(s.path.EndpointA)
// Consumer send validatorSet information to coordinator.
// So we must get ibc packet from events which emit in `EndBlock` and relay it to coordinator
err = s.path.EndpointB.ChanOpenConfirm()
s.Require().NoError(err)
consumerUserAddr := s.path.EndpointA.Chain.SenderAccount.GetAddress()
s.RelayIBCPacket(s.path, events, consumerUserAddr.String())
}
func CreateConsumerAdditionalProposal(path *ibctesting.Path, consumerChain *ibctesting.TestChain) *rscoordinatortypes.ConsumerAdditionProposal {
tmClientCfg, ok := path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig)
if !ok {
panic("create consumer additional proposal failed ")
}
return &rscoordinatortypes.ConsumerAdditionProposal{
Title: fmt.Sprintf("Add consumer chain %s proposal", consumerChain.ChainID),
Description: "test consumer addition proposal",
ChainId: consumerChain.ChainID,
UnbondingPeriod: tmClientCfg.UnbondingPeriod,
TimeoutPeriod: tmClientCfg.TrustingPeriod,
TransferTimeoutPeriod: tmClientCfg.MaxClockDrift,
RestakingTokens: []string{coordapp.DefaultBondDenom},
RewardTokens: []string{coordapp.DefaultBondDenom},
}
}