Skip to content

Commit

Permalink
Emit even when DAO address is set (#60)
Browse files Browse the repository at this point in the history
* Emit event when DAO address is set

* Test that events LSKClaimed and ClaimingEnded are emitted

* Check for LSKClaimed events in claimMultisigAccount unit tests
  • Loading branch information
matjazv authored Mar 21, 2024
1 parent a072d82 commit ea850a5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/L2/L2Claim.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ contract L2Claim is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, ISe
mapping(bytes20 => address) public claimedTo;

/// @notice Emitted when an address has claimed the LSK.
event LSKClaimed(bytes20 lskAddress, address recipient, uint256 amount);
event LSKClaimed(bytes20 indexed lskAddress, address indexed recipient, uint256 amount);

/// @notice Emitted when the DAO address is set.
/// @param daoAddress Address of the DAO.
event DaoAddressSet(address indexed daoAddress);

/// @notice Event indicating the end of the claiming period.
event ClaimingEnded();
Expand Down Expand Up @@ -235,6 +239,7 @@ contract L2Claim is Initializable, Ownable2StepUpgradeable, UUPSUpgradeable, ISe
require(daoAddress == address(0), "L2Claim: DAO Address has already been set");
require(_daoAddress != address(0), "L2Claim: DAO Address cannot be zero");
daoAddress = _daoAddress;
emit DaoAddressSet(_daoAddress);
}

/// @notice Allows the contract owner to recover unclaimed LSK tokens to the DAO address after the claim period is
Expand Down
38 changes: 37 additions & 1 deletion test/L2/L2Claim.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ contract L2ClaimTest is Test {
Signature memory signature = getSignature(_accountIndex);

bytes32 pubKey = signature.sigs[0].pubKey;

// check that the LSKClaimed event is emitted
vm.expectEmit(true, true, true, true);
emit L2Claim.LSKClaimed(bytes20(sha256(abi.encode(pubKey))), address(this), leaf.balanceBeddows);

l2Claim.claimRegularAccount(
leaf.proof,
pubKey,
Expand Down Expand Up @@ -412,6 +417,11 @@ contract L2ClaimTest is Test {
}

bytes20 lskAddress = bytes20(leaf.b32Address << 96);

// check that the LSKClaimed event is emitted
vm.expectEmit(true, true, true, true);
emit L2Claim.LSKClaimed(lskAddress, address(this), leaf.balanceBeddows);

l2Claim.claimMultisigAccount(
leaf.proof,
lskAddress,
Expand Down Expand Up @@ -439,6 +449,11 @@ contract L2ClaimTest is Test {
ed25519Signatures[1] = ED25519Signature(bytes32(0), bytes32(0));

bytes20 lskAddress = bytes20(leaf.b32Address << 96);

// check that the LSKClaimed event is emitted
vm.expectEmit(true, true, true, true);
emit L2Claim.LSKClaimed(lskAddress, address(this), leaf.balanceBeddows);

l2Claim.claimMultisigAccount(
leaf.proof,
lskAddress,
Expand Down Expand Up @@ -467,6 +482,11 @@ contract L2ClaimTest is Test {
ed25519Signatures[4] = ED25519Signature(bytes32(0), bytes32(0));

bytes20 lskAddress = bytes20(leaf.b32Address << 96);

// check that the LSKClaimed event is emitted
vm.expectEmit(true, true, true, true);
emit L2Claim.LSKClaimed(lskAddress, address(this), leaf.balanceBeddows);

l2Claim.claimMultisigAccount(
leaf.proof,
lskAddress,
Expand All @@ -493,6 +513,11 @@ contract L2ClaimTest is Test {
}

bytes20 lskAddress = bytes20(leaf.b32Address << 96);

// check that the LSKClaimed event is emitted
vm.expectEmit(true, true, true, true);
emit L2Claim.LSKClaimed(lskAddress, address(this), leaf.balanceBeddows);

l2Claim.claimMultisigAccount(
leaf.proof,
bytes20(leaf.b32Address << 96),
Expand Down Expand Up @@ -553,6 +578,10 @@ contract L2ClaimTest is Test {
}

function test_SetDAOAddress_SuccessSet() public {
// check that the DaoAddressSet event is emitted
vm.expectEmit(true, true, true, true);
emit L2Claim.DaoAddressSet(daoAddress);

l2Claim.setDAOAddress(daoAddress);
assertEq(l2Claim.daoAddress(), daoAddress);
}
Expand Down Expand Up @@ -581,11 +610,18 @@ contract L2ClaimTest is Test {

function test_RecoverLSK_SuccessRecover() public {
l2Claim.setDAOAddress(daoAddress);
uint256 claimContractBalance = lsk.balanceOf(daoAddress);
uint256 claimContractBalance = lsk.balanceOf(address(l2Claim));
assert(claimContractBalance > 0);

vm.warp(RECOVER_PERIOD + 1 seconds);

// check that the ClaimingEnded event is emitted
vm.expectEmit(true, true, true, true);
emit L2Claim.ClaimingEnded();

l2Claim.recoverLSK();
assertEq(lsk.balanceOf(daoAddress), claimContractBalance);
assertEq(lsk.balanceOf(address(l2Claim)), 0);
}

function test_TransferOwnership() public {
Expand Down

0 comments on commit ea850a5

Please sign in to comment.