Skip to content

Commit

Permalink
stricter constraint that fails unqualified commission at check tx (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
nghuyenthevinh2000 authored Nov 28, 2023
1 parent a0a38c3 commit cf55a25
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 174 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ run:
linters:
disable-all: true
enable:
- depguard
- dogsled
- exportloopref
- goconst
Expand Down
19 changes: 12 additions & 7 deletions app/testing/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktestutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
Expand All @@ -21,8 +24,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/libs/log"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtypes "github.com/tendermint/tendermint/types"
Expand All @@ -43,14 +44,16 @@ type KeeperTestHelper struct {
suite.Suite

App *app.TerraApp
Ctx sdk.Context
Ctx sdk.Context // ctx is deliver ctx
CheckCtx sdk.Context
QueryHelper *baseapp.QueryServiceTestHelper
TestAccs []sdk.AccAddress
}

func (s *KeeperTestHelper) Setup(t *testing.T) {
func (s *KeeperTestHelper) Setup(_ *testing.T, chainID string) {
s.App = SetupApp(s.T())
s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: "columbus-5", Time: time.Now().UTC()})
s.Ctx = s.App.BaseApp.NewContext(false, tmproto.Header{Height: 1, ChainID: chainID, Time: time.Now().UTC()})
s.CheckCtx = s.App.BaseApp.NewContext(true, tmproto.Header{Height: 1, ChainID: chainID, Time: time.Now().UTC()})
s.QueryHelper = &baseapp.QueryServiceTestHelper{
GRPCQueryRouter: s.App.GRPCQueryRouter(),
Ctx: s.Ctx,
Expand Down Expand Up @@ -126,6 +129,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
// init chain will set the validator set and initialize the genesis accounts
terraApp.InitChain(
abci.RequestInitChain{
ChainId: SimAppChainID,
Validators: []abci.ValidatorUpdate{},
ConsensusParams: DefaultConsensusParams,
AppStateBytes: stateBytes,
Expand All @@ -135,6 +139,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
// commit genesis changes
terraApp.Commit()
terraApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{
ChainID: SimAppChainID,
Height: terraApp.LastBlockHeight() + 1,
AppHash: terraApp.LastCommitID().Hash,
ValidatorsHash: valSet.Hash(),
Expand Down Expand Up @@ -248,7 +253,7 @@ func genesisStateWithValSet(t *testing.T,
return genesisState
}

func (s *KeeperTestHelper) KeyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccAddress) {
func (s *KeeperTestHelper) Ed25519PubAddr() (cryptotypes.PrivKey, cryptotypes.PubKey, sdk.AccAddress) {
key := ed25519.GenPrivKey()
pub := key.PubKey()
addr := sdk.AccAddress(pub.Address())
Expand All @@ -258,7 +263,7 @@ func (s *KeeperTestHelper) KeyPubAddr() (crypto.PrivKey, crypto.PubKey, sdk.AccA
func (s *KeeperTestHelper) RandomAccountAddresses(n int) []sdk.AccAddress {
addrsList := make([]sdk.AccAddress, n)
for i := 0; i < n; i++ {
_, _, addrs := s.KeyPubAddr()
_, _, addrs := testdata.KeyTestPubAddr()
addrsList[i] = addrs
}
return addrsList
Expand Down
3 changes: 2 additions & 1 deletion custom/staking/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

apptesting "github.com/classic-terra/core/v2/app/testing"
"github.com/classic-terra/core/v2/types"
simapp "github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
disttypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
Expand All @@ -23,7 +24,7 @@ func TestStakingTestSuite(t *testing.T) {

// go test -v -run=TestStakingTestSuite/TestValidatorVPLimit github.com/classic-terra/core/v2/custom/staking
func (s *StakingTestSuite) TestValidatorVPLimit() {
s.KeeperTestHelper.Setup(s.T())
s.KeeperTestHelper.Setup(s.T(), types.ColumbusChainID)

// construct new validators, to a total of 10 validators, each with 10% of the total voting power
num := 9
Expand Down
2 changes: 1 addition & 1 deletion wasmbinding/test/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestWasmTestSuite(t *testing.T) {
}

func (s *WasmTestSuite) SetupTest() {
s.Setup(s.T())
s.Setup(s.T(), apptesting.SimAppChainID)
}

func (s *WasmTestSuite) InstantiateContract(addr sdk.AccAddress, contractPath string) sdk.AccAddress {
Expand Down
4 changes: 0 additions & 4 deletions x/dyncomm/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ func (dd DyncommDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
return next(ctx, tx, simulate)
}

if ctx.IsCheckTx() {
return next(ctx, tx, simulate)
}

msgs := tx.GetMsgs()
err := dd.FilterMsgsAndProcessMsgs(ctx, msgs...)
if err != nil {
Expand Down
Loading

0 comments on commit cf55a25

Please sign in to comment.