Skip to content

Commit

Permalink
fix: unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
taramakage committed Jul 6, 2023
1 parent e820536 commit 27081cc
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 7 deletions.
9 changes: 9 additions & 0 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,15 @@ func TestABCI_P2PQuery(t *testing.T) {

suite := NewBaseAppSuite(t, addrPeerFilterOpt, idPeerFilterOpt)

// As the modified handleQueryP2P needs a query context, the lastBlockHeight
// must not be zero. Therefore, we initiate the chain and commit one block here.
suite.baseApp.InitChain(abci.RequestInitChain{
ConsensusParams: &tmproto.ConsensusParams{},
})
header := tmproto.Header{Height: suite.baseApp.LastBlockHeight() + 1}
suite.baseApp.BeginBlock(abci.RequestBeginBlock{Header: header})
suite.baseApp.Commit()

addrQuery := abci.RequestQuery{
Path: "/p2p/filter/addr/1.1.1.1:8000",
}
Expand Down
2 changes: 1 addition & 1 deletion baseapp/block_gas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func TestBaseApp_BlockGas(t *testing.T) {
require.Equal(t, []byte("ok"), okValue)
}
// check block gas is always consumed
baseGas := uint64(51732) // baseGas is the gas consumed before tx msg
baseGas := uint64(51759) // baseGas is the gas consumed before tx msg
expGasConsumed := addUint64Saturating(tc.gasToConsume, baseGas)
if expGasConsumed > txtypes.MaxGasWanted {
// capped by gasLimit
Expand Down
6 changes: 3 additions & 3 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ func (app *BaseApp) SetEndBlocker(endBlocker sdk.EndBlocker) {
}

func (app *BaseApp) SetAnteHandler(ah sdk.AnteHandler) {
//if app.sealed {
// panic("SetAnteHandler() on sealed BaseApp")
//}
if app.sealed {
panic("SetAnteHandler() on sealed BaseApp")
}

app.anteHandler = ah
}
Expand Down
5 changes: 3 additions & 2 deletions x/auth/keeper/deterministic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ func (suite *DeterministicTestSuite) TestGRPCQueryParameters() {
rapid.Uint64Min(1).Draw(t, "tx-size-cost-per-byte"),
rapid.Uint64Min(1).Draw(t, "sig-verify-cost-ed25519"),
rapid.Uint64Min(1).Draw(t, "sig-verify-cost-Secp256k1"),
rapid.Uint64Min(1).Draw(t, "sig-verify-cost-Sm2"),
)
err := suite.accountKeeper.SetParams(suite.ctx, params)
suite.Require().NoError(err)
Expand All @@ -202,13 +203,13 @@ func (suite *DeterministicTestSuite) TestGRPCQueryParameters() {
})

// Regression test
params := types.NewParams(15, 167, 100, 1, 21457)
params := types.NewParams(15, 167, 100, 1, 21457, 7850)

err := suite.accountKeeper.SetParams(suite.ctx, params)
suite.Require().NoError(err)

req := &types.QueryParamsRequest{}
testdata.DeterministicIterations(suite.ctx, suite.Require(), req, suite.queryClient.Params, 1042, false)
testdata.DeterministicIterations(suite.ctx, suite.Require(), req, suite.queryClient.Params, 1051, true)
}

func (suite *DeterministicTestSuite) TestGRPCQueryAccountInfo() {
Expand Down
1 change: 1 addition & 0 deletions x/auth/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func (suite *KeeperTestSuite) TestInitGenesis() {
TxSizeCostPerByte: types.DefaultTxSizeCostPerByte + 1,
SigVerifyCostED25519: types.DefaultSigVerifyCostED25519 + 1,
SigVerifyCostSecp256k1: types.DefaultSigVerifyCostSecp256k1 + 1,
SigVerifyCostSm2: types.DefaultSigVerifyCostSm2 + 1,
},
}

