-
Notifications
You must be signed in to change notification settings - Fork 625
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: adding test for RegisterInterchainAccount & adding check to rel… (
#552) * test: adding test for RegisterInterchainAccount & adding check to relay_test * Update modules/apps/27-interchain-accounts/host/keeper/relay_test.go Co-authored-by: Damian Nolan <[email protected]> * Update modules/apps/27-interchain-accounts/host/keeper/relay_test.go Co-authored-by: Damian Nolan <[email protected]> * Update modules/apps/27-interchain-accounts/host/keeper/account_test.go * Update modules/apps/27-interchain-accounts/host/keeper/account_test.go Co-authored-by: Damian Nolan <[email protected]>
- Loading branch information
1 parent
b87b806
commit 3a06187
Showing
5 changed files
with
73 additions
and
19 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
modules/apps/27-interchain-accounts/host/keeper/account.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package keeper | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
|
||
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" | ||
) | ||
|
||
// RegisterInterchainAccount attempts to create a new account using the provided address and stores it in state keyed by the provided port identifier | ||
// If an account for the provided address already exists this function returns early (no-op) | ||
func (k Keeper) RegisterInterchainAccount(ctx sdk.Context, accAddr sdk.AccAddress, controllerPortID string) { | ||
if acc := k.accountKeeper.GetAccount(ctx, accAddr); acc != nil { | ||
return | ||
} | ||
|
||
interchainAccount := types.NewInterchainAccount( | ||
authtypes.NewBaseAccountWithAddress(accAddr), | ||
controllerPortID, | ||
) | ||
|
||
k.accountKeeper.NewAccount(ctx, interchainAccount) | ||
k.accountKeeper.SetAccount(ctx, interchainAccount) | ||
|
||
k.SetInterchainAccountAddress(ctx, controllerPortID, interchainAccount.Address) | ||
} |
33 changes: 33 additions & 0 deletions
33
modules/apps/27-interchain-accounts/host/keeper/account_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types" | ||
ibctesting "github.com/cosmos/ibc-go/v2/testing" | ||
) | ||
|
||
func (suite *KeeperTestSuite) TestRegisterInterchainAccount() { | ||
suite.SetupTest() | ||
|
||
path := NewICAPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupConnections(path) | ||
|
||
// InitInterchainAccount | ||
err := SetupICAPath(path, TestOwnerAddress) | ||
suite.Require().NoError(err) | ||
|
||
portID, err := types.GeneratePortID(TestOwnerAddress, ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) | ||
suite.Require().NoError(err) | ||
|
||
// Get the address of the interchain account stored in state during handshake step | ||
storedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), portID) | ||
suite.Require().True(found) | ||
|
||
icaAddr, err := sdk.AccAddressFromBech32(storedAddr) | ||
suite.Require().NoError(err) | ||
|
||
// Check if account is created | ||
interchainAccount := suite.chainB.GetSimApp().AccountKeeper.GetAccount(suite.chainB.GetContext(), icaAddr) | ||
suite.Require().Equal(interchainAccount.GetAddress().String(), storedAddr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,6 @@ func (suite *KeeperTestSuite) TestOnChanOpenTry() { | |
} else { | ||
suite.Require().Error(err) | ||
} | ||
|
||
}) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters