Skip to content

Commit

Permalink
fix: add parameter ('provider') to the custom error ProviderAlreadyEx…
Browse files Browse the repository at this point in the history
…ists

- added test cases to check that these errors are thrown
- adjust test case for GitcoinPassportDecoder to redeploy contract before every test
  • Loading branch information
nutrina committed Nov 9, 2023
1 parent 9abea2d commit 30c315a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
7 changes: 3 additions & 4 deletions contracts/GitcoinPassportDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract GitcoinPassportDecoder is
bytes32 public schemaUID;

// Errors
error ProviderAlreadyExists();
error ProviderAlreadyExists(string provider);

function initialize() public initializer {
__Ownable_init();
Expand Down Expand Up @@ -88,10 +88,10 @@ contract GitcoinPassportDecoder is
function addProviders(string[] memory providers) public onlyOwner {
for (uint256 i = 0; i < providers.length; ) {
if (savedProviders[providers[i]] == 1) {
revert ProviderAlreadyExists();
revert ProviderAlreadyExists(providers[i]);
}

providerVersions[currentVersion].push(providers[i]);
providerVersions[currentVersion].push(providers[i]);
savedProviders[providers[i]] = 1;

unchecked {
Expand Down Expand Up @@ -226,4 +226,3 @@ contract GitcoinPassportDecoder is
return passportMemoryArray;
}
}

51 changes: 47 additions & 4 deletions test/GitcoinPassportDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ const easEncodeInvalidStamp = () => {
return encodedData;
};

describe.only("GitcoinPassportDecoder", function () {
this.beforeAll(async function () {
describe("GitcoinPassportDecoder", function () {
this.beforeEach(async function () {
// this.beforeAll(async function () {
const [ownerAccount, iamAcct, recipientAccount, otherAccount] =
await ethers.getSigners();

Expand Down Expand Up @@ -233,9 +234,7 @@ describe.only("GitcoinPassportDecoder", function () {
await this.gitcoinPassportDecoder.setEASAddress(EAS_CONTRACT_ADDRESS);
await this.gitcoinPassportDecoder.setGitcoinResolver(this.resolverAddress);
await this.gitcoinPassportDecoder.setSchemaUID(this.passportSchemaUID);
});

this.beforeEach(async function () {
this.passport.nonce = await this.gitcoinVerifier.recipientNonces(
this.passport.multiAttestationRequest[0].data[0].recipient
);
Expand Down Expand Up @@ -270,6 +269,42 @@ describe.only("GitcoinPassportDecoder", function () {
.addProviders(["NewStamp3"])
).to.be.revertedWith("Ownable: caller is not the owner");
});

it("should throw an error when trying to add the same provider twice in different function calls", async function () {
const providersForCall1 = ["NewStamp1", "NewStamp2"];
const providersForCall2 = ["NewStamp3", "NewStamp2"];

await this.gitcoinPassportDecoder
.connect(this.owner)
.addProviders(providersForCall1);

await expect(
this.gitcoinPassportDecoder
.connect(this.owner)
.addProviders(providersForCall2)
).to.be.revertedWithCustomError(
this.gitcoinPassportDecoder,
"ProviderAlreadyExists"
);
});

it("should throw an error when trying to add the same provider twice in the same function call", async function () {
const providersForCall1 = [
"NewStamp1",
"NewStamp2",
"NewStamp3",
"NewStamp2",
];

await expect(
this.gitcoinPassportDecoder
.connect(this.owner)
.addProviders(providersForCall1)
).to.be.revertedWithCustomError(
this.gitcoinPassportDecoder,
"ProviderAlreadyExists"
);
});
});

describe("Decoding Passports", async function () {
Expand All @@ -284,6 +319,10 @@ describe.only("GitcoinPassportDecoder", function () {

const { v, r, s } = ethers.Signature.from(signature);

await this.gitcoinPassportDecoder
.connect(this.owner)
.addProviders(providers);

// Submit attestations
const verifiedPassport = await this.gitcoinVerifier.verifyAndAttest(
this.passport,
Expand Down Expand Up @@ -320,6 +359,10 @@ describe.only("GitcoinPassportDecoder", function () {

const { v, r, s } = ethers.Signature.from(signature);

await this.gitcoinPassportDecoder
.connect(this.owner)
.addProviders(providers);

// Submit attestations
const verifiedPassport = await this.gitcoinVerifier.verifyAndAttest(
this.passport,
Expand Down

0 comments on commit 30c315a

Please sign in to comment.