Skip to content

Commit 1c0bee5

Browse files
chore: use host chain connection id in ica address generation (#790)
Co-authored-by: colin axnér <[email protected]>
1 parent 90a175e commit 1c0bee5

File tree

7 files changed

+12
-14
lines changed

7 files changed

+12
-14
lines changed

modules/apps/27-interchain-accounts/controller/ibc_module_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var (
2222
// https://github.com/cosmos/cosmos-sdk/issues/10225
2323
//
2424
// TestAccAddress defines a resuable bech32 address for testing purposes
25-
TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), TestPortID)
25+
TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), ibctesting.FirstConnectionID, TestPortID)
2626

2727
// TestOwnerAddress defines a reusable bech32 address for testing purposes
2828
TestOwnerAddress = "cosmos17dtl0mjt3t77kpuhg2edqzjpszulwhgzuj9ljs"

modules/apps/27-interchain-accounts/controller/keeper/keeper_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
sdk "github.com/cosmos/cosmos-sdk/types"
7-
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
87
"github.com/stretchr/testify/suite"
98
"github.com/tendermint/tendermint/crypto"
109

@@ -18,7 +17,7 @@ var (
1817
// https://github.com/cosmos/cosmos-sdk/issues/10225
1918
//
2019
// TestAccAddress defines a resuable bech32 address for testing purposes
21-
TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), TestPortID)
20+
TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), ibctesting.FirstConnectionID, TestPortID)
2221

2322
// TestOwnerAddress defines a reusable bech32 address for testing purposes
2423
TestOwnerAddress = "cosmos17dtl0mjt3t77kpuhg2edqzjpszulwhgzuj9ljs"
@@ -152,7 +151,7 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
152151
suite.Require().NoError(err)
153152

154153
counterpartyPortID := path.EndpointA.ChannelConfig.PortID
155-
expectedAddr := authtypes.NewBaseAccountWithAddress(icatypes.GenerateAddress(suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(icatypes.ModuleName), counterpartyPortID)).GetAddress()
154+
expectedAddr := icatypes.GenerateAddress(suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(icatypes.ModuleName), ibctesting.FirstConnectionID, counterpartyPortID)
156155

157156
retrievedAddr, found := suite.chainA.GetSimApp().ICAControllerKeeper.GetInterchainAccountAddress(suite.chainA.GetContext(), ibctesting.FirstConnectionID, counterpartyPortID)
158157
suite.Require().True(found)

modules/apps/27-interchain-accounts/host/ibc_module_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
// https://github.com/cosmos/cosmos-sdk/issues/10225
2525
//
2626
// TestAccAddress defines a resuable bech32 address for testing purposes
27-
TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), TestPortID)
27+
TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), ibctesting.FirstConnectionID, TestPortID)
2828

2929
// TestOwnerAddress defines a reusable bech32 address for testing purposes
3030
TestOwnerAddress = "cosmos17dtl0mjt3t77kpuhg2edqzjpszulwhgzuj9ljs"

modules/apps/27-interchain-accounts/host/keeper/handshake.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (k Keeper) OnChanOpenTry(
5353
return "", sdkerrors.Wrapf(err, "failed to claim capability for channel %s on port %s", channelID, portID)
5454
}
5555

56-
accAddress := icatypes.GenerateAddress(k.accountKeeper.GetModuleAddress(icatypes.ModuleName), counterparty.PortId)
56+
accAddress := icatypes.GenerateAddress(k.accountKeeper.GetModuleAddress(icatypes.ModuleName), metadata.HostConnectionId, counterparty.PortId)
5757

5858
// Register interchain account if it does not already exist
5959
k.RegisterInterchainAccount(ctx, metadata.HostConnectionId, counterparty.PortId, accAddress)

modules/apps/27-interchain-accounts/host/keeper/keeper_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"testing"
55

66
sdk "github.com/cosmos/cosmos-sdk/types"
7-
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
87
"github.com/stretchr/testify/suite"
98
"github.com/tendermint/tendermint/crypto"
109

@@ -18,7 +17,7 @@ var (
1817
// https://github.com/cosmos/cosmos-sdk/issues/10225
1918
//
2019
// TestAccAddress defines a resuable bech32 address for testing purposes
21-
TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), TestPortID)
20+
TestAccAddress = icatypes.GenerateAddress(sdk.AccAddress(crypto.AddressHash([]byte(icatypes.ModuleName))), ibctesting.FirstConnectionID, TestPortID)
2221

2322
// TestOwnerAddress defines a reusable bech32 address for testing purposes
2423
TestOwnerAddress = "cosmos17dtl0mjt3t77kpuhg2edqzjpszulwhgzuj9ljs"
@@ -136,7 +135,7 @@ func (suite *KeeperTestSuite) TestGetInterchainAccountAddress() {
136135
suite.Require().NoError(err)
137136

138137
counterpartyPortID := path.EndpointA.ChannelConfig.PortID
139-
expectedAddr := authtypes.NewBaseAccountWithAddress(icatypes.GenerateAddress(suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(icatypes.ModuleName), counterpartyPortID)).GetAddress()
138+
expectedAddr := icatypes.GenerateAddress(suite.chainA.GetSimApp().AccountKeeper.GetModuleAddress(icatypes.ModuleName), ibctesting.FirstConnectionID, counterpartyPortID)
140139

141140
retrievedAddr, found := suite.chainB.GetSimApp().ICAHostKeeper.GetInterchainAccountAddress(suite.chainB.GetContext(), ibctesting.FirstConnectionID, counterpartyPortID)
142141
suite.Require().True(found)

modules/apps/27-interchain-accounts/types/account.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ type interchainAccountPretty struct {
3939
AccountOwner string `json:"account_owner" yaml:"account_owner"`
4040
}
4141

42-
// GenerateAddress returns an sdk.AccAddress derived using the provided module account address and port identifier.
43-
// The sdk.AccAddress returned is a sub-address of the module account, using the controller chain's port identifier as the derivation key
44-
func GenerateAddress(moduleAccAddr sdk.AccAddress, portID string) sdk.AccAddress {
45-
return sdk.AccAddress(sdkaddress.Derive(moduleAccAddr, []byte(portID)))
42+
// GenerateAddress returns an sdk.AccAddress derived using the provided module account address and connection and port identifiers.
43+
// The sdk.AccAddress returned is a sub-address of the module account, using the host chain connection ID and controller chain's port ID as the derivation key
44+
func GenerateAddress(moduleAccAddr sdk.AccAddress, connectionID, portID string) sdk.AccAddress {
45+
return sdk.AccAddress(sdkaddress.Derive(moduleAccAddr, []byte(connectionID+portID)))
4646
}
4747

4848
// ValidateAccountAddress performs basic validation of interchain account addresses, enforcing constraints

modules/apps/27-interchain-accounts/types/account_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func TestTypesTestSuite(t *testing.T) {
4343
}
4444

4545
func (suite *TypesTestSuite) TestGenerateAddress() {
46-
addr := types.GenerateAddress([]byte{}, "test-port-id")
46+
addr := types.GenerateAddress([]byte{}, "test-connection-id", "test-port-id")
4747
accAddr, err := sdk.AccAddressFromBech32(addr.String())
4848

4949
suite.Require().NoError(err, "TestGenerateAddress failed")

0 commit comments

Comments
 (0)