Skip to content

Commit

Permalink
Provide fix gas limit for exit transaction (pass child chain mintable…
Browse files Browse the repository at this point in the history
… e2e test)
  • Loading branch information
Stefan-Ethernal committed Jun 17, 2023
1 parent b44363c commit 0e71291
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions command/bridge/exit/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func createExitTxn(sender ethgo.Address, proof types.Proof) (*ethgo.Transaction,
From: sender,
To: &exitHelperAddr,
Input: input,
Gas: txrelayer.DefaultGasLimit,
}

return txn, exitEvent, err
Expand Down
2 changes: 1 addition & 1 deletion e2e-polybft/e2e/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ func TestE2E_Bridge_ChildChainMintableTokensTransfer(t *testing.T) {
cluster := framework.NewTestCluster(t, 5,
framework.WithNumBlockConfirmations(0),
framework.WithEpochSize(epochSize),
framework.WithNativeTokenConfig(fmt.Sprintf("Mintable Edge Coin:MEC:18:true:%s", adminAddr)),
framework.WithNativeTokenConfig(fmt.Sprintf(nativeTokenMintableTestCfg, adminAddr)),
framework.WithBridgeAllowListAdmin(adminAddr),
framework.WithBridgeBlockListAdmin(adminAddr),
framework.WithPremine(append(depositors, adminAddr)...)) //nolint:makezero
Expand Down
15 changes: 9 additions & 6 deletions e2e-polybft/framework/test-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -871,15 +871,15 @@ func (c *TestCluster) Transfer(t *testing.T, sender ethgo.Key, target types.Addr

targetAddr := ethgo.Address(target)

return c.SendTxn(t, sender, &ethgo.Transaction{To: &targetAddr, Value: value})
return c.SendTxn(t, sender, &ethgo.Transaction{From: sender.Address(), To: &targetAddr, Value: value})
}

func (c *TestCluster) MethodTxn(t *testing.T, sender ethgo.Key, target types.Address, input []byte) *TestTxn {
t.Helper()

targetAddr := ethgo.Address(target)

return c.SendTxn(t, sender, &ethgo.Transaction{To: &targetAddr, Input: input})
return c.SendTxn(t, sender, &ethgo.Transaction{From: sender.Address(), To: &targetAddr, Input: input})
}

// SendTxn sends a transaction
Expand Down Expand Up @@ -912,7 +912,12 @@ func (c *TestCluster) SendTxn(t *testing.T, sender ethgo.Key, txn *ethgo.Transac
}

if txn.Gas == 0 {
txn.Gas = txrelayer.DefaultGasLimit
callMsg := txrelayer.ConvertTxnToCallMsg(txn)

gasLimit, err := client.Eth().EstimateGas(callMsg)
require.NoError(t, err)

txn.Gas = gasLimit
}

chainID, err := client.Eth().ChainID()
Expand All @@ -928,13 +933,11 @@ func (c *TestCluster) SendTxn(t *testing.T, sender ethgo.Key, txn *ethgo.Transac
hash, err := client.Eth().SendRawTransaction(txnRaw)
require.NoError(t, err)

tTxn := &TestTxn{
return &TestTxn{
client: client.Eth(),
txn: txn,
hash: hash,
}

return tTxn
}

type TestTxn struct {
Expand Down
15 changes: 8 additions & 7 deletions txrelayer/txrelayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,18 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo.
return ethgo.ZeroHash, err
}

fmt.Println("Tx relayer Gas Price", gasPrice, "To", txn.To)
txn.GasPrice = gasPrice
}

if txn.Gas == 0 {
gasLimit, err := t.estimateGasLimit(txn)
gasLimit, err := t.client.Eth().EstimateGas(ConvertTxnToCallMsg(txn))
if err != nil {
return ethgo.ZeroHash, err
}

fmt.Println("Tx relayer Gas Limit", gasLimit, "To", txn.To)

txn.Gas = gasLimit
}

Expand Down Expand Up @@ -155,7 +158,7 @@ func (t *TxRelayerImpl) SendTransactionLocal(txn *ethgo.Transaction) (*ethgo.Rec

txn.From = accounts[0]

gasLimit, err := t.estimateGasLimit(txn)
gasLimit, err := t.client.Eth().EstimateGas(ConvertTxnToCallMsg(txn))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -195,18 +198,16 @@ func (t *TxRelayerImpl) waitForReceipt(hash ethgo.Hash) (*ethgo.Receipt, error)
}
}

// estimateGasLimit returns estimated gas limit for the given transaction
func (t *TxRelayerImpl) estimateGasLimit(txn *ethgo.Transaction) (uint64, error) {
callMsg := &ethgo.CallMsg{
// ConvertTxnToCallMsg converts txn instance to call message
func ConvertTxnToCallMsg(txn *ethgo.Transaction) *ethgo.CallMsg {
return &ethgo.CallMsg{
From: txn.From,
To: txn.To,
Data: txn.Input,
GasPrice: txn.GasPrice,
Value: txn.Value,
Gas: big.NewInt(int64(txn.Gas)),
}

return t.client.Eth().EstimateGas(callMsg)
}

type TxRelayerOption func(*TxRelayerImpl)
Expand Down

0 comments on commit 0e71291

Please sign in to comment.