Skip to content

Commit

Permalink
EstimateGas
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsqe committed Oct 2, 2024
1 parent bfc19fb commit d8b2fd5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 47 deletions.
4 changes: 2 additions & 2 deletions rpc/backend/call_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rp
return 0, err
}

header, err := b.TendermintBlockByNumber(blockNr)
header, err := b.TendermintHeaderByNumber(blockNr)
if err != nil {
// the error message imitates geth behavior
return 0, errors.New("header not found")
Expand All @@ -342,7 +342,7 @@ func (b *Backend) EstimateGas(args evmtypes.TransactionArgs, blockNrOptional *rp
req := evmtypes.EthCallRequest{
Args: bz,
GasCap: b.RPCGasCap(),
ProposerAddress: sdk.ConsAddress(header.Block.ProposerAddress),
ProposerAddress: sdk.ConsAddress(header.Header.ProposerAddress),
ChainId: b.chainID.Int64(),
}

Expand Down
69 changes: 35 additions & 34 deletions rpc/backend/call_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (suite *BackendTestSuite) TestResend() {
toAddr := tests.GenerateAddress()
chainID := (*hexutil.Big)(suite.backend.chainID)
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())
height := int64(1)
callArgs := evmtypes.TransactionArgs{
From: nil,
To: &toAddr,
Expand Down Expand Up @@ -65,8 +66,8 @@ func (suite *BackendTestSuite) TestResend() {
var header metadata.MD
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, 1, nil)
RegisterParams(queryClient, &header, height)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, 1)
RegisterBaseFeeDisabled(queryClient)
RegisterValidatorAccount(queryClient, validator)
Expand All @@ -87,10 +88,10 @@ func (suite *BackendTestSuite) TestResend() {
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
feeMarketClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient)
RegisterParams(queryClient, &header, 1)
RegisterFeeMarketParams(feeMarketClient, 1)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterParams(queryClient, &header, height)
RegisterFeeMarketParams(feeMarketClient, height)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
Expand All @@ -108,9 +109,9 @@ func (suite *BackendTestSuite) TestResend() {
var header metadata.MD
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterParams(queryClient, &header, height)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFeeDisabled(queryClient)
RegisterValidatorAccount(queryClient, validator)
},
Expand Down Expand Up @@ -145,8 +146,8 @@ func (suite *BackendTestSuite) TestResend() {
var header metadata.MD
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParams(queryClient, &header, 1)
RegisterBlockError(client, 1)
RegisterParams(queryClient, &header, height)
RegisterHeaderError(client, &height)
},
evmtypes.TransactionArgs{
Nonce: &txNonce,
Expand All @@ -162,9 +163,9 @@ func (suite *BackendTestSuite) TestResend() {
var header metadata.MD
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterParams(queryClient, &header, height)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
Expand All @@ -186,9 +187,9 @@ func (suite *BackendTestSuite) TestResend() {
var header metadata.MD
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterParams(queryClient, &header, height)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
Expand All @@ -208,12 +209,12 @@ func (suite *BackendTestSuite) TestResend() {
var header metadata.MD
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, baseFee)
RegisterEstimateGas(queryClient, callArgs)
RegisterParams(queryClient, &header, 1)
RegisterParamsWithoutHeader(queryClient, 1)
RegisterParams(queryClient, &header, height)
RegisterParamsWithoutHeader(queryClient, height)
RegisterUnconfirmedTxsError(client, nil)
RegisterValidatorAccount(queryClient, validator)
},
Expand All @@ -237,12 +238,12 @@ func (suite *BackendTestSuite) TestResend() {
var header metadata.MD
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, baseFee)
RegisterEstimateGas(queryClient, callArgs)
RegisterParams(queryClient, &header, 1)
RegisterParamsWithoutHeader(queryClient, 1)
RegisterParams(queryClient, &header, height)
RegisterParamsWithoutHeader(queryClient, height)
RegisterUnconfirmedTxsEmpty(client, nil)
RegisterValidatorAccount(queryClient, validator)
},
Expand Down Expand Up @@ -449,7 +450,7 @@ func (suite *BackendTestSuite) TestDoCall() {
func (suite *BackendTestSuite) TestGasPrice() {
defaultGasPrice := (*hexutil.Big)(big.NewInt(1))
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())

height := int64(1)
testCases := []struct {
name string
registerMock func()
Expand All @@ -463,10 +464,10 @@ func (suite *BackendTestSuite) TestGasPrice() {
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
feeMarketClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient)
RegisterFeeMarketParams(feeMarketClient, 1)
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterFeeMarketParams(feeMarketClient, height)
RegisterParams(queryClient, &header, height)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, sdkmath.NewInt(1))
RegisterValidatorAccount(queryClient, validator)
},
Expand All @@ -480,10 +481,10 @@ func (suite *BackendTestSuite) TestGasPrice() {
client := suite.backend.clientCtx.Client.(*mocks.Client)
queryClient := suite.backend.queryClient.QueryClient.(*mocks.EVMQueryClient)
feeMarketClient := suite.backend.queryClient.FeeMarket.(*mocks.FeeMarketQueryClient)
RegisterFeeMarketParamsError(feeMarketClient, 1)
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterFeeMarketParamsError(feeMarketClient, height)
RegisterParams(queryClient, &header, height)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, sdkmath.NewInt(1))
RegisterValidatorAccount(queryClient, validator)
},
Expand Down
22 changes: 11 additions & 11 deletions rpc/backend/sign_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (suite *BackendTestSuite) TestSendTransaction() {
}
hash := common.Hash{}
validator := sdk.AccAddress(tests.GenerateAddress().Bytes())

height := int64(1)
testCases := []struct {
name string
registerMock func()
Expand All @@ -60,8 +60,8 @@ func (suite *BackendTestSuite) TestSendTransaction() {
client := suite.backend.clientCtx.Client.(*mocks.Client)
armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1")
suite.backend.clientCtx.Keyring.ImportPrivKey("test_key", armor, "")
RegisterParams(queryClient, &header, 1)
RegisterBlockError(client, 1)
RegisterParams(queryClient, &header, height)
RegisterHeaderError(client, &height)
},
callArgsDefault,
hash,
Expand All @@ -76,8 +76,8 @@ func (suite *BackendTestSuite) TestSendTransaction() {
armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1")
suite.backend.clientCtx.Keyring.ImportPrivKey("test_key", armor, "")
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, baseFee)
RegisterValidatorAccount(queryClient, validator)
},
Expand All @@ -100,10 +100,10 @@ func (suite *BackendTestSuite) TestSendTransaction() {
armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1")
suite.backend.clientCtx.Keyring.ImportPrivKey("test_key", armor, "")
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, baseFee)
RegisterParamsWithoutHeader(queryClient, 1)
RegisterParamsWithoutHeader(queryClient, height)
ethSigner := ethtypes.LatestSigner(suite.backend.ChainConfig())
msg := callArgsDefault.ToTransaction()
msg.Sign(ethSigner, suite.backend.clientCtx.Keyring)
Expand All @@ -126,10 +126,10 @@ func (suite *BackendTestSuite) TestSendTransaction() {
armor := crypto.EncryptArmorPrivKey(priv, "", "eth_secp256k1")
suite.backend.clientCtx.Keyring.ImportPrivKey("test_key", armor, "")
RegisterParams(queryClient, &header, 1)
RegisterBlock(client, 1, nil)
RegisterBlockResults(client, 1)
RegisterHeader(client, &height, nil)
RegisterBlockResults(client, height)
RegisterBaseFee(queryClient, baseFee)
RegisterParamsWithoutHeader(queryClient, 1)
RegisterParamsWithoutHeader(queryClient, height)
ethSigner := ethtypes.LatestSigner(suite.backend.ChainConfig())
msg := callArgsDefault.ToTransaction()
msg.Sign(ethSigner, suite.backend.clientCtx.Keyring)
Expand Down

0 comments on commit d8b2fd5

Please sign in to comment.