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

difftreelog

source

tests/src/eth/collectionProperties.test.ts3.1 KiBsourcehistory
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/playgrounds';18import {IKeyringPair} from '@polkadot/types/types';1920describe('EVM collection properties', () => {21  let donor: IKeyringPair;22  let alice: IKeyringPair;2324  before(async function() {25    await usingEthPlaygrounds(async (_helper, privateKey) => {26      donor = await privateKey({filename: __filename});27      [alice] = await _helper.arrange.createAccounts([10n], donor);28    });29  });3031  itEth('Can be set', async({helper}) => {32    const caller = await helper.eth.createAccountWithBalance(donor);33    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test'});34    await collection.addAdmin(alice, {Ethereum: caller});3536    const address = helper.ethAddress.fromCollectionId(collection.collectionId);37    const contract = helper.ethNativeContract.collection(address, 'nft', caller);3839    await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});4041    const raw = (await collection.getData())?.raw;4243    expect(raw.properties[0].value).to.equal('testValue');44  });4546  itEth('Can be deleted', async({helper}) => {47    const caller = await helper.eth.createAccountWithBalance(donor);48    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});4950    await collection.addAdmin(alice, {Ethereum: caller});5152    const address = helper.ethAddress.fromCollectionId(collection.collectionId);53    const contract = helper.ethNativeContract.collection(address, 'nft', caller);5455    await contract.methods.deleteCollectionProperty('testKey').send({from: caller});5657    const raw = (await collection.getData())?.raw;5859    expect(raw.properties.length).to.equal(0);60  });6162  itEth('Can be read', async({helper}) => {63    const caller = helper.eth.createAccount();64    const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});6566    const address = helper.ethAddress.fromCollectionId(collection.collectionId);67    const contract = helper.ethNativeContract.collection(address, 'nft', caller);6869    const value = await contract.methods.collectionProperty('testKey').call();70    expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));71  });72});