--- a/tests/src/eth/collectionProperties.test.ts +++ b/tests/src/eth/collectionProperties.test.ts @@ -1,53 +1,56 @@ -import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess} from '../util/helpers'; -import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers'; -import nonFungibleAbi from './nonFungibleAbi.json'; -import {expect} from 'chai'; -import {executeTransaction} from '../substrate/substrate-api'; +import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds'; +import {IKeyringPair} from '@polkadot/types/types'; describe('EVM collection properties', () => { - itWeb3('Can be set', async({web3, api, privateKeyWrapper}) => { - const alice = privateKeyWrapper('//Alice'); - const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); + let donor: IKeyringPair; + let alice: IKeyringPair; + + before(async function() { + await usingEthPlaygrounds(async (_helper, privateKey) => { + donor = privateKey('//Alice'); + [alice] = await _helper.arrange.createAccounts([10n], donor); + }); + }); - await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller}); + itEth('Can be set', async({helper}) => { + const caller = await helper.eth.createAccountWithBalance(donor); + const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test'}); + await collection.addAdmin(alice, {Ethereum: caller}); - const address = collectionIdToAddress(collection); - const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}); + const address = helper.ethAddress.fromCollectionId(collection.collectionId); + const contract = helper.ethNativeContract.collection(address, 'nft', caller); await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller}); - const [{value}] = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toHuman()! as any; - expect(value).to.equal('testValue'); + const raw = (await collection.getData())?.raw; + + expect(raw.properties[0].value).to.equal('testValue'); }); - itWeb3('Can be deleted', async({web3, api, privateKeyWrapper}) => { - const alice = privateKeyWrapper('//Alice'); - const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}}); - await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}])); + itEth('Can be deleted', async({helper}) => { + const caller = await helper.eth.createAccountWithBalance(donor); + const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]}); - await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller}); + await collection.addAdmin(alice, {Ethereum: caller}); - const address = collectionIdToAddress(collection); - const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}); + const address = helper.ethAddress.fromCollectionId(collection.collectionId); + const contract = helper.ethNativeContract.collection(address, 'nft', caller); await contract.methods.deleteCollectionProperty('testKey').send({from: caller}); - const result = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toJSON()! as any; - expect(result.length).to.equal(0); + const raw = (await collection.getData())?.raw; + + expect(raw.properties.length).to.equal(0); }); - itWeb3('Can be read', async({web3, api, privateKeyWrapper}) => { - const alice = privateKeyWrapper('//Alice'); - const caller = createEthAccount(web3); - const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}}); - await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}])); + itEth('Can be read', async({helper}) => { + const caller = helper.eth.createAccount(); + const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]}); - const address = collectionIdToAddress(collection); - const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}); + const address = helper.ethAddress.fromCollectionId(collection.collectionId); + const contract = helper.ethNativeContract.collection(address, 'nft', caller); const value = await contract.methods.collectionProperty('testKey').call(); - expect(value).to.equal(web3.utils.toHex('testValue')); + expect(value).to.equal(helper.web3?.utils.toHex('testValue')); }); });