Expand Down
21 changes: 21 additions & 0 deletions x/auth/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 100,
},
},
expectErr: true,
Expand All @@ -44,6 +45,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 100,
},
},
expectErr: true,
Expand All @@ -59,6 +61,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
TxSizeCostPerByte: 0,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 100,
},
},
expectErr: true,
Expand All @@ -74,6 +77,7 @@ func (s *KeeperTestSuite) TestUpdateParams() {
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 0,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 100,
},
},
expectErr: true,
Expand All @@ -89,11 +93,28 @@ func (s *KeeperTestSuite) TestUpdateParams() {
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 0,
SigVerifyCostSm2: 100,
},
},
expectErr: true,
expErrMsg: "invalid SECK256k1 signature verification cost",
},
{
name: "set invalid sig verify cost Sm2",
req: &types.MsgUpdateParams{
Authority: s.accountKeeper.GetAuthority(),
Params: types.Params{
MaxMemoCharacters: 140,
TxSigLimit: 9,
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 0,
},
},
expectErr: true,
expErrMsg: "invalid Sm2 signature verification cost",
},
}

for _, tc := range testCases {
Expand Down
18 changes: 18 additions & 0 deletions x/auth/keeper/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (s *KeeperTestSuite) TestParams() {
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 100,
},
expectErr: true,
expErrMsg: "invalid max memo characters",
Expand All @@ -31,6 +32,7 @@ func (s *KeeperTestSuite) TestParams() {
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 100,
},
expectErr: true,
expErrMsg: "invalid tx signature limit",
Expand All @@ -43,6 +45,7 @@ func (s *KeeperTestSuite) TestParams() {
TxSizeCostPerByte: 0,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 100,
},
expectErr: true,
expErrMsg: "invalid tx size cost per byte",
Expand All @@ -55,6 +58,7 @@ func (s *KeeperTestSuite) TestParams() {
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 0,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 100,
},
expectErr: true,
expErrMsg: "invalid ED25519 signature verification cost",
Expand All @@ -67,10 +71,24 @@ func (s *KeeperTestSuite) TestParams() {
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 0,
SigVerifyCostSm2: 100,
},
expectErr: true,
expErrMsg: "invalid SECK256k1 signature verification cost",
},
{
name: "set invalid sig verify cost Sm2",
input: types.Params{
MaxMemoCharacters: 140,
TxSigLimit: 9,
TxSizeCostPerByte: 5,
SigVerifyCostED25519: 694,
SigVerifyCostSecp256k1: 511,
SigVerifyCostSm2: 0,
},
expectErr: true,
expErrMsg: "invalid Sm2 signature verification cost",
},
}
for _, tc := range testCases {
tc := tc
Expand Down
4 changes: 3 additions & 1 deletion x/auth/types/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ func TestParams_Validate(t *testing.T) {
{"invalid ED25519 signature verification cost", types.NewParams(types.DefaultMaxMemoCharacters, types.DefaultTxSigLimit, types.DefaultTxSizeCostPerByte,
0, types.DefaultSigVerifyCostSecp256k1, types.DefaultSigVerifyCostSm2), fmt.Errorf("invalid ED25519 signature verification cost: 0")},
{"invalid SECK256k1 signature verification cost", types.NewParams(types.DefaultMaxMemoCharacters, types.DefaultTxSigLimit, types.DefaultTxSizeCostPerByte,
types.DefaultSigVerifyCostED25519, types.DefaultSigVerifyCostSm2, 0), fmt.Errorf("invalid SECK256k1 signature verification cost: 0")},
types.DefaultSigVerifyCostED25519, 0, types.DefaultSigVerifyCostSm2), fmt.Errorf("invalid SECK256k1 signature verification cost: 0")},
{"invalid SM2 signature verification cost", types.NewParams(types.DefaultMaxMemoCharacters, types.DefaultTxSigLimit, types.DefaultTxSizeCostPerByte,
types.DefaultSigVerifyCostED25519, types.DefaultSigVerifyCostSm2, 0), fmt.Errorf("invalid Sm2 signature verification cost: 0")},
{"invalid max memo characters", types.NewParams(0, types.DefaultTxSigLimit, types.DefaultTxSizeCostPerByte,
types.DefaultSigVerifyCostED25519, types.DefaultSigVerifyCostSecp256k1, types.DefaultSigVerifyCostSm2), fmt.Errorf("invalid max memo characters: 0")},
{"invalid tx size cost per byte", types.NewParams(types.DefaultMaxMemoCharacters, types.DefaultTxSigLimit, 0,
Expand Down

0 comments on commit 27081cc

Please sign in to comment.