Skip to content

Commit

Permalink
fix unused fnc
Browse files Browse the repository at this point in the history
  • Loading branch information
tungleanh0902 committed Mar 7, 2024
1 parent 6260cc8 commit bbe4dab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 86 deletions.
76 changes: 0 additions & 76 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,82 +288,6 @@ func SetupWithEmptyStore(tb testing.TB) *ComposableApp {

type GenerateAccountStrategy func(int) []sdk.AccAddress

func genesisStateWithValSet(t *testing.T,
app *ComposableApp, genesisState GenesisState,
valSet *tmtypes.ValidatorSet, genAccs []authtypes.GenesisAccount,
balances ...banktypes.Balance,
) GenesisState {
// set genesis accounts
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

bondAmt := sdk.DefaultPowerReduction

for _, val := range valSet.Validators {
pk, err := cryptocodec.FromTmPubKeyInterface(val.PubKey)
require.NoError(t, err)
pkAny, err := codectypes.NewAnyWithValue(pk)
require.NoError(t, err)
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stakingtypes.Bonded,
Tokens: bondAmt,
DelegatorShares: sdk.OneDec(),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
MinSelfDelegation: sdk.ZeroInt(),
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))
}
// set validators and delegations
defaultStParams := stakingtypes.DefaultParams()
stParams := stakingtypes.NewParams(
defaultStParams.UnbondingTime,
defaultStParams.MaxValidators,
defaultStParams.MaxEntries,
defaultStParams.HistoricalEntries,
typesconfig.BaseCoinUnit,
defaultStParams.MinCommissionRate,
)

// set validators and delegations
stakingGenesis := stakingtypes.NewGenesisState(stParams, validators, delegations)
genesisState[stakingtypes.ModuleName] = app.AppCodec().MustMarshalJSON(stakingGenesis)

totalSupply := sdk.NewCoins()
for _, b := range balances {
// add genesis acc tokens to total supply
totalSupply = totalSupply.Add(b.Coins...)
}

for range delegations {
// add delegated tokens to total supply
totalSupply = totalSupply.Add(sdk.NewCoin(typesconfig.BaseCoinUnit, bondAmt))
}

// add bonded amount to bonded pool module account
balances = append(balances, banktypes.Balance{
Address: authtypes.NewModuleAddress(stakingtypes.BondedPoolName).String(),
Coins: sdk.Coins{sdk.NewCoin(typesconfig.BaseCoinUnit, bondAmt)},
})

// update total supply
bankGenesis := banktypes.NewGenesisState(banktypes.DefaultGenesisState().Params, balances, totalSupply, []banktypes.Metadata{},
banktypes.DefaultGenesisState().SendEnabled)

genesisState[banktypes.ModuleName] = app.AppCodec().MustMarshalJSON(bankGenesis)

return genesisState
}

