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 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 {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -380,12 +380,12 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
|||
contractAddr, _, _, _ := bind.DeployContract(opts, parsed, common.FromHex(contractBin), sim)
|
||||
sim.Commit()
|
||||
|
||||
var cases = []struct{
|
||||
var cases = []struct {
|
||||
name string
|
||||
message ethereum.CallMsg
|
||||
expect uint64
|
||||
expectError error
|
||||
} {
|
||||
}{
|
||||
{"plain transfer(valid)", ethereum.CallMsg{
|
||||
From: addr,
|
||||
To: &addr,
|
||||
|
|
@ -402,7 +402,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
|||
GasPrice: big.NewInt(0),
|
||||
Value: big.NewInt(1),
|
||||
Data: nil,
|
||||
}, 0, errors.New("transaction reverted (0x)")},
|
||||
}, 0, errors.New("always failing transaction (execution reverted)")},
|
||||
|
||||
{"Revert", ethereum.CallMsg{
|
||||
From: addr,
|
||||
|
|
@ -411,7 +411,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
|||
GasPrice: big.NewInt(0),
|
||||
Value: nil,
|
||||
Data: common.Hex2Bytes("d8b98391"),
|
||||
}, 0, errors.New("transaction reverted (0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d72657665727420726561736f6e00000000000000000000000000000000000000)")},
|
||||
}, 0, errors.New("always failing transaction (execution reverted) (0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d72657665727420726561736f6e00000000000000000000000000000000000000)")},
|
||||
|
||||
{"PureRevert", ethereum.CallMsg{
|
||||
From: addr,
|
||||
|
|
@ -420,7 +420,7 @@ func TestSimulatedBackend_EstimateGas(t *testing.T) {
|
|||
GasPrice: big.NewInt(0),
|
||||
Value: nil,
|
||||
Data: common.Hex2Bytes("aa8b1d30"),
|
||||
}, 0, errors.New("transaction reverted (0x)")},
|
||||
}, 0, errors.New("always failing transaction (execution reverted)")},
|
||||
|
||||
{"OOG", ethereum.CallMsg{
|
||||
From: addr,
|
||||
|
|
|
|||
|
|
@ -947,13 +947,12 @@ func DoEstimateGas(ctx context.Context, b Backend, args CallArgs, blockNrOrHash
|
|||
}
|
||||
if failed {
|
||||
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 {
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue