-
Notifications
You must be signed in to change notification settings - Fork 0
/
operator.go
61 lines (46 loc) · 2.11 KB
/
operator.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
package integration
import (
"strings"
sdk "github.com/cosmos/cosmos-sdk/types"
rscoordinatortypes "github.com/celinium-network/restaking_protocol/x/restaking/coordinator/types"
)
func (s *IntegrationTestSuite) TestRegisterOperator() {
proposal := CreateConsumerAdditionalProposal(s.path, s.rsConsumerChain)
coordApp := getCoordinatorApp(s.rsCoordinatorChain)
coordCtx := s.rsCoordinatorChain.GetContext()
coordApp.RestakingCoordinatorKeeper.SetConsumerAdditionProposal(coordCtx, proposal)
s.SetupRestakingPath()
consumerChainID := s.rsConsumerChain.ChainID
registerAccAddr := s.path.EndpointA.Chain.SenderAccount.GetAddress()
valSets := s.getConsumerValidators(consumerChainID)
s.registerOperator(consumerChainID, proposal.RestakingTokens[0], valSets[0].Address, registerAccAddr)
coordCtx = s.rsCoordinatorChain.GetContext()
allOperator := coordApp.RestakingCoordinatorKeeper.GetAllOperators(coordCtx)
s.Require().Equal(len(allOperator), 1)
strings.EqualFold(allOperator[0].Owner, registerAccAddr.String())
}
func (s *IntegrationTestSuite) getConsumerValidators(chainID string) []rscoordinatortypes.ConsumerValidator {
coordCtx := s.rsCoordinatorChain.GetContext()
coordApp := getCoordinatorApp(s.rsCoordinatorChain)
clientID, found := coordApp.RestakingCoordinatorKeeper.GetConsumerClientID(coordCtx, chainID)
s.Require().True(found)
consumerValidators := coordApp.RestakingCoordinatorKeeper.GetConsumerValidators(coordCtx, string(clientID), 100)
s.Require().True(found)
return consumerValidators
}
func (s *IntegrationTestSuite) registerOperator(
consumerChainID,
restakingDenom string,
consumerValidatorAddress string,
register sdk.AccAddress,
) {
coordCtx := s.rsCoordinatorChain.GetContext()
coordApp := getCoordinatorApp(s.rsCoordinatorChain)
err := coordApp.RestakingCoordinatorKeeper.RegisterOperator(coordCtx, rscoordinatortypes.MsgRegisterOperatorRequest{
ConsumerChainIDs: []string{consumerChainID},
ConsumerValidatorAddresses: []string{consumerValidatorAddress},
RestakingDenom: restakingDenom,
Sender: register.String(),
})
s.Require().NoError(err)
}