accounts/abi/bind/backends, internal: cleanup error message

This commit is contained in:
rjl493456442 2020-03-28 14:55:02 +08:00
parent e390d4ff7e
commit af58d13ca3
3 changed files with 23 additions and 25 deletions

View file

@ -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

View file

@ -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,

View file

@ -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