// createRandomAccounts is a strategy used by addTestAddrs() in order to generated addresses in random order.
func createRandomAccounts(accNum int) []sdk.AccAddress {
testAddrs := make([]sdk.AccAddress, accNum)
Expand Down
17 changes: 8 additions & 9 deletions app/upgrades/v6_4_6/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
Expand Down Expand Up @@ -161,26 +160,26 @@ func prepareForTestingAuthModule(s *UpgradeTestSuite) (sdk.AccAddress, sdk.AccAd

addr2 := s.TestAccs[2]
baseAccount2 := authtypes.NewBaseAccount(addr2, nil, 0, 0)
baseVestingAccount := authvesting.NewBaseVestingAccount(baseAccount2, sdk.NewCoins(sdk.NewCoin(COIN_DENOM, math.NewIntFromUint64(1))), 60)
baseVestingAccount := vestingtypes.NewBaseVestingAccount(baseAccount2, sdk.NewCoins(sdk.NewCoin(COIN_DENOM, math.NewIntFromUint64(1))), 60)
s.App.AccountKeeper.SetAccount(s.Ctx, baseVestingAccount)

continuousVestingAccount := CreateVestingAccount(s)

addr3 := s.TestAccs[3]
baseAccount3 := authtypes.NewBaseAccount(addr3, nil, 0, 0)
baseVestingAccount2 := authvesting.NewBaseVestingAccount(baseAccount3, sdk.NewCoins(sdk.NewCoin(COIN_DENOM, math.NewIntFromUint64(1))), 60)
delayedVestingAccount := authvesting.NewDelayedVestingAccountRaw(baseVestingAccount2)
baseVestingAccount2 := vestingtypes.NewBaseVestingAccount(baseAccount3, sdk.NewCoins(sdk.NewCoin(COIN_DENOM, math.NewIntFromUint64(1))), 60)
delayedVestingAccount := vestingtypes.NewDelayedVestingAccountRaw(baseVestingAccount2)
s.App.AccountKeeper.SetAccount(s.Ctx, delayedVestingAccount)

addr4 := s.TestAccs[4]
baseAccount4 := authtypes.NewBaseAccount(addr4, nil, 0, 0)
baseVestingAccount3 := authvesting.NewBaseVestingAccount(baseAccount4, sdk.NewCoins(sdk.NewCoin(COIN_DENOM, math.NewIntFromUint64(1))), 60)
periodicVestingAccount := authvesting.NewPeriodicVestingAccountRaw(baseVestingAccount3, 0, vestingtypes.Periods{})
baseVestingAccount3 := vestingtypes.NewBaseVestingAccount(baseAccount4, sdk.NewCoins(sdk.NewCoin(COIN_DENOM, math.NewIntFromUint64(1))), 60)
periodicVestingAccount := vestingtypes.NewPeriodicVestingAccountRaw(baseVestingAccount3, 0, vestingtypes.Periods{})
s.App.AccountKeeper.SetAccount(s.Ctx, periodicVestingAccount)

addr5 := s.TestAccs[5]
baseAccount5 := authtypes.NewBaseAccount(addr5, nil, 0, 0)
permanentLockedAccount := authvesting.NewPermanentLockedAccount(baseAccount5, sdk.NewCoins(sdk.NewCoin(COIN_DENOM, math.NewIntFromUint64(1))))
permanentLockedAccount := vestingtypes.NewPermanentLockedAccount(baseAccount5, sdk.NewCoins(sdk.NewCoin(COIN_DENOM, math.NewIntFromUint64(1))))
s.App.AccountKeeper.SetAccount(s.Ctx, permanentLockedAccount)

return baseAccount.GetAddress(), stakingModuleAccount.GetAddress(), baseVestingAccount.GetAddress(), continuousVestingAccount.GetAddress(), delayedVestingAccount.GetAddress(), periodicVestingAccount.GetAddress(), permanentLockedAccount.GetAddress()
Expand Down Expand Up @@ -251,7 +250,7 @@ func checkUpgradeSlashingModule(s *UpgradeTestSuite, oldConsAddress sdk.ConsAddr
s.Suite.Equal(valSigningInfo.Address, newBech32Addr)
}

func checkUpgradeStakingModule(s *UpgradeTestSuite, oldValAddress sdk.ValAddress, oldValAddress2 sdk.ValAddress, acc1 sdk.AccAddress, afterOneDay time.Time) {
func checkUpgradeStakingModule(s *UpgradeTestSuite, oldValAddress, oldValAddress2 sdk.ValAddress, acc1 sdk.AccAddress, afterOneDay time.Time) {
// CONVERT TO ACC TO NEW PREFIX
_, bz, _ := bech32.DecodeAndConvert(oldValAddress.String())
newBech32Addr, _ := bech32.ConvertAndEncode(utils.NewBech32PrefixValAddr, bz)
Expand Down Expand Up @@ -296,7 +295,7 @@ func checkUpgradeStakingModule(s *UpgradeTestSuite, oldValAddress sdk.ValAddress
s.Suite.Equal(strings.Contains(RedelegationQueueTimeSlice[0].ValidatorSrcAddress, "pica"), true)
}

func checkUpgradeAuthModule(s *UpgradeTestSuite, baseAccount sdk.AccAddress, stakingModuleAccount sdk.AccAddress, baseVestingAccount sdk.AccAddress, continuousVestingAccount sdk.AccAddress, delayedVestingAccount sdk.AccAddress, periodicVestingAccount sdk.AccAddress, permanentLockedAccount sdk.AccAddress) {
func checkUpgradeAuthModule(s *UpgradeTestSuite, baseAccount, stakingModuleAccount, baseVestingAccount, continuousVestingAccount, delayedVestingAccount, periodicVestingAccount, permanentLockedAccount sdk.AccAddress) {
/* CHECK BASE ACCOUNT */
_, bz, _ := bech32.DecodeAndConvert(baseAccount.String())
newBech32AddrBaseAccount, _ := bech32.ConvertAndEncode(utils.NewBech32PrefixAccAddr, bz)
Expand Down
1 change: 0 additions & 1 deletion bech32-migration/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func IterateStoreByPrefix(
newValue := fn(iterator.Value())
store.Set(iterator.Key(), newValue)
}

}

// AccAddressFromBech32 creates an AccAddress from a Bech32 string.
Expand Down

0 comments on commit bbe4dab

Please sign in to comment.