Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update upgrade chain Test to v5 #229

Merged
merged 9 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ linters:
- nakedret
- nolintlint
- staticcheck
- revive
- stylecheck
- thelper
- typecheck
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ func (app *CentauriApp) setupUpgradeStoreLoaders() {
}

for _, upgrade := range Upgrades {
upgrade := upgrade
if upgradeInfo.Name == upgrade.UpgradeName {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &upgrade.StoreUpgrades))
}
Expand Down
4 changes: 2 additions & 2 deletions app/upgrades/v5/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const (
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
_ upgrades.BaseAppParamManager,
_ *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
// add min amount for rate limit
Expand Down
3 changes: 1 addition & 2 deletions custom/bank/bank_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/stretchr/testify/suite"

Expand Down Expand Up @@ -59,7 +58,7 @@ func (suite *CustomBankTestSuite) TestTotalSupply() {
var (
expChainBBalanceDiff sdk.Coin
path = NewTransferPath(suite.chainA, suite.chainB)
escrowAddr = transfertypes.GetEscrowAddress(transfertypes.PortID, "channel-0")
escrowAddr = ibctransfertypes.GetEscrowAddress(ibctransfertypes.PortID, "channel-0")
)

testCases := []struct {
Expand Down
4 changes: 2 additions & 2 deletions tests/interchaintest/upgrade_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (

func TestCentauriUpgrade(t *testing.T) {
repo, version := GetDockerImageInfo()
CosmosChainUpgradeTest(t, repo, version, "v4")
CosmosChainUpgradeTest(t, repo, version, "v5")
}

func CosmosChainUpgradeTest(t *testing.T, upgradeContainerRepo, upgradeVersion, upgradeName string) {
Expand All @@ -39,7 +39,7 @@ func CosmosChainUpgradeTest(t *testing.T, upgradeContainerRepo, upgradeVersion,
Images: []ibc.DockerImage{
{
Repository: "ghcr.io/notional-labs/centauri",
Version: "3.2.3",
Version: "4.5.1",
UidGid: "1025:1025",
},
},
Expand Down
1 change: 1 addition & 0 deletions x/mint/simulation/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func TestRandomizedGenState1(t *testing.T) {
}

for _, tt := range tests {
tt := tt
require.Panicsf(t, func() { simulation.RandomizedGenState(&tt.simState) }, tt.panicMsg)
}
}
2 changes: 1 addition & 1 deletion x/ratelimit/keeper/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func EmitTransferDeniedEvent(ctx sdk.Context, reason, denom, channelID string, d
}

// Adds an amount to the flow in either the SEND or RECV direction
func (k Keeper) UpdateFlow(ctx sdk.Context, rateLimit types.RateLimit, direction types.PacketDirection, amount math.Int) error {
func (k Keeper) UpdateFlow(_ sdk.Context, rateLimit types.RateLimit, direction types.PacketDirection, amount math.Int) error {
switch direction {
case types.PACKET_SEND:
return rateLimit.Flow.AddOutflow(amount, *rateLimit.Quota, rateLimit.MinRateLimitAmount)
Expand Down
2 changes: 1 addition & 1 deletion x/ratelimit/types/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// CheckExceedsQuota checks if new in/out flow is going to reach the max in/out or not
func (q *Quota) CheckExceedsQuota(direction PacketDirection, amount math.Int, totalValue math.Int, minRateLimitAmount math.Int) bool {
func (q *Quota) CheckExceedsQuota(direction PacketDirection, amount, totalValue, minRateLimitAmount math.Int) bool {
// If there's no channel value (this should be almost impossible), it means there is no
// supply of the asset, so we shoudn't prevent inflows/outflows
if totalValue.IsZero() {
Expand Down
1 change: 0 additions & 1 deletion x/tx-boundary/ante/antetest/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,4 @@ func (s *AnteTestSuite) TestStakingAnte() {
s.Require().Error(err)
}
}

}
7 changes: 5 additions & 2 deletions x/tx-boundary/ante/antetest/ante_test_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"github.com/notional-labs/centauri/v5/app/helpers"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"

"github.com/notional-labs/centauri/v5/app"
"github.com/notional-labs/centauri/v5/app/helpers"
)

var BaseBalance = sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(10000000000)))
Expand All @@ -41,7 +44,7 @@ type AnteTestSuite struct {
func (suite *AnteTestSuite) SetupTest() {
suite.app, suite.delegator, suite.validators = helpers.SetupCentauriAppWithValSetWithGenAccout(suite.T())
suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "centauri-1", Time: time.Now().UTC()})
app.FundAccount(suite.app.BankKeeper, suite.ctx, sdk.AccAddress(suite.delegator), BaseBalance)
app.FundAccount(suite.app.BankKeeper, suite.ctx, suite.delegator, BaseBalance)

encodingConfig := app.MakeEncodingConfig()
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
Expand Down Expand Up @@ -78,7 +81,7 @@ func (suite *AnteTestSuite) SetupTest() {
suite.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
}

func (s *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
func (s *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
var sigsV2 []signing.SignatureV2
for i, priv := range privs {
sigV2 := signing.SignatureV2{
Expand Down
20 changes: 10 additions & 10 deletions x/tx-boundary/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ func GetTxCmd() *cobra.Command {

func GetCmdUpdateDelegateBoundary() *cobra.Command {
cmd := &cobra.Command{
Use: "update-delegate [tx_limit] [block_per_generation]",
Use: "update-delegate [txLimit] [blockPerGeneration]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

tx_limit, err := strconv.ParseUint(args[0], 10, 64)
txLimit, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

block_per_generation, err := strconv.ParseUint(args[1], 10, 64)
blockPerGeneration, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgUpdateDelegateBoundary(
types.Boundary{
TxLimit: tx_limit,
BlocksPerGeneration: block_per_generation,
TxLimit: txLimit,
BlocksPerGeneration: blockPerGeneration,
},
clientCtx.GetFromAddress().String(),
)
Expand All @@ -64,28 +64,28 @@ func GetCmdUpdateDelegateBoundary() *cobra.Command {

func GetCmdUpdateRedelegateBoundary() *cobra.Command {
cmd := &cobra.Command{
Use: "update-redelegate [tx_limit] [block_per_generation]",
Use: "update-redelegate [txLimit] [blockPerGeneration]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

tx_limit, err := strconv.ParseUint(args[0], 10, 64)
txLimit, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

block_per_generation, err := strconv.ParseUint(args[1], 10, 64)
blockPerGeneration, err := strconv.ParseUint(args[1], 10, 64)
if err != nil {
return err
}

msg := types.NewMsgUpdateRedelegateBoundary(
types.Boundary{
TxLimit: tx_limit,
BlocksPerGeneration: block_per_generation,
TxLimit: txLimit,
BlocksPerGeneration: blockPerGeneration,
},
clientCtx.GetFromAddress().String(),
)
Expand Down
2 changes: 1 addition & 1 deletion x/tx-boundary/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
var _ types.QueryServer = Keeper{}

// DelegateBoundary returns delegate boundary of the tx-boundary module.
func (k Keeper) DelegateBoundary(c context.Context, req *types.QueryDelegateBoundaryRequest) (*types.QueryDelegateBoundaryResponse, error) {
func (k Keeper) DelegateBoundary(c context.Context, _ *types.QueryDelegateBoundaryRequest) (*types.QueryDelegateBoundaryResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
boundary := k.GetDelegateBoundary(ctx)

Expand Down
57 changes: 27 additions & 30 deletions x/tx-boundary/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ func (k Keeper) GetRedelegateBoundary(ctx sdk.Context) (boundary types.Boundary)
}

// SetDelegateCount set the number of delegate tx for a given address
func (k Keeper) SetLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress, limit_per_addr types.LimitPerAddr) {
func (k Keeper) SetLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress, limitPerAddr types.LimitPerAddr) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&limit_per_addr)
bz := k.cdc.MustMarshal(&limitPerAddr)
store.Set(addr, bz)
}

func (k Keeper) IncrementDelegateCount(ctx sdk.Context, addr sdk.AccAddress) {
store := ctx.KVStore(k.storeKey)
if store.Has(addr) == false {
if !store.Has(addr) {
k.SetLimitPerAddr(ctx, addr, types.LimitPerAddr{
DelegateCount: 1,
ReledegateCount: 0,
Expand All @@ -105,16 +105,15 @@ func (k Keeper) IncrementDelegateCount(ctx sdk.Context, addr sdk.AccAddress) {
return
}
bz := store.Get(addr)
var limit_per_addr types.LimitPerAddr
k.cdc.MustUnmarshal(bz, &limit_per_addr)
limit_per_addr.DelegateCount += 1
k.SetLimitPerAddr(ctx, addr, limit_per_addr)
return
var limitPerAddr types.LimitPerAddr
k.cdc.MustUnmarshal(bz, &limitPerAddr)
limitPerAddr.DelegateCount++
k.SetLimitPerAddr(ctx, addr, limitPerAddr)
}

func (k Keeper) IncrementRedelegateCount(ctx sdk.Context, addr sdk.AccAddress) {
store := ctx.KVStore(k.storeKey)
if store.Has(addr) == false {
if !store.Has(addr) {
k.SetLimitPerAddr(ctx, addr, types.LimitPerAddr{
DelegateCount: 0,
ReledegateCount: 1,
Expand All @@ -123,59 +122,57 @@ func (k Keeper) IncrementRedelegateCount(ctx sdk.Context, addr sdk.AccAddress) {
return
}
bz := store.Get(addr)
var limit_per_addr types.LimitPerAddr
k.cdc.MustUnmarshal(bz, &limit_per_addr)
limit_per_addr.ReledegateCount += 1
k.SetLimitPerAddr(ctx, addr, limit_per_addr)
return
var limitPerAddr types.LimitPerAddr
k.cdc.MustUnmarshal(bz, &limitPerAddr)
limitPerAddr.ReledegateCount++
k.SetLimitPerAddr(ctx, addr, limitPerAddr)
}

// GetDelegateCount get the number of delegate tx for a given address
func (k Keeper) GetLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress) (limit_per_addr types.LimitPerAddr) {
func (k Keeper) GetLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress) (limitPerAddr types.LimitPerAddr) {
store := ctx.KVStore(k.storeKey)
if store.Has(addr) == false {
if !store.Has(addr) {
return types.LimitPerAddr{
DelegateCount: 0,
ReledegateCount: 0,
LatestUpdateBlock: 0,
}
}
bz := store.Get(addr)
k.cdc.MustUnmarshal(bz, &limit_per_addr)
k.cdc.MustUnmarshal(bz, &limitPerAddr)
return
}

func (k Keeper) UpdateLimitPerAddr(ctx sdk.Context, addr sdk.AccAddress) {
limit_per_addr := k.GetLimitPerAddr(ctx, addr)
if limit_per_addr.LatestUpdateBlock == 0 {
limitPerAddr := k.GetLimitPerAddr(ctx, addr)
if limitPerAddr.LatestUpdateBlock == 0 {
return
}
boundary := k.GetDelegateBoundary(ctx)
if limit_per_addr.LatestUpdateBlock+int64(boundary.BlocksPerGeneration) >= ctx.BlockHeight() {
// Calculate the generated tx number from the duration between latest update block and curent block height
if limitPerAddr.LatestUpdateBlock+int64(boundary.BlocksPerGeneration) >= ctx.BlockHeight() {
// Calculate the generated tx number from the duration between latest update block and current block height
var generatedTx uint64
duration := uint64(limit_per_addr.LatestUpdateBlock) + boundary.BlocksPerGeneration - uint64(ctx.BlockHeight())
duration := uint64(limitPerAddr.LatestUpdateBlock) + boundary.BlocksPerGeneration - uint64(ctx.BlockHeight())
if duration/boundary.BlocksPerGeneration > 5 {
generatedTx = 5
} else {
generatedTx = duration / boundary.BlocksPerGeneration
}

// Update the delegate tx limit
if uint64(generatedTx) > limit_per_addr.DelegateCount {
limit_per_addr.DelegateCount = 0
if generatedTx > limitPerAddr.DelegateCount {
limitPerAddr.DelegateCount = 0
} else {
limit_per_addr.DelegateCount -= uint64(generatedTx)
limitPerAddr.DelegateCount -= generatedTx
}
// Update the redelegate tx limit
if uint64(generatedTx) > limit_per_addr.ReledegateCount {
limit_per_addr.ReledegateCount = 0
if generatedTx > limitPerAddr.ReledegateCount {
limitPerAddr.ReledegateCount = 0
} else {
limit_per_addr.ReledegateCount -= uint64(generatedTx)
limitPerAddr.ReledegateCount -= generatedTx
}
// Update LatestUpdateBlock
limit_per_addr.LatestUpdateBlock = ctx.BlockHeight()
limitPerAddr.LatestUpdateBlock = ctx.BlockHeight()
return
}
return
}
2 changes: 1 addition & 1 deletion x/tx-boundary/keeper/msg_server.go
Original file line number Diff line number Diff line change
@@ -1 +1 @@
package keeper
package keeper
4 changes: 2 additions & 2 deletions x/tx-boundary/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

// RegisterServices registers a gRPC query service to respond to the
// module-specific gRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
func (am AppModule) RegisterServices(_ module.Configurator) {
// types.RegisterQueryServer(cfg.QueryServer(), am.keeper)
// types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper))
}
Expand All @@ -136,7 +136,7 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw
func (AppModule) ConsensusVersion() uint64 { return 1 }

// BeginBlock returns the begin blocker for the tx-boundary module.
func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) {}
func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {}

// ProposalContents doesn't return any content functions for governance proposals.
func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalMsg {
Expand Down
4 changes: 2 additions & 2 deletions x/tx-boundary/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func init() {
}

// RegisterLegacyAminoCodec registers concrete types on the LegacyAmino codec
func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
func RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {
}

// RegisterInterfaces registers the interfaces types with the interface registry.
func RegisterInterfaces(registry types.InterfaceRegistry) {
func RegisterInterfaces(_ types.InterfaceRegistry) {
}