Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Error contract to test the behavior of RPC when a smart contract reverts #1

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions artifacts/contracts/BlockHash.sol/BlockHash.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"type": "function"
}
],
"bytecode": "0x6080604052348015600f57600080fd5b50609c8061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063ee82ac5e14602d575b600080fd5b603c6038366004604e565b4090565b60405190815260200160405180910390f35b600060208284031215605f57600080fd5b503591905056fea26469706673582212208904e83430f50e304447f185e01de520d4d1c6270dd6eaeb453731ecfd7d487364736f6c63430008130033",
"deployedBytecode": "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063ee82ac5e14602d575b600080fd5b603c6038366004604e565b4090565b60405190815260200160405180910390f35b600060208284031215605f57600080fd5b503591905056fea26469706673582212208904e83430f50e304447f185e01de520d4d1c6270dd6eaeb453731ecfd7d487364736f6c63430008130033",
"bytecode": "0x6080604052348015600f57600080fd5b50609c8061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063ee82ac5e14602d575b600080fd5b603c6038366004604e565b4090565b60405190815260200160405180910390f35b600060208284031215605f57600080fd5b503591905056fea26469706673582212206fca5f6755dc8ccd19faaaef23ba290721d2ff0351f33a1bfbf39d33a21ccd1e64736f6c63430008130033",
"deployedBytecode": "0x6080604052348015600f57600080fd5b506004361060285760003560e01c8063ee82ac5e14602d575b600080fd5b603c6038366004604e565b4090565b60405190815260200160405180910390f35b600060208284031215605f57600080fd5b503591905056fea26469706673582212206fca5f6755dc8ccd19faaaef23ba290721d2ff0351f33a1bfbf39d33a21ccd1e64736f6c63430008130033",
"linkReferences": {},
"deployedLinkReferences": {}
}
99 changes: 99 additions & 0 deletions artifacts/contracts/Error.sol/Error.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "Error",
"sourceName": "contracts/Error.sol",
"abi": [
{
"inputs": [
{
"internalType": "uint256",
"name": "balance",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "withdrawAmount",
"type": "uint256"
}
],
"name": "InsufficientBalance",
"type": "error"
},
{
"inputs": [],
"name": "num",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "testAssert",
"outputs": [],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_withdrawAmount",
"type": "uint256"
}
],
"name": "testCustomError",
"outputs": [],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_i",
"type": "uint256"
}
],
"name": "testRequire",
"outputs": [],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "_i",
"type": "uint256"
}
],
"name": "testRevert",
"outputs": [],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "x",
"type": "uint256"
}
],
"name": "yul_revert",
"outputs": [],
"stateMutability": "pure",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b506101d2806100206000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806320987767146100675780632b813bc01461007c5780634e70b1dc14610084578063699f66031461009f57806375f7286c146100b2578063b8bd717f14610067575b600080fd5b61007a61007536600461016d565b6100c5565b005b61007a61011d565b61008d60005481565b60405190815260200160405180910390f35b61007a6100ad36600461016d565b61012f565b61007a6100c036600461016d565b61013d565b600a811161011a5760405162461bcd60e51b815260206004820152601d60248201527f496e707574206d7573742062652067726561746572207468616e20313000000060448201526064015b60405180910390fd5b50565b6000541561012d5761012d610186565b565b600a81111561011a57600080fd5b47818110156101695760405163cf47918160e01b81526004810182905260248101839052604401610111565b5050565b60006020828403121561017f57600080fd5b5035919050565b634e487b7160e01b600052600160045260246000fdfea264697066735822122007ea70e1e76a93259eac93eb38b01dec4a502dff44b357107596a6650fb5550164736f6c63430008130033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100625760003560e01c806320987767146100675780632b813bc01461007c5780634e70b1dc14610084578063699f66031461009f57806375f7286c146100b2578063b8bd717f14610067575b600080fd5b61007a61007536600461016d565b6100c5565b005b61007a61011d565b61008d60005481565b60405190815260200160405180910390f35b61007a6100ad36600461016d565b61012f565b61007a6100c036600461016d565b61013d565b600a811161011a5760405162461bcd60e51b815260206004820152601d60248201527f496e707574206d7573742062652067726561746572207468616e20313000000060448201526064015b60405180910390fd5b50565b6000541561012d5761012d610186565b565b600a81111561011a57600080fd5b47818110156101695760405163cf47918160e01b81526004810182905260248101839052604401610111565b5050565b60006020828403121561017f57600080fd5b5035919050565b634e487b7160e01b600052600160045260246000fdfea264697066735822122007ea70e1e76a93259eac93eb38b01dec4a502dff44b357107596a6650fb5550164736f6c63430008130033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b506103c8806100206000396000f3fe60806040526004361061003f5760003560e01c8063c040622614610044578063d4f639ea1461004e578063e22a5d5b14610056578063fb7897361461006b575b600080fd5b61004c610073565b005b61004c610174565b34801561006257600080fd5b5061004c610226565b61004c6102e1565b604051600160621b906060906000906330b4ef7d60e01b9061009b908590859060240161032d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051909150600090600661011160931b01906100ea908490610376565b6000604051808303816000865af19150503d8060008114610127576040519150601f19603f3d011682016040523d82523d6000602084013e61012c565b606091505b505090508061016e5760405162461bcd60e51b815260206004820152600960248201526810d85b1b0811985a5b60ba1b60448201526064015b60405180910390fd5b50505050565b604051600160621b9060609060009063bea05ee360e01b9061019c908590859060240161032d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051909150600090600661011160931b01906101eb908490610376565b600060405180830381855afa9150503d8060008114610127576040519150601f19603f3d011682016040523d82523d6000602084013e61012c565b60408051600481526024810182526020810180516001600160e01b0316637dbc4b9b60e11b17905290516000903090610260908490610376565b600060405180830381855afa9150503d806000811461029b576040519150601f19603f3d011682016040523d82523d6000602084013e6102a0565b606091505b50509050806102dd5760405162461bcd60e51b815260206004820152600960248201526810d85b1b0811985a5b60ba1b6044820152606401610165565b5050565b604051600160621b9060609060009063bea05ee360e01b9061009b908590859060240161032d565b60005b8381101561032457818101518382015260200161030c565b50506000910152565b6bffffffffffffffffffffffff19831681526040602082015260008251806040840152610361816060850160208701610309565b601f01601f1916919091016060019392505050565b60008251610388818460208701610309565b919091019291505056fea2646970667358221220124acba961c0cdb80521483a1ff3486f413a4c7e71e4c72f2960196d63992fa064736f6c63430008130033",
"deployedBytecode": "0x60806040526004361061003f5760003560e01c8063c040622614610044578063d4f639ea1461004e578063e22a5d5b14610056578063fb7897361461006b575b600080fd5b61004c610073565b005b61004c610174565b34801561006257600080fd5b5061004c610226565b61004c6102e1565b604051600160621b906060906000906330b4ef7d60e01b9061009b908590859060240161032d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051909150600090600661011160931b01906100ea908490610376565b6000604051808303816000865af19150503d8060008114610127576040519150601f19603f3d011682016040523d82523d6000602084013e61012c565b606091505b505090508061016e5760405162461bcd60e51b815260206004820152600960248201526810d85b1b0811985a5b60ba1b60448201526064015b60405180910390fd5b50505050565b604051600160621b9060609060009063bea05ee360e01b9061019c908590859060240161032d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051909150600090600661011160931b01906101eb908490610376565b600060405180830381855afa9150503d8060008114610127576040519150601f19603f3d011682016040523d82523d6000602084013e61012c565b60408051600481526024810182526020810180516001600160e01b0316637dbc4b9b60e11b17905290516000903090610260908490610376565b600060405180830381855afa9150503d806000811461029b576040519150601f19603f3d011682016040523d82523d6000602084013e6102a0565b606091505b50509050806102dd5760405162461bcd60e51b815260206004820152600960248201526810d85b1b0811985a5b60ba1b6044820152606401610165565b5050565b604051600160621b9060609060009063bea05ee360e01b9061009b908590859060240161032d565b60005b8381101561032457818101518382015260200161030c565b50506000910152565b6bffffffffffffffffffffffff19831681526040602082015260008251806040840152610361816060850160208701610309565b601f01601f1916919091016060019392505050565b60008251610388818460208701610309565b919091019291505056fea2646970667358221220124acba961c0cdb80521483a1ff3486f413a4c7e71e4c72f2960196d63992fa064736f6c63430008130033",
"bytecode": "0x608060405234801561001057600080fd5b506103c8806100206000396000f3fe60806040526004361061003f5760003560e01c8063c040622614610044578063d4f639ea1461004e578063e22a5d5b14610056578063fb7897361461006b575b600080fd5b61004c610073565b005b61004c610174565b34801561006257600080fd5b5061004c610226565b61004c6102e1565b604051600160621b906060906000906330b4ef7d60e01b9061009b908590859060240161032d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051909150600090600661011160931b01906100ea908490610376565b6000604051808303816000865af19150503d8060008114610127576040519150601f19603f3d011682016040523d82523d6000602084013e61012c565b606091505b505090508061016e5760405162461bcd60e51b815260206004820152600960248201526810d85b1b0811985a5b60ba1b60448201526064015b60405180910390fd5b50505050565b604051600160621b9060609060009063bea05ee360e01b9061019c908590859060240161032d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051909150600090600661011160931b01906101eb908490610376565b600060405180830381855afa9150503d8060008114610127576040519150601f19603f3d011682016040523d82523d6000602084013e61012c565b60408051600481526024810182526020810180516001600160e01b0316637dbc4b9b60e11b17905290516000903090610260908490610376565b600060405180830381855afa9150503d806000811461029b576040519150601f19603f3d011682016040523d82523d6000602084013e6102a0565b606091505b50509050806102dd5760405162461bcd60e51b815260206004820152600960248201526810d85b1b0811985a5b60ba1b6044820152606401610165565b5050565b604051600160621b9060609060009063bea05ee360e01b9061009b908590859060240161032d565b60005b8381101561032457818101518382015260200161030c565b50506000910152565b6bffffffffffffffffffffffff19831681526040602082015260008251806040840152610361816060850160208701610309565b601f01601f1916919091016060019392505050565b60008251610388818460208701610309565b919091019291505056fea264697066735822122069d7c0b84cd77db30440c9ccd7fa5250c8bcbc9b804430cd7dc6296d031b549464736f6c63430008130033",
"deployedBytecode": "0x60806040526004361061003f5760003560e01c8063c040622614610044578063d4f639ea1461004e578063e22a5d5b14610056578063fb7897361461006b575b600080fd5b61004c610073565b005b61004c610174565b34801561006257600080fd5b5061004c610226565b61004c6102e1565b604051600160621b906060906000906330b4ef7d60e01b9061009b908590859060240161032d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051909150600090600661011160931b01906100ea908490610376565b6000604051808303816000865af19150503d8060008114610127576040519150601f19603f3d011682016040523d82523d6000602084013e61012c565b606091505b505090508061016e5760405162461bcd60e51b815260206004820152600960248201526810d85b1b0811985a5b60ba1b60448201526064015b60405180910390fd5b50505050565b604051600160621b9060609060009063bea05ee360e01b9061019c908590859060240161032d565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051909150600090600661011160931b01906101eb908490610376565b600060405180830381855afa9150503d8060008114610127576040519150601f19603f3d011682016040523d82523d6000602084013e61012c565b60408051600481526024810182526020810180516001600160e01b0316637dbc4b9b60e11b17905290516000903090610260908490610376565b600060405180830381855afa9150503d806000811461029b576040519150601f19603f3d011682016040523d82523d6000602084013e6102a0565b606091505b50509050806102dd5760405162461bcd60e51b815260206004820152600960248201526810d85b1b0811985a5b60ba1b6044820152606401610165565b5050565b604051600160621b9060609060009063bea05ee360e01b9061009b908590859060240161032d565b60005b8381101561032457818101518382015260200161030c565b50506000910152565b6bffffffffffffffffffffffff19831681526040602082015260008251806040840152610361816060850160208701610309565b601f01601f1916919091016060019392505050565b60008251610388818460208701610309565b919091019291505056fea264697066735822122069d7c0b84cd77db30440c9ccd7fa5250c8bcbc9b804430cd7dc6296d031b549464736f6c63430008130033",
"linkReferences": {},
"deployedLinkReferences": {}
}
56 changes: 56 additions & 0 deletions contracts/Error.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

