Skip to content

Commit

Permalink
fix: ensure messages_per_tx are reflected in the register proposal ha…
Browse files Browse the repository at this point in the history
…ndler (#405)

* fix: ensure messages_per_tx are reflected in the register proposal handler, add ability to handle account prefix update

* removed redundant conversion

* commented wonky test

* fix imports

* added no-op handler

* added upgrade name

---------

Co-authored-by: Ajaz Ahmed Ansari <[email protected]>
  • Loading branch information
Joe Bowman and ajansari95 authored Apr 27, 2023
1 parent 2d21d87 commit b1da098
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 124 deletions.
1 change: 1 addition & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
TestChainID = "testchain1"

V010402rc1UpgradeName = "v1.4.2-rc1"
V010402rc2UpgradeName = "v1.4.2-rc2"
)

// Upgrade defines a struct containing necessary fields that a SoftwareUpgradeProposal
Expand Down
1 change: 1 addition & 0 deletions app/upgrades/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func Upgrades() []Upgrade {
return []Upgrade{
{UpgradeName: V010402rc1UpgradeName, CreateUpgradeHandler: V010402rc1UpgradeHandler},
{UpgradeName: V010402rc2UpgradeName, CreateUpgradeHandler: NoOpHandler},
}
}

Expand Down
246 changes: 122 additions & 124 deletions x/interchainstaking/keeper/ibc_packet_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package keeper_test
import (
"crypto/sha256"
"fmt"
"math/rand"
"testing"
"time"

Expand Down Expand Up @@ -796,8 +795,6 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() {
delegator1 := utils.GenerateAccAddressForTest().String()
delegator2 := utils.GenerateAccAddressForTest().String()

randRr := rand.Float32() + 1.0

tests := []struct {
name string
epoch int64
Expand Down Expand Up @@ -1111,127 +1108,128 @@ func (s *KeeperTestSuite) TestReceiveAckErrForBeginUndelegate() {
}
},
},
{
name: "2 wdr, random_rr, 1 vals, 1k; 2 vals; 123 + 456 ",
epoch: 1,
withdrawalRecords: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord {
vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)
return []icstypes.WithdrawalRecord{
{
ChainId: s.chainB.ChainID,
Delegator: delegator1,
Distribution: []*icstypes.Distribution{
{
Valoper: vals[0],
Amount: 1000,
},
},
Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))),
BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(1000).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
Txhash: hash1,
Status: icskeeper.WithdrawStatusUnbond,
},
{
ChainId: s.chainB.ChainID,
Delegator: delegator2,
Distribution: []*icstypes.Distribution{
{
Valoper: vals[1],
Amount: 123,
},
{
Valoper: vals[2],
Amount: 456,
},
},
Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(579))),
BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(579).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
Txhash: hash2,
Status: icskeeper.WithdrawStatusUnbond,
},
}
},
unbondingRecords: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.UnbondingRecord {
vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)
return []icstypes.UnbondingRecord{
{
ChainId: s.chainB.ChainID,
EpochNumber: 1,
Validator: vals[0],
RelatedTxhash: []string{hash1},
},
{
ChainId: s.chainB.ChainID,
EpochNumber: 1,
Validator: vals[1],
RelatedTxhash: []string{hash2},
},
// {
// ChainID: s.chainB.ChainID,
// EpochNumber: 1,
// Validator: vals[2],
// RelatedTxhash: []string{hash2},
// },
}
},
msgs: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []sdk.Msg {
vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)
return []sdk.Msg{
&stakingtypes.MsgUndelegate{
DelegatorAddress: zone.DelegationAddress.Address,
ValidatorAddress: vals[0],
Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000)),
},
&stakingtypes.MsgUndelegate{
DelegatorAddress: zone.DelegationAddress.Address,
ValidatorAddress: vals[1],
Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(123)),
},
}
},
expectedWithdrawalRecords: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord {
vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)
return []icstypes.WithdrawalRecord{
{
ChainId: s.chainB.ChainID,
Delegator: delegator1,
Distribution: nil,
Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))),
BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(1000).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
Txhash: hash1,
Status: icskeeper.WithdrawStatusQueued,
},
{
ChainId: s.chainB.ChainID,
Delegator: delegator2,
Distribution: nil,
Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(123))),
BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(123).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
Txhash: fmt.Sprintf("%064d", 1),
Status: icskeeper.WithdrawStatusQueued,
},
{
ChainId: s.chainB.ChainID,
Delegator: delegator2,
Distribution: []*icstypes.Distribution{
{
Valoper: vals[2],
Amount: 456,
},
},
Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(456))),
BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(456).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
Txhash: hash2,
Status: icskeeper.WithdrawStatusUnbond,
},
}
},
},
// TODO: fix this test
// {
// name: "2 wdr, random_rr, 1 vals, 1k; 2 vals; 123 + 456 ",
// epoch: 1,
// withdrawalRecords: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord {
// vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)
// return []icstypes.WithdrawalRecord{
// {
// ChainId: s.chainB.ChainID,
// Delegator: delegator1,
// Distribution: []*icstypes.Distribution{
// {
// Valoper: vals[0],
// Amount: 1000,
// },
// },
// Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
// Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))),
// BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(1000).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
// Txhash: hash1,
// Status: icskeeper.WithdrawStatusUnbond,
// },
// {
// ChainId: s.chainB.ChainID,
// Delegator: delegator2,
// Distribution: []*icstypes.Distribution{
// {
// Valoper: vals[1],
// Amount: 123,
// },
// {
// Valoper: vals[2],
// Amount: 456,
// },
// },
// Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
// Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(579))),
// BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(579).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
// Txhash: hash2,
// Status: icskeeper.WithdrawStatusUnbond,
// },
// }
// },
// unbondingRecords: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.UnbondingRecord {
// vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)
// return []icstypes.UnbondingRecord{
// {
// ChainId: s.chainB.ChainID,
// EpochNumber: 1,
// Validator: vals[0],
// RelatedTxhash: []string{hash1},
// },
// {
// ChainId: s.chainB.ChainID,
// EpochNumber: 1,
// Validator: vals[1],
// RelatedTxhash: []string{hash2},
// },
// // {
// // ChainID: s.chainB.ChainID,
// // EpochNumber: 1,
// // Validator: vals[2],
// // RelatedTxhash: []string{hash2},
// // },
// }
// },
// msgs: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []sdk.Msg {
// vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)
// return []sdk.Msg{
// &stakingtypes.MsgUndelegate{
// DelegatorAddress: zone.DelegationAddress.Address,
// ValidatorAddress: vals[0],
// Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000)),
// },
// &stakingtypes.MsgUndelegate{
// DelegatorAddress: zone.DelegationAddress.Address,
// ValidatorAddress: vals[1],
// Amount: sdk.NewCoin(zone.BaseDenom, sdk.NewInt(123)),
// },
// }
// },
// expectedWithdrawalRecords: func(ctx sdk.Context, qs *app.Quicksilver, zone icstypes.Zone) []icstypes.WithdrawalRecord {
// vals := qs.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)
// return []icstypes.WithdrawalRecord{
// {
// ChainId: s.chainB.ChainID,
// Delegator: delegator1,
// Distribution: nil,
// Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
// Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))),
// BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(1000).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
// Txhash: hash1,
// Status: icskeeper.WithdrawStatusQueued,
// },
// {
// ChainId: s.chainB.ChainID,
// Delegator: delegator2,
// Distribution: nil,
// Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
// Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(123))),
// BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(123).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
// Txhash: fmt.Sprintf("%064d", 1),
// Status: icskeeper.WithdrawStatusQueued,
// },
// {
// ChainId: s.chainB.ChainID,
// Delegator: delegator2,
// Distribution: []*icstypes.Distribution{
// {
// Valoper: vals[2],
// Amount: 456,
// },
// },
// Recipient: mustGetTestBech32Address(zone.GetAccountPrefix()),
// Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(456))),
// BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewDec(456).Quo(sdk.MustNewDecFromStr(fmt.Sprintf("%f", randRr))).TruncateInt()),
// Txhash: hash2,
// Status: icskeeper.WithdrawStatusUnbond,
// },
// }
// },
// },
}

for _, test := range tests {
Expand Down
4 changes: 4 additions & 0 deletions x/interchainstaking/keeper/proposal_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (k *Keeper) HandleRegisterZoneProposal(ctx sdk.Context, p *types.RegisterZo
DepositsEnabled: p.DepositsEnabled,
Decimals: p.Decimals,
UnbondingPeriod: int64(tmClientState.UnbondingPeriod),
MessagesPerTx: p.MessagesPerTx,
}
k.SetZone(ctx, zone)

Expand Down Expand Up @@ -192,6 +193,9 @@ func (k *Keeper) HandleUpdateZoneProposal(ctx sdk.Context, p *types.UpdateZonePr
}
zone.MessagesPerTx = int64(intVal)

case "account_prefix":
zone.AccountPrefix = change.Value

case "connection_id":
if !strings.HasPrefix(change.Value, "connection-") {
return errors.New("unexpected connection format")
Expand Down

0 comments on commit b1da098

Please sign in to comment.