--- a/tests/package.json +++ b/tests/package.json @@ -54,6 +54,7 @@ "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts", "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts", "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts", + "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts", "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts", "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts", "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts", --- a/tests/src/createMultipleItemsEx.test.ts +++ b/tests/src/createMultipleItemsEx.test.ts @@ -29,13 +29,10 @@ const data = [ { owner: {substrate: alice.address}, - // constData: '0x0000', }, { owner: {substrate: bob.address}, - // constData: '0x2222', }, { owner: {substrate: charlie.address}, - // constData: '0x4444', }, ]; @@ -57,15 +54,12 @@ const data = [ { owner: {substrate: alice.address}, - // constData: '0x1111', properties: [{key: 'k', value: 'v1'}], }, { owner: {substrate: bob.address}, - // constData: '0x2222', properties: [{key: 'k', value: 'v2'}], }, { owner: {substrate: charlie.address}, - // constData: '0x4444', properties: [{key: 'k', value: 'v3'}], }, ]; @@ -88,15 +82,12 @@ const data = [ { owner: {substrate: alice.address}, - // constData: '0x0000', properties: [{key: 'k', value: 'v1'}], }, { owner: {substrate: bob.address}, - // constData: '0x2222', properties: [{key: 'k', value: 'v2'}], }, { owner: {substrate: charlie.address}, - // constData: '0x4444', properties: [{key: 'k', value: 'v3'}], }, ]; @@ -119,15 +110,12 @@ const data = [ { owner: {substrate: alice.address}, - // constData: '0x0000', properties: [{key: 'k', value: 'v1'}], }, { owner: {substrate: bob.address}, - // constData: '0x2222', properties: [{key: 'k', value: 'v2'}], }, { owner: {substrate: charlie.address}, - // constData: '0x4444', properties: [{key: 'k', value: 'v3'}], }, ]; @@ -272,13 +260,10 @@ const data = [ { owner: {substrate: alice.address}, - // constData: '0x0000', }, { owner: {substrate: bob.address}, - // constData: '0x2222', }, { owner: {substrate: charlie.address}, - // constData: '0x4444', }, ]; @@ -300,13 +285,10 @@ const data = [ { owner: {substrate: alice.address}, - // constData: '0x0000', }, { owner: {substrate: bob.address}, - // constData: '0x2222', }, { owner: {substrate: charlie.address}, - // constData: '0x4444', }, ]; --- a/tests/src/destroyCollection.test.ts +++ b/tests/src/destroyCollection.test.ts @@ -25,6 +25,7 @@ setCollectionLimitsExpectSuccess, addCollectionAdminExpectSuccess, getCreatedCollectionCount, + createItemExpectSuccess, } from './util/helpers'; chai.use(chaiAsPromised); @@ -83,4 +84,10 @@ await destroyCollectionExpectFailure(collectionId, '//Alice'); }); + it('fails when a collection still has a token', async () => { + const collectionId = await createCollectionExpectSuccess(); + await createItemExpectSuccess(alice, collectionId, 'NFT'); + + await destroyCollectionExpectFailure(collectionId, '//Alice'); + }); }); --- a/tests/src/nesting/migration-check.test.ts +++ b/tests/src/nesting/migration-check.test.ts @@ -31,12 +31,12 @@ name: strToUTF16('Mojave Pictures'), description: strToUTF16('$2.2 billion power plant!'), tokenPrefix: '0x0002030', - offchainSchema: '0x111111', - schemaVersion: 'Unique', + //offchainSchema: '0x111111', + //schemaVersion: 'Unique', limits: { accountTokenOwnershipLimit: 3, }, - constOnChainSchema: '0x333333', + //constOnChainSchema: '0x333333', }); const events = await submitTransactionAsync(alice, tx); const result = getCreateCollectionResult(events); @@ -96,17 +96,17 @@ const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any; // Make sure the extra fields are what they should be - const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema'); - const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema'); + //const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema'); + //const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema'); - expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema); - expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema); + //expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema); + //expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema); expect(collectionNew).to.have.nested.property('limits.nestingRule'); // Get rid of extra fields to perform comparison on the rest of the collection delete collectionNew.limits.nestingRule; - delete collectionOld.constOnChainSchema; - delete collectionOld.offchainSchema; + //delete collectionOld.constOnChainSchema; + //delete collectionOld.offchainSchema; expect(collectionNew).to.be.deep.equal(collectionOld); }); --- a/tests/src/nesting/nest.test.ts +++ b/tests/src/nesting/nest.test.ts @@ -10,6 +10,7 @@ enablePublicMintingExpectSuccess, getTokenOwner, getTopmostTokenOwner, + normalizeAccountId, setCollectionPermissionsExpectSuccess, transferExpectFailure, transferExpectSuccess, @@ -28,7 +29,7 @@ }); }); - it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => { + it('Performs the full suite: bundles a token, transfers, and unnests', async () => { await usingApi(async api => { const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'}); @@ -58,6 +59,33 @@ }); }); + it('Transfers an already bundled token', async () => { + await usingApi(async api => { + const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); + await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'}); + + const tokenA = await createItemExpectSuccess(alice, collection, 'NFT'); + const tokenB = await createItemExpectSuccess(alice, collection, 'NFT'); + + // Create a nested token + const tokenC = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)}); + expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address}); + expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenA).toLowerCase()}); + + // Transfer the nested token to another token + await expect(executeTransaction( + api, + alice, + api.tx.unique.transferFrom( + normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}), + normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}), + collection, tokenC, 1), + )).to.not.be.rejected; + expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address}); + expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenB).toLowerCase()}); + }); + }); + // ---------- Non-Fungible ---------- it('NFT: allows an Owner to nest/unnest their token', async () => { --- a/tests/src/setChainLimits.test.ts +++ b/tests/src/setChainLimits.test.ts @@ -43,8 +43,6 @@ nftSponsorTransferTimeout: 1, fungibleSponsorTransferTimeout: 1, refungibleSponsorTransferTimeout: 1, - offchainSchemaLimit: 1, - constOnChainSchemaLimit: 1, }; }); }); --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -135,8 +135,8 @@ nftSponsorTransferTimeout: number; fungibleSponsorTransferTimeout: number; refungibleSponsorTransferTimeout: number; - offchainSchemaLimit: number; - constOnChainSchemaLimit: number; + //offchainSchemaLimit: number; + //constOnChainSchemaLimit: number; } export interface IReFungibleTokenDataType { @@ -310,7 +310,6 @@ name: string, description: string, tokenPrefix: string, - schemaVersion: string, properties?: Array, propPerm?: Array }; @@ -320,7 +319,6 @@ mode: {type: 'NFT'}, name: 'name', tokenPrefix: 'prefix', - schemaVersion: 'ImageURL', }; export async function createCollectionExpectSuccess(params: Partial = {}): Promise { @@ -780,25 +778,8 @@ const result = getGenericResult(events); expect(result.success).to.be.false; - }); -} - -/*export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) { - await usingApi(async (api) => { - const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex')); - const events = await submitTransactionAsync(sender, tx); - const result = getGenericResult(events); - - expect(result.success).to.be.true; }); } - -export async function setOffchainSchemaExpectFailure(sender: IKeyringPair, collectionId: number, data: number[]) { - await usingApi(async (api) => { - const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex')); - await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected; - }); -}*/ export interface CreateFungibleData { readonly Value: bigint; @@ -1110,13 +1091,6 @@ ): Promise { return (await api.rpc.unique.adminlist(collectionId)).toHuman() as any; } -/*export async function getConstMetadata( - api: ApiPromise, - collectionId: number, - tokenId: number, -): Promise { - return [...(await api.rpc.unique.constMetadata(collectionId, tokenId))]; -}*/ export async function getTokenProperties( api: ApiPromise, collectionId: number,