contract Error {
// custom error
error InsufficientBalance(uint balance, uint withdrawAmount);

function testRequire(uint _i) public pure {
// Require should be used to validate conditions such as:
// - inputs
// - conditions before execution
// - return values from calls to other functions
require(_i > 10, "Input must be greater than 10");
}

// function testCustomErrorWithRequire(uint _withdrawAmount) public view returns (uint) {
// uint bal = address(this).balance;
// require(_withdrawAmount > 10, InsufficientBalance({balance: bal, withdrawAmount: _withdrawAmount}));
// return bal;
// }

function testRevert(uint _i) public pure {
// Revert is useful when the condition to check is complex.
// This code does the exact same thing as the example above
if (_i <= 10) {
revert("Input must be greater than 10");
}
}

uint public num;

function testAssert() public view {
// Assert should only be used to test for internal errors,
// and to check invariants.

// Here we assert that num is always equal to 0
// since it is impossible to update the value of num
assert(num == 0);
}

function testCustomError(uint _withdrawAmount) public view {
uint bal = address(this).balance;
if (bal < _withdrawAmount) {
revert InsufficientBalance({balance: bal, withdrawAmount: _withdrawAmount});
}
}

function yul_revert(uint x) public pure {
assembly {
// revert(p, s) - end execution
// revert state changes
// return data mem[p…(p+s))
if gt(x, 10) { revert(0, 0) }
}
}
}