Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion evmd/tests/ibc/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,24 @@ func SetupNativeErc20(t *testing.T, chain *evmibctesting.TestChain, senderAcc ev
}

// Verify minted balance
bal := evmApp.GetErc20Keeper().BalanceOf(evmCtx, contractAbi, contractAddr, common.BytesToAddress(senderAddr))
ethRes, err := evmApp.GetEVMKeeper().CallEVM(
evmCtx,
contractAbi,
common.BytesToAddress(senderAddr),
contractAddr,
false,
nil,
"balanceOf",
common.BytesToAddress(senderAddr),
)
if err != nil {
t.Fatalf("balanceOf call failed: %v", err)
}
var bal *big.Int
err = contractAbi.UnpackIntoInterface(&bal, "balanceOf", ethRes.Ret)
if err != nil {
t.Fatalf("balanceOf call failed: %v", err)
}
if bal.Cmp(big.NewInt(sendAmt.Int64())) != 0 {
t.Fatalf("unexpected ERC20 balance; got %s, want %s", bal.String(), sendAmt.String())
}
Expand Down
14 changes: 13 additions & 1 deletion evmd/tests/ibc/ics20_recursive_precompile_calls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,19 @@ func (suite *ICS20RecursivePrecompileCallsTestSuite) setupContractForTesting(
suite.chainA.NextBlock()

// Verify minted balance
bal := evmAppA.GetErc20Keeper().BalanceOf(ctxA, contractData.ABI, contractAddr, common.BytesToAddress(senderAddr))
ethRes, err := evmAppA.GetEVMKeeper().CallEVM(
ctxA,
contractData.ABI,
common.BytesToAddress(senderAddr),
contractAddr,
false,
nil,
"balanceOf",
common.BytesToAddress(senderAddr),
)
var bal *big.Int
err = contractData.ABI.UnpackIntoInterface(&bal, "balanceOf", ethRes.Ret)
suite.Require().NoError(err)
suite.Require().Equal(big.NewInt(InitialTokenAmount), bal, "unexpected ERC20 balance")
}

