accounts/abi/bind/backends: added revert reason logic to simulated backend

This commit is contained in:
Marius van der Wijden 2020-05-15 09:31:32 +02:00 committed by Péter Szilágyi
parent 6d13d42e71
commit 23312e0716
No known key found for this signature in database
GPG Key ID: E9AE538CEDF8293D
1 changed files with 16 additions and 0 deletions

View File

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