From 9a8e823ca7b3baa17334077c89c377fc793e5811 Mon Sep 17 00:00:00 2001 From: Kristen Pire Date: Wed, 12 Jun 2024 13:20:53 +0200 Subject: [PATCH] feat(BlacklistValidator): adding tests and deployment script --- script/deploy.s.sol | 17 +++++++++++++++++ test/Blacklist.t.sol | 37 ++++++++++++++++++++++++++++++++++++- test/ERC20.t.sol | 8 ++------ test/Mintable.t.sol | 2 +- test/gas.t.sol | 2 +- 5 files changed, 57 insertions(+), 9 deletions(-) diff --git a/script/deploy.s.sol b/script/deploy.s.sol index 32713a7..c1f732d 100644 --- a/script/deploy.s.sol +++ b/script/deploy.s.sol @@ -54,6 +54,23 @@ contract All is Script { } } +contract BlacklistValidator is Script { + function run() external { + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + + vm.startBroadcast(deployerPrivateKey); + + BlacklistValidatorUpgradeable blacklistValidator = new BlacklistValidatorUpgradeable(); + ERC1967Proxy proxy = new ERC1967Proxy( + address(blacklistValidator), + abi.encodeWithSelector(BlacklistValidatorUpgradeable.initialize.selector) + ); + + console.log("Deployed", "Validator", "at", address(proxy)); + vm.stopBroadcast(); + } +} + contract AllControllerGnosis is Script { function run() external { uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); diff --git a/test/Blacklist.t.sol b/test/Blacklist.t.sol index 3666e4d..b03a9c8 100644 --- a/test/Blacklist.t.sol +++ b/test/Blacklist.t.sol @@ -76,7 +76,9 @@ contract BlackListValidatorTest is Test { token.setValidator(address(notAMoneriumValidator)); } - function test_shouldNotAcceptANotMoneriumValidatorAtInitialization() public { + function test_shouldNotAcceptANotMoneriumValidatorAtInitialization() + public + { // Deploy the implementation contract Token implementation = new Token(); @@ -115,6 +117,39 @@ contract BlackListValidatorTest is Test { validator.ban(user1); } + function test_owner_can_add_admin() public { + assertTrue(validator.owner() == address(this)); + validator.addAdminAccount(user1); + assertTrue(validator.isAdminAccount(user1)); + } + + function test_non_owner_cannot_add_admin() public { + vm.startPrank(user1); + assertTrue(validator.owner() != user1); + vm.expectRevert( + abi.encodeWithSignature("OwnableUnauthorizedAccount(address)", address(user1)) + ); + validator.addAdminAccount(user1); + } + + function test_owner_can_remove_admin() public { + assertTrue(validator.owner() == address(this)); + validator.addAdminAccount(user1); + assertTrue(validator.isAdminAccount(user1)); + validator.removeAdminAccount(user1); + assertTrue(!validator.isAdminAccount(user1)); + } + + function test_non_owner_cannot_remove_admin() public { + vm.startPrank(user1); + assertTrue(validator.owner() != user1); + assertTrue(validator.isAdminAccount(admin)); + vm.expectRevert( + abi.encodeWithSignature("OwnableUnauthorizedAccount(address)", address(user1)) + ); + validator.removeAdminAccount(admin); + } + function test_can_remove_admin() public { // Add user1 to blacklist assertTrue(validator.isAdminAccount(admin)); diff --git a/test/ERC20.t.sol b/test/ERC20.t.sol index a1f5e82..682208c 100644 --- a/test/ERC20.t.sol +++ b/test/ERC20.t.sol @@ -280,9 +280,7 @@ contract ERC20TokenTest is Test { uint256 privateKey = 0xabc123; // Assuming this private key corresponds to `user1`. address signer = vm.addr(privateKey); - bytes32 messageHash = keccak256( - "I hereby declare that I am the address owner." - ); + bytes32 messageHash = 0xb77c35c892a1b24b10a2ce49b424e578472333ee8d2456234fff90626332c50f; // Simulate signing the message by `user1` (uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, messageHash); @@ -330,9 +328,7 @@ contract ERC20TokenTest is Test { uint256 privateKey = 0xabc123; address signer = vm.addr(privateKey); - bytes32 messageHash = keccak256( - "I hereby declare that I am the address owner." - ); + bytes32 messageHash = 0xb77c35c892a1b24b10a2ce49b424e578472333ee8d2456234fff90626332c50f; (uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, messageHash); vm.prank(system); diff --git a/test/Mintable.t.sol b/test/Mintable.t.sol index cbeff17..e2a9052 100644 --- a/test/Mintable.t.sol +++ b/test/Mintable.t.sol @@ -123,7 +123,7 @@ contract MintableTokenTest is Test { test_system_account_can_mint_tokens(); address user = vm.addr(userPrivateKey); - bytes32 hash = keccak256("I hereby declare that I am the address owner."); + bytes32 hash = 0xb77c35c892a1b24b10a2ce49b424e578472333ee8d2456234fff90626332c50f; (uint8 v, bytes32 r, bytes32 s) = vm.sign(userPrivateKey, hash); bytes memory signature = abi.encodePacked(r, s, v); diff --git a/test/gas.t.sol b/test/gas.t.sol index 46b48d7..6cc740b 100644 --- a/test/gas.t.sol +++ b/test/gas.t.sol @@ -84,7 +84,7 @@ contract ERC20TokenTest is Test { console.log("gasUsed for transferFrom", gasUsed); address user = vm.addr(0xabc123); - bytes32 hash = keccak256("I hereby declare that I am the address owner."); + bytes32 hash = 0xb77c35c892a1b24b10a2ce49b424e578472333ee8d2456234fff90626332c50f; (uint8 v, bytes32 r, bytes32 s) = vm.sign(0xabc123, hash); bytes memory signature = abi.encodePacked(r, s, v);