Skip to content

Commit

Permalink
feat(BlacklistValidator): adding tests and deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
KristenPire committed Jun 12, 2024
1 parent 1b64e79 commit 9a8e823
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
17 changes: 17 additions & 0 deletions script/deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
37 changes: 36 additions & 1 deletion test/Blacklist.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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));
Expand Down
8 changes: 2 additions & 6 deletions test/ERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/Mintable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion test/gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 9a8e823

Please sign in to comment.