Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(app): checking onchain badges to see if hash used before, adding tests #2962

Merged
merged 7 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/.env-example.env
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,4 @@ NEXT_PUBLIC_GA_ID=id
NEXT_PUBLIC_SCROLL_BADGE_PROVIDER_INFO='[{"badgeContractAddress":"0x71A848A38fFCcA5c7A431F2BB411Ab632Fa0c456","title":"Passport Developer","providers":[{"level":100,"name":"DeveloperList#ContributorPassport10#b1933500","image":"https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent1.svg"},{"level":200,"name":"DeveloperList#ContributorPassport20#a4d87d4e","image":"https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent1.svg"},{"level":300,"name":"DeveloperList#ContributorPassport30#4f1f3558","image":"https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent1.svg"}]},{"badgeContractAddress":"0x71A848A38fFCcA5c7A431F2BB411Ab632Fa0c456","title":"Passport Developer 2","providers":[{"level":100,"name":"DeveloperList#ContributorPassport10#b1933500","image":"https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent1.svg"},{"level":200,"name":"DeveloperList#ContributorPassport20#a4d87d4e","image":"https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent1.svg"},{"level":300,"name":"DeveloperList#ContributorPassport30#4f1f3558","image":"https://raw.githubusercontent.com/passportxyz/passport/10533495e270f7f0706e16d0d7c8ff0e68aa6c34/app/public/assets/zkInfraTalent1.svg"}]}]'
# testnet
NEXT_PUBLIC_SCROLL_CAMPAIGN_CHAIN_ID=0x8274f
NEXT_PUBLIC_SCROLL_CANVAS_PROFILE_REGISTRY_ADDRESS=
46 changes: 30 additions & 16 deletions app/__tests__/components/ScrollCampaign.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import { useScrollBadge } from "../../hooks/useScrollBadge";
import { ScrollStepsBar } from "../../components/scroll/ScrollLayout";
import { useMintBadge } from "../../hooks/useMintBadge";
import { ProviderWithTitle } from "../../components/ScrollCampaign";
import { ethers } from "ethers";
import { scrollCampaignChain } from "../../config/scroll_campaign";

jest.mock("@gitcoin/passport-database-client");
jest.mock("ethers");

const navigateMock = jest.fn();
jest.mock("react-router-dom", () => ({
Expand Down Expand Up @@ -49,8 +52,6 @@ jest.mock("../../utils/helpers", () => {
});

jest.mock("../../config/scroll_campaign", () => {
const originalModule = jest.requireActual("../../config/scroll_campaign");

const mockBadgeProviders = [
{
badgeContractAddress: "0xMockContractAddress",
Expand All @@ -75,13 +76,13 @@ jest.mock("../../config/scroll_campaign", () => {
};

return {
...originalModule,
badgeContractInfo: mockBadgeProviders,
scrollCampaignBadgeProviderInfo: mockScrollCampaignBadgeProviderInfo,
scrollCampaignBadgeProviders: ["SomeDeveloperProvider"],
loadBadgeProviders: jest.fn().mockImplementation(() => {
return mockBadgeProviders;
}),
scrollCampaignChain: { id: "0x1", rpcUrl: "https://example.com" },
};
});

Expand Down Expand Up @@ -312,9 +313,6 @@ describe("Github Connect page tests", () => {
</MemoryRouter>
);

// const canvasRedirectButton = screen.queryByTestId("canvasRedirectButton");
// expect(canvasRedirectButton).toBeInTheDocument();

expect(navigateMock).toHaveBeenCalledTimes(1);
});
});
Expand Down Expand Up @@ -403,22 +401,36 @@ describe("ScrollCampaign Step 2 (Mint Badge) tests", () => {
it("renders ScrollMintingBadge when syncingToChain is true", async () => {
(useParams as jest.Mock).mockReturnValue({ campaignId: "scroll-developer", step: "2" });

const earnedBadges: ProviderWithTitle[] = [
{
name: "SomeDeveloperProvider" as PROVIDER_ID,
title: "Mock Badge Title",
image: "mockImage.png",
level: 1,
(mockDatabase.getPassport as jest.Mock).mockResolvedValue({
status: "Success",
passport: {
stamps: [
{
provider: "SomeDeveloperProvider",
credential: {
credentialSubject: {
hash: "hash:0xMockHash",
},
},
},
],
},
];
});

(useMintBadge as jest.Mock).mockReturnValue({
onMint: jest.fn(),
syncingToChain: true,
earnedBadges: earnedBadges,
badgesFreshlyMinted: false,
});

const mockContract = {
getProfile: jest.fn().mockResolvedValue("0xMockProfileAddress"),
isProfileMinted: jest.fn().mockResolvedValue(true),
burntProviderHashes: jest.fn().mockResolvedValue(false),
};

(ethers.Contract as jest.Mock).mockImplementation(() => mockContract);

renderWithContext(
mockCeramicContext,
<MemoryRouter initialEntries={["/campaign/scroll-developer/2"]}>
Expand All @@ -427,9 +439,11 @@ describe("ScrollCampaign Step 2 (Mint Badge) tests", () => {
);

// Verify that the ScrollMintingBadge component is rendered
expect(screen.getByText("Minting badges...")).toBeInTheDocument();
expect(screen.getByText("Minting badge...")).toBeInTheDocument();

// Check that the badges are displayed
expect(screen.getByText("Mock Badge Title")).toBeInTheDocument();
await waitFor(() => {
expect(screen.getByText("Mock Badge Title")).toBeInTheDocument();
});
});
});
Loading
Loading