Skip to content

Commit

Permalink
Add test cases using signature for reactivateDKIMPublicKeyHash function.
Browse files Browse the repository at this point in the history
  • Loading branch information
wshino committed Jun 11, 2024
1 parent 2b7baa0 commit c3bb059
Showing 1 changed file with 114 additions and 2 deletions.
116 changes: 114 additions & 2 deletions packages/contracts/test/UserOverrideableDKIMRegistry.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,33 @@ contract UserOverrideableDKIMRegistryTest is Test {
vm.stopPrank();
}

function testSetDKIMPublicKeyHashByMainAuthorizerContract() public {
vm.startPrank(address(mainAuthorizerContract));

vm.expectEmit();
emit UserOverrideableDKIMRegistry.DKIMPublicKeyHashRegistered(
domainName,
publicKeyHash,
address(mainAuthorizerContract)
);
registry.setDKIMPublicKeyHash(
domainName,
publicKeyHash,
address(mainAuthorizerContract),
new bytes(0)
);
vm.stopPrank();

require(
registry.isDKIMPublicKeyHashValid(
domainName,
publicKeyHash,
address(mainAuthorizerContract)
),
"Invalid public key hash"
);
}

function testSetDKIMPublicKeyHashByUser1() public {
vm.startPrank(user1);

Expand Down Expand Up @@ -601,15 +628,49 @@ contract UserOverrideableDKIMRegistryTest is Test {

vm.startPrank(user1);

vm.expectEmit();
emit UserOverrideableDKIMRegistry.DKIMPublicKeyHashReactivated(
publicKeyHash,
user1
);
registry.reactivateDKIMPublicKeyHash(
domainName,
publicKeyHash,
user1,
new bytes(0)
);
vm.stopPrank();

require(
registry.isDKIMPublicKeyHashValid(domainName, publicKeyHash, user1),
"Invalid public key hash"
);
}

function testReactivateDKIMPublicKeyHashByUser2WithUser1Signature() public {
testSetDKIMPublicKeyHashByUser1();
testRevokeDKIMPublicKeyHashByMainAuthorizer();

require(
!registry.isDKIMPublicKeyHashValid(
domainName,
publicKeyHash,
user1
),
"public key hash is not revoked"
);

vm.startPrank(user2);

string memory signedMsg = registryWithContract.computeSignedMsg(
registryWithContract.REVOKE_PREFIX(),
registryWithContract.REACTIVATE_PREFIX(),
domainName,
publicKeyHash
);
bytes32 digest = MessageHashUtils.toEthSignedMessageHash(
bytes(signedMsg)
);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(9, digest);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(2, digest);
bytes memory signature = abi.encodePacked(r, s, v);

vm.expectEmit();
Expand All @@ -630,4 +691,55 @@ contract UserOverrideableDKIMRegistryTest is Test {
"Invalid public key hash"
);
}

function testReactivateDKIMPublicKeyHashByUser1WithMainAuthorizerSignature()
public
{
testSetDKIMPublicKeyHashByMainAuthorizerContract();
testRevokeDKIMPublicKeyHashByMainAuthorizer();

require(
!registry.isDKIMPublicKeyHashValid(
domainName,
publicKeyHash,
address(mainAuthorizerContract)
),
"public key hash is not revoked"
);

vm.startPrank(user1);

string memory signedMsg = registryWithContract.computeSignedMsg(
registryWithContract.REACTIVATE_PREFIX(),
domainName,
publicKeyHash
);
bytes32 digest = MessageHashUtils.toEthSignedMessageHash(
bytes(signedMsg)
);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(9, digest);
bytes memory signature = abi.encodePacked(r, s, v);

vm.expectEmit();
emit UserOverrideableDKIMRegistry.DKIMPublicKeyHashReactivated(
publicKeyHash,
address(mainAuthorizerContract)
);
registry.reactivateDKIMPublicKeyHash(
domainName,
publicKeyHash,
address(mainAuthorizerContract),
signature
);
vm.stopPrank();

require(
registry.isDKIMPublicKeyHashValid(
domainName,
publicKeyHash,
address(mainAuthorizerContract)
),
"Invalid public key hash"
);
}
}

0 comments on commit c3bb059

Please sign in to comment.