difftreelog
Tests: code-style fixes
in: master
14 files changed
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -110,7 +110,7 @@
const [alice, ...accounts] = await helper.arrange.createAccounts([10n, 0n, 0n, 0n, 0n, 0n, 0n, 0n], donor);
const collection = await helper.nft.mintCollection(alice, {name: 'Collection Name', description: 'Collection Description', tokenPrefix: 'COL'});
- const chainAdminLimit = (helper.api!.consts.common.collectionAdminsLimit as any).toNumber();
+ const chainAdminLimit = (helper.getApi().consts.common.collectionAdminsLimit as any).toNumber();
expect(chainAdminLimit).to.be.equal(5);
for (let i = 0; i < chainAdminLimit; i++) {
tests/src/approve.test.tsdiffbeforeafterboth--- a/tests/src/approve.test.ts
+++ b/tests/src/approve.test.ts
@@ -60,7 +60,7 @@
const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
- await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));
+ await helper.signTransaction(alice, helper.constructApiCall('api.tx.unique.approve', [{Substrate: bob.address}, collectionId, tokenId, 0]));
expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
});
@@ -275,7 +275,7 @@
const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: alice.address});
await helper.nft.approveToken(alice, collectionId, tokenId, {Substrate: bob.address});
expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.true;
- await helper.signTransaction(alice, helper.api?.tx.unique.approve({Substrate: bob.address}, collectionId, tokenId, 0));
+ await helper.signTransaction(alice, helper.constructApiCall('api.tx.unique.approve', [{Substrate: bob.address}, collectionId, tokenId, 0]));
expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: bob.address})).to.be.false;
const transferTokenFromTx = async () => helper.nft.transferTokenFrom(bob, collectionId, tokenId, {Substrate: bob.address}, {Substrate: bob.address});
await expect(transferTokenFromTx()).to.be.rejected;
@@ -328,7 +328,7 @@
itSub('1 for NFT', async ({helper}) => {
const {collectionId} = await helper.nft.mintCollection(alice, {name: 'col', description: 'descr', tokenPrefix: 'COL'});
const {tokenId} = await helper.nft.mintToken(alice, {collectionId: collectionId, owner: bob.address});
- const approveTx = async () => helper.signTransaction(bob, helper.api?.tx.unique.approve({Substrate: charlie.address}, collectionId, tokenId, 2));
+ const approveTx = async () => helper.signTransaction(bob, helper.constructApiCall('api.tx.unique.approve', [{Substrate: charlie.address}, collectionId, tokenId, 2]));
await expect(approveTx()).to.be.rejected;
expect(await helper.nft.isTokenApproved(collectionId, tokenId, {Substrate: charlie.address})).to.be.false;
});
tests/src/block-production.test.tsdiffbeforeafterboth--- a/tests/src/block-production.test.ts
+++ b/tests/src/block-production.test.ts
@@ -37,7 +37,7 @@
describe('Block Production smoke test', () => {
itSub('Node produces new blocks', async ({helper}) => {
- const blocks: number[] | undefined = await getBlocks(helper.api!);
+ const blocks: number[] | undefined = await getBlocks(helper.getApi());
expect(blocks[0]).to.be.lessThan(blocks[1]);
});
});
tests/src/createMultipleItemsEx.test.tsdiffbeforeafterboth--- a/tests/src/createMultipleItemsEx.test.ts
+++ b/tests/src/createMultipleItemsEx.test.ts
@@ -178,13 +178,12 @@
tokenPrefix: 'COL',
}, 0);
- const api = helper.api;
- await helper.signTransaction(alice, api?.tx.unique.createMultipleItemsEx(collection.collectionId, {
+ await helper.executeExtrinsic(alice, 'api.tx.unique.createMultipleItemsEx',[collection.collectionId, {
Fungible: new Map([
[JSON.stringify({Substrate: alice.address}), 50],
[JSON.stringify({Substrate: bob.address}), 100],
]),
- }));
+ }], true);
expect(await collection.getBalance({Substrate: alice.address})).to.be.equal(50n);
expect(await collection.getBalance({Substrate: bob.address})).to.be.equal(100n);
@@ -200,8 +199,7 @@
],
});
- const api = helper.api;
- await helper.signTransaction(alice, api?.tx.unique.createMultipleItemsEx(collection.collectionId, {
+ await helper.executeExtrinsic(alice, 'api.tx.unique.createMultipleItemsEx', [collection.collectionId, {
RefungibleMultipleOwners: {
users: new Map([
[JSON.stringify({Substrate: alice.address}), 1],
@@ -211,7 +209,7 @@
{key: 'k', value: 'v'},
],
},
- }));
+ }], true);
const tokenId = await collection.getLastTokenId();
expect(tokenId).to.be.equal(1);
expect(await collection.getTokenBalance(1, {Substrate: alice.address})).to.be.equal(1n);
@@ -228,9 +226,7 @@
],
});
- const api = helper.api;
-
- await helper.signTransaction(alice, api?.tx.unique.createMultipleItemsEx(collection.collectionId, {
+ await helper.executeExtrinsic(alice, 'api.tx.unique.createMultipleItemsEx', [collection.collectionId, {
RefungibleMultipleItems: [
{
user: {Substrate: alice.address}, pieces: 1,
@@ -245,7 +241,7 @@
],
},
],
- }));
+ }], true);
expect(await collection.getLastTokenId()).to.be.equal(2);
expect(await collection.getTokenBalance(1, {Substrate: alice.address})).to.be.equal(1n);
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -70,7 +70,7 @@
});
itSub('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async ({helper}) => {
- await skipInflationBlock(helper.api!);
+ await skipInflationBlock(helper.getApi());
await helper.wait.newBlocks(1);
const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
@@ -89,7 +89,7 @@
});
itSub('Treasury balance increased by failed tx fee', async ({helper}) => {
- const api = helper.api!;
+ const api = helper.getApi();
await helper.wait.newBlocks(1);
const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
@@ -107,7 +107,7 @@
});
itSub('NFT Transactions also send fees to Treasury', async ({helper}) => {
- await skipInflationBlock(helper.api!);
+ await skipInflationBlock(helper.getApi());
await helper.wait.newBlocks(1);
const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
@@ -125,7 +125,7 @@
itSub('Fees are sane', async ({helper}) => {
const unique = helper.balance.getOneTokenNominal();
- await skipInflationBlock(helper.api!);
+ await skipInflationBlock(helper.getApi());
await helper.wait.newBlocks(1);
const aliceBalanceBefore = await helper.balance.getSubstrate(alice.address);
@@ -140,7 +140,7 @@
});
itSub('NFT Transfer fee is close to 0.1 Unique', async ({helper}) => {
- await skipInflationBlock(helper.api!);
+ await skipInflationBlock(helper.getApi());
await helper.wait.newBlocks(1);
const collection = await helper.nft.mintCollection(alice, {
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -152,7 +152,7 @@
before(async function() {
await usingEthPlaygrounds(async (helper, privateKey) => {
donor = privateKey('//Alice');
- nominal = helper.balance.getOneTokenNominal()
+ nominal = helper.balance.getOneTokenNominal();
});
});
tests/src/eth/proxy/nonFungibleProxy.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 {readFile} from 'fs/promises';18import {IKeyringPair} from '@polkadot/types/types';19import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from '../util/playgrounds';202122async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {23 // Proxy owner has no special privilegies, we don't need to reuse them24 const owner = await helper.eth.createAccountWithBalance(donor);25 const web3 = helper.getWeb3();26 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {27 from: owner,28 gas: helper.eth.DEFAULT_GAS,29 });30 const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});31 return proxy;32}3334describe('NFT (Via EVM proxy): Information getting', () => {35 let alice: IKeyringPair;36 let donor: IKeyringPair;3738 before(async function() {39 await usingEthPlaygrounds(async (helper, privateKey) => {40 donor = privateKey('//Alice');41 [alice] = await helper.arrange.createAccounts([10n], donor);42 });43 });4445 itEth('totalSupply', async ({helper}) => {46 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});47 const caller = await helper.eth.createAccountWithBalance(donor);48 await collection.mintToken(alice, {Substrate: alice.address});4950 const address = helper.ethAddress.fromCollectionId(collection.collectionId);51 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);52 const contract = await proxyWrap(helper, evmCollection, donor);53 const totalSupply = await contract.methods.totalSupply().call();5455 expect(totalSupply).to.equal('1');56 });5758 itEth('balanceOf', async ({helper}) => {59 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});6061 const caller = await helper.eth.createAccountWithBalance(donor);62 await collection.mintMultipleTokens(alice, [63 {owner: {Ethereum: caller}},64 {owner: {Ethereum: caller}},65 {owner: {Ethereum: caller}},66 ]);6768 const address = helper.ethAddress.fromCollectionId(collection.collectionId);69 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);70 const contract = await proxyWrap(helper, evmCollection, donor);71 const balance = await contract.methods.balanceOf(caller).call();7273 expect(balance).to.equal('3');74 });7576 itEth('ownerOf', async ({helper}) => {77 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});7879 const caller = await helper.eth.createAccountWithBalance(donor);80 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});8182 const address = helper.ethAddress.fromCollectionId(collection.collectionId);83 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);84 const contract = await proxyWrap(helper, evmCollection, donor);85 const owner = await contract.methods.ownerOf(tokenId).call();8687 expect(owner).to.equal(caller);88 });89});9091describe('NFT (Via EVM proxy): Plain calls', () => {92 let alice: IKeyringPair;93 let donor: IKeyringPair;9495 before(async function() {96 await usingEthPlaygrounds(async (helper, privateKey) => {97 donor = privateKey('//Alice');98 [alice] = await helper.arrange.createAccounts([10n], donor);99 });100 });101102 itEth('Can perform mint()', async ({helper}) => {103 const owner = await helper.eth.createAccountWithBalance(donor);104 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'A', 'A');105 const caller = await helper.eth.createAccountWithBalance(donor);106 const receiver = helper.eth.createAccount();107108 const collectionEvmOwned = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);109 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);110 const contract = await proxyWrap(helper, collectionEvm, donor);111 await collectionEvmOwned.methods.addCollectionAdmin(contract.options.address).send();112113 {114 const nextTokenId = await contract.methods.nextTokenId().call();115 expect(nextTokenId).to.be.equal('1');116 const result = await contract.methods.mintWithTokenURI(117 receiver,118 nextTokenId,119 'Test URI',120 ).send({from: caller});121 const events = helper.eth.normalizeEvents(result.events);122 events[0].address = events[0].address.toLocaleLowerCase();123124 expect(events).to.be.deep.equal([125 {126 address: collectionAddress.toLocaleLowerCase(),127 event: 'Transfer',128 args: {129 from: '0x0000000000000000000000000000000000000000',130 to: receiver,131 tokenId: nextTokenId,132 },133 },134 ]);135136 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');137 }138 });139140 //TODO: CORE-302 add eth methods141 itEth.skip('Can perform mintBulk()', async ({helper, privateKey}) => {142 const api = helper.getApi();143 const web3 = helper.getWeb3();144 const privateKeyWrapper = privateKey;145 /*146 const collection = await createCollectionExpectSuccess({147 mode: {type: 'NFT'},148 });149 const alice = privateKeyWrapper('//Alice');150151 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);152 const receiver = createEthAccount(web3);153154 const address = collectionIdToAddress(collection);155 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);156 const changeAdminTx = api.tx.unique.addCollectionAdmin(collection, {Ethereum: contract.options.address});157 await submitTransactionAsync(alice, changeAdminTx);158159 {160 const nextTokenId = await contract.methods.nextTokenId().call();161 expect(nextTokenId).to.be.equal('1');162 const result = await contract.methods.mintBulkWithTokenURI(163 receiver,164 [165 [nextTokenId, 'Test URI 0'],166 [+nextTokenId + 1, 'Test URI 1'],167 [+nextTokenId + 2, 'Test URI 2'],168 ],169 ).send({from: caller});170 const events = normalizeEvents(result.events);171172 expect(events).to.be.deep.equal([173 {174 address,175 event: 'Transfer',176 args: {177 from: '0x0000000000000000000000000000000000000000',178 to: receiver,179 tokenId: nextTokenId,180 },181 },182 {183 address,184 event: 'Transfer',185 args: {186 from: '0x0000000000000000000000000000000000000000',187 to: receiver,188 tokenId: String(+nextTokenId + 1),189 },190 },191 {192 address,193 event: 'Transfer',194 args: {195 from: '0x0000000000000000000000000000000000000000',196 to: receiver,197 tokenId: String(+nextTokenId + 2),198 },199 },200 ]);201202 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');203 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');204 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');205 }206 */207 });208209 itEth('Can perform burn()', async ({helper}) => {210 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});211 const caller = await helper.eth.createAccountWithBalance(donor);212213 const address = helper.ethAddress.fromCollectionId(collection.collectionId);214 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);215 const contract = await proxyWrap(helper, evmCollection, donor);216 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});217 await collection.addAdmin(alice, {Ethereum: contract.options.address});218219 {220 const result = await contract.methods.burn(tokenId).send({from: caller});221 const events = helper.eth.normalizeEvents(result.events);222223 expect(events).to.be.deep.equal([224 {225 address,226 event: 'Transfer',227 args: {228 from: contract.options.address,229 to: '0x0000000000000000000000000000000000000000',230 tokenId: tokenId.toString(),231 },232 },233 ]);234 }235 });236237 itEth('Can perform approve()', async ({helper}) => {238 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});239 const caller = await helper.eth.createAccountWithBalance(donor);240 const spender = helper.eth.createAccount();241242 const address = helper.ethAddress.fromCollectionId(collection.collectionId);243 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);244 const contract = await proxyWrap(helper, evmCollection, donor);245 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});246247 {248 const result = await contract.methods.approve(spender, tokenId).send({from: caller, gas: helper.eth.DEFAULT_GAS});249 const events = helper.eth.normalizeEvents(result.events);250251 expect(events).to.be.deep.equal([252 {253 address,254 event: 'Approval',255 args: {256 owner: contract.options.address,257 approved: spender,258 tokenId: tokenId.toString(),259 },260 },261 ]);262 }263 });264265 itEth('Can perform transferFrom()', async ({helper}) => {266 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});267 const caller = await helper.eth.createAccountWithBalance(donor);268 const owner = await helper.eth.createAccountWithBalance(donor);269270 const receiver = helper.eth.createAccount();271272 const address = helper.ethAddress.fromCollectionId(collection.collectionId);273 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);274 const contract = await proxyWrap(helper, evmCollection, donor);275 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});276277 await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});278279 {280 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: caller});281 const events = helper.eth.normalizeEvents(result.events);282 expect(events).to.be.deep.equal([283 {284 address,285 event: 'Transfer',286 args: {287 from: owner,288 to: receiver,289 tokenId: tokenId.toString(),290 },291 },292 ]);293 }294295 {296 const balance = await contract.methods.balanceOf(receiver).call();297 expect(+balance).to.equal(1);298 }299300 {301 const balance = await contract.methods.balanceOf(contract.options.address).call();302 expect(+balance).to.equal(0);303 }304 });305306 itEth('Can perform transfer()', async ({helper}) => {307 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});308 const caller = await helper.eth.createAccountWithBalance(donor);309 const receiver = helper.eth.createAccount();310311 const address = helper.ethAddress.fromCollectionId(collection.collectionId);312 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);313 const contract = await proxyWrap(helper, evmCollection, donor);314 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});315316 {317 const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});318 const events = helper.eth.normalizeEvents(result.events);319 expect(events).to.be.deep.equal([320 {321 address,322 event: 'Transfer',323 args: {324 from: contract.options.address,325 to: receiver,326 tokenId: tokenId.toString(),327 },328 },329 ]);330 }331332 {333 const balance = await contract.methods.balanceOf(contract.options.address).call();334 expect(+balance).to.equal(0);335 }336337 {338 const balance = await contract.methods.balanceOf(receiver).call();339 expect(+balance).to.equal(1);340 }341 });342});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 {readFile} from 'fs/promises';18import {IKeyringPair} from '@polkadot/types/types';19import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from '../util/playgrounds';202122async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {23 // Proxy owner has no special privilegies, we don't need to reuse them24 const owner = await helper.eth.createAccountWithBalance(donor);25 const web3 = helper.getWeb3();26 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {27 from: owner,28 gas: helper.eth.DEFAULT_GAS,29 });30 const proxy = await proxyContract.deploy({data: (await readFile(`${__dirname}/UniqueNFTProxy.bin`)).toString(), arguments: [wrapped.options.address]}).send({from: owner});31 return proxy;32}3334describe('NFT (Via EVM proxy): Information getting', () => {35 let alice: IKeyringPair;36 let donor: IKeyringPair;3738 before(async function() {39 await usingEthPlaygrounds(async (helper, privateKey) => {40 donor = privateKey('//Alice');41 [alice] = await helper.arrange.createAccounts([10n], donor);42 });43 });4445 itEth('totalSupply', async ({helper}) => {46 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});47 const caller = await helper.eth.createAccountWithBalance(donor);48 await collection.mintToken(alice, {Substrate: alice.address});4950 const address = helper.ethAddress.fromCollectionId(collection.collectionId);51 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);52 const contract = await proxyWrap(helper, evmCollection, donor);53 const totalSupply = await contract.methods.totalSupply().call();5455 expect(totalSupply).to.equal('1');56 });5758 itEth('balanceOf', async ({helper}) => {59 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});6061 const caller = await helper.eth.createAccountWithBalance(donor);62 await collection.mintMultipleTokens(alice, [63 {owner: {Ethereum: caller}},64 {owner: {Ethereum: caller}},65 {owner: {Ethereum: caller}},66 ]);6768 const address = helper.ethAddress.fromCollectionId(collection.collectionId);69 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);70 const contract = await proxyWrap(helper, evmCollection, donor);71 const balance = await contract.methods.balanceOf(caller).call();7273 expect(balance).to.equal('3');74 });7576 itEth('ownerOf', async ({helper}) => {77 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});7879 const caller = await helper.eth.createAccountWithBalance(donor);80 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});8182 const address = helper.ethAddress.fromCollectionId(collection.collectionId);83 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);84 const contract = await proxyWrap(helper, evmCollection, donor);85 const owner = await contract.methods.ownerOf(tokenId).call();8687 expect(owner).to.equal(caller);88 });89});9091describe('NFT (Via EVM proxy): Plain calls', () => {92 let alice: IKeyringPair;93 let donor: IKeyringPair;9495 before(async function() {96 await usingEthPlaygrounds(async (helper, privateKey) => {97 donor = privateKey('//Alice');98 [alice] = await helper.arrange.createAccounts([10n], donor);99 });100 });101102 itEth('Can perform mint()', async ({helper}) => {103 const owner = await helper.eth.createAccountWithBalance(donor);104 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'A', 'A');105 const caller = await helper.eth.createAccountWithBalance(donor);106 const receiver = helper.eth.createAccount();107108 const collectionEvmOwned = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);109 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);110 const contract = await proxyWrap(helper, collectionEvm, donor);111 await collectionEvmOwned.methods.addCollectionAdmin(contract.options.address).send();112113 {114 const nextTokenId = await contract.methods.nextTokenId().call();115 expect(nextTokenId).to.be.equal('1');116 const result = await contract.methods.mintWithTokenURI(117 receiver,118 nextTokenId,119 'Test URI',120 ).send({from: caller});121 const events = helper.eth.normalizeEvents(result.events);122 events[0].address = events[0].address.toLocaleLowerCase();123124 expect(events).to.be.deep.equal([125 {126 address: collectionAddress.toLocaleLowerCase(),127 event: 'Transfer',128 args: {129 from: '0x0000000000000000000000000000000000000000',130 to: receiver,131 tokenId: nextTokenId,132 },133 },134 ]);135136 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');137 }138 });139140 //TODO: CORE-302 add eth methods141 itEth.skip('Can perform mintBulk()', async ({helper}) => {142 const collection = await helper.nft.mintCollection(donor, {name: 'New', description: 'New collection', tokenPrefix: 'NEW'});143144 const caller = await helper.eth.createAccountWithBalance(donor, 30n);145 const receiver = helper.eth.createAccount();146147 const address = helper.ethAddress.fromCollectionId(collection.collectionId);148 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);149 const contract = await proxyWrap(helper, evmCollection, donor);150 await collection.addAdmin(donor, {Ethereum: contract.options.address});151152 {153 const nextTokenId = await contract.methods.nextTokenId().call();154 expect(nextTokenId).to.be.equal('1');155 const result = await contract.methods.mintBulkWithTokenURI(156 receiver,157 [158 [nextTokenId, 'Test URI 0'],159 [+nextTokenId + 1, 'Test URI 1'],160 [+nextTokenId + 2, 'Test URI 2'],161 ],162 ).send({from: caller});163 const events = helper.eth.normalizeEvents(result.events);164165 expect(events).to.be.deep.equal([166 {167 address,168 event: 'Transfer',169 args: {170 from: '0x0000000000000000000000000000000000000000',171 to: receiver,172 tokenId: nextTokenId,173 },174 },175 {176 address,177 event: 'Transfer',178 args: {179 from: '0x0000000000000000000000000000000000000000',180 to: receiver,181 tokenId: String(+nextTokenId + 1),182 },183 },184 {185 address,186 event: 'Transfer',187 args: {188 from: '0x0000000000000000000000000000000000000000',189 to: receiver,190 tokenId: String(+nextTokenId + 2),191 },192 },193 ]);194195 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');196 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');197 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');198 }199 });200201 itEth('Can perform burn()', async ({helper}) => {202 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});203 const caller = await helper.eth.createAccountWithBalance(donor);204205 const address = helper.ethAddress.fromCollectionId(collection.collectionId);206 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);207 const contract = await proxyWrap(helper, evmCollection, donor);208 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});209 await collection.addAdmin(alice, {Ethereum: contract.options.address});210211 {212 const result = await contract.methods.burn(tokenId).send({from: caller});213 const events = helper.eth.normalizeEvents(result.events);214215 expect(events).to.be.deep.equal([216 {217 address,218 event: 'Transfer',219 args: {220 from: contract.options.address,221 to: '0x0000000000000000000000000000000000000000',222 tokenId: tokenId.toString(),223 },224 },225 ]);226 }227 });228229 itEth('Can perform approve()', async ({helper}) => {230 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});231 const caller = await helper.eth.createAccountWithBalance(donor);232 const spender = helper.eth.createAccount();233234 const address = helper.ethAddress.fromCollectionId(collection.collectionId);235 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);236 const contract = await proxyWrap(helper, evmCollection, donor);237 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});238239 {240 const result = await contract.methods.approve(spender, tokenId).send({from: caller, gas: helper.eth.DEFAULT_GAS});241 const events = helper.eth.normalizeEvents(result.events);242243 expect(events).to.be.deep.equal([244 {245 address,246 event: 'Approval',247 args: {248 owner: contract.options.address,249 approved: spender,250 tokenId: tokenId.toString(),251 },252 },253 ]);254 }255 });256257 itEth('Can perform transferFrom()', async ({helper}) => {258 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});259 const caller = await helper.eth.createAccountWithBalance(donor);260 const owner = await helper.eth.createAccountWithBalance(donor);261262 const receiver = helper.eth.createAccount();263264 const address = helper.ethAddress.fromCollectionId(collection.collectionId);265 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);266 const contract = await proxyWrap(helper, evmCollection, donor);267 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});268269 await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});270271 {272 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: caller});273 const events = helper.eth.normalizeEvents(result.events);274 expect(events).to.be.deep.equal([275 {276 address,277 event: 'Transfer',278 args: {279 from: owner,280 to: receiver,281 tokenId: tokenId.toString(),282 },283 },284 ]);285 }286287 {288 const balance = await contract.methods.balanceOf(receiver).call();289 expect(+balance).to.equal(1);290 }291292 {293 const balance = await contract.methods.balanceOf(contract.options.address).call();294 expect(+balance).to.equal(0);295 }296 });297298 itEth('Can perform transfer()', async ({helper}) => {299 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});300 const caller = await helper.eth.createAccountWithBalance(donor);301 const receiver = helper.eth.createAccount();302303 const address = helper.ethAddress.fromCollectionId(collection.collectionId);304 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);305 const contract = await proxyWrap(helper, evmCollection, donor);306 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});307308 {309 const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});310 const events = helper.eth.normalizeEvents(result.events);311 expect(events).to.be.deep.equal([312 {313 address,314 event: 'Transfer',315 args: {316 from: contract.options.address,317 to: receiver,318 tokenId: tokenId.toString(),319 },320 },321 ]);322 }323324 {325 const balance = await contract.methods.balanceOf(contract.options.address).call();326 expect(+balance).to.equal(0);327 }328329 {330 const balance = await contract.methods.balanceOf(receiver).call();331 expect(+balance).to.equal(1);332 }333 });334});tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -285,8 +285,8 @@
await code();
// In dev mode, the transaction might not finish processing in time
await this.helper.wait.newBlocks(1);
- }
- return await this.helper.arrange.calculcateFee(address, code);
+ };
+ return await this.helper.arrange.calculcateFee(address, wrappedCode);
}
}
tests/src/inflation.test.tsdiffbeforeafterboth--- a/tests/src/inflation.test.ts
+++ b/tests/src/inflation.test.ts
@@ -40,9 +40,9 @@
const tx = helper.constructApiCall('api.tx.inflation.startInflation', [1]);
await expect(helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [tx])).to.not.be.rejected;
- const blockInterval = (helper.api!.consts.inflation.inflationBlockInterval as any).toBigInt();
- const totalIssuanceStart = ((await helper.api!.query.inflation.startingYearTotalIssuance()) as any).toBigInt();
- const blockInflation = (await helper.api!.query.inflation.blockInflation() as any).toBigInt();
+ const blockInterval = (helper.getApi().consts.inflation.inflationBlockInterval as any).toBigInt();
+ const totalIssuanceStart = ((await helper.callRpc('api.query.inflation.startingYearTotalIssuance', [])) as any).toBigInt();
+ const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();
const YEAR = 5259600n; // 6-second block. Blocks in one year
// const YEAR = 2629800n; // 12-second block. Blocks in one year
tests/src/nesting/properties.test.tsdiffbeforeafterboth--- a/tests/src/nesting/properties.test.ts
+++ b/tests/src/nesting/properties.test.ts
@@ -276,7 +276,7 @@
itSub('Reads access rights to properties of a collection', async ({helper}) => {
const collection = await helper.nft.mintCollection(alice);
- const propertyRights = (await helper.api!.query.common.collectionPropertyPermissions(collection.collectionId)).toJSON();
+ const propertyRights = (await helper.callRpc('api.query.common.collectionPropertyPermissions', [collection.collectionId])).toJSON();
expect(propertyRights).to.be.empty;
});
@@ -817,7 +817,7 @@
).to.be.fulfilled;
}
- const originalSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
+ const originalSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
return originalSpace;
}
@@ -840,7 +840,7 @@
).to.be.rejectedWith(/common\.NoPermission/);
}
- const consumedSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
+ const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
expect(consumedSpace).to.be.equal(originalSpace);
}
@@ -875,7 +875,7 @@
).to.be.rejectedWith(/common\.NoPermission/);
}
- const consumedSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
+ const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
expect(consumedSpace).to.be.equal(originalSpace);
}
@@ -911,7 +911,7 @@
expect(await token.getProperties(['non-existent', 'now-existent'])).to.be.empty;
- const consumedSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
+ const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
expect(consumedSpace).to.be.equal(originalSpace);
}
@@ -951,7 +951,7 @@
])).to.be.rejectedWith(/common\.NoSpaceForProperty/);
expect(await token.getProperties(['a_holy_book', 'young_years'])).to.be.empty;
- const consumedSpace = await getConsumedSpace(token.collection.helper.api, token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
+ const consumedSpace = await getConsumedSpace(token.collection.helper.getApi(), token.collectionId, token.tokenId, pieces == 1n ? 'NFT' : 'RFT');
expect(consumedSpace).to.be.equal(originalSpace);
}
tests/src/pallet-presence.test.tsdiffbeforeafterboth--- a/tests/src/pallet-presence.test.ts
+++ b/tests/src/pallet-presence.test.ts
@@ -59,7 +59,7 @@
describe('Pallet presence', () => {
before(async () => {
await usingPlaygrounds(async helper => {
- const chain = await helper.api!.rpc.system.chain();
+ const chain = await helper.callRpc('api.rpc.system.chain', []);
const refungible = 'refungible';
const scheduler = 'scheduler';
tests/src/tx-version-presence.test.tsdiffbeforeafterboth--- a/tests/src/tx-version-presence.test.ts
+++ b/tests/src/tx-version-presence.test.ts
@@ -22,7 +22,7 @@
describe('TxVersion is present', () => {
before(async () => {
await usingPlaygrounds(async helper => {
- metadata = await helper.api!.rpc.state.getMetadata();
+ metadata = await helper.callRpc('api.rpc.state.getMetadata', []);
});
});
tests/src/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.dev.ts
+++ b/tests/src/util/playgrounds/unique.dev.ts
@@ -215,8 +215,8 @@
};
isDevNode = async () => {
- const block1 = await this.helper.api?.rpc.chain.getBlock(await this.helper.api?.rpc.chain.getBlockHash(1));
- const block2 = await this.helper.api?.rpc.chain.getBlock(await this.helper.api?.rpc.chain.getBlockHash(2));
+ const block1 = await this.helper.callRpc('api.rpc.chain.getBlock', [await this.helper.callRpc('api.rpc.chain.getBlockHash', [1])]);
+ const block2 = await this.helper.callRpc('api.rpc.chain.getBlock', [await this.helper.callRpc('api.rpc.chain.getBlockHash', [2])]);
const findCreationDate = async (block: any) => {
const humanBlock = block.toHuman();
let date;
@@ -259,7 +259,7 @@
async newBlocks(blocksCount = 1): Promise<void> {
// eslint-disable-next-line no-async-promise-executor
const promise = new Promise<void>(async (resolve) => {
- const unsubscribe = await this.helper.api!.rpc.chain.subscribeNewHeads(() => {
+ const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads(() => {
if (blocksCount > 0) {
blocksCount--;
} else {
@@ -274,7 +274,7 @@
async forParachainBlockNumber(blockNumber: bigint) {
// eslint-disable-next-line no-async-promise-executor
return new Promise<void>(async (resolve) => {
- const unsubscribe = await this.helper.api!.rpc.chain.subscribeNewHeads(async (data: any) => {
+ const unsubscribe = await this.helper.getApi().rpc.chain.subscribeNewHeads(async (data: any) => {
if (data.number.toNumber() >= blockNumber) {
unsubscribe();
resolve();
@@ -286,7 +286,7 @@
async forRelayBlockNumber(blockNumber: bigint) {
// eslint-disable-next-line no-async-promise-executor
return new Promise<void>(async (resolve) => {
- const unsubscribe = await this.helper.api!.query.parachainSystem.validationData(async (data: any) => {
+ const unsubscribe = await this.helper.getApi().query.parachainSystem.validationData(async (data: any) => {
if (data.value.relayParentNumber.toNumber() >= blockNumber) {
// @ts-ignore
unsubscribe();
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -1991,7 +1991,7 @@
* @returns ss58Format, token decimals, and token symbol
*/
getChainProperties(): IChainProperties {
- const properties = (this.helper.api as any).registry.getChainProperties().toJSON();
+ const properties = (this.helper.getApi() as any).registry.getChainProperties().toJSON();
return {
ss58Format: properties.ss58Format.toJSON(),
tokenDecimals: properties.tokenDecimals.toJSON(),
@@ -2034,7 +2034,7 @@
* @returns number, account's nonce
*/
async getNonce(address: TSubstrateAccount): Promise<number> {
- return (await (this.helper.api as any).query.system.account(address)).nonce.toNumber();
+ return (await this.helper.callRpc('api.query.system.account', [address])).nonce.toNumber();
}
}