git.delta.rocks / unique-network / refs/commits / c4efebc46da8

difftreelog

test transfer already nested token + destroy a non-empty collection + additional refactoring

Fahrrader2022-05-30parent: #b46fb6f.patch.diff
in: master

7 files changed

modifiedtests/package.jsondiffbeforeafterboth
54 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",54 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
55 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",55 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",
56 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",56 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
57 "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts",
57 "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",58 "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",
58 "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",59 "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",
59 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",60 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",
modifiedtests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth
29 const data = [29 const data = [
30 {30 {
31 owner: {substrate: alice.address},31 owner: {substrate: alice.address},
32 // constData: '0x0000',
33 }, {32 }, {
34 owner: {substrate: bob.address},33 owner: {substrate: bob.address},
35 // constData: '0x2222',
36 }, {34 }, {
37 owner: {substrate: charlie.address},35 owner: {substrate: charlie.address},
38 // constData: '0x4444',
39 },36 },
40 ];37 ];
4138
57 const data = [54 const data = [
58 {55 {
59 owner: {substrate: alice.address},56 owner: {substrate: alice.address},
60 // constData: '0x1111',
61 properties: [{key: 'k', value: 'v1'}],57 properties: [{key: 'k', value: 'v1'}],
62 }, {58 }, {
63 owner: {substrate: bob.address},59 owner: {substrate: bob.address},
64 // constData: '0x2222',
65 properties: [{key: 'k', value: 'v2'}],60 properties: [{key: 'k', value: 'v2'}],
66 }, {61 }, {
67 owner: {substrate: charlie.address},62 owner: {substrate: charlie.address},
68 // constData: '0x4444',
69 properties: [{key: 'k', value: 'v3'}],63 properties: [{key: 'k', value: 'v3'}],
70 },64 },
71 ];65 ];
88 const data = [82 const data = [
89 {83 {
90 owner: {substrate: alice.address},84 owner: {substrate: alice.address},
91 // constData: '0x0000',
92 properties: [{key: 'k', value: 'v1'}],85 properties: [{key: 'k', value: 'v1'}],
93 }, {86 }, {
94 owner: {substrate: bob.address},87 owner: {substrate: bob.address},
95 // constData: '0x2222',
96 properties: [{key: 'k', value: 'v2'}],88 properties: [{key: 'k', value: 'v2'}],
97 }, {89 }, {
98 owner: {substrate: charlie.address},90 owner: {substrate: charlie.address},
99 // constData: '0x4444',
100 properties: [{key: 'k', value: 'v3'}],91 properties: [{key: 'k', value: 'v3'}],
101 },92 },
102 ];93 ];
119 const data = [110 const data = [
120 {111 {
121 owner: {substrate: alice.address},112 owner: {substrate: alice.address},
122 // constData: '0x0000',
123 properties: [{key: 'k', value: 'v1'}],113 properties: [{key: 'k', value: 'v1'}],
124 }, {114 }, {
125 owner: {substrate: bob.address},115 owner: {substrate: bob.address},
126 // constData: '0x2222',
127 properties: [{key: 'k', value: 'v2'}],116 properties: [{key: 'k', value: 'v2'}],
128 }, {117 }, {
129 owner: {substrate: charlie.address},118 owner: {substrate: charlie.address},
130 // constData: '0x4444',
131 properties: [{key: 'k', value: 'v3'}],119 properties: [{key: 'k', value: 'v3'}],
132 },120 },
133 ];121 ];
272 const data = [260 const data = [
273 {261 {
274 owner: {substrate: alice.address},262 owner: {substrate: alice.address},
275 // constData: '0x0000',
276 }, {263 }, {
277 owner: {substrate: bob.address},264 owner: {substrate: bob.address},
278 // constData: '0x2222',
279 }, {265 }, {
280 owner: {substrate: charlie.address},266 owner: {substrate: charlie.address},
281 // constData: '0x4444',
282 },267 },
283 ];268 ];
284269
300 const data = [285 const data = [
301 {286 {
302 owner: {substrate: alice.address},287 owner: {substrate: alice.address},
303 // constData: '0x0000',
304 }, {288 }, {
305 owner: {substrate: bob.address},289 owner: {substrate: bob.address},
306 // constData: '0x2222',
307 }, {290 }, {
308 owner: {substrate: charlie.address},291 owner: {substrate: charlie.address},
309 // constData: '0x4444',
310 },292 },
311 ];293 ];
312294
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
25 setCollectionLimitsExpectSuccess,25 setCollectionLimitsExpectSuccess,
26 addCollectionAdminExpectSuccess,26 addCollectionAdminExpectSuccess,
27 getCreatedCollectionCount,27 getCreatedCollectionCount,
28 createItemExpectSuccess,
28} from './util/helpers';29} from './util/helpers';
2930
30chai.use(chaiAsPromised);31chai.use(chaiAsPromised);
8384
84 await destroyCollectionExpectFailure(collectionId, '//Alice');85 await destroyCollectionExpectFailure(collectionId, '//Alice');
85 });86 });
87 it('fails when a collection still has a token', async () => {
88 const collectionId = await createCollectionExpectSuccess();
89 await createItemExpectSuccess(alice, collectionId, 'NFT');
90
91 await destroyCollectionExpectFailure(collectionId, '//Alice');
92 });
86});93});
8794
modifiedtests/src/nesting/migration-check.test.tsdiffbeforeafterboth
31 name: strToUTF16('Mojave Pictures'),31 name: strToUTF16('Mojave Pictures'),
32 description: strToUTF16('$2.2 billion power plant!'),32 description: strToUTF16('$2.2 billion power plant!'),
33 tokenPrefix: '0x0002030',33 tokenPrefix: '0x0002030',
34 offchainSchema: '0x111111',34 //offchainSchema: '0x111111',
35 schemaVersion: 'Unique',35 //schemaVersion: 'Unique',
36 limits: {36 limits: {
37 accountTokenOwnershipLimit: 3,37 accountTokenOwnershipLimit: 3,
38 },38 },
39 constOnChainSchema: '0x333333',39 //constOnChainSchema: '0x333333',
40 });40 });
41 const events = await submitTransactionAsync(alice, tx);41 const events = await submitTransactionAsync(alice, tx);
42 const result = getCreateCollectionResult(events);42 const result = getCreateCollectionResult(events);
96 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;96 const collectionNew = (await api.query.common.collectionById(collectionId)).toJSON() as any;
9797
98 // Make sure the extra fields are what they should be98 // Make sure the extra fields are what they should be
99 const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');99 //const constOnChainSchema = await api.query.common.collectionData(collectionId, 'ConstOnChainSchema');
100 const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');100 //const offchainSchema = await api.query.common.collectionData(collectionId, 'OffchainSchema');
101101
102 expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);102 //expect(constOnChainSchema.toHex()).to.be.deep.equal(collectionOld.constOnChainSchema);
103 expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);103 //expect(offchainSchema.toHex()).to.be.deep.equal(collectionOld.offchainSchema);
104 expect(collectionNew).to.have.nested.property('limits.nestingRule');104 expect(collectionNew).to.have.nested.property('limits.nestingRule');
105105
106 // Get rid of extra fields to perform comparison on the rest of the collection106 // Get rid of extra fields to perform comparison on the rest of the collection
107 delete collectionNew.limits.nestingRule;107 delete collectionNew.limits.nestingRule;
108 delete collectionOld.constOnChainSchema;108 //delete collectionOld.constOnChainSchema;
109 delete collectionOld.offchainSchema;109 //delete collectionOld.offchainSchema;
110110
111 expect(collectionNew).to.be.deep.equal(collectionOld);111 expect(collectionNew).to.be.deep.equal(collectionOld);
112 });112 });
modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
10 enablePublicMintingExpectSuccess,10 enablePublicMintingExpectSuccess,
11 getTokenOwner,11 getTokenOwner,
12 getTopmostTokenOwner,12 getTopmostTokenOwner,
13 normalizeAccountId,
13 setCollectionPermissionsExpectSuccess,14 setCollectionPermissionsExpectSuccess,
14 transferExpectFailure,15 transferExpectFailure,
15 transferExpectSuccess,16 transferExpectSuccess,
28 });29 });
29 });30 });
3031
31 it('Performs the full suite: bundles a token, transfers, and allows to unnest', async () => {32 it('Performs the full suite: bundles a token, transfers, and unnests', async () => {
32 await usingApi(async api => {33 await usingApi(async api => {
33 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});34 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
34 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});35 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
58 });59 });
59 });60 });
61
62 it('Transfers an already bundled token', async () => {
63 await usingApi(async api => {
64 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
65 await setCollectionPermissionsExpectSuccess(alice, collection, {nesting: 'Owner'});
66
67 const tokenA = await createItemExpectSuccess(alice, collection, 'NFT');
68 const tokenB = await createItemExpectSuccess(alice, collection, 'NFT');
69
70 // Create a nested token
71 const tokenC = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: tokenIdToAddress(collection, tokenA)});
72 expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});
73 expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenA).toLowerCase()});
74
75 // Transfer the nested token to another token
76 await expect(executeTransaction(
77 api,
78 alice,
79 api.tx.unique.transferFrom(
80 normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenA)}),
81 normalizeAccountId({Ethereum: tokenIdToAddress(collection, tokenB)}),
82 collection, tokenC, 1),
83 )).to.not.be.rejected;
84 expect(await getTopmostTokenOwner(api, collection, tokenC)).to.be.deep.equal({Substrate: alice.address});
85 expect(await getTokenOwner(api, collection, tokenC)).to.be.deep.equal({Ethereum: tokenIdToAddress(collection, tokenB).toLowerCase()});
86 });
87 });
6088
61 // ---------- Non-Fungible ----------89 // ---------- Non-Fungible ----------
6290
modifiedtests/src/setChainLimits.test.tsdiffbeforeafterboth
43 nftSponsorTransferTimeout: 1,43 nftSponsorTransferTimeout: 1,
44 fungibleSponsorTransferTimeout: 1,44 fungibleSponsorTransferTimeout: 1,
45 refungibleSponsorTransferTimeout: 1,45 refungibleSponsorTransferTimeout: 1,
46 offchainSchemaLimit: 1,
47 constOnChainSchemaLimit: 1,
48 };46 };
49 });47 });
50 });48 });
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
135 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}
141141
142export 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};
325323
326export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {324export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
783 });781 });
784}782}
785
786/*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);
791
792 expect(result.success).to.be.true;
793 });
794}
795
796export 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}*/
802783
803export 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,