Skip to content

Commit

Permalink
test: fix nightly test
Browse files Browse the repository at this point in the history
  • Loading branch information
fx0x55 authored and zakir-code committed Jul 23, 2024
1 parent 53a4ca4 commit a74600b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
3 changes: 2 additions & 1 deletion tests/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tests

import (
"fmt"
"os"
"runtime"
"testing"
Expand Down Expand Up @@ -109,7 +110,7 @@ func (suite *IntegrationTest) GetCrossChainByName(chainName string) CrosschainTe
return c
}
}
panic("chain not found")
panic(fmt.Sprintf("chain not found %s", chainName))
}

type IntegrationMultiNodeTest struct {
Expand Down
4 changes: 2 additions & 2 deletions tests/staking_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (suite *IntegrationTest) StakingPrecompileRedelegateTest() {
// query delegate
valAddrShares1, _ := suite.staking.Delegation(valAddr.String(), hexAddr)

resp := suite.staking.CreateValidator(valNew.PrivKey())
resp := suite.staking.CreateValidator(valNew.PrivKey(), false)
suite.Equal(resp.Code, uint32(0))

receipt = suite.staking.Redelegate(delSigner.PrivKey(), valAddr.String(), sdk.ValAddress(valNew.AccAddress()).String(), valAddrShares1)
Expand Down Expand Up @@ -512,7 +512,7 @@ func (suite *IntegrationTest) StakingPrecompileRedelegateByContractTest() {
// query delegate
valAddrShares1, _ := suite.staking.Delegation(valAddr.String(), contract)

resp := suite.staking.CreateValidator(valNew.PrivKey())
resp := suite.staking.CreateValidator(valNew.PrivKey(), false)
suite.Equal(resp.Code, uint32(0))

receipt = suite.staking.RedelegateByContract(delSigner.PrivKey(), contract, valAddr.String(), sdk.ValAddress(valNew.AccAddress()).String(), valAddrShares1)
Expand Down
12 changes: 9 additions & 3 deletions tests/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (suite *TestSuite) SetupSuite() {
cfg := testutil.DefaultNetworkConfig(encCfg, ibcGenesisOpt, bankGenesisOpt, govGenesisOpt, slashingGenesisOpt)
cfg.TimeoutCommit = timeoutCommit
cfg.NumValidators = numValidators
cfg.EnableJSONRPC = true
if suite.enableTMLogging {
cfg.EnableTMLogging = true
}
Expand Down Expand Up @@ -359,10 +360,14 @@ func (suite *TestSuite) BroadcastProposalTx2(msgs []sdk.Msg, title, summary stri
return txResponse, proposalId
}

func (suite *TestSuite) CreateValidator(valPriv cryptotypes.PrivKey) *sdk.TxResponse {
func (suite *TestSuite) CreateValidator(valPriv cryptotypes.PrivKey, toBondedVal bool) *sdk.TxResponse {
valAddr := sdk.ValAddress(valPriv.PubKey().Address())
selfDelegate := sdk.NewCoin(suite.GetStakingDenom(), sdkmath.NewIntFromUint64(1e18).Mul(sdkmath.NewInt(100)))
minSelfDelegate := sdkmath.NewIntFromUint64(1e18).Mul(sdkmath.NewInt(1))
minSelfDelegate := sdkmath.NewInt(1)
stakingDenom := suite.GetStakingDenom()
selfDelegate := sdk.NewCoin(stakingDenom, minSelfDelegate)
if toBondedVal {
selfDelegate = sdk.NewCoin(stakingDenom, sdkmath.NewIntFromUint64(1e18).Mul(sdkmath.NewInt(100)))
}
description := stakingtypes.Description{
Moniker: "val2",
Identity: "",
Expand Down Expand Up @@ -467,6 +472,7 @@ func (suite *TestSuite) CheckUndelegate(delegatorAddr sdk.AccAddress, validatorA
suite.NoError(err)
suite.Equal(len(response.Unbond.Entries), len(entries))
for i, entry := range response.Unbond.Entries {
entry.UnbondingId = 0
suite.Equal(entry.String(), entries[i].String())
}
}
Expand Down
5 changes: 2 additions & 3 deletions testutil/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
Expand Down Expand Up @@ -188,9 +187,9 @@ func BankGenesisState(cdc codec.Codec, genesisState app.GenesisState) app.Genesi
}

func GovGenesisState(cdc codec.Codec, genesisState app.GenesisState, votingPeriod time.Duration) app.GenesisState {
var govGenState govv1beta1.GenesisState
var govGenState govv1.GenesisState
cdc.MustUnmarshalJSON(genesisState[govtypes.ModuleName], &govGenState)
govGenState.VotingParams.VotingPeriod = votingPeriod
govGenState.Params.VotingPeriod = &votingPeriod

genesisState[govtypes.ModuleName] = cdc.MustMarshalJSON(&govGenState)
return genesisState
Expand Down
18 changes: 14 additions & 4 deletions x/staking/precompile/transfer_shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,15 @@ func (c *Contract) handlerTransferShares(
// withdraw reward
distrKeeper := c.distrKeeper.(distrkeeper.Keeper)
impl := distrkeeper.NewMsgServerImpl(distrKeeper)
if _, err := impl.WithdrawDelegatorReward(sdk.WrapSDKContext(ctx), &distrtypes.MsgWithdrawDelegatorReward{
withdrawRewardRes, err := impl.WithdrawDelegatorReward(sdk.WrapSDKContext(ctx), &distrtypes.MsgWithdrawDelegatorReward{
DelegatorAddress: sdk.AccAddress(from.Bytes()).String(),
ValidatorAddress: valAddr.String(),
}); err != nil {
})
if err != nil {
return nil, nil, err
}

if err = c.AddLog(evm, WithdrawEvent, []common.Hash{from.Hash()}, valAddr.String(), withdrawRewardRes.Amount.AmountOf(evmDenom).BigInt()); err != nil {
return nil, nil, err
}

Expand All @@ -149,10 +154,15 @@ func (c *Contract) handlerTransferShares(
// if address to not delegate before, increase validator period
_ = c.distrKeeper.IncrementValidatorPeriod(ctx, validator)
} else {
if _, err := impl.WithdrawDelegatorReward(sdk.WrapSDKContext(ctx), &distrtypes.MsgWithdrawDelegatorReward{
toWithdrawRewardsRes, err := impl.WithdrawDelegatorReward(sdk.WrapSDKContext(ctx), &distrtypes.MsgWithdrawDelegatorReward{
DelegatorAddress: sdk.AccAddress(to.Bytes()).String(),
ValidatorAddress: valAddr.String(),
}); err != nil {
})
if err != nil {
return nil, nil, err
}

if err = c.AddLog(evm, WithdrawEvent, []common.Hash{to.Hash()}, valAddr.String(), toWithdrawRewardsRes.Amount.AmountOf(evmDenom).BigInt()); err != nil {
return nil, nil, err
}
}
Expand Down

0 comments on commit a74600b

Please sign in to comment.