Compare commits

...

2 Commits

Author SHA1 Message Date
David E. Perez Negron R. 47285e3167 Update License 2023-09-17 22:44:16 -06:00
David E. Perez Negron R. 915fcadb97 Testing Errors 2023-09-17 22:43:56 -06:00
5 changed files with 64 additions and 0 deletions

16
src/Error.sol Normal file
View File

@ -0,0 +1,16 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
contract Error {
error NotAuthorized();
function throwError() external {
require(false, "not authorized");
}
function throwCustomError() external {
revert NotAuthorized();
}
}

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
contract HelloWorld {

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "solmate/tokens/ERC20.sol";

View File

@ -1,3 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
contract Wallet {

45
test/Error.t.sol Normal file
View File

@ -0,0 +1,45 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import "forge-std/Test.sol";
import {Error} from "../src/Error.sol";
contract ErrorTest is Test {
Error public err;
function setUp() public {
err = new Error();
}
function testFail() public {
err.throwError();
}
// Does the same test as above
function testRevert() public {
vm.expectRevert();
err.throwError();
}
// Test with require error message
function testRequireMessage() public {
vm.expectRevert(bytes("not authorized"));
err.throwError();
}
// Test custom error
function testCustomError() public {
vm.expectRevert(Error.NotAuthorized.selector);
err.throwCustomError();
}
// Test Error Label
function testErrorLabel() public {
assertEq(uint(1), uint(1), "test 1");
assertEq(uint(1), uint(1), "test 2");
assertEq(uint(1), uint(1), "test 3");
assertEq(uint(1), uint(1), "test 4");
// assertEq(uint(0), uint(2), "test 5");
}
}