Skip to content

Commit

Permalink
Add some safety checks
Browse files Browse the repository at this point in the history
  • Loading branch information
RubenSousaDinis committed Apr 18, 2024
1 parent ab58cbb commit b1b67b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
8 changes: 6 additions & 2 deletions contracts/passport/PassportRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ contract PassportRegistry is Ownable, Pausable {
uint256 id
) public onlyOwner whenNotPaused whenAdminGeneration {
require(passportId[wallet] == 0, "Passport already exists");
require(idPassport[id] == address(0), "Passport id already issued");

totalAdminsCreates.increment();

Expand All @@ -117,12 +116,15 @@ contract PassportRegistry is Ownable, Pausable {
*/
function transfer(address newWallet) public whenNotPaused {
uint256 id = passportId[msg.sender];
uint256 newWalletId = passportId[newWallet];
require(id != 0, "Passport does not exist");
require(newWalletId == 0, "Wallet passed already has a passport");

passportId[msg.sender] = 0;
passportId[newWallet] = id;
idPassport[id] = newWallet;
walletActive[msg.sender] = false;
walletActive[newWallet] = true;
totalPassportTransfers.increment();

emit Transfer(id, id, msg.sender, newWallet);
Expand Down Expand Up @@ -208,7 +210,7 @@ contract PassportRegistry is Ownable, Pausable {
* @notice Changes the contract generation mode.
* @dev Can only be called by the owner.
*/
function setGenerationMode(bool sequencialFlag, uint256 nextSequencialPassportId) public whenNotPaused onlyOwner {
function setGenerationMode(bool sequencialFlag, uint256 nextSequencialPassportId) public onlyOwner {
_sequencial = sequencialFlag;
_nextSequencialPassportId = nextSequencialPassportId;

Expand All @@ -232,6 +234,8 @@ contract PassportRegistry is Ownable, Pausable {
// private

function _create(address wallet, uint256 id, string memory source) private {
require(idPassport[id] == address(0), "Passport id already issued");

totalCreates.increment();

idPassport[id] = wallet;
Expand Down
21 changes: 21 additions & 0 deletions test/contracts/passport/passportRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,27 @@ describe("Passport", () => {
expect(holderThreePreviousPassportId).to.eq(false);
});

it("allows the passport owner to transfer the passport", async () => {
await contract.connect(holderOne).create("farcaster");

await contract.connect(holderOne).transfer(holderThree.address);

const holderOnePassportId = await contract.passportId(holderOne.address);
const holderThreePassportId = await contract.passportId(holderThree.address);

expect(holderOnePassportId).to.eq(0);
expect(holderThreePassportId).to.eq(1);
});

it("prevents the passport owner to transfer the passport to an existing owner wallet", async () => {
await contract.connect(holderOne).create("farcaster");
await contract.connect(holderThree).create("lens");

const action = contract.connect(holderOne).transfer(holderThree.address);

await expect(action).to.be.revertedWith("Wallet passed already has a passport");
});

it("admin generation", async () => {
const action = contract.connect(admin).adminCreate("farcaster", holderOne.address, 1010);

Expand Down

0 comments on commit b1b67b8

Please sign in to comment.