difftreelog
chore skip test if refungible pallet is not supported
in: master
2 files changed
tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionProperties.test.ts
+++ b/tests/src/eth/collectionProperties.test.ts
@@ -196,7 +196,7 @@
itEth('Set/read properties ft', async ({helper}) => {
await testSetReadProperties(helper, 'ft');
});
- itEth('Set/read properties rft', async ({helper}) => {
+ itEth.ifWithPallets('Set/read properties rft', [Pallets.ReFungible], async ({helper}) => {
await testSetReadProperties(helper, 'rft');
});
itEth('Set/read properties nft', async ({helper}) => {
@@ -242,7 +242,7 @@
itEth('Delete properties ft', async ({helper}) => {
await testDeleteProperties(helper, 'ft');
});
- itEth('Delete properties rft', async ({helper}) => {
+ itEth.ifWithPallets('Delete properties rft', [Pallets.ReFungible], async ({helper}) => {
await testDeleteProperties(helper, 'rft');
});
itEth('Delete properties nft', async ({helper}) => {
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {itEth, usingEthPlaygrounds, expect} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {ITokenPropertyPermission} from '../util/playgrounds/types';2021describe('EVM token properties', () => {22 let donor: IKeyringPair;23 let alice: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (helper, privateKey) => {27 donor = await privateKey({filename: __filename});28 [alice] = await helper.arrange.createAccounts([100n], donor);29 });30 });3132 itEth('Can be reconfigured', async({helper}) => {33 const caller = await helper.eth.createAccountWithBalance(donor);34 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {35 const collection = await helper.nft.mintCollection(alice);36 await collection.addAdmin(alice, {Ethereum: caller});37 38 const address = helper.ethAddress.fromCollectionId(collection.collectionId);39 const contract = helper.ethNativeContract.collection(address, 'nft', caller);40 41 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});42 43 expect(await collection.getPropertyPermissions()).to.be.deep.equal([{44 key: 'testKey',45 permission: {mutable, collectionAdmin, tokenOwner},46 }]);47 }48 });4950 itEth('Can be set', async({helper}) => {51 const caller = await helper.eth.createAccountWithBalance(donor);52 const collection = await helper.nft.mintCollection(alice, {53 tokenPropertyPermissions: [{54 key: 'testKey',55 permission: {56 collectionAdmin: true,57 },58 }],59 });60 const token = await collection.mintToken(alice);6162 await collection.addAdmin(alice, {Ethereum: caller});6364 const address = helper.ethAddress.fromCollectionId(collection.collectionId);65 const contract = helper.ethNativeContract.collection(address, 'nft', caller);6667 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});6869 const [{value}] = await token.getProperties(['testKey']);70 expect(value).to.equal('testValue');71 });72 73 itEth('Can be multiple set for NFT ', async({helper}) => {74 const caller = await helper.eth.createAccountWithBalance(donor);75 76 const properties = Array(5).fill(0).map((_, i) => { return {field_0: `key_${i}`, field_1: Buffer.from(`value_${i}`)}; });77 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.field_0, permission: {tokenOwner: true,78 collectionAdmin: true,79 mutable: true}}; });80 81 const collection = await helper.nft.mintCollection(alice, {82 tokenPrefix: 'ethp',83 tokenPropertyPermissions: permissions,84 });85 86 const token = await collection.mintToken(alice);87 88 const valuesBefore = await token.getProperties(properties.map(p => p.field_0));89 expect(valuesBefore).to.be.deep.equal([]);90 91 await collection.addAdmin(alice, {Ethereum: caller});9293 const address = helper.ethAddress.fromCollectionId(collection.collectionId);94 const contract = helper.ethNativeContract.collection(address, 'nft', caller);9596 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});9798 const values = await token.getProperties(properties.map(p => p.field_0));99 expect(values).to.be.deep.equal(properties.map(p => { return {key: p.field_0, value: p.field_1.toString()}; }));100 });101 102 itEth('Can be multiple set for RFT ', async({helper}) => {103 const caller = await helper.eth.createAccountWithBalance(donor);104 105 const properties = Array(5).fill(0).map((_, i) => { return {field_0: `key_${i}`, field_1: Buffer.from(`value_${i}`)}; });106 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.field_0, permission: {tokenOwner: true,107 collectionAdmin: true,108 mutable: true}}; });109 110 const collection = await helper.rft.mintCollection(alice, {111 tokenPrefix: 'ethp',112 tokenPropertyPermissions: permissions,113 });114 115 const token = await collection.mintToken(alice);116 117 const valuesBefore = await token.getProperties(properties.map(p => p.field_0));118 expect(valuesBefore).to.be.deep.equal([]);119 120 await collection.addAdmin(alice, {Ethereum: caller});121122 const address = helper.ethAddress.fromCollectionId(collection.collectionId);123 const contract = helper.ethNativeContract.collection(address, 'rft', caller);124125 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});126127 const values = await token.getProperties(properties.map(p => p.field_0));128 expect(values).to.be.deep.equal(properties.map(p => { return {key: p.field_0, value: p.field_1.toString()}; }));129 });130131 itEth('Can be deleted', async({helper}) => {132 const caller = await helper.eth.createAccountWithBalance(donor);133 const collection = await helper.nft.mintCollection(alice, {134 tokenPropertyPermissions: [{135 key: 'testKey',136 permission: {137 mutable: true,138 collectionAdmin: true,139 },140 }],141 });142 143 const token = await collection.mintToken(alice);144 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);145146 await collection.addAdmin(alice, {Ethereum: caller});147148 const address = helper.ethAddress.fromCollectionId(collection.collectionId);149 const contract = helper.ethNativeContract.collection(address, 'nft', caller);150151 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});152153 const result = await token.getProperties(['testKey']);154 expect(result.length).to.equal(0);155 });156157 itEth('Can be read', async({helper}) => {158 const caller = helper.eth.createAccount();159 const collection = await helper.nft.mintCollection(alice, {160 tokenPropertyPermissions: [{161 key: 'testKey',162 permission: {163 collectionAdmin: true,164 },165 }],166 });167 168 const token = await collection.mintToken(alice);169 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);170171 const address = helper.ethAddress.fromCollectionId(collection.collectionId);172 const contract = helper.ethNativeContract.collection(address, 'nft', caller);173174 const value = await contract.methods.property(token.tokenId, 'testKey').call();175 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));176 });177});178179180type ElementOf<A> = A extends readonly (infer T)[] ? T : never;181function* cartesian<T extends Array<Array<any>>, R extends Array<any>>(internalRest: [...R], ...args: [...T]): Generator<[...R, ...{[K in keyof T]: ElementOf<T[K]>}]> {182 if(args.length === 0) {183 yield internalRest as any;184 return;185 }186 for(const value of args[0]) {187 yield* cartesian([...internalRest, value], ...args.slice(1)) as any;188 }189}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {itEth, usingEthPlaygrounds, expect} from './util';18import {IKeyringPair} from '@polkadot/types/types';19import {ITokenPropertyPermission} from '../util/playgrounds/types';20import {Pallets} from '../util';2122describe('EVM token properties', () => {23 let donor: IKeyringPair;24 let alice: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (helper, privateKey) => {28 donor = await privateKey({filename: __filename});29 [alice] = await helper.arrange.createAccounts([100n], donor);30 });31 });3233 itEth('Can be reconfigured', async({helper}) => {34 const caller = await helper.eth.createAccountWithBalance(donor);35 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {36 const collection = await helper.nft.mintCollection(alice);37 await collection.addAdmin(alice, {Ethereum: caller});38 39 const address = helper.ethAddress.fromCollectionId(collection.collectionId);40 const contract = helper.ethNativeContract.collection(address, 'nft', caller);41 42 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});43 44 expect(await collection.getPropertyPermissions()).to.be.deep.equal([{45 key: 'testKey',46 permission: {mutable, collectionAdmin, tokenOwner},47 }]);48 }49 });5051 itEth('Can be set', async({helper}) => {52 const caller = await helper.eth.createAccountWithBalance(donor);53 const collection = await helper.nft.mintCollection(alice, {54 tokenPropertyPermissions: [{55 key: 'testKey',56 permission: {57 collectionAdmin: true,58 },59 }],60 });61 const token = await collection.mintToken(alice);6263 await collection.addAdmin(alice, {Ethereum: caller});6465 const address = helper.ethAddress.fromCollectionId(collection.collectionId);66 const contract = helper.ethNativeContract.collection(address, 'nft', caller);6768 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});6970 const [{value}] = await token.getProperties(['testKey']);71 expect(value).to.equal('testValue');72 });73 74 itEth('Can be multiple set for NFT ', async({helper}) => {75 const caller = await helper.eth.createAccountWithBalance(donor);76 77 const properties = Array(5).fill(0).map((_, i) => { return {field_0: `key_${i}`, field_1: Buffer.from(`value_${i}`)}; });78 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.field_0, permission: {tokenOwner: true,79 collectionAdmin: true,80 mutable: true}}; });81 82 const collection = await helper.nft.mintCollection(alice, {83 tokenPrefix: 'ethp',84 tokenPropertyPermissions: permissions,85 });86 87 const token = await collection.mintToken(alice);88 89 const valuesBefore = await token.getProperties(properties.map(p => p.field_0));90 expect(valuesBefore).to.be.deep.equal([]);91 92 await collection.addAdmin(alice, {Ethereum: caller});9394 const address = helper.ethAddress.fromCollectionId(collection.collectionId);95 const contract = helper.ethNativeContract.collection(address, 'nft', caller);9697 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});9899 const values = await token.getProperties(properties.map(p => p.field_0));100 expect(values).to.be.deep.equal(properties.map(p => { return {key: p.field_0, value: p.field_1.toString()}; }));101 });102 103 itEth.ifWithPallets('Can be multiple set for RFT ', [Pallets.ReFungible], async({helper}) => {104 const caller = await helper.eth.createAccountWithBalance(donor);105 106 const properties = Array(5).fill(0).map((_, i) => { return {field_0: `key_${i}`, field_1: Buffer.from(`value_${i}`)}; });107 const permissions: ITokenPropertyPermission[] = properties.map(p => { return {key: p.field_0, permission: {tokenOwner: true,108 collectionAdmin: true,109 mutable: true}}; });110 111 const collection = await helper.rft.mintCollection(alice, {112 tokenPrefix: 'ethp',113 tokenPropertyPermissions: permissions,114 });115 116 const token = await collection.mintToken(alice);117 118 const valuesBefore = await token.getProperties(properties.map(p => p.field_0));119 expect(valuesBefore).to.be.deep.equal([]);120 121 await collection.addAdmin(alice, {Ethereum: caller});122123 const address = helper.ethAddress.fromCollectionId(collection.collectionId);124 const contract = helper.ethNativeContract.collection(address, 'rft', caller);125126 await contract.methods.setProperties(token.tokenId, properties).send({from: caller});127128 const values = await token.getProperties(properties.map(p => p.field_0));129 expect(values).to.be.deep.equal(properties.map(p => { return {key: p.field_0, value: p.field_1.toString()}; }));130 });131132 itEth('Can be deleted', async({helper}) => {133 const caller = await helper.eth.createAccountWithBalance(donor);134 const collection = await helper.nft.mintCollection(alice, {135 tokenPropertyPermissions: [{136 key: 'testKey',137 permission: {138 mutable: true,139 collectionAdmin: true,140 },141 }],142 });143 144 const token = await collection.mintToken(alice);145 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);146147 await collection.addAdmin(alice, {Ethereum: caller});148149 const address = helper.ethAddress.fromCollectionId(collection.collectionId);150 const contract = helper.ethNativeContract.collection(address, 'nft', caller);151152 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});153154 const result = await token.getProperties(['testKey']);155 expect(result.length).to.equal(0);156 });157158 itEth('Can be read', async({helper}) => {159 const caller = helper.eth.createAccount();160 const collection = await helper.nft.mintCollection(alice, {161 tokenPropertyPermissions: [{162 key: 'testKey',163 permission: {164 collectionAdmin: true,165 },166 }],167 });168 169 const token = await collection.mintToken(alice);170 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);171172 const address = helper.ethAddress.fromCollectionId(collection.collectionId);173 const contract = helper.ethNativeContract.collection(address, 'nft', caller);174175 const value = await contract.methods.property(token.tokenId, 'testKey').call();176 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));177 });178});179180181type ElementOf<A> = A extends readonly (infer T)[] ? T : never;182function* cartesian<T extends Array<Array<any>>, R extends Array<any>>(internalRest: [...R], ...args: [...T]): Generator<[...R, ...{[K in keyof T]: ElementOf<T[K]>}]> {183 if(args.length === 0) {184 yield internalRest as any;185 return;186 }187 for(const value of args[0]) {188 yield* cartesian([...internalRest, value], ...args.slice(1)) as any;189 }190}