mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/abi/bind/backends, internal: cleanup error message
This commit is contained in:
parent
e390d4ff7e
commit
af58d13ca3
3 changed files with 23 additions and 25 deletions
|
|
@ -443,13 +443,12 @@ func (b *SimulatedBackend) EstimateGas(ctx context.Context, call ethereum.CallMs
|
||||||
}
|
}
|
||||||
if failed {
|
if failed {
|
||||||
if result != nil {
|
if result != nil {
|
||||||
// If the revert reason is provided, return it to user.
|
|
||||||
if result.Err == vm.ErrExecutionReverted {
|
|
||||||
return 0, fmt.Errorf("transaction reverted (0x%x)", result.RevertReason)
|
|
||||||
}
|
|
||||||
// If it's an invalid transaction, return the concrete vm error
|
|
||||||
if result.Err != vm.ErrOutOfGas {
|
if result.Err != vm.ErrOutOfGas {
|
||||||
return 0, fmt.Errorf("always failing transaction (%v)", result.Err)
|
errMsg := fmt.Sprintf("always failing transaction (%v)", result.Err)
|
||||||
|
if len(result.RevertReason) > 0 {
|
||||||
|
errMsg += fmt.Sprintf(" (0x%x)", result.RevertReason)
|
||||||
|
}
|
||||||
|
return 0, errors.New(errMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, the specified gas cap is too low
|
// Otherwise, the specified gas cap is too low
|
||||||
|
|
|
||||||
|
|
@ -358,14 +358,14 @@ func TestSimulatedBackend_TransactionByHash(t *testing.T) {
|
||||||
|
|
||||||
func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||||
/*
|
/*
|
||||||
pragma solidity ^0.6.4;
|
pragma solidity ^0.6.4;
|
||||||
contract GasEstimation {
|
contract GasEstimation {
|
||||||
function PureRevert() public { revert(); }
|
function PureRevert() public { revert(); }
|
||||||
function Revert() public { revert("revert reason");}
|
function Revert() public { revert("revert reason");}
|
||||||
function OOG() public { for (uint i = 0; ; i++) {}}
|
function OOG() public { for (uint i = 0; ; i++) {}}
|
||||||
function Assert() public { assert(false);}
|
function Assert() public { assert(false);}
|
||||||
function Valid() public {}
|
function Valid() public {}
|
||||||
}*/
|
}*/
|
||||||
const contractAbi = "[{\"inputs\":[],\"name\":\"Assert\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OOG\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PureRevert\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"Revert\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"Valid\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
|
const contractAbi = "[{\"inputs\":[],\"name\":\"Assert\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"OOG\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"PureRevert\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"Revert\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"Valid\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]"
|
||||||
const contractBin = "0x60806040523480156100115760006000fd5b50610017565b61016e806100266000396000f3fe60806040523480156100115760006000fd5b506004361061005c5760003560e01c806350f6fe3414610062578063aa8b1d301461006c578063b9b046f914610076578063d8b9839114610080578063e09fface1461008a5761005c565b60006000fd5b61006a610094565b005b6100746100ad565b005b61007e6100b5565b005b6100886100c2565b005b610092610135565b005b6000600090505b5b808060010191505061009b565b505b565b60006000fd5b565b600015156100bf57fe5b5b565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f72657665727420726561736f6e0000000000000000000000000000000000000081526020015060200191505060405180910390fd5b565b5b56fea2646970667358221220345bbcbb1a5ecf22b53a78eaebf95f8ee0eceff6d10d4b9643495084d2ec934a64736f6c63430006040033"
|
const contractBin = "0x60806040523480156100115760006000fd5b50610017565b61016e806100266000396000f3fe60806040523480156100115760006000fd5b506004361061005c5760003560e01c806350f6fe3414610062578063aa8b1d301461006c578063b9b046f914610076578063d8b9839114610080578063e09fface1461008a5761005c565b60006000fd5b61006a610094565b005b6100746100ad565b005b61007e6100b5565b005b6100886100c2565b005b610092610135565b005b6000600090505b5b808060010191505061009b565b505b565b60006000fd5b565b600015156100bf57fe5b5b565b6040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600d8152602001807f72657665727420726561736f6e0000000000000000000000000000000000000081526020015060200191505060405180910390fd5b565b5b56fea2646970667358221220345bbcbb1a5ecf22b53a78eaebf95f8ee0eceff6d10d4b9643495084d2ec934a64736f6c63430006040033"
|
||||||
|
|
||||||
|
|
@ -380,12 +380,12 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||||
contractAddr, _, _, _ := bind.DeployContract(opts, parsed, common.FromHex(contractBin), sim)
|
contractAddr, _, _, _ := bind.DeployContract(opts, parsed, common.FromHex(contractBin), sim)
|
||||||
sim.Commit()
|
sim.Commit()
|
||||||
|
|
||||||
var cases = []struct{
|
var cases = []struct {
|
||||||
name string
|
name string
|
||||||
message ethereum.CallMsg
|
message ethereum.CallMsg
|
||||||
expect uint64
|
expect uint64
|
||||||
expectError error
|
expectError error
|
||||||
} {
|
}{
|
||||||
{"plain transfer(valid)", ethereum.CallMsg{
|
{"plain transfer(valid)", ethereum.CallMsg{
|
||||||
From: addr,
|
From: addr,
|
||||||
To: &addr,
|
To: &addr,
|
||||||
|
|
@ -402,7 +402,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||||
GasPrice: big.NewInt(0),
|
GasPrice: big.NewInt(0),
|
||||||
Value: big.NewInt(1),
|
Value: big.NewInt(1),
|
||||||
Data: nil,
|
Data: nil,
|
||||||
}, 0, errors.New("transaction reverted (0x)")},
|
}, 0, errors.New("always failing transaction (execution reverted)")},
|
||||||
|
|
||||||
{"Revert", ethereum.CallMsg{
|
{"Revert", ethereum.CallMsg{
|
||||||
From: addr,
|
From: addr,
|
||||||
|
|
@ -411,7 +411,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||||
GasPrice: big.NewInt(0),
|
GasPrice: big.NewInt(0),
|
||||||
Value: nil,
|
Value: nil,
|
||||||
Data: common.Hex2Bytes("d8b98391"),
|
Data: common.Hex2Bytes("d8b98391"),
|
||||||
}, 0, errors.New("transaction reverted (0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d72657665727420726561736f6e00000000000000000000000000000000000000)")},
|
}, 0, errors.New("always failing transaction (execution reverted) (0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d72657665727420726561736f6e00000000000000000000000000000000000000)")},
|
||||||
|
|
||||||
{"PureRevert", ethereum.CallMsg{
|
{"PureRevert", ethereum.CallMsg{
|
||||||
From: addr,
|
From: addr,
|
||||||
|
|
@ -420,7 +420,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
||||||
GasPrice: big.NewInt(0),
|
GasPrice: big.NewInt(0),
|
||||||
Value: nil,
|
Value: nil,
|
||||||
Data: common.Hex2Bytes("aa8b1d30"),
|
Data: common.Hex2Bytes("aa8b1d30"),
|
||||||
}, 0, errors.New("transaction reverted (0x)")},
|
}, 0, errors.New("always failing transaction (execution reverted)")},
|
||||||
|
|
||||||
{"OOG", ethereum.CallMsg{
|
{"OOG", ethereum.CallMsg{
|
||||||
From: addr,
|
From: addr,
|
||||||
|
|
|
||||||
|
|
@ -947,13 +947,12 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
|
||||||
}
|
}
|
||||||
if failed {
|
if failed {
|
||||||
if result != nil {
|
if result != nil {
|
||||||
// If the revert reason is provided, return it to user.
|
|
||||||
if result.Err == vm.ErrExecutionReverted {
|
|
||||||
return 0, fmt.Errorf("transaction reverted (0x%x)", result.RevertReason)
|
|
||||||
}
|
|
||||||
// If it's an invalid transaction, return the concrete vm error
|
|
||||||
if result.Err != vm.ErrOutOfGas {
|
if result.Err != vm.ErrOutOfGas {
|
||||||
return 0, fmt.Errorf("always failing transaction (%v)", result.Err)
|
errMsg := fmt.Sprintf("always failing transaction (%v)", result.Err)
|
||||||
|
if len(result.RevertReason) > 0 {
|
||||||
|
errMsg += fmt.Sprintf(" (0x%x)", result.RevertReason)
|
||||||
|
}
|
||||||
|
return 0, errors.New(errMsg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Otherwise, the specified gas cap is too low
|
// Otherwise, the specified gas cap is too low
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue