Open
Description
I'm testing a contract with a custom Error.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.4;
/// Insufficient balance for transfer. Needed `required` but only
/// `available` available.
/// @param available balance available.
/// @param required requested amount to transfer.
error InsufficientBalance(uint256 available, uint256 required);
contract TestToken {
mapping(address => uint) balance;
function transfer(address to, uint256 amount) public {
if (amount > balance[msg.sender])
revert InsufficientBalance({
available: balance[msg.sender],
required: amount
});
balance[msg.sender] -= amount;
balance[to] += amount;
}
// ...
}
When I test the transfer(address,uint256)
method of a contract deployed on a private chain through the eth_call
interface, if a revert exception occurs, I can't get the returned data data and thus can't resolve the custom error. The interface returns the following:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32000,
"message": "REVERT opcode executed",
"data": "{}"
}
}
But when testing through the triggerconstantcontract
interface, there is a return result, as follows
{
"result": {
"result": true,
"message": "REVERT opcode executed"
},
"energy_used": 1267,
"constant_result": [
"cf47918100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"
],
"transaction": {
"ret": [
{
"ret": "FAILED"
}
],
"visible": true,
...
Metadata
Metadata
Assignees
Type
Projects
Status
In Progress