2024-03-19 14:27:51 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
pragma solidity ^0.8.4;
|
|
|
|
|
|
|
|
contract TestCustomErrors {
|
|
|
|
|
|
|
|
error SimpleError();
|
|
|
|
error ErrorWithArguments(uint256 one, bool two);
|
|
|
|
error ErrorWithStaticStruct(StaticStruct one, StaticStruct two);
|
|
|
|
error ErrorWithDynamicStruct(DynamicStruct one, DynamicStruct two);
|
|
|
|
error ErrorWithDynamicAndStaticStruct(DynamicStruct one, StaticStruct two);
|
|
|
|
|
|
|
|
struct StaticStruct {
|
|
|
|
uint256 a;
|
|
|
|
uint256 b;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DynamicStruct {
|
|
|
|
string a;
|
|
|
|
uint256 b;
|
|
|
|
}
|
|
|
|
|
|
|
|
function revertsSimpleError() public pure {
|
|
|
|
revert SimpleError();
|
|
|
|
}
|
|
|
|
|
|
|
|
function revertsErrorWithArguments() public pure {
|
|
|
|
revert ErrorWithArguments(1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
function revertsErrorWithStaticStruct() public pure {
|
|
|
|
revert ErrorWithStaticStruct(StaticStruct(1, 2), StaticStruct(3, 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
function revertsErrorWithDynamicStruct() public pure {
|
|
|
|
revert ErrorWithDynamicStruct(DynamicStruct("1", 2), DynamicStruct("3", 4));
|
|
|
|
}
|
|
|
|
|
|
|
|
function revertsErrorWithDynamicAndStaticStruct() public pure {
|
|
|
|
revert ErrorWithDynamicAndStaticStruct(
|
|
|
|
DynamicStruct("1", 2),
|
|
|
|
StaticStruct(3, 4)
|
|
|
|
);
|
|
|
|
}
|
2024-03-21 07:21:12 +00:00
|
|
|
|
2024-05-15 11:43:42 +00:00
|
|
|
function revertsMultipleErrors(bool simple) public pure {
|
|
|
|
if (simple) {
|
|
|
|
revert SimpleError();
|
|
|
|
}
|
|
|
|
revert ErrorWithArguments(1, false);
|
|
|
|
}
|
|
|
|
|
2024-03-21 07:21:12 +00:00
|
|
|
string private state;
|
|
|
|
|
|
|
|
function revertsTransaction() public {
|
|
|
|
state = "updated state";
|
|
|
|
revert ErrorWithArguments(1, true);
|
|
|
|
}
|
2024-03-19 14:27:51 +00:00
|
|
|
}
|