Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nialexsan committed Oct 3, 2024
1 parent 533199f commit b0eadc3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 78 deletions.
8 changes: 4 additions & 4 deletions cadence/__test__/src/nftcatalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const deployNFTCatalog = async () => {
await deployContractByName({ to: NFTCatalogAdmin, name: 'NFTCatalogAdmin' })
}

export const updateSnapshotAdmin = async(catalogAccount, collections) => {
export const updateSnapshotAdmin = async (catalogAccount, collections) => {
const name = 'update_snapshot_admin';

const args = [collections]
Expand All @@ -19,7 +19,7 @@ export const updateSnapshotAdmin = async(catalogAccount, collections) => {
return sendTransaction({ name, args, signers });
}

export const updateShouldUseSnapshotAdmin = async(catalogAccount, shouldUseSnapshot) => {
export const updateShouldUseSnapshotAdmin = async (catalogAccount, shouldUseSnapshot) => {
const name = 'set_snapshot_enabled_admin';

const args = [shouldUseSnapshot]
Expand Down Expand Up @@ -84,9 +84,9 @@ export const sendAdminProxyCapability = async (ownerAccount) => {
return sendTransaction({ name, args, signers });
}

export const proposeNFTToCatalog = async (account, collectionIdentifier, contractName, contractAddress, nftTypeIdentifier, storagePathIdentifier, publicPathIdentifier, publicLinkedTypeIdentifier, publicLinkedTypeRestrictions, collectionName, collectionDescription, externalURL, squareURL, squareMediaType, bannerURL, bannerMediaType, socials, message) => {
export const proposeNFTToCatalog = async (account, collectionIdentifier, contractName, contractAddress, nftTypeIdentifier, storagePathIdentifier, publicPathIdentifier, publicLinkedTypeIdentifier, collectionName, collectionDescription, externalURL, squareURL, squareMediaType, bannerURL, bannerMediaType, socials, message) => {
const name = 'propose_nft_to_catalog';
const args = [collectionIdentifier, contractName, contractAddress, nftTypeIdentifier, storagePathIdentifier, publicPathIdentifier, publicLinkedTypeIdentifier, publicLinkedTypeRestrictions, collectionName, collectionDescription, externalURL, squareURL, squareMediaType, bannerURL, bannerMediaType, socials, message];
const args = [collectionIdentifier, contractName, contractAddress, nftTypeIdentifier, storagePathIdentifier, publicPathIdentifier, publicLinkedTypeIdentifier, collectionName, collectionDescription, externalURL, squareURL, squareMediaType, bannerURL, bannerMediaType, socials, message];
const signers = [account];

return sendTransaction({ name, args, signers });
Expand Down
139 changes: 65 additions & 74 deletions cadence/__test__/test/nftcatalog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,37 +485,37 @@ describe("NFT Catalog Test Suite", () => {
)
);

let [result, error] = await shallResolve(
const [result1, error1] = await shallResolve(
getNFTInAccountFromPath(Bob, "exampleNFTCollection", 0)
);

await proposeNFTToCatalogWithData(
Bob,
nftCreationEvent,
nftTypeIdentifier,
result
result1
);

[result, error] = await shallResolve(
const [result2, error2] = await shallResolve(
getNFTMetadataForCollectionIdentifier("ExampleNFT")
);
expect(result).toBe(null);
expect(result2).toBe(null);

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result.status).toBe("IN_REVIEW");
expect(result.collectionIdentifier).toBe(nftCreationEvent.data.contract);
const [result3, error3] = await shallResolve(getNFTProposalForID(1));
expect(result3.status).toBe("IN_REVIEW");
expect(result3.collectionIdentifier).toBe(nftCreationEvent.data.contract);

await shallPass(approveNFTProposal(Alice, 1));

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result.status).toBe("APPROVED");
const [result4, error4] = await shallResolve(getNFTProposalForID(1));
expect(result4.status).toBe("APPROVED");

[result, error] = await shallResolve(
const [result5, error5] = await shallResolve(
getNFTMetadataForCollectionIdentifier("ExampleNFT")
);
expect(result).not.toBe(null);
expect(result.contractName).toBe(nftCreationEvent.data.contract);
expect(error).toBe(null);
expect(result5).not.toBe(null);
expect(result5.contractName).toBe(nftCreationEvent.data.contract);
expect(error5).toBe(null);
});

it("should be able to make proposals to update", async () => {
Expand Down Expand Up @@ -550,62 +550,62 @@ describe("NFT Catalog Test Suite", () => {
)
);

let [result, error] = await shallResolve(
const [result1, error1] = await shallResolve(
getNFTInAccountFromPath(Bob, "exampleNFTCollection", 0)
);

await proposeNFTToCatalogWithData(
Bob,
nftCreationEvent,
nftTypeIdentifier,
result
result1
);

[result, error] = await shallResolve(
const [result2, error2] = await shallResolve(
getNFTMetadataForCollectionIdentifier("ExampleNFT")
);
expect(result).toBe(null);
expect(result2).toBe(null);

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result.status).toBe("IN_REVIEW");
expect(result.collectionIdentifier).toBe(nftCreationEvent.data.contract);
const [result3, error3] = await shallResolve(getNFTProposalForID(1));
expect(result3.status).toBe("IN_REVIEW");
expect(result3.collectionIdentifier).toBe(nftCreationEvent.data.contract);

await shallPass(approveNFTProposal(Alice, 1));

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result.status).toBe("APPROVED");
const [result4, error4] = await shallResolve(getNFTProposalForID(1));
expect(result4.status).toBe("APPROVED");

[result, error] = await shallResolve(
const [result5, error5] = await shallResolve(
getNFTMetadataForCollectionIdentifier("ExampleNFT")
);
expect(result).not.toBe(null);
expect(result.contractName).toBe(nftCreationEvent.data.contract);
expect(error).toBe(null);
expect(result5).not.toBe(null);
expect(result5.contractName).toBe(nftCreationEvent.data.contract);
expect(error5).toBe(null);

// test updating path
[result, error] = await shallResolve(
const [result6, error6] = await shallResolve(
getNFTInAccountFromPath(Bob, "exampleNFTCollection", 0)
);

await proposeNFTToCatalogWithData(
Bob,
nftCreationEvent,
nftTypeIdentifier,
result
result6
);

[result, error] = await shallResolve(getNFTProposalForID(2));
expect(result.status).toBe("IN_REVIEW");
expect(result.collectionIdentifier).toBe(nftCreationEvent.data.contract);
const [result7, error7] = await shallResolve(getNFTProposalForID(2));
expect(result7.status).toBe("IN_REVIEW");
expect(result7.collectionIdentifier).toBe(nftCreationEvent.data.contract);

await shallPass(approveNFTProposal(Alice, 2));

[result, error] = await shallResolve(
const [result8, error8] = await shallResolve(
getNFTMetadataForCollectionIdentifier("ExampleNFT")
);
expect(result).not.toBe(null);
expect(result.contractName).toBe(nftCreationEvent.data.contract);
expect(error).toBe(null);
expect(result8).not.toBe(null);
expect(result8.contractName).toBe(nftCreationEvent.data.contract);
expect(error8).toBe(null);
});

it("should be able to reject proposals", async () => {
Expand Down Expand Up @@ -640,35 +640,35 @@ describe("NFT Catalog Test Suite", () => {
)
);

let [result, error] = await shallResolve(
const [result1, error1] = await shallResolve(
getNFTInAccountFromPath(Bob, "exampleNFTCollection", 0)
);

await proposeNFTToCatalogWithData(
Bob,
nftCreationEvent,
nftTypeIdentifier,
result
result1
);

[result, error] = await shallResolve(
const [result2, error2] = await shallResolve(
getNFTMetadataForCollectionIdentifier("ExampleNFT")
);
expect(result).toBe(null);
expect(result2).toBe(null);

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result.status).toBe("IN_REVIEW");
expect(result.collectionIdentifier).toBe(nftCreationEvent.data.contract);
const [result3, error3] = await shallResolve(getNFTProposalForID(1));
expect(result3.status).toBe("IN_REVIEW");
expect(result3.collectionIdentifier).toBe(nftCreationEvent.data.contract);

await shallPass(rejectNFTProposal(Alice, 1));

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result.status).toBe("REJECTED");
const [result4, error4] = await shallResolve(getNFTProposalForID(1));
expect(result4.status).toBe("REJECTED");

[result, error] = await shallResolve(
const [result5, error5] = await shallResolve(
getNFTMetadataForCollectionIdentifier("ExampleNFT")
);
expect(result).toBe(null);
expect(result5).toBe(null);
});

it("should be able to remove proposals", async () => {
Expand Down Expand Up @@ -703,35 +703,35 @@ describe("NFT Catalog Test Suite", () => {
)
);

let [result, error] = await shallResolve(
const [result1, error1] = await shallResolve(
getNFTInAccountFromPath(Bob, "exampleNFTCollection", 0)
);

await proposeNFTToCatalogWithData(
Bob,
nftCreationEvent,
nftTypeIdentifier,
result
result1
);

[result, error] = await shallResolve(
const [result2, error2] = await shallResolve(
getNFTMetadataForCollectionIdentifier("ExampleNFT")
);
expect(result).toBe(null);
expect(result2).toBe(null);

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result.status).toBe("IN_REVIEW");
expect(result.collectionIdentifier).toBe(nftCreationEvent.data.contract);
const [result3, error3] = await shallResolve(getNFTProposalForID(1));
expect(result3.status).toBe("IN_REVIEW");
expect(result3.collectionIdentifier).toBe(nftCreationEvent.data.contract);

await shallPass(removeNFTProposal(Alice, 1));

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result).toBe(null);
const [result4, error4] = await shallResolve(getNFTProposalForID(1));
expect(result4).toBe(null);

[result, error] = await shallResolve(
const [result5, error5] = await shallResolve(
getNFTMetadataForCollectionIdentifier("ExampleNFT")
);
expect(result).toBe(null);
expect(result5).toBe(null);
});

it("should be able to withdraw proposals", async () => {
Expand Down Expand Up @@ -760,28 +760,28 @@ describe("NFT Catalog Test Suite", () => {
)
);

let [result, error] = await shallResolve(
const [result1, error1] = await shallResolve(
getNFTInAccountFromPath(Bob, "exampleNFTCollection", 0)
);

await proposeNFTToCatalogWithData(
Bob,
nftCreationEvent,
nftTypeIdentifier,
result
result1
);

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result.status).toBe("IN_REVIEW");
expect(result.collectionIdentifier).toBe(nftCreationEvent.data.contract);
const [result2, error2] = await shallResolve(getNFTProposalForID(1));
expect(result2.status).toBe("IN_REVIEW");
expect(result2.collectionIdentifier).toBe(nftCreationEvent.data.contract);

const Alice = await getAccountAddress("Alice");
await shallRevert(withdrawNFTProposalFromCatalog(Alice, 1));

await shallPass(withdrawNFTProposalFromCatalog(Bob, 1));

[result, error] = await shallResolve(getNFTProposalForID(1));
expect(result).toBe(null);
const [result3, error3] = await shallResolve(getNFTProposalForID(1));
expect(result3).toBe(null);
});
});

Expand All @@ -804,8 +804,7 @@ const proposeNFTToCatalogWithData = async (
nftTypeIdentifier,
struct.NFTCollectionData.storagePath.identifier,
struct.NFTCollectionData.publicPath.identifier,
struct.NFTCollectionData.publicLinkedType.type.type.typeID,
buildRestrictions(struct.NFTCollectionData.publicLinkedType.type),
struct.NFTCollectionData.publicLinkedType.type.typeID,
struct.NFTCollectionDisplay.collectionName,
struct.NFTCollectionDisplay.collectionDescription,
struct.ExternalURL.externalURL,
Expand All @@ -818,11 +817,3 @@ const proposeNFTToCatalogWithData = async (
)
);
};

const buildRestrictions = (restrictedType) => {
let res = [];
restrictedType.restrictions.forEach((value) => {
res.push(value.typeID);
});
return res;
};

0 comments on commit b0eadc3

Please sign in to comment.