Skip to content

Commit

Permalink
set up test
Browse files Browse the repository at this point in the history
  • Loading branch information
trung2891 committed Nov 14, 2023
1 parent f33e61d commit e4dcff4
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
9 changes: 9 additions & 0 deletions x/feeburn/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package feeburn

import (
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/types"
)

const (
ModuleName = types.ModuleName
)
108 changes: 108 additions & 0 deletions x/feeburn/ante/antetest/fee_test_setup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package antetest

import (
"fmt"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
"github.com/cosmos/cosmos-sdk/x/params/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/stretchr/testify/suite"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

migalooaapp "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/app"
"github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn"
feeburnmoduletypes "github.com/White-Whale-Defi-Platform/migaloo-chain/v3/x/feeburn/types"
)

type IntegrationTestSuite struct {
suite.Suite

app *migalooaapp.MigalooApp
ctx sdk.Context
clientCtx client.Context
txBuilder client.TxBuilder
}

func (s *IntegrationTestSuite) SetupTest() {
app := migalooaapp.SetupMigalooAppWithValSet(s.T())
ctx := app.BaseApp.NewContext(false, tmproto.Header{
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)),
Height: 1,
})

encodingConfig := migalooaapp.MakeEncodingConfig()
encodingConfig.Amino.RegisterConcrete(&testdata.TestMsg{}, "testdata.TestMsg", nil)
testdata.RegisterInterfaces(encodingConfig.InterfaceRegistry)

s.app = app
s.ctx = ctx
s.clientCtx = client.Context{}.WithTxConfig(encodingConfig.TxConfig)
}

func (s *IntegrationTestSuite) SetupTestBurnFeeStore(minGasPrice []sdk.DecCoin, feeBurnParams *feeburnmoduletypes.Params) types.Subspace {
subspace := s.app.GetSubspace(feeburn.ModuleName)
subspace.SetParamSet(s.ctx, feeBurnParams)

return subspace
}

// SetupTestStakingSubspace sets uatom as bond denom for the fee tests.
func (s *IntegrationTestSuite) SetupTestStakingSubspace(params stakingtypes.Params) types.Subspace {
s.app.GetSubspace(stakingtypes.ModuleName).SetParamSet(s.ctx, &params)
return s.app.GetSubspace(stakingtypes.ModuleName)
}

func (s *IntegrationTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
var sigsV2 []signing.SignatureV2
for i, priv := range privs {
sigV2 := signing.SignatureV2{
PubKey: priv.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: s.clientCtx.TxConfig.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: accSeqs[i],
}

sigsV2 = append(sigsV2, sigV2)
}

if err := s.txBuilder.SetSignatures(sigsV2...); err != nil {
return nil, err
}

sigsV2 = []signing.SignatureV2{}
for i, priv := range privs {
signerData := xauthsigning.SignerData{
ChainID: chainID,
AccountNumber: accNums[i],
Sequence: accSeqs[i],
}
sigV2, err := tx.SignWithPrivKey(
s.clientCtx.TxConfig.SignModeHandler().DefaultMode(),
signerData,
s.txBuilder,
priv,
s.clientCtx.TxConfig,
accSeqs[i],
)
if err != nil {
return nil, err
}

sigsV2 = append(sigsV2, sigV2)
}

if err := s.txBuilder.SetSignatures(sigsV2...); err != nil {
return nil, err
}

return s.txBuilder.GetTx(), nil
}
7 changes: 7 additions & 0 deletions x/feeburn/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"strconv"

"gopkg.in/yaml.v2"

paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
)

var (
Expand All @@ -29,6 +31,11 @@ func DefaultParams() Params {
)
}

// ParamSetPairs get the params.ParamSet
func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs {
return paramtypes.ParamSetPairs{}
}

// Validate validates the set of params
func (p Params) Validate() error {
return validateTxFeeBurnPercent(p.TxFeeBurnPercent)
Expand Down

0 comments on commit e4dcff4

Please sign in to comment.