Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantran1702 committed Apr 8, 2024
1 parent a2861fe commit b3c60b2
Showing 1 changed file with 0 additions and 116 deletions.
116 changes: 0 additions & 116 deletions x/feeabs/ante/testutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import (
ubermock "go.uber.org/mock/gomock"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/tx"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
"github.com/cosmos/cosmos-sdk/x/auth"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
xauthsigning "github.com/cosmos/cosmos-sdk/x/auth/signing"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"

Expand All @@ -35,7 +32,6 @@ type TestAccount struct {

// AnteTestSuite is a test suite to be used with ante handler tests.
type AnteTestSuite struct {
anteHandler sdk.AnteHandler
ctx sdk.Context
clientCtx client.Context
txBuilder client.TxBuilder
Expand Down Expand Up @@ -106,71 +102,6 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite {
return suite
}

// TestCase represents a test case used in test tables.
type TestCase struct {
_ string
_ func(*AnteTestSuite) TestCaseArgs
simulate bool
expPass bool
expErr error
}

type TestCaseArgs struct {
chainID string
accNums []uint64
accSeqs []uint64
feeAmount sdk.Coins
gasLimit uint64
msgs []sdk.Msg
privs []cryptotypes.PrivKey
}

// DeliverMsgs constructs a tx and runs it through the ante handler. This is used to set the context for a test case, for
// example to test for replay protection.
func (suite *AnteTestSuite) DeliverMsgs(t *testing.T, privs []cryptotypes.PrivKey, msgs []sdk.Msg, feeAmount sdk.Coins, gasLimit uint64, accNums, accSeqs []uint64, chainID string, simulate bool) (sdk.Context, error) {
t.Helper()
require.NoError(t, suite.txBuilder.SetMsgs(msgs...))
suite.txBuilder.SetFeeAmount(feeAmount)
suite.txBuilder.SetGasLimit(gasLimit)

tx, txErr := suite.CreateTestTx(privs, accNums, accSeqs, chainID)
require.NoError(t, txErr)
return suite.anteHandler(suite.ctx, tx, simulate)
}

func (suite *AnteTestSuite) RunTestCase(t *testing.T, tc TestCase, args TestCaseArgs) {
t.Helper()
require.NoError(t, suite.txBuilder.SetMsgs(args.msgs...))
suite.txBuilder.SetFeeAmount(args.feeAmount)
suite.txBuilder.SetGasLimit(args.gasLimit)
// Theoretically speaking, ante handler unit tests should only test
// ante handlers, but here we sometimes also test the tx creation
// process.
tx, txErr := suite.CreateTestTx(args.privs, args.accNums, args.accSeqs, args.chainID)
newCtx, anteErr := suite.anteHandler(suite.ctx, tx, tc.simulate)

if tc.expPass {
require.NoError(t, txErr)
require.NoError(t, anteErr)
require.NotNil(t, newCtx)

suite.ctx = newCtx
} else {
switch {
case txErr != nil:
require.Error(t, txErr)
require.ErrorIs(t, txErr, tc.expErr)

case anteErr != nil:
require.Error(t, anteErr)
require.ErrorIs(t, anteErr, tc.expErr)

default:
t.Fatal("expected one of txErr, anteErr to be an error")
}
}
}

func (suite *AnteTestSuite) CreateTestAccounts(numAccs int) []TestAccount {
var accounts []TestAccount

Expand All @@ -187,50 +118,3 @@ func (suite *AnteTestSuite) CreateTestAccounts(numAccs int) []TestAccount {

return accounts
}

// CreateTestTx is a helper function to create a tx given multiple inputs.
func (suite *AnteTestSuite) CreateTestTx(privs []cryptotypes.PrivKey, accNums []uint64, accSeqs []uint64, chainID string) (xauthsigning.Tx, error) {
// First round: we gather all the signer infos. We use the "set empty
// signature" hack to do that.
var sigsV2 []signing.SignatureV2
for i, priv := range privs {
sigV2 := signing.SignatureV2{
PubKey: priv.PubKey(),
Data: &signing.SingleSignatureData{
SignMode: suite.clientCtx.TxConfig.SignModeHandler().DefaultMode(),
Signature: nil,
},
Sequence: accSeqs[i],
}

sigsV2 = append(sigsV2, sigV2)
}
err := suite.txBuilder.SetSignatures(sigsV2...)
if err != nil {
return nil, err
}

// Second round: all signer infos are set, so each signer can sign.
sigsV2 = []signing.SignatureV2{}
for i, priv := range privs {
signerData := xauthsigning.SignerData{
ChainID: chainID,
AccountNumber: accNums[i],
Sequence: accSeqs[i],
}
sigV2, err := tx.SignWithPrivKey(
suite.clientCtx.TxConfig.SignModeHandler().DefaultMode(), signerData,
suite.txBuilder, priv, suite.clientCtx.TxConfig, accSeqs[i])
if err != nil {
return nil, err
}

sigsV2 = append(sigsV2, sigV2)
}
err = suite.txBuilder.SetSignatures(sigsV2...)
if err != nil {
return nil, err
}

return suite.txBuilder.GetTx(), nil
}

0 comments on commit b3c60b2

Please sign in to comment.