Skip to content

Commit

Permalink
Add new e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
goran-ethernal committed Oct 19, 2023
1 parent 1063ef9 commit c59a937
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
35 changes: 35 additions & 0 deletions e2e-polybft/e2e/jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/e2e-polybft/framework"
"github.com/0xPolygon/polygon-edge/helper/hex"
"github.com/0xPolygon/polygon-edge/state"
"github.com/0xPolygon/polygon-edge/types"
)

Expand Down Expand Up @@ -126,6 +127,40 @@ func TestE2E_JsonRPC(t *testing.T) {
require.Equal(t, uint64(0x56a3), resp)
})

t.Run("eth_estimateGas by zero-balance account - simple value transfer", func(t *testing.T) {
acctZeroBalance, err := wallet.GenerateKey()
require.NoError(t, err)

fundedAccountAddress := acct.Address()
nonFundedAccountAddress := acctZeroBalance.Address()

estimateGasFn := func(value *big.Int) {
resp, err := client.EstimateGas(&ethgo.CallMsg{
From: nonFundedAccountAddress,
To: &fundedAccountAddress,
Value: value,
})

require.NoError(t, err)
require.Equal(t, state.TxGas, resp)
}

estimateGasFn(ethgo.Gwei(1))

// transfer some funds to zero balance account
valueTransferTxn := cluster.SendTxn(t, acct, &ethgo.Transaction{
From: fundedAccountAddress,
To: &nonFundedAccountAddress,
Value: ethgo.Gwei(10),
})

require.NoError(t, valueTransferTxn.Wait())
require.True(t, valueTransferTxn.Succeed())

// now call estimate gas again for the now funded account
estimateGasFn(ethgo.Gwei(1))
})

t.Run("eth_getBalance", func(t *testing.T) {
key1, err := wallet.GenerateKey()
require.NoError(t, err)
Expand Down
11 changes: 9 additions & 2 deletions jsonrpc/eth_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ func (e *Eth) EstimateGas(arg *txnArgs, rawNum *BlockNumber) (interface{}, error

forksInTime := e.store.GetForksInTime(header.Number)

if transaction.IsValueTransfer() || transaction.IsContractCreation() {
if transaction.IsValueTransfer() {
// if it is a simple value transfer or a contract creation,
// we already know what is the transaction gas cost, no need to apply transaction
gasCost, err := state.TransactionGasCost(transaction, forksInTime.Homestead, forksInTime.Istanbul)
Expand All @@ -569,8 +569,15 @@ func (e *Eth) EstimateGas(arg *txnArgs, rawNum *BlockNumber) (interface{}, error
return nil, err
}

var standardGas uint64
if transaction.IsContractCreation() && forksInTime.Homestead {
standardGas = state.TxGasContractCreation
} else {
standardGas = state.TxGas
}

var (
lowEnd = state.TxGas
lowEnd = standardGas
highEnd uint64
)

Expand Down

0 comments on commit c59a937

Please sign in to comment.