difftreelog
test transfer already nested token + destroy a non-empty collection + additional refactoring
in: master
7 files changed
tests/package.jsondiffbeforeafterboth--- 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",
tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth--- 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',
},
];
tests/src/destroyCollection.test.tsdiffbeforeafterboth--- 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');
+ });
});
tests/src/nesting/migration-check.test.tsdiffbeforeafterboth--- 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);
});
tests/src/nesting/nest.test.tsdiffbeforeafterboth--- 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 () => {
tests/src/setChainLimits.test.tsdiffbeforeafterboth--- 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,
};
});
});
tests/src/util/helpers.tsdiffbeforeafterboth135 nftSponsorTransferTimeout: number;135 nftSponsorTransferTimeout: number;136 fungibleSponsorTransferTimeout: number;136 fungibleSponsorTransferTimeout: number;137 refungibleSponsorTransferTimeout: number;137 refungibleSponsorTransferTimeout: number;138 offchainSchemaLimit: number;138 //offchainSchemaLimit: number;139 constOnChainSchemaLimit: number;139 //constOnChainSchemaLimit: number;140}140}141141142export interface IReFungibleTokenDataType {142export interface IReFungibleTokenDataType {310 name: string,310 name: string,311 description: string,311 description: string,312 tokenPrefix: string,312 tokenPrefix: string,313 schemaVersion: string,314 properties?: Array<Property>,313 properties?: Array<Property>,315 propPerm?: Array<PropertyPermission>314 propPerm?: Array<PropertyPermission>316};315};320 mode: {type: 'NFT'},319 mode: {type: 'NFT'},321 name: 'name',320 name: 'name',322 tokenPrefix: 'prefix',321 tokenPrefix: 'prefix',323 schemaVersion: 'ImageURL',324};322};325323326export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {324export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {783 });781 });784}782}785786/*export async function setOffchainSchemaExpectSuccess(sender: IKeyringPair, collectionId: number, data: number[]) {787 await usingApi(async (api) => {788 const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));789 const events = await submitTransactionAsync(sender, tx);790 const result = getGenericResult(events);791792 expect(result.success).to.be.true;793 });794}795796export async function setOffchainSchemaExpectFailure(sender: IKeyringPair, collectionId: number, data: number[]) {797 await usingApi(async (api) => {798 const tx = api.tx.unique.setOffchainSchema(collectionId, '0x' + Buffer.from(data).toString('hex'));799 await expect(submitTransactionExpectFailAsync(sender, tx)).to.be.rejected;800 });801}*/802783803export interface CreateFungibleData {784export interface CreateFungibleData {804 readonly Value: bigint;785 readonly Value: bigint;1110): Promise<string[]> {1091): Promise<string[]> {1111 return (await api.rpc.unique.adminlist(collectionId)).toHuman() as any;1092 return (await api.rpc.unique.adminlist(collectionId)).toHuman() as any;1112}1093}1113/*export async function getConstMetadata(1114 api: ApiPromise,1115 collectionId: number,1116 tokenId: number,1117): Promise<number[]> {1118 return [...(await api.rpc.unique.constMetadata(collectionId, tokenId))];1119}*/1120export async function getTokenProperties(1094export async function getTokenProperties(1121 api: ApiPromise,1095 api: ApiPromise,1122 collectionId: number,1096 collectionId: number,