Skip to content

Commit

Permalink
cleanup integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Mar 12, 2024
1 parent 6123239 commit 12318d0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
26 changes: 13 additions & 13 deletions x/evm/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ var _ = Describe("Evm", func() {
// 100_000`. With the fee calculation `Fee = (baseFee + tip) * gasLimit`,
// a `minGasPrices = 5_000_000_000` results in `minGlobalFee =
// 500_000_000_000_000`
s.SetupTest(sdk.NewDec(minGasPrices), big.NewInt(baseFee))
setupTest(sdk.NewDec(minGasPrices), big.NewInt(baseFee))
})

Context("during CheckTx", func() {
DescribeTable("should accept transactions with gas Limit > 0",
func(malleate getprices) {
p := malleate()
res := s.CheckTx(s.prepareEthTx(p))
res := s.CheckTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
},
Entry("legacy tx", func() txParams {
Expand All @@ -76,7 +76,7 @@ var _ = Describe("Evm", func() {
DescribeTable("should not accept transactions with gas Limit > 0",
func(malleate getprices) {
p := malleate()
res := s.CheckTx(s.prepareEthTx(p))
res := s.CheckTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(false), "transaction should have failed", res.GetLog())
},
Entry("legacy tx", func() txParams {
Expand All @@ -92,7 +92,7 @@ var _ = Describe("Evm", func() {
DescribeTable("should accept transactions with gas Limit > 0",
func(malleate getprices) {
p := malleate()
res := s.DeliverTx(s.prepareEthTx(p))
res := s.DeliverTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
},
Entry("legacy tx", func() txParams {
Expand All @@ -105,7 +105,7 @@ var _ = Describe("Evm", func() {
DescribeTable("should not accept transactions with gas Limit > 0",
func(malleate getprices) {
p := malleate()
res := s.DeliverTx(s.prepareEthTx(p))
res := s.DeliverTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(false), "transaction should have failed", res.GetLog())
},
Entry("legacy tx", func() txParams {
Expand All @@ -124,8 +124,8 @@ type IntegrationTestSuite struct {
testutil.BaseTestSuiteWithAccount
}

func (suite *IntegrationTestSuite) SetupTest(minGasPrice sdk.Dec, baseFee *big.Int) {
suite.BaseTestSuiteWithAccount.SetupTestWithCbAndOpts(
func setupTest(minGasPrice sdk.Dec, baseFee *big.Int) {
s.SetupTestWithCbAndOpts(
s.T(),
func(app *app.EthermintApp, genesis app.GenesisState) app.GenesisState {
feemarketGenesis := feemarkettypes.DefaultGenesisState()
Expand All @@ -136,22 +136,22 @@ func (suite *IntegrationTestSuite) SetupTest(minGasPrice sdk.Dec, baseFee *big.I
simtestutil.AppOptionsMap{server.FlagMinGasPrices: "1" + evmtypes.DefaultEVMDenom},
)
amount, ok := sdk.NewIntFromString("10000000000000000000")
suite.Require().True(ok)
s.Require().True(ok)
initBalance := sdk.Coins{sdk.Coin{
Denom: evmtypes.DefaultEVMDenom,
Amount: amount,
}}
testutil.FundAccount(s.App.BankKeeper, s.Ctx, sdk.AccAddress(suite.Address.Bytes()), initBalance)
testutil.FundAccount(s.App.BankKeeper, s.Ctx, sdk.AccAddress(s.Address.Bytes()), initBalance)
s.Commit()
params := feemarkettypes.DefaultParams()
params.MinGasPrice = minGasPrice
suite.App.FeeMarketKeeper.SetParams(suite.Ctx, params)
suite.App.FeeMarketKeeper.SetBaseFee(suite.Ctx, baseFee)
s.App.FeeMarketKeeper.SetParams(s.Ctx, params)
s.App.FeeMarketKeeper.SetBaseFee(s.Ctx, baseFee)
s.Commit()
}

func (suite *IntegrationTestSuite) prepareEthTx(p txParams) []byte {
func prepareEthTx(p txParams) []byte {
to := tests.GenerateAddress()
msg := s.BuildEthTx(&to, p.gasLimit, p.gasPrice, p.gasFeeCap, p.gasTipCap, p.accesses, s.PrivKey)
return s.PrepareEthTx(msg, suite.PrivKey)
return s.PrepareEthTx(msg, s.PrivKey)
}
78 changes: 39 additions & 39 deletions x/feemarket/keeper/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ var _ = Describe("Feemarket", func() {
Describe("Performing Cosmos transactions", func() {
Context("with min-gas-prices (local) < MinGasPrices (feemarket param)", func() {
BeforeEach(func() {
msg = s.SetupTest("1", sdk.NewDec(3), sdk.ZeroInt())
msg = setupTest("1", sdk.NewDec(3), sdk.ZeroInt())
})

Context("during CheckTx", func() {
It("should reject transactions with gasPrice < MinGasPrices", func() {
gasPrice := sdkmath.NewInt(2)
res := s.checkTx(&gasPrice, &msg)
res := checkTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -70,15 +70,15 @@ var _ = Describe("Feemarket", func() {

It("should accept transactions with gasPrice >= MinGasPrices", func() {
gasPrice := sdkmath.NewInt(3)
res := s.checkTx(&gasPrice, &msg)
res := checkTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
})
})

Context("during DeliverTx", func() {
It("should reject transactions with gasPrice < MinGasPrices", func() {
gasPrice := sdkmath.NewInt(2)
res := s.deliverTx(&gasPrice, &msg)
res := deliverTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -88,21 +88,21 @@ var _ = Describe("Feemarket", func() {

It("should accept transactions with gasPrice >= MinGasPrices", func() {
gasPrice := sdkmath.NewInt(3)
res := s.deliverTx(&gasPrice, &msg)
res := deliverTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
})
})
})

Context("with min-gas-prices (local) == MinGasPrices (feemarket param)", func() {
BeforeEach(func() {
msg = s.SetupTest("3", sdk.NewDec(3), sdk.ZeroInt())
msg = setupTest("3", sdk.NewDec(3), sdk.ZeroInt())
})

Context("during CheckTx", func() {
It("should reject transactions with gasPrice < min-gas-prices", func() {
gasPrice := sdkmath.NewInt(2)
res := s.checkTx(&gasPrice, &msg)
res := checkTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -112,15 +112,15 @@ var _ = Describe("Feemarket", func() {

It("should accept transactions with gasPrice >= MinGasPrices", func() {
gasPrice := sdkmath.NewInt(3)
res := s.checkTx(&gasPrice, &msg)
res := checkTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
})
})

Context("during DeliverTx", func() {
It("should reject transactions with gasPrice < MinGasPrices", func() {
gasPrice := sdkmath.NewInt(2)
res := s.deliverTx(&gasPrice, &msg)
res := deliverTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -130,20 +130,20 @@ var _ = Describe("Feemarket", func() {

It("should accept transactions with gasPrice >= MinGasPrices", func() {
gasPrice := sdkmath.NewInt(3)
res := s.deliverTx(&gasPrice, &msg)
res := deliverTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
})
})
})

Context("with MinGasPrices (feemarket param) < min-gas-prices (local)", func() {
BeforeEach(func() {
msg = s.SetupTest("5", sdk.NewDec(3), sdk.NewInt(5))
msg = setupTest("5", sdk.NewDec(3), sdk.NewInt(5))
})
Context("during CheckTx", func() {
It("should reject transactions with gasPrice < MinGasPrices", func() {
gasPrice := sdkmath.NewInt(2)
res := s.checkTx(&gasPrice, &msg)
res := checkTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -153,7 +153,7 @@ var _ = Describe("Feemarket", func() {

It("should reject transactions with MinGasPrices < gasPrice < baseFee", func() {
gasPrice := sdkmath.NewInt(4)
res := s.checkTx(&gasPrice, &msg)
res := checkTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -163,15 +163,15 @@ var _ = Describe("Feemarket", func() {

It("should accept transactions with gasPrice >= baseFee", func() {
gasPrice := sdkmath.NewInt(5)
res := s.checkTx(&gasPrice, &msg)
res := checkTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
})
})

Context("during DeliverTx", func() {
It("should reject transactions with gasPrice < MinGasPrices", func() {
gasPrice := sdkmath.NewInt(2)
res := s.deliverTx(&gasPrice, &msg)
res := deliverTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -181,7 +181,7 @@ var _ = Describe("Feemarket", func() {

It("should reject transactions with MinGasPrices < gasPrice < baseFee", func() {
gasPrice := sdkmath.NewInt(4)
res := s.checkTx(&gasPrice, &msg)
res := checkTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -190,7 +190,7 @@ var _ = Describe("Feemarket", func() {
})
It("should accept transactions with gasPrice >= baseFee", func() {
gasPrice := sdkmath.NewInt(5)
res := s.deliverTx(&gasPrice, &msg)
res := deliverTx(&gasPrice, &msg)
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
})
})
Expand All @@ -214,14 +214,14 @@ var _ = Describe("Feemarket", func() {
// 100000`. With the fee calculation `Fee = (baseFee + tip) * gasLimit`,
// a `minGasPrices = 40_000_000_000` results in `minGlobalFee =
// 4000000000000000`
s.SetupTest("1", sdk.NewDec(minGasPrices), sdkmath.NewInt(baseFee))
setupTest("1", sdk.NewDec(minGasPrices), sdkmath.NewInt(baseFee))
})

Context("during CheckTx", func() {
DescribeTable("should reject transactions with EffectivePrice < MinGasPrices",
func(malleate getprices) {
p := malleate()
res := s.CheckTx(s.prepareEthTx(p))
res := s.CheckTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -246,7 +246,7 @@ var _ = Describe("Feemarket", func() {
DescribeTable("should accept transactions with gasPrice >= MinGasPrices",
func(malleate getprices) {
p := malleate()
res := s.CheckTx(s.prepareEthTx(p))
res := s.CheckTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
},
Entry("legacy tx", func() txParams {
Expand All @@ -265,7 +265,7 @@ var _ = Describe("Feemarket", func() {
DescribeTable("should reject transactions with gasPrice < MinGasPrices",
func(malleate getprices) {
p := malleate()
res := s.DeliverTx(s.prepareEthTx(p))
res := s.DeliverTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -287,7 +287,7 @@ var _ = Describe("Feemarket", func() {
DescribeTable("should accept transactions with gasPrice >= MinGasPrices",
func(malleate getprices) {
p := malleate()
res := s.DeliverTx(s.prepareEthTx(p))
res := s.DeliverTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
},
Entry("legacy tx", func() txParams {
Expand All @@ -314,14 +314,14 @@ var _ = Describe("Feemarket", func() {
// 100_000`. With the fee calculation `Fee = (baseFee + tip) * gasLimit`,
// a `minGasPrices = 5_000_000_000` results in `minGlobalFee =
// 500_000_000_000_000`
s.SetupTest("1", sdk.NewDec(minGasPrices), sdkmath.NewInt(baseFee))
setupTest("1", sdk.NewDec(minGasPrices), sdkmath.NewInt(baseFee))
})

Context("during CheckTx", func() {
DescribeTable("should reject transactions with gasPrice < MinGasPrices",
func(malleate getprices) {
p := malleate()
res := s.CheckTx(s.prepareEthTx(p))
res := s.CheckTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -342,7 +342,7 @@ var _ = Describe("Feemarket", func() {
DescribeTable("should reject transactions with MinGasPrices < tx gasPrice < EffectivePrice",
func(malleate getprices) {
p := malleate()
res := s.CheckTx(s.prepareEthTx(p))
res := s.CheckTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -360,7 +360,7 @@ var _ = Describe("Feemarket", func() {
DescribeTable("should accept transactions with gasPrice >= EffectivePrice",
func(malleate getprices) {
p := malleate()
res := s.CheckTx(s.prepareEthTx(p))
res := s.CheckTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
},
Entry("legacy tx", func() txParams {
Expand All @@ -376,7 +376,7 @@ var _ = Describe("Feemarket", func() {
DescribeTable("should reject transactions with gasPrice < MinGasPrices",
func(malleate getprices) {
p := malleate()
res := s.DeliverTx(s.prepareEthTx(p))
res := s.DeliverTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -394,7 +394,7 @@ var _ = Describe("Feemarket", func() {
DescribeTable("should reject transactions with MinGasPrices < gasPrice < EffectivePrice",
func(malleate getprices) {
p := malleate()
res := s.DeliverTx(s.prepareEthTx(p))
res := s.DeliverTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(false), "transaction should have failed")
Expect(
strings.Contains(res.GetLog(),
Expand All @@ -413,7 +413,7 @@ var _ = Describe("Feemarket", func() {
DescribeTable("should accept transactions with gasPrice >= EffectivePrice",
func(malleate getprices) {
p := malleate()
res := s.DeliverTx(s.prepareEthTx(p))
res := s.DeliverTx(prepareEthTx(p))
Expect(res.IsOK()).To(Equal(true), "transaction should have succeeded", res.GetLog())
},
Entry("legacy tx", func() txParams {
Expand All @@ -434,8 +434,8 @@ type IntegrationTestSuite struct {

// SetupTest sets up a test chain with an example Cosmos send msg,
// given a local (validator config) and a gloabl (feemarket param) minGasPrice
func (suite *IntegrationTestSuite) SetupTest(valMinGasPrice string, minGasPrice sdk.Dec, baseFee sdkmath.Int) banktypes.MsgSend {
suite.BaseTestSuiteWithAccount.SetupTestWithCbAndOpts(
func setupTest(valMinGasPrice string, minGasPrice sdk.Dec, baseFee sdkmath.Int) banktypes.MsgSend {
s.SetupTestWithCbAndOpts(
s.T(),
nil,
simtestutil.AppOptionsMap{server.FlagMinGasPrices: valMinGasPrice + evmtypes.DefaultEVMDenom},
Expand All @@ -446,7 +446,7 @@ func (suite *IntegrationTestSuite) SetupTest(valMinGasPrice string, minGasPrice
Denom: evmtypes.DefaultEVMDenom,
Amount: amount,
}}
address := sdk.AccAddress(suite.Address.Bytes())
address := sdk.AccAddress(s.Address.Bytes())
testutil.FundAccount(s.App.BankKeeper, s.Ctx, address, initBalance)
msg := banktypes.MsgSend{
FromAddress: address.String(),
Expand All @@ -465,7 +465,7 @@ func (suite *IntegrationTestSuite) SetupTest(valMinGasPrice string, minGasPrice
return msg
}

func (suite *IntegrationTestSuite) prepareCosmosTx(gasPrice *sdkmath.Int, msgs ...sdk.Msg) []byte {
func prepareCosmosTx(gasPrice *sdkmath.Int, msgs ...sdk.Msg) []byte {
encodingConfig := encoding.MakeConfig(app.ModuleBasics)
accountAddress := sdk.AccAddress(s.PrivKey.PubKey().Address().Bytes())

Expand Down Expand Up @@ -524,17 +524,17 @@ func (suite *IntegrationTestSuite) prepareCosmosTx(gasPrice *sdkmath.Int, msgs .
return bz
}

func (suite *IntegrationTestSuite) prepareEthTx(p txParams) []byte {
func prepareEthTx(p txParams) []byte {
to := tests.GenerateAddress()
const gasLimit = uint64(100000)
msg := s.BuildEthTx(&to, gasLimit, p.gasPrice, p.gasFeeCap, p.gasTipCap, p.accesses, s.PrivKey)
return s.PrepareEthTx(msg, suite.PrivKey)
return s.PrepareEthTx(msg, s.PrivKey)
}

func (suite *IntegrationTestSuite) checkTx(gasPrice *sdkmath.Int, msgs ...sdk.Msg) abci.ResponseCheckTx {
return suite.CheckTx(suite.prepareCosmosTx(gasPrice, msgs...))
func checkTx(gasPrice *sdkmath.Int, msgs ...sdk.Msg) abci.ResponseCheckTx {
return s.CheckTx(prepareCosmosTx(gasPrice, msgs...))
}

func (suite *IntegrationTestSuite) deliverTx(gasPrice *sdkmath.Int, msgs ...sdk.Msg) abci.ResponseDeliverTx {
return suite.DeliverTx(suite.prepareCosmosTx(gasPrice, msgs...))
func deliverTx(gasPrice *sdkmath.Int, msgs ...sdk.Msg) abci.ResponseDeliverTx {
return s.DeliverTx(prepareCosmosTx(gasPrice, msgs...))
}

0 comments on commit 12318d0

Please sign in to comment.