Skip to content

Commit

Permalink
updated createICAAccount to closer resemble ibc code
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Jun 27, 2023
1 parent 6ebf1a5 commit 8723b96
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
21 changes: 12 additions & 9 deletions x/staking/keeper/liquid_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ func createBaseAccount(app *simapp.SimApp, ctx sdk.Context, accountName string)

// Helper function to create 32-length account
// Used to mock an liquid staking provider's ICA account
func createICAAccount(app *simapp.SimApp, ctx sdk.Context, accountName string) sdk.AccAddress {
accountAddress := address.Module(accountName, []byte(accountName))
account := authtypes.NewModuleAccount(
authtypes.NewBaseAccountWithAddress(accountAddress),
accountName,
)
func createICAAccount(app *simapp.SimApp, ctx sdk.Context) sdk.AccAddress {
icahost := "icahost"
connectionID := "connection-0"
portID := icahost

moduleAddress := app.AccountKeeper.GetModuleAddress(icahost)
icaAddress := sdk.AccAddress(address.Derive(moduleAddress, []byte(connectionID+portID)))

account := authtypes.NewBaseAccountWithAddress(icaAddress)
app.AccountKeeper.SetAccount(ctx, account)

return accountAddress
return icaAddress
}

// Helper function to create a module account address from a tokenized share
Expand Down Expand Up @@ -82,7 +85,7 @@ func TestAccountIsLiquidStakingProvider(t *testing.T) {

// Create base and ICA accounts
baseAccountAddress := createBaseAccount(app, ctx, "base-account")
icaAccountAddress := createICAAccount(app, ctx, "ica-account")
icaAccountAddress := createICAAccount(app, ctx)

// Only the ICA module account should be considered a liquid staking provider
require.False(t, app.StakingKeeper.AccountIsLiquidStakingProvider(baseAccountAddress), "base account")
Expand Down Expand Up @@ -1093,7 +1096,7 @@ func TestCalculateTotalLiquidStaked(t *testing.T) {
var delegatorAddress sdk.AccAddress
switch {
case delegationCase.isLSTP:
delegatorAddress = createICAAccount(app, ctx, delegationCase.delegation.DelegatorAddress)
delegatorAddress = createICAAccount(app, ctx)
case delegationCase.isTokenized:
delegatorAddress = createTokenizeShareModuleAccount(1)
default:
Expand Down
4 changes: 2 additions & 2 deletions x/staking/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ func TestTokenizeSharesAndRedeemTokens(t *testing.T) {
addrVal1, addrVal2 := sdk.ValAddress(addrAcc1), sdk.ValAddress(addrAcc2)

// Create ICA module account
icaAccountAddress := createICAAccount(app, ctx, "ica-module-account")
icaAccountAddress := createICAAccount(app, ctx)

// Fund module account
delegationCoin := sdk.NewCoin(app.StakingKeeper.BondDenom(ctx), tc.delegationAmount)
Expand Down Expand Up @@ -695,7 +695,7 @@ func TestValidatorBond(t *testing.T) {

delegatorAddress := sdk.AccAddress(delegatorPubKey.Address())
validatorAddress := sdk.ValAddress(validatorPubKey.Address())
icaAccountAddress := createICAAccount(app, ctx, "ica-module-account")
icaAccountAddress := createICAAccount(app, ctx)

// Set the delegator address to either be a user account or an ICA account depending on the test case
if tc.delegatorIsLSTP {
Expand Down

0 comments on commit 8723b96

Please sign in to comment.