From 23312e071673a6248fcc78721778ad0a08f5c951 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Fri, 15 May 2020 09:31:32 +0200 Subject: [PATCH] accounts/abi/bind/backends: added revert reason logic to simulated backend --- accounts/abi/bind/backends/simulated.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/accounts/abi/bind/backends/simulated.go b/accounts/abi/bind/backends/simulated.go index 3571595662..90c74ce7a6 100644 --- a/accounts/abi/bind/backends/simulated.go +++ b/accounts/abi/bind/backends/simulated.go @@ -360,6 +360,14 @@ func (b *SimulatedBackend) CallContract(ctx context.Context, call ethereum.CallM if err != nil { return nil, err } + // If the result contains a revert reason, unpack and return it. + if res.Err != nil { + reason, err := abi.UnpackRevert(res.Revert()) + if err != nil { + return nil, err + } + return nil, fmt.Errorf("execution reverted: %v", reason) + } return res.Return(), nil } @@ -373,6 +381,14 @@ func (b *SimulatedBackend) PendingCallContract(ctx context.Context, call ethereu if err != nil { return nil, err } + // If the result contains a revert reason, unpack and return it. + if res.Err != nil { + reason, err := abi.UnpackRevert(res.Revert()) + if err != nil { + return nil, err + } + return nil, fmt.Errorf("execution reverted: %v", reason) + } return res.Return(), nil }