Skip to content

Commit

Permalink
feat: implement feature to disable invitation
Browse files Browse the repository at this point in the history
  • Loading branch information
andresaiello committed Jan 29, 2024
1 parent d7f76a5 commit 6528582
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ contract InvitationManager {
bytes32 r;
bytes32 s;
}

// Indicate if invitation is still available. The default value is true.
mapping(address => bool) public invitationEnabled;

// Records the timestamp when a particular user gets verified.
mapping(address => uint256) public userVerificationTimestamps;

Expand All @@ -24,6 +28,7 @@ contract InvitationManager {
mapping(address => mapping(uint256 => uint256)) public totalInvitesByInviterByDay;

error UserAlreadyVerified();
error UserNotVerified();
error UnrecognizedInvitation();
error IndexOutOfBounds();
error CanNotInviteYourself();
Expand All @@ -41,6 +46,12 @@ contract InvitationManager {

function markAsVerified() external {
_markAsVerified(msg.sender);
invitationEnabled[msg.sender] = true;
}

function udpateInvitationStatus(bool value) external {
if (userVerificationTimestamps[msg.sender] == 0) revert UserNotVerified();
invitationEnabled[msg.sender] = value;
}

function hasBeenVerified(address userAddress) external view returns (bool) {
Expand All @@ -61,7 +72,8 @@ contract InvitationManager {

function confirmAndAcceptInvitation(address inviter, Signature calldata signature) external {
if (inviter == msg.sender) revert CanNotInviteYourself();
if (userVerificationTimestamps[inviter] == 0) revert UnrecognizedInvitation();
if (!invitationEnabled[inviter]) revert UnrecognizedInvitation();

_verifySignature(inviter, signature);

acceptedInvitationsTimestamp[inviter][msg.sender] = block.timestamp;
Expand Down
11 changes: 8 additions & 3 deletions packages/zevm-app-contracts/test/Disperse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parseUnits } from "@ethersproject/units";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { parseEther } from "ethers/lib/utils";
import { ethers, network } from "hardhat";

import { Disperse, Disperse__factory, MockZRC20, MockZRC20__factory } from "../typechain-types";
Expand All @@ -26,15 +27,19 @@ describe("Disperse tests", () => {
const amount = parseUnits("10");
const balance0 = await ethers.provider.getBalance(accounts[0].address);
const balance1 = await ethers.provider.getBalance(accounts[1].address);
await disperseContract.disperseEther([accounts[0].address, accounts[1].address], [amount, amount.mul(2)], {

const bigArrayAddress = new Array(500).fill(accounts[0].address);
const bigArrayAmount = new Array(500).fill(parseEther("0.01"));

await disperseContract.disperseEther(bigArrayAddress, bigArrayAmount, {
value: amount.mul(3),
});

const balance0After = await ethers.provider.getBalance(accounts[0].address);
const balance1After = await ethers.provider.getBalance(accounts[1].address);

expect(balance0After.sub(balance0)).to.be.eq(amount);
expect(balance1After.sub(balance1)).to.be.eq(amount.mul(2));
expect(balance0After.sub(balance0)).to.be.eq(parseEther("0.01").mul("500"));
expect(balance1After.sub(balance1)).to.be.eq(0);
});

it("Should disperse ETH with surplus", async () => {
Expand Down

0 comments on commit 6528582

Please sign in to comment.