difftreelog
Tests: eth tokenProperties small improvements
in: master
1 file changed
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth1import {cartesian} from './util/helpers';2import {itEth, expect} from '../eth/util/playgrounds';34describe('EVM token properties', () => {5 itEth('Can be reconfigured', async({helper, privateKey}) => {6 const alice = privateKey('//Alice');7 const caller = await helper.eth.createAccountWithBalance(alice);89 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {10 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'ethp'});11 await collection.addAdmin(alice, {Ethereum: caller});1213 const address = helper.ethAddress.fromCollectionId(collection.collectionId);14 const contract = helper.ethNativeContract.collection(address, 'nft', caller);1516 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});17 18 const state = await collection.getPropertyPermissions();19 expect(state).to.be.deep.equal([{20 key: 'testKey',21 permission: {mutable, collectionAdmin, tokenOwner},22 }]);23 }24 });2526 itEth('Can be set', async({helper, privateKey}) => {27 const alice = privateKey('//Alice');28 const caller = await helper.eth.createAccountWithBalance(alice);29 const collection = await helper.nft.mintCollection(alice, {30 tokenPrefix: 'ethp',31 tokenPropertyPermissions: [{32 key: 'testKey',33 permission: {34 collectionAdmin: true,35 },36 }],37 });38 const token = await collection.mintToken(alice);3940 await collection.addAdmin(alice, {Ethereum: caller});4142 const address = helper.ethAddress.fromCollectionId(collection.collectionId);43 const contract = helper.ethNativeContract.collection(address, 'nft', caller);4445 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});4647 const [{value}] = await token.getProperties(['testKey']);48 expect(value).to.equal('testValue');49 });5051 itEth('Can be deleted', async({helper, privateKey}) => {52 const alice = privateKey('//Alice');53 const caller = await helper.eth.createAccountWithBalance(alice);54 const collection = await helper.nft.mintCollection(alice, {55 tokenPrefix: 'ethp',56 tokenPropertyPermissions: [{57 key: 'testKey',58 permission: {59 mutable: true,60 collectionAdmin: true,61 },62 }],63 });6465 await collection.addAdmin(alice, {Ethereum: caller});6667 const token = await collection.mintToken(alice);68 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);6970 const address = helper.ethAddress.fromCollectionId(collection.collectionId);71 const contract = helper.ethNativeContract.collection(address, 'nft', caller);7273 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});7475 const result = await token.getProperties(['testKey']);76 expect(result.length).to.equal(0);77 });7879 itEth('Can be read', async({helper, privateKey}) => {80 const alice = privateKey('//Alice');81 const caller = await helper.eth.createAccountWithBalance(alice);82 const collection = await helper.nft.mintCollection(alice, {83 tokenPrefix: 'ethp',84 tokenPropertyPermissions: [{85 key: 'testKey',86 permission: {87 collectionAdmin: true,88 },89 }],90 });91 const token = await collection.mintToken(alice);92 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);9394 const address = helper.ethAddress.fromCollectionId(collection.collectionId);95 const contract = helper.ethNativeContract.collection(address, 'nft', caller);9697 const value = await contract.methods.property(token.tokenId, 'testKey').call();98 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));99 });100});1import {IKeyringPair} from '@polkadot/types/types';2import {usingPlaygrounds} from './../util/playgrounds/index';3import {itEth, expect} from '../eth/util/playgrounds';45describe('EVM token properties', () => {6 let donor: IKeyringPair;7 let alice: IKeyringPair;89 before(async () => {10 await usingPlaygrounds(async (helper, privateKey) => {11 donor = privateKey('//Alice');12 [alice] = await helper.arrange.createAccounts([1000n], donor);13 });14 });1516 itEth('Can be reconfigured', async({helper}) => {17 const caller = await helper.eth.createAccountWithBalance(donor);1819 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {20 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'ethp'});21 await collection.addAdmin(alice, {Ethereum: caller});2223 const address = helper.ethAddress.fromCollectionId(collection.collectionId);24 const contract = helper.ethNativeContract.collection(address, 'nft', caller);2526 await contract.methods.setTokenPropertyPermission('testKey', mutable, collectionAdmin, tokenOwner).send({from: caller});27 28 const state = await collection.getPropertyPermissions();29 expect(state).to.be.deep.equal([{30 key: 'testKey',31 permission: {mutable, collectionAdmin, tokenOwner},32 }]);33 }34 });3536 itEth('Can be set', async({helper}) => {37 const caller = await helper.eth.createAccountWithBalance(donor);38 const collection = await helper.nft.mintCollection(alice, {39 tokenPrefix: 'ethp',40 tokenPropertyPermissions: [{41 key: 'testKey',42 permission: {43 collectionAdmin: true,44 },45 }],46 });47 const token = await collection.mintToken(alice);4849 await collection.addAdmin(alice, {Ethereum: caller});5051 const address = helper.ethAddress.fromCollectionId(collection.collectionId);52 const contract = helper.ethNativeContract.collection(address, 'nft', caller);5354 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});5556 const [{value}] = await token.getProperties(['testKey']);57 expect(value).to.equal('testValue');58 });5960 itEth('Can be deleted', async({helper}) => {61 const caller = await helper.eth.createAccountWithBalance(donor);62 const collection = await helper.nft.mintCollection(alice, {63 tokenPrefix: 'ethp',64 tokenPropertyPermissions: [{65 key: 'testKey',66 permission: {67 mutable: true,68 collectionAdmin: true,69 },70 }],71 });7273 await collection.addAdmin(alice, {Ethereum: caller});7475 const token = await collection.mintToken(alice);76 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);7778 const address = helper.ethAddress.fromCollectionId(collection.collectionId);79 const contract = helper.ethNativeContract.collection(address, 'nft', caller);8081 await contract.methods.deleteProperty(token.tokenId, 'testKey').send({from: caller});8283 const result = await token.getProperties(['testKey']);84 expect(result.length).to.equal(0);85 });8687 itEth('Can be read', async({helper}) => {88 const caller = await helper.eth.createAccountWithBalance(donor);89 const collection = await helper.nft.mintCollection(alice, {90 tokenPrefix: 'ethp',91 tokenPropertyPermissions: [{92 key: 'testKey',93 permission: {94 collectionAdmin: true,95 },96 }],97 });98 const token = await collection.mintToken(alice);99 await token.setProperties(alice, [{key: 'testKey', value: 'testValue'}]);100101 const address = helper.ethAddress.fromCollectionId(collection.collectionId);102 const contract = helper.ethNativeContract.collection(address, 'nft', caller);103104 const value = await contract.methods.property(token.tokenId, 'testKey').call();105 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));106 });107});108109110type ElementOf<A> = A extends readonly (infer T)[] ? T : never;111function* cartesian<T extends Array<Array<any>>, R extends Array<any>>(internalRest: [...R], ...args: [...T]): Generator<[...R, ...{[K in keyof T]: ElementOf<T[K]>}]> {112 if(args.length === 0) {113 yield internalRest as any;114 return;115 }116 for(const value of args[0]) {117 yield* cartesian([...internalRest, value], ...args.slice(1)) as any;118 }119}