git.delta.rocks / unique-network / refs/commits / 1813dc305c53

difftreelog

source

tests/src/rmrk/setNftProperty.test.ts3.2 KiBsourcehistory
1import { getApiConnection } from "../substrate/substrate-api";2import { NftIdTuple } from "./util/fetch";3import { expectTxFailure } from "./util/helpers";4import { createCollection, mintNft, sendNft, setNftProperty } from "./util/tx";56describe("integration test: set NFT property", () => {7    let api: any;8    before(async () => { api = await getApiConnection(); });910    const alice = "//Alice";11    const bob = "//Bob";1213    const createTestCollection = async (issuerUri: string) => {14        return await createCollection(15            api,16            issuerUri,17            "setprop-nft-collection-metadata",18            null,19            "setprop"20        );21    };2223    it("set NFT property", async () => {24        const ownerAlice = alice;2526        const collectionId = await createTestCollection(alice);27        const nftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-nft");2829        await setNftProperty(api, alice, collectionId, nftId, 'test-key', 'test-key-value');30        await setNftProperty(api, alice, collectionId, nftId, 'test-key', 'updated-key-value');31        await setNftProperty(api, alice, collectionId, nftId, 'second-test-key', 'second-test-key-value');32    });3334    it("[negative] unable to set a property of non-existing NFT", async () => {35        const collectionId = 0;36        const maxNftId = 0xFFFFFFFF;3738        const tx = setNftProperty(api, alice, collectionId, maxNftId, 'test-key', 'test-value');3940        await expectTxFailure(/rmrkCore\.NoAvailableNftId/, tx);41    });4243    it("[negative] unable to set a property by not-an-owner", async () => {44        const ownerAlice = alice;4546        const collectionId = await createTestCollection(alice);47        const nftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-nft");4849        const tx = setNftProperty(api, bob, collectionId, nftId, 'test-key', 'test-key-value');5051        await expectTxFailure(/rmrkCore\.NoPermission/, tx);52    });5354    it("set a property to nested NFT", async () => {55        const ownerAlice = alice;5657        const collectionId = await createTestCollection(alice);58        const parentNftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-parent-nft");59        const childNftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-child-nft");6061        const ownerNft: NftIdTuple = [collectionId, parentNftId];6263        await sendNft(api, "sent", ownerAlice, collectionId, childNftId, ownerNft);6465        await setNftProperty(api, alice, collectionId, childNftId, 'test-key', 'test-key-value');66    });6768    it("[negative] set a property to nested NFT (by not-root-owner)", async () => {69        const ownerAlice = alice;7071        const collectionId = await createTestCollection(alice);72        const parentNftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-parent-nft");73        const childNftId = await mintNft(api, alice, ownerAlice, collectionId, "prop-child-nft");7475        const ownerNft: NftIdTuple = [collectionId, parentNftId];7677        await sendNft(api, "sent", ownerAlice, collectionId, childNftId, ownerNft);7879        const tx = setNftProperty(api, bob, collectionId, childNftId, 'test-key', 'test-key-value');8081        await expectTxFailure(/rmrkCore\.NoPermission/, tx);82    });8384    after(() => { api.disconnect(); });85});