Expand Down
2 changes: 0 additions & 2 deletions interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ type (
}
GovPrecompileApp interface {
TestApp
FeeMarketKeeperProvider // Should be removed after refactoring test code
GovKeeperProvider
}
ICS20PrecompileApp interface {
Expand All @@ -217,7 +216,6 @@ type (
TestApp
AccountKeeperProvider
BankKeeperProvider
Erc20KeeperProvider // Should be removed after refactoring test code
StakingKeeperProvider
}
WERC20PrecompileApp interface {
Expand Down
35 changes: 14 additions & 21 deletions tests/integration/precompiles/gov/test_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
It("cancels a proposal and see cancellation fee charged", func() {
// Fix the gas limit and gas price for predictable gas usage.
// This is for calculating expected cancellation fee.
baseFee := s.network.App.GetFeeMarketKeeper().GetBaseFee(s.network.GetContext())
baseFeeInt := baseFee.TruncateInt64()
txArgs.GasPrice = new(big.Int).SetInt64(baseFeeInt)
baseFee := s.network.App.GetEVMKeeper().GetBaseFee(s.network.GetContext())
txArgs.GasPrice = baseFee
txArgs.GasLimit = 500_000

// Get the prposal for cancellation
Expand Down Expand Up @@ -1248,9 +1247,8 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
func(tc testCase) {
// Fix the gas limit and gas price for predictable gas usage.
// This is for calculating expected cancellation fee.
baseFee := s.network.App.GetFeeMarketKeeper().GetBaseFee(s.network.GetContext())
baseFeeInt := baseFee.TruncateInt64()
txArgs.GasPrice = new(big.Int).SetInt64(baseFeeInt)
baseFee := s.network.App.GetEVMKeeper().GetBaseFee(s.network.GetContext())
txArgs.GasPrice = baseFee
txArgs.GasLimit = 500_000

// Prepare the proposal
Expand Down Expand Up @@ -1406,9 +1404,8 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
func(tc testCase) {
// Fix the gas limit and gas price for predictable gas usage.
// This is for calculating expected cancellation fee.
baseFee := s.network.App.GetFeeMarketKeeper().GetBaseFee(s.network.GetContext())
baseFeeInt := baseFee.TruncateInt64()
txArgs.GasPrice = new(big.Int).SetInt64(baseFeeInt)
baseFee := s.network.App.GetEVMKeeper().GetBaseFee(s.network.GetContext())
txArgs.GasPrice = baseFee
txArgs.GasLimit = 500_000

// Prepare the proposal
Expand Down Expand Up @@ -1502,9 +1499,8 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
func(tc testCase) {
// Fix the gas limit and gas price for predictable gas usage.
// This is for calculating expected cancellation fee.
baseFee := s.network.App.GetFeeMarketKeeper().GetBaseFee(s.network.GetContext())
baseFeeInt := baseFee.TruncateInt64()
txArgs.GasPrice = new(big.Int).SetInt64(baseFeeInt)
baseFee := s.network.App.GetEVMKeeper().GetBaseFee(s.network.GetContext())
txArgs.GasPrice = baseFee
txArgs.GasLimit = 500_000
txArgs.Amount = big.NewInt(300)

Expand Down Expand Up @@ -1692,9 +1688,8 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
func(tc testCase) {
// Fix the gas limit and gas ice for predictable gas usage.
// This is for calculating expected cancellation fee.
baseFee := s.network.App.GetFeeMarketKeeper().GetBaseFee(s.network.GetContext())
baseFeeInt := baseFee.TruncateInt64()
txArgs.GasPrice = new(big.Int).SetInt64(baseFeeInt)
baseFee := s.network.App.GetEVMKeeper().GetBaseFee(s.network.GetContext())
txArgs.GasPrice = baseFee
txArgs.GasLimit = 500_000
txArgs.Amount = big.NewInt(100)

Expand Down Expand Up @@ -1925,9 +1920,8 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
func(tc testCase) {
// Fix the gas limit and gas ice for predictable gas usage.
// This is for calculating expected cancellation fee.
baseFee := s.network.App.GetFeeMarketKeeper().GetBaseFee(s.network.GetContext())
baseFeeInt := baseFee.TruncateInt64()
txArgs.GasPrice = new(big.Int).SetInt64(baseFeeInt)
baseFee := s.network.App.GetEVMKeeper().GetBaseFee(s.network.GetContext())
txArgs.GasPrice = baseFee
txArgs.GasLimit = 500_000
txArgs.Amount = big.NewInt(100)

Expand Down Expand Up @@ -2076,9 +2070,8 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
func(tc testCase) {
// Fix the gas limit and gas price for predictable gas usage.
// This is for calculating expected cancellation fee.
baseFee := s.network.App.GetFeeMarketKeeper().GetBaseFee(s.network.GetContext())
baseFeeInt := baseFee.TruncateInt64()
txArgs.GasPrice = new(big.Int).SetInt64(baseFeeInt)
baseFee := s.network.App.GetEVMKeeper().GetBaseFee(s.network.GetContext())
txArgs.GasPrice = baseFee
txArgs.GasLimit = 500_000
txArgs.Amount = big.NewInt(100)
randomAddr := testutiltx.GenerateAddress()
Expand Down
70 changes: 63 additions & 7 deletions tests/integration/precompiles/staking/test_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3374,7 +3374,21 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
Expect(s.network.NextBlock()).To(BeNil())

// Check that the StakingCaller contract has the correct balance
erc20Balance := s.network.App.GetErc20Keeper().BalanceOf(s.network.GetContext(), erc20Contract.ABI, erc20ContractAddr, contractAddr)
ethRes, err := s.factory.QueryContract(
evmtypes.EvmTxArgs{
To: &erc20ContractAddr,
},
testutiltypes.CallArgs{
ContractABI: erc20Contract.ABI,
MethodName: "balanceOf",
Args: []interface{}{contractAddr},
},
0,
)
Expect(err).To(BeNil(), "error while querying the ERC20 balance of the StakingCaller contract")
var erc20Balance *big.Int
err = erc20Contract.ABI.UnpackIntoInterface(&erc20Balance, "balanceOf", ethRes.Ret)
Expect(err).To(BeNil(), "error while unpacking the ERC20 balance result")
Expect(erc20Balance).To(Equal(mintAmount), "expected different ERC20 balance for the StakingCaller contract")

// populate default call args
Expand Down Expand Up @@ -3457,9 +3471,23 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
Expect(res.DelegationResponse).NotTo(BeNil())
delegationPost := res.DelegationResponse.Delegation
sharesPost := delegationPost.GetShares()
erc20BalancePost := s.network.App.GetErc20Keeper().BalanceOf(s.network.GetContext(), erc20Contract.ABI, erc20ContractAddr, delegator.Addr)

Expect(sharesPost).To(Equal(sharesPre), "expected shares to be equal when reverting state")

var erc20BalancePost *big.Int
ethRes, err := s.factory.QueryContract(
evmtypes.EvmTxArgs{
To: &erc20ContractAddr,
},
testutiltypes.CallArgs{
ContractABI: erc20Contract.ABI,
MethodName: "balanceOf",
Args: []interface{}{delegator.Addr},
},
0,
)
Expect(err).To(BeNil(), "error while querying the ERC20 balance of delegator")
err = erc20Contract.ABI.UnpackIntoInterface(&erc20BalancePost, "balanceOf", ethRes.Ret)
Expect(err).To(BeNil(), "error while unpacking the ERC20 balance result")
Expect(erc20BalancePost.Int64()).To(BeZero(), "expected erc20 balance of target address to be zero when reverting state")
})

Expand Down Expand Up @@ -3490,9 +3518,23 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
Expect(res.DelegationResponse).NotTo(BeNil())
delegationPost := res.DelegationResponse.Delegation
sharesPost := delegationPost.GetShares()
erc20BalancePost := s.network.App.GetErc20Keeper().BalanceOf(s.network.GetContext(), erc20Contract.ABI, erc20ContractAddr, delegator.Addr)

Expect(sharesPost).To(Equal(sharesPre), "expected shares to be equal when reverting state")

ethRes, err := s.factory.QueryContract(
evmtypes.EvmTxArgs{
To: &erc20ContractAddr,
},
testutiltypes.CallArgs{
ContractABI: erc20Contract.ABI,
MethodName: "balanceOf",
Args: []interface{}{delegator.Addr},
},
0,
)
Expect(err).To(BeNil(), "error while querying the ERC20 balance of delegator")
var erc20BalancePost *big.Int
err = erc20Contract.ABI.UnpackIntoInterface(&erc20BalancePost, "balanceOf", ethRes.Ret)
Expect(err).To(BeNil(), "error while unpacking the ERC20 balance result")
Expect(erc20BalancePost.Int64()).To(BeZero(), "expected erc20 balance of target address to be zero when reverting state")
})

Expand Down Expand Up @@ -3538,9 +3580,23 @@ func TestPrecompileIntegrationTestSuite(t *testing.T, create network.CreateEvmAp
)
delegationPost := res.DelegationResponse.Delegation
sharesPost := delegationPost.GetShares()
erc20BalancePost := s.network.App.GetErc20Keeper().BalanceOf(s.network.GetContext(), erc20Contract.ABI, erc20ContractAddr, delegator.Addr)

Expect(sharesPost.GT(sharesPre)).To(BeTrue(), "expected shares to be more than before")

ethRes, err := s.factory.QueryContract(
evmtypes.EvmTxArgs{
To: &erc20ContractAddr,
},
testutiltypes.CallArgs{
ContractABI: erc20Contract.ABI,
MethodName: "balanceOf",
Args: []interface{}{delegator.Addr},
},
0,
)
Expect(err).To(BeNil(), "error while querying the ERC20 balance of delegator")
var erc20BalancePost *big.Int
err = erc20Contract.ABI.UnpackIntoInterface(&erc20BalancePost, "balanceOf", ethRes.Ret)
Expect(err).To(BeNil(), "error while unpacking the ERC20 balance result")
Expect(erc20BalancePost).To(Equal(transferredAmount), "expected different erc20 balance of target address")
})
})
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/x/vm/test_fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,11 @@ func (s *KeeperTestSuite) TestVerifyFeeAndDeductTxCostsFromUserBalance() {
if tc.expectPassVerify {
s.Require().NoError(err, "valid test %d failed - '%s'", i, tc.name)
if tc.EnableFeemarket {
baseFee := s.Network.App.GetFeeMarketKeeper().GetBaseFee(s.Network.GetContext())
baseFee := s.Network.App.GetEVMKeeper().GetBaseFee(s.Network.GetContext())
s.Require().Equal(
fees,
sdk.NewCoins(
sdk.NewCoin(baseDenom, sdkmath.NewIntFromBigInt(tx.GetEffectiveFee(baseFee.TruncateInt().BigInt()))),
sdk.NewCoin(baseDenom, sdkmath.NewIntFromBigInt(tx.GetEffectiveFee(baseFee))),
),
"valid test %d failed, fee value is wrong - '%s'", i, tc.name,
)
Expand Down
Loading