github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/apps/27-interchain-accounts/controller/keeper/account_test.go (about) 1 package keeper_test 2 3 import ( 4 icatypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/apps/27-interchain-accounts/types" 5 channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 6 host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host" 7 ibctesting "github.com/fibonacci-chain/fbc/libs/ibc-go/testing" 8 ) 9 10 func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { 11 var ( 12 owner string 13 path *ibctesting.Path 14 err error 15 ) 16 17 testCases := []struct { 18 name string 19 malleate func() 20 expPass bool 21 }{ 22 { 23 "success", func() {}, true, 24 }, 25 { 26 "port is already bound for owner but capability is claimed by another module", 27 func() { 28 cap := suite.chainA.GetSimApp().IBCKeeper.V2Keeper.PortKeeper.BindPort(suite.chainA.GetContext(), TestPortID) 29 err := suite.chainA.GetSimApp().TransferKeeper.ClaimCapability(suite.chainA.GetContext(), cap, host.PortPath(TestPortID)) 30 suite.Require().NoError(err) 31 }, 32 false, 33 }, 34 { 35 "fails to generate port-id", 36 func() { 37 owner = "" 38 }, 39 false, 40 }, 41 { 42 "MsgChanOpenInit fails - channel is already active & in state OPEN", 43 func() { 44 portID, err := icatypes.NewControllerPortID(TestOwnerAddress) 45 suite.Require().NoError(err) 46 47 suite.chainA.GetSimApp().ICAControllerKeeper.SetActiveChannelID(suite.chainA.GetContext(), ibctesting.FirstConnectionID, portID, path.EndpointA.ChannelID) 48 49 counterparty := channeltypes.NewCounterparty(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) 50 channel := channeltypes.Channel{ 51 State: channeltypes.OPEN, 52 Ordering: channeltypes.ORDERED, 53 Counterparty: counterparty, 54 ConnectionHops: []string{path.EndpointA.ConnectionID}, 55 Version: TestVersion, 56 } 57 suite.chainA.GetSimApp().IBCKeeper.V2Keeper.ChannelKeeper.SetChannel(suite.chainA.GetContext(), portID, path.EndpointA.ChannelID, channel) 58 }, 59 false, 60 }, 61 } 62 for _, tc := range testCases { 63 tc := tc 64 65 suite.Run(tc.name, func() { 66 suite.SetupTest() 67 68 owner = TestOwnerAddress // must be explicitly changed 69 70 path = NewICAPath(suite.chainA, suite.chainB) 71 suite.coordinator.SetupConnections(path) 72 73 tc.malleate() // malleate mutates test data 74 75 err = suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), path.EndpointA.ConnectionID, owner, TestVersion) 76 77 if tc.expPass { 78 suite.Require().NoError(err) 79 } else { 80 suite.Require().Error(err) 81 } 82 }) 83 } 84 } 85 86 func (suite *KeeperTestSuite) TestRegisterSameOwnerMultipleConnections() { 87 suite.SetupTest() 88 89 owner := TestOwnerAddress 90 91 pathAToB := NewICAPath(suite.chainA, suite.chainB) 92 suite.coordinator.SetupConnections(pathAToB) 93 94 pathAToC := NewICAPath(suite.chainA, suite.chainC) 95 suite.coordinator.SetupConnections(pathAToC) 96 97 // build ICS27 metadata with connection identifiers for path A->B 98 metadata := &icatypes.Metadata{ 99 Version: icatypes.Version, 100 ControllerConnectionId: pathAToB.EndpointA.ConnectionID, 101 HostConnectionId: pathAToB.EndpointB.ConnectionID, 102 Encoding: icatypes.EncodingProtobuf, 103 TxType: icatypes.TxTypeSDKMultiMsg, 104 } 105 106 err := suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToB.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata))) 107 suite.Require().NoError(err) 108 109 // build ICS27 metadata with connection identifiers for path A->C 110 metadata = &icatypes.Metadata{ 111 Version: icatypes.Version, 112 ControllerConnectionId: pathAToC.EndpointA.ConnectionID, 113 HostConnectionId: pathAToC.EndpointB.ConnectionID, 114 Encoding: icatypes.EncodingProtobuf, 115 TxType: icatypes.TxTypeSDKMultiMsg, 116 } 117 118 err = suite.chainA.GetSimApp().ICAControllerKeeper.RegisterInterchainAccount(suite.chainA.GetContext(), pathAToC.EndpointA.ConnectionID, owner, string(icatypes.ModuleCdc.MustMarshalJSON(metadata))) 119 suite.Require().NoError(err) 120 }