Skip to content

Commit

Permalink
1236 update hypercert permissions (passportxyz#1307)
Browse files Browse the repository at this point in the history
* chore(platforms): update hypercert copy

* feat(platforms): check that hypercerts are greater than 15 days and that they have more than one

* chore(platforms): update hypercert eligibility
  • Loading branch information
Tim Schultz authored May 25, 2023
1 parent 9e97510 commit aa34ad7
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
7 changes: 5 additions & 2 deletions platforms/src/Hypercerts/Providers-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ export const HypercertsPlatformDetails: PlatformSpec = {
icon: "./assets/hypercertsStampIcon.svg",
platform: "Hypercerts",
name: "Hypercerts",
description: "Connect your wallet to verify that you hold a Hypercert",
description: "Connect your wallet to verify that you hold Hypercerts",
connectMessage: "Connect Wallet",
isEVM: true,
};

export const HypercertsProviderConfig: PlatformGroupSpec[] = [
{ platformGroup: "Account Name", providers: [{ title: "Holds at least 1 Hypercert", name: "Hypercerts" }] },
{
platformGroup: "Account Name",
providers: [{ title: "Held at least two Hypercerts for more than 15 days", name: "Hypercerts" }],
},
];
9 changes: 8 additions & 1 deletion platforms/src/Hypercerts/Providers/Hypercerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ type ClaimTokensResponse = {
claimTokens: ClaimToken[];
};

function checkTokenCreation(claimTokens: ClaimToken[]): ClaimToken[] {
const fifteenDaysAgo = Date.now() - 15 * 24 * 60 * 60 * 1000;
return claimTokens.filter(({ claim: { creation } }) => Number(creation) * 1000 < fifteenDaysAgo);
}

export class HypercertsProvider implements Provider {
// Give the provider a type so that we can select it with a payload
type = "Hypercerts";
Expand Down Expand Up @@ -59,7 +64,9 @@ export class HypercertsProvider implements Provider {
},
});

const valid = result.data.data.claimTokens.length > 0;
const { claimTokens } = result.data.data;

const valid = checkTokenCreation(claimTokens).length > 1;

return {
valid: valid,
Expand Down
82 changes: 82 additions & 0 deletions platforms/src/Hypercerts/Providers/__tests__/Hypercerts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const mockedAxiosPost = jest.spyOn(axios, "post");
const MOCK_ADDRESS = "0xcF314CE817E25b4F784bC1f24c9A79A525fEC50f";
const MOCK_ADDRESS_LOWER = MOCK_ADDRESS.toLowerCase();

// Mock current date
jest.spyOn(Date, "now").mockImplementation(() => 1677350400000); // This corresponds to "2023-01-25T00:00:00.000Z"

// Mock Claim Tokens Response
const mockClaimTokensResponse = {
data: {
Expand All @@ -26,6 +29,18 @@ const mockClaimTokensResponse = {
totalUnits: "1000",
},
},
{
id: "2",
owner: MOCK_ADDRESS_LOWER,
tokenID: "2",
units: "100",
claim: {
id: "2",
creation: "1632189185",
uri: "https://hypercerts.com/token/2",
totalUnits: "1000",
},
},
],
},
},
Expand Down Expand Up @@ -94,4 +109,71 @@ describe("Hypercerts Provider", () => {

expect(mockedAxiosPost).toBeCalledTimes(1);
});

it("should handle claims older than 15 days", async () => {
const hypercertsProvider = new HypercertsProvider();
const verifiedPayload = await hypercertsProvider.verify({
address: MOCK_ADDRESS,
} as RequestPayload);

expect(verifiedPayload).toEqual({
valid: true,
record: {
address: MOCK_ADDRESS_LOWER,
},
});

expect(mockedAxiosPost).toBeCalledTimes(1);
});

it("should handle claims less than 15 days old", async () => {
mockedAxiosPost.mockResolvedValueOnce({
data: {
data: {
claimTokens: [
{
id: "1",
owner: MOCK_ADDRESS_LOWER,
tokenID: "1",
units: "100",
claim: {
id: "1",
// This timestamp corresponds to "2023-01-20T00:00:00.000Z" (less than 15 days ago)
creation: "1676889600",
uri: "https://hypercerts.com/token/1",
totalUnits: "1000",
},
},
{
id: "2",
owner: MOCK_ADDRESS_LOWER,
tokenID: "2",
units: "100",
claim: {
id: "2",
// Valid TS
creation: "1632189185",
uri: "https://hypercerts.com/token/2",
totalUnits: "1000",
},
},
],
},
},
});

const hypercertsProvider = new HypercertsProvider();
const verifiedPayload = await hypercertsProvider.verify({
address: MOCK_ADDRESS,
} as RequestPayload);

expect(verifiedPayload).toEqual({
valid: false,
record: {
address: MOCK_ADDRESS_LOWER,
},
});

expect(mockedAxiosPost).toBeCalledTimes(1);
});
});

0 comments on commit aa34ad7

Please sign in to comment.