diff --git a/command/bridge/exit/exit.go b/command/bridge/exit/exit.go index 14c8762187..dc74eef0d9 100644 --- a/command/bridge/exit/exit.go +++ b/command/bridge/exit/exit.go @@ -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 diff --git a/e2e-polybft/e2e/bridge_test.go b/e2e-polybft/e2e/bridge_test.go index 6ac8ec5011..e6c33cf376 100644 --- a/e2e-polybft/e2e/bridge_test.go +++ b/e2e-polybft/e2e/bridge_test.go @@ -674,7 +674,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 @@ -1295,7 +1295,7 @@ func TestE2E_Bridge_Transfers_AccessLists(t *testing.T) { contracts.ChildERC20PredicateContract, contracts.NativeERC20TokenContract, false) - require.ErrorContains(t, err, "failed to execute withdrawal") + require.ErrorContains(t, err, "failed to send withdraw transaction") currentBlock, err := childEthEndpoint.GetBlockByNumber(ethgo.Latest, false) require.NoError(t, err) diff --git a/e2e-polybft/e2e/consensus_test.go b/e2e-polybft/e2e/consensus_test.go index 92a11f1a1b..98863cbc23 100644 --- a/e2e-polybft/e2e/consensus_test.go +++ b/e2e-polybft/e2e/consensus_test.go @@ -565,8 +565,8 @@ func TestE2E_Consensus_MintableERC20NativeToken(t *testing.T) { To: &nativeTokenAddr, Input: mintInput, }, nonMinterAcc.Ecdsa) - require.NoError(t, err) - require.Equal(t, uint64(types.ReceiptFailed), receipt.Status) + require.Error(t, err) + require.Nil(t, receipt) } func TestE2E_Consensus_CustomRewardToken(t *testing.T) { diff --git a/e2e-polybft/framework/test-cluster.go b/e2e-polybft/framework/test-cluster.go index 5e237d0129..eb57b9c321 100644 --- a/e2e-polybft/framework/test-cluster.go +++ b/e2e-polybft/framework/test-cluster.go @@ -857,7 +857,7 @@ func (c *TestCluster) Call(t *testing.T, to types.Address, method *abi.Method, func (c *TestCluster) Deploy(t *testing.T, sender ethgo.Key, bytecode []byte) *TestTxn { t.Helper() - return c.SendTxn(t, sender, ðgo.Transaction{Input: bytecode}) + return c.SendTxn(t, sender, ðgo.Transaction{From: sender.Address(), Input: bytecode}) } func (c *TestCluster) Transfer(t *testing.T, sender ethgo.Key, target types.Address, value *big.Int) *TestTxn { @@ -865,7 +865,7 @@ func (c *TestCluster) Transfer(t *testing.T, sender ethgo.Key, target types.Addr targetAddr := ethgo.Address(target) - return c.SendTxn(t, sender, ðgo.Transaction{To: &targetAddr, Value: value}) + return c.SendTxn(t, sender, ðgo.Transaction{From: sender.Address(), To: &targetAddr, Value: value}) } func (c *TestCluster) MethodTxn(t *testing.T, sender ethgo.Key, target types.Address, input []byte) *TestTxn { @@ -873,7 +873,7 @@ func (c *TestCluster) MethodTxn(t *testing.T, sender ethgo.Key, target types.Add targetAddr := ethgo.Address(target) - return c.SendTxn(t, sender, ðgo.Transaction{To: &targetAddr, Input: input}) + return c.SendTxn(t, sender, ðgo.Transaction{From: sender.Address(), To: &targetAddr, Input: input}) } // SendTxn sends a transaction @@ -906,7 +906,16 @@ 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) + if err != nil { + // gas estimation can fail in case an account is not allow-listed + // (fallback it to default gas limit in that case) + txn.Gas = txrelayer.DefaultGasLimit + } else { + txn.Gas = gasLimit + } } chainID, err := client.Eth().ChainID() @@ -922,13 +931,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 { diff --git a/txrelayer/txrelayer.go b/txrelayer/txrelayer.go index bf53a3c54d..aa4fe1983f 100644 --- a/txrelayer/txrelayer.go +++ b/txrelayer/txrelayer.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io" + "math/big" "sync" "time" @@ -98,6 +99,8 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo. t.lock.Lock() defer t.lock.Unlock() + txn.From = key.Address() + nonce, err := t.client.Eth().GetNonce(key.Address(), ethgo.Pending) if err != nil { return ethgo.ZeroHash, err @@ -117,7 +120,12 @@ func (t *TxRelayerImpl) sendTransactionLocked(txn *ethgo.Transaction, key ethgo. } if txn.Gas == 0 { - txn.Gas = DefaultGasLimit + gasLimit, err := t.client.Eth().EstimateGas(ConvertTxnToCallMsg(txn)) + if err != nil { + return ethgo.ZeroHash, err + } + + txn.Gas = gasLimit } chainID, err := t.client.Eth().ChainID() @@ -157,7 +165,13 @@ func (t *TxRelayerImpl) SendTransactionLocal(txn *ethgo.Transaction) (*ethgo.Rec } txn.From = accounts[0] - txn.Gas = DefaultGasLimit + + gasLimit, err := t.client.Eth().EstimateGas(ConvertTxnToCallMsg(txn)) + if err != nil { + return nil, err + } + + txn.Gas = gasLimit txn.GasPrice = defaultGasPrice txnHash, err := t.client.Eth().SendTransaction(txn) @@ -192,6 +206,18 @@ func (t *TxRelayerImpl) waitForReceipt(hash ethgo.Hash) (*ethgo.Receipt, error) } } +// ConvertTxnToCallMsg converts txn instance to call message +func ConvertTxnToCallMsg(txn *ethgo.Transaction) *ethgo.CallMsg { + return ðgo.CallMsg{ + From: txn.From, + To: txn.To, + Data: txn.Input, + GasPrice: txn.GasPrice, + Value: txn.Value, + Gas: new(big.Int).SetUint64(txn.Gas), + } +} + type TxRelayerOption func(*TxRelayerImpl) func WithClient(client *jsonrpc.Client) TxRelayerOption {