git.delta.rocks / unique-network / refs/commits / 3a01a5229f7a

difftreelog

Merge pull request #622 from UniqueNetwork/test/playground-migration

ut-akuznetsov2022-10-04parents: #d3b796f #686b7bd.patch.diff
in: master
Test/playground migration

13 files changed

modifiedtests/src/check-event/burnItemEvent.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
18import {ApiPromise} from '@polkadot/api';
19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
20import chai from 'chai';
21import chaiAsPromised from 'chai-as-promised';
22import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import {usingPlaygrounds, expect, itSub} from '../util/playgrounds';
23import {createCollectionExpectSuccess, createItemExpectSuccess, uniqueEventMessage} from '../util/helpers';20import {IEvent} from '../util/playgrounds/types';
2421
25chai.use(chaiAsPromised);
26const expect = chai.expect;
2722
28describe('Burn Item event ', () => {23describe('Burn Item event ', () => {
29 let alice: IKeyringPair;24 let alice: IKeyringPair;
30 const checkSection = 'ItemDestroyed';
31 const checkTreasury = 'Deposit';
32 const checkSystem = 'ExtrinsicSuccess';
33 before(async () => {25 before(async () => {
34 await usingApi(async (api, privateKeyWrapper) => {26 await usingPlaygrounds(async (helper, privateKey) => {
35 alice = privateKeyWrapper('//Alice');27 const donor = privateKey('//Alice');
28 [alice] = await helper.arrange.createAccounts([10n], donor);
36 });29 });
37 });30 });
38 it('Check event from burnItem(): ', async () => {31 itSub('Check event from burnItem(): ', async ({helper}) => {
39 await usingApi(async (api: ApiPromise) => {32 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
33 const token = await collection.mintToken(alice, {Substrate: alice.address});
40 const collectionID = await createCollectionExpectSuccess();34 await token.burn(alice);
41 const itemID = await createItemExpectSuccess(alice, collectionID, 'NFT');35
42 const burnItem = api.tx.unique.burnItem(collectionID, itemID, 1);36 const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
43 const events = await submitTransactionAsync(alice, burnItem);
44 const msg = JSON.stringify(uniqueEventMessage(events));37 const eventStrings = event.map(e => `${e.section}.${e.method}`);
38
45 expect(msg).to.be.contain(checkSection);39 expect(eventStrings).to.contains('common.ItemDestroyed');
46 expect(msg).to.be.contain(checkTreasury);40 expect(eventStrings).to.contains('treasury.Deposit');
47 expect(msg).to.be.contain(checkSystem);41 expect(eventStrings).to.contains('system.ExtrinsicSuccess');
48 });
49 });42 });
50});43});
5144
modifiedtests/src/check-event/createCollectionEvent.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
18import {ApiPromise} from '@polkadot/api';
19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
20import chai from 'chai';
21import chaiAsPromised from 'chai-as-promised';
22import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import {usingPlaygrounds, itSub, expect} from '../util/playgrounds';
23import {uniqueEventMessage} from '../util/helpers';20import {IEvent} from '../util/playgrounds/types';
24
25chai.use(chaiAsPromised);
26const expect = chai.expect;
2721
28describe('Create collection event ', () => {22describe('Create collection event ', () => {
29 let alice: IKeyringPair;23 let alice: IKeyringPair;
30 const checkSection = 'CollectionCreated';
31 const checkTreasury = 'Deposit';
32 const checkSystem = 'ExtrinsicSuccess';
33 before(async () => {24 before(async () => {
34 await usingApi(async (api, privateKeyWrapper) => {25 await usingPlaygrounds(async (helper, privateKey) => {
35 alice = privateKeyWrapper('//Alice');26 const donor = privateKey('//Alice');
27 [alice] = await helper.arrange.createAccounts([10n], donor);
36 });28 });
37 });29 });
38 it('Check event from createCollection(): ', async () => {30 itSub('Check event from createCollection(): ', async ({helper}) => {
39 await usingApi(async (api: ApiPromise) => {
40 const tx = api.tx.unique.createCollectionEx({name: [0x31], description: [0x32], tokenPrefix: '0x33', mode: 'NFT'});31 await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
41 const events = await submitTransactionAsync(alice, tx);32 const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
42 const msg = JSON.stringify(uniqueEventMessage(events));33 const eventStrings = event.map(e => `${e.section}.${e.method}`);
34
43 expect(msg).to.be.contain(checkSection);35 expect(eventStrings).to.contains('common.CollectionCreated');
44 expect(msg).to.be.contain(checkTreasury);36 expect(eventStrings).to.contains('treasury.Deposit');
45 expect(msg).to.be.contain(checkSystem);37 expect(eventStrings).to.contains('system.ExtrinsicSuccess');
46 });
47 });38 });
48});39});
4940
modifiedtests/src/check-event/createItemEvent.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
18import {ApiPromise} from '@polkadot/api';
19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
20import chai from 'chai';
21import chaiAsPromised from 'chai-as-promised';
22import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import {itSub, usingPlaygrounds, expect} from '../util/playgrounds';
23import {createCollectionExpectSuccess, uniqueEventMessage, normalizeAccountId} from '../util/helpers';20import {IEvent} from '../util/playgrounds/types';
24
25chai.use(chaiAsPromised);
26const expect = chai.expect;
2721
28describe('Create Item event ', () => {22describe('Create Item event ', () => {
29 let alice: IKeyringPair;23 let alice: IKeyringPair;
30 const checkSection = 'ItemCreated';
31 const checkTreasury = 'Deposit';
32 const checkSystem = 'ExtrinsicSuccess';
33 before(async () => {24 before(async () => {
34 await usingApi(async (api, privateKeyWrapper) => {25 await usingPlaygrounds(async (helper, privateKey) => {
35 alice = privateKeyWrapper('//Alice');26 const donor = privateKey('//Alice');
27 [alice] = await helper.arrange.createAccounts([10n], donor);
36 });28 });
37 });29 });
38 it('Check event from createItem(): ', async () => {30 itSub('Check event from createItem(): ', async ({helper}) => {
39 await usingApi(async (api: ApiPromise) => {31 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
40 const collectionID = await createCollectionExpectSuccess();32 await collection.mintToken(alice, {Substrate: alice.address});
41 const createItem = api.tx.unique.createItem(collectionID, normalizeAccountId(alice.address), 'NFT');33 const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
42 const events = await submitTransactionAsync(alice, createItem);
43 const msg = JSON.stringify(uniqueEventMessage(events));34 const eventStrings = event.map(e => `${e.section}.${e.method}`);
35
44 expect(msg).to.be.contain(checkSection);36 expect(eventStrings).to.contains('common.ItemCreated');
45 expect(msg).to.be.contain(checkTreasury);37 expect(eventStrings).to.contains('treasury.Deposit');
46 expect(msg).to.be.contain(checkSystem);38 expect(eventStrings).to.contains('system.ExtrinsicSuccess');
47 });
48 });39 });
49});40});
5041
modifiedtests/src/check-event/createMultipleItemsEvent.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
18import {ApiPromise} from '@polkadot/api';
19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
20import chai from 'chai';
21import chaiAsPromised from 'chai-as-promised';
22import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import {usingPlaygrounds, itSub, expect} from '../util/playgrounds';
23import {createCollectionExpectSuccess, uniqueEventMessage, normalizeAccountId} from '../util/helpers';20import {IEvent} from '../util/playgrounds/types';
24
25chai.use(chaiAsPromised);
26const expect = chai.expect;
2721
28describe('Create Multiple Items Event event ', () => {22describe('Create Multiple Items Event event ', () => {
29 let alice: IKeyringPair;23 let alice: IKeyringPair;
30 const checkSection = 'ItemCreated';
31 const checkTreasury = 'Deposit';
32 const checkSystem = 'ExtrinsicSuccess';
33 before(async () => {24 before(async () => {
34 await usingApi(async (api, privateKeyWrapper) => {25 await usingPlaygrounds(async (helper, privateKey) => {
35 alice = privateKeyWrapper('//Alice');26 const donor = privateKey('//Alice');
27 [alice] = await helper.arrange.createAccounts([10n], donor);
36 });28 });
37 });29 });
38 it('Check event from createMultipleItems(): ', async () => {30 itSub('Check event from createMultipleItems(): ', async ({helper}) => {
39 await usingApi(async (api: ApiPromise) => {31 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
32
33 await collection.mintMultipleTokens(alice, [
34 {owner: {Substrate: alice.address}},
35 {owner: {Substrate: alice.address}},
40 const collectionID = await createCollectionExpectSuccess();36 ]);
41 const args = [{NFT: {}}, {NFT: {}}, {NFT: {}}];37
42 const createMultipleItems = api.tx.unique.createMultipleItems(collectionID, normalizeAccountId(alice.address), args);38 const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
43 const events = await submitTransactionAsync(alice, createMultipleItems);
44 const msg = JSON.stringify(uniqueEventMessage(events));39 const eventStrings = event.map(e => `${e.section}.${e.method}`);
40
45 expect(msg).to.be.contain(checkSection);41 expect(eventStrings).to.contains('common.ItemCreated');
46 expect(msg).to.be.contain(checkTreasury);42 expect(eventStrings).to.contains('treasury.Deposit');
47 expect(msg).to.be.contain(checkSystem);43 expect(eventStrings).to.contains('system.ExtrinsicSuccess');
48 });
49 });44 });
50});45});
5146
modifiedtests/src/check-event/destroyCollectionEvent.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
18import {ApiPromise} from '@polkadot/api';
19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
20import chai from 'chai';
21import chaiAsPromised from 'chai-as-promised';
22import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import {itSub, usingPlaygrounds, expect} from '../util/playgrounds';
23import {createCollectionExpectSuccess, uniqueEventMessage} from '../util/helpers';20import {IEvent} from '../util/playgrounds/types';
24
25chai.use(chaiAsPromised);
26const expect = chai.expect;
2721
28describe('Destroy collection event ', () => {22describe('Destroy collection event ', () => {
29 let alice: IKeyringPair;23 let alice: IKeyringPair;
30 const checkTreasury = 'Deposit';
31 const checkSystem = 'ExtrinsicSuccess';
32 before(async () => {24 before(async () => {
33 await usingApi(async (api, privateKeyWrapper) => {25 await usingPlaygrounds(async (helper, privateKey) => {
34 alice = privateKeyWrapper('//Alice');26 const donor = privateKey('//Alice');
27 [alice] = await helper.arrange.createAccounts([10n], donor);
35 });28 });
36 });29 });
30
37 it('Check event from destroyCollection(): ', async () => {31 itSub('Check event from destroyCollection(): ', async ({helper}) => {
38 await usingApi(async (api: ApiPromise) => {32 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
39 const collectionID = await createCollectionExpectSuccess();33 await collection.burn(alice);
40 const destroyCollection = api.tx.unique.destroyCollection(collectionID);34 const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
41 const events = await submitTransactionAsync(alice, destroyCollection);35 const eventStrings = event.map(e => `${e.section}.${e.method}`);
36
42 const msg = JSON.stringify(uniqueEventMessage(events));37 expect(eventStrings).to.contains('common.CollectionDestroyed');
43 expect(msg).to.be.contain(checkTreasury);38 expect(eventStrings).to.contains('treasury.Deposit');
44 expect(msg).to.be.contain(checkSystem);39 expect(eventStrings).to.contains('system.ExtrinsicSuccess');
45 });
46 });40 });
47});41});
4842
modifiedtests/src/check-event/transferEvent.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
18import {ApiPromise} from '@polkadot/api';
19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
20import chai from 'chai';
21import chaiAsPromised from 'chai-as-promised';
22import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import {usingPlaygrounds, expect, itSub} from '../util/playgrounds';
23import {createCollectionExpectSuccess, createItemExpectSuccess, uniqueEventMessage, normalizeAccountId} from '../util/helpers';20import {IEvent} from '../util/playgrounds/types';
24
25chai.use(chaiAsPromised);
26const expect = chai.expect;
2721
28describe('Transfer event ', () => {22describe('Transfer event ', () => {
29 let alice: IKeyringPair;23 let alice: IKeyringPair;
30 let bob: IKeyringPair;24 let bob: IKeyringPair;
31 const checkSection = 'Transfer';25
32 const checkTreasury = 'Deposit';
33 const checkSystem = 'ExtrinsicSuccess';
34 before(async () => {26 before(async () => {
35 await usingApi(async (api, privateKeyWrapper) => {27 await usingPlaygrounds(async (helper, privateKey) => {
36 alice = privateKeyWrapper('//Alice');28 const donor = privateKey('//Alice');
37 bob = privateKeyWrapper('//Bob');29 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
38 });30 });
39 });31 });
32
40 it('Check event from transfer(): ', async () => {33 itSub('Check event from transfer(): ', async ({helper}) => {
41 await usingApi(async (api: ApiPromise) => {34 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
35 const token = await collection.mintToken(alice, {Substrate: alice.address});
42 const collectionID = await createCollectionExpectSuccess();36 await token.transfer(alice, {Substrate: bob.address});
43 const itemID = await createItemExpectSuccess(alice, collectionID, 'NFT');
44 const transfer = api.tx.unique.transfer(normalizeAccountId(bob.address), collectionID, itemID, 1);37 const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
45 const events = await submitTransactionAsync(alice, transfer);
46 const msg = JSON.stringify(uniqueEventMessage(events));38 const eventStrings = event.map(e => `${e.section}.${e.method}`);
39
47 expect(msg).to.be.contain(checkSection);40 expect(eventStrings).to.contains('common.Transfer');
48 expect(msg).to.be.contain(checkTreasury);41 expect(eventStrings).to.contains('treasury.Deposit');
49 expect(msg).to.be.contain(checkSystem);42 expect(eventStrings).to.contains('system.ExtrinsicSuccess');
50 });
51 });43 });
52});44});
5345
modifiedtests/src/check-event/transferFromEvent.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits17// https://unique-network.readthedocs.io/en/latest/jsapi.html#setchainlimits
18import {ApiPromise} from '@polkadot/api';
19import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
20import chai from 'chai';
21import chaiAsPromised from 'chai-as-promised';
22import usingApi, {submitTransactionAsync} from '../substrate/substrate-api';19import {usingPlaygrounds, expect, itSub} from '../util/playgrounds';
23import {createCollectionExpectSuccess, createItemExpectSuccess, uniqueEventMessage, normalizeAccountId} from '../util/helpers';20import {IEvent} from '../util/playgrounds/types';
24
25chai.use(chaiAsPromised);
26const expect = chai.expect;
2721
28describe('Transfer from event ', () => {22describe('Transfer event ', () => {
29 let alice: IKeyringPair;23 let alice: IKeyringPair;
30 let bob: IKeyringPair;24 let bob: IKeyringPair;
31 const checkSection = 'Transfer';
32 const checkTreasury = 'Deposit';
33 const checkSystem = 'ExtrinsicSuccess';
34 before(async () => {25 before(async () => {
35 await usingApi(async (api, privateKeyWrapper) => {26 await usingPlaygrounds(async (helper, privateKey) => {
36 alice = privateKeyWrapper('//Alice');27 const donor = privateKey('//Alice');
37 bob = privateKeyWrapper('//Bob');28 [alice, bob] = await helper.arrange.createAccounts([10n, 10n], donor);
38 });29 });
39 });30 });
31
40 it('Check event from transferFrom(): ', async () => {32 itSub('Check event from transfer(): ', async ({helper}) => {
41 await usingApi(async (api: ApiPromise) => {33 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
34 const token = await collection.mintToken(alice, {Substrate: alice.address});
42 const collectionID = await createCollectionExpectSuccess();35 await token.transferFrom(alice, {Substrate: alice.address}, {Substrate: bob.address});
43 const itemID = await createItemExpectSuccess(alice, collectionID, 'NFT');
44 const transferFrom = api.tx.unique.transferFrom(normalizeAccountId(alice.address), normalizeAccountId(bob.address), collectionID, itemID, 1);36 const event = helper.chainLog[helper.chainLog.length - 1].events as IEvent[];
45 const events = await submitTransactionAsync(alice, transferFrom);
46 const msg = JSON.stringify(uniqueEventMessage(events));37 const eventStrings = event.map(e => `${e.section}.${e.method}`);
38
47 expect(msg).to.be.contain(checkSection);39 expect(eventStrings).to.contains('common.Transfer');
48 expect(msg).to.be.contain(checkTreasury);40 expect(eventStrings).to.contains('treasury.Deposit');
49 expect(msg).to.be.contain(checkSystem);41 expect(eventStrings).to.contains('system.ExtrinsicSuccess');
50 });
51 });42 });
52});43});
5344
modifiedtests/src/eth/allowlist.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {expect} from 'chai';
19import {isAllowlisted, normalizeAccountId} from '../util/helpers';
20import {
21 contractHelpers,
22 createEthAccount,
23 createEthAccountWithBalance,
24 deployFlipper,
25 evmCollection,
26 evmCollectionHelpers,
27 getCollectionAddressFromResult,
28 itWeb3,
29} from './util/helpers';
30import {itEth, usingEthPlaygrounds} from './util/playgrounds';18import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';
3119
32describe('EVM contract allowlist', () => {20describe('EVM contract allowlist', () => {
21 let donor: IKeyringPair;
22
23 before(async function() {
24 await usingEthPlaygrounds(async (_helper, privateKey) => {
25 donor = privateKey('//Alice');
26 });
27 });
28
33 itWeb3('Contract allowlist can be toggled', async ({api, web3, privateKeyWrapper}) => {29 itEth('Contract allowlist can be toggled', async ({helper}) => {
34 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);30 const owner = await helper.eth.createAccountWithBalance(donor);
35 const flipper = await deployFlipper(web3, owner);31 const flipper = await helper.eth.deployFlipper(owner);
36
37 const helpers = contractHelpers(web3, owner);32 const helpers = helper.ethNativeContract.contractHelpers(owner);
3833
39 // Any user is allowed by default34 // Any user is allowed by default
40 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;35 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;
48 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;43 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;
49 });44 });
5045
51 itWeb3('Non-allowlisted user can\'t call contract with allowlist enabled', async ({api, web3, privateKeyWrapper}) => {46 itEth('Non-allowlisted user can\'t call contract with allowlist enabled', async ({helper}) => {
52 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);47 const owner = await helper.eth.createAccountWithBalance(donor);
53 const flipper = await deployFlipper(web3, owner);48 const caller = await helper.eth.createAccountWithBalance(donor);
54 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);49 const flipper = await helper.eth.deployFlipper(owner);
55
56 const helpers = contractHelpers(web3, owner);50 const helpers = helper.ethNativeContract.contractHelpers(owner);
5751
58 // User can flip with allowlist disabled52 // User can flip with allowlist disabled
59 await flipper.methods.flip().send({from: caller});53 await flipper.methods.flip().send({from: caller});
modifiedtests/src/eth/base.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {17import {
18 collectionIdToAddress,
19 createEthAccount,
20 createEthAccountWithBalance,
21 deployFlipper,
22 ethBalanceViaSub,18 ethBalanceViaSub,
23 GAS_ARGS,19 GAS_ARGS,
24 itWeb3,
25 recordEthFee,20 recordEthFee,
26 usingWeb3,
27} from './util/helpers';21} from './util/helpers';
28import {expect} from 'chai';22import {Contract} from 'web3-eth-contract';
23
29import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';24import {IKeyringPair} from '@polkadot/types/types';
30import nonFungibleAbi from './nonFungibleAbi.json';
31import {Contract} from 'web3-eth-contract';25import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';
32import Web3 from 'web3';
3326
34describe('Contract calls', () => {27describe('Contract calls', () => {
28 let donor: IKeyringPair;
29
30 before(async function() {
31 await usingEthPlaygrounds(async (_helper, privateKey) => {
32 donor = privateKey('//Alice');
33 });
34 });
35
35 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api, privateKeyWrapper}) => {36 itEth('Call of simple contract fee is less than 0.2 UNQ', async ({helper}) => {
36 const deployer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);37 const deployer = await helper.eth.createAccountWithBalance(donor);
37 const flipper = await deployFlipper(web3, deployer);38 const flipper = await helper.eth.deployFlipper(deployer);
3839
39 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));40 const cost = await recordEthFee(helper.api!, deployer, () => flipper.methods.flip().send({from: deployer}));
40 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;41 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;
41 });42 });
4243
43 itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api, privateKeyWrapper}) => {44 itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {
44 const userA = await createEthAccountWithBalance(api, web3, privateKeyWrapper);45 const userA = await helper.eth.createAccountWithBalance(donor);
45 const userB = createEthAccount(web3);46 const userB = helper.eth.createAccount();
46
47 const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));47 const cost = await recordEthFee(helper.api!, userA, () => helper.web3!.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));
48 const balanceB = await ethBalanceViaSub(api, userB);48 const balanceB = await ethBalanceViaSub(helper.api!, userB);
49 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;49 expect(cost - balanceB < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;
50 });50 });
5151
52 itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api, privateKeyWrapper}) => {52 itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {
53 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);53 const caller = await helper.eth.createAccountWithBalance(donor);
54 const receiver = createEthAccount(web3);54 const receiver = helper.eth.createAccount();
5555
56 const alice = privateKeyWrapper('//Alice');56 const [alice] = await helper.arrange.createAccounts([10n], donor);
57 const collection = await createCollectionExpectSuccess({57 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
58 mode: {type: 'NFT'},
59 });
60 const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});58 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});
6159
62 const address = collectionIdToAddress(collection);60 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
63 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});61 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
6462
65 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));63 const cost = await recordEthFee(helper.api!, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));
6664
67 const fee = Number(cost) / Number(UNIQUE);65 const fee = Number(cost) / Number(helper.balance.getOneTokenNominal());
68 const expectedFee = 0.15;66 const expectedFee = 0.15;
69 const tolerance = 0.001;67 const tolerance = 0.001;
7068
78 let collection: number;76 let collection: number;
79 let minter: string;77 let minter: string;
8078
81 function contract(web3: Web3): Contract {79 function contract(helper: EthUniqueHelper): Contract {
82 return new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});80 return helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection), 'nft', minter);
83 }81 }
8482
85 before(async () => {83 before(async () => {
86 await usingWeb3 (async (web3) => {84 await usingEthPlaygrounds(async (helper, privateKey) => {
85 const donor = privateKey('//Alice');
86 const [alice] = await helper.arrange.createAccounts([10n], donor);
87 collection = await createCollectionExpectSuccess();87 ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}));
88 minter = createEthAccount(web3);88 minter = helper.eth.createAccount();
89 });89 });
90 });90 });
9191
92 itWeb3('interfaceID == 0xffffffff always false', async ({web3}) => {92 itEth('interfaceID == 0xffffffff always false', async ({helper}) => {
93 expect(await contract(web3).methods.supportsInterface('0xffffffff').call()).to.be.false;93 expect(await contract(helper).methods.supportsInterface('0xffffffff').call()).to.be.false;
94 });94 });
9595
96 itWeb3('ERC721 support', async ({web3}) => {96 itEth('ERC721 support', async ({helper}) => {
97 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;97 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;
98 });98 });
9999
100 itWeb3('ERC721Metadata support', async ({web3}) => {100 itEth('ERC721Metadata support', async ({helper}) => {
101 expect(await contract(web3).methods.supportsInterface('0x5b5e139f').call()).to.be.true;101 expect(await contract(helper).methods.supportsInterface('0x5b5e139f').call()).to.be.true;
102 });102 });
103103
104 itWeb3('ERC721Mintable support', async ({web3}) => {104 itEth('ERC721Mintable support', async ({helper}) => {
105 expect(await contract(web3).methods.supportsInterface('0x68ccfe89').call()).to.be.true;105 expect(await contract(helper).methods.supportsInterface('0x68ccfe89').call()).to.be.true;
106 });106 });
107107
108 itWeb3('ERC721Enumerable support', async ({web3}) => {108 itEth('ERC721Enumerable support', async ({helper}) => {
109 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;109 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;
110 });110 });
111111
112 itWeb3('ERC721UniqueExtensions support', async ({web3}) => {112 itEth('ERC721UniqueExtensions support', async ({helper}) => {
113 expect(await contract(web3).methods.supportsInterface('0xd74d154f').call()).to.be.true;113 expect(await contract(helper).methods.supportsInterface('0xd74d154f').call()).to.be.true;
114 });114 });
115115
116 itWeb3('ERC721Burnable support', async ({web3}) => {116 itEth('ERC721Burnable support', async ({helper}) => {
117 expect(await contract(web3).methods.supportsInterface('0x42966c68').call()).to.be.true;117 expect(await contract(helper).methods.supportsInterface('0x42966c68').call()).to.be.true;
118 });118 });
119119
120 itWeb3('ERC165 support', async ({web3}) => {120 itEth('ERC165 support', async ({helper}) => {
121 expect(await contract(web3).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;121 expect(await contract(helper).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;
122 });122 });
123});123});
124124
modifiedtests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth
13// You should have received a copy of the GNU General Public License13// You should have received a copy of the GNU General Public License
14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.14// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1515
16import {expect} from 'chai';16import {IKeyringPair} from '@polkadot/types/types';
17import privateKey from '../substrate/privateKey';
18import {UNIQUE} from '../util/helpers';17import {usingEthPlaygrounds, itEth, expect, EthUniqueHelper} from './util/playgrounds';
19import {
20 createEthAccount,
21 createEthAccountWithBalance,
22 evmCollection,
23 evmCollectionHelpers,
24 getCollectionAddressFromResult,
25 itWeb3,
26 recordEthFee,
27} from './util/helpers';
2818
19async function recordEthFee(helper: EthUniqueHelper, userAddress: string, call: () => Promise<any>) {
20 const before = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));
21 await call();
22 await helper.wait.newBlocks(1);
23 const after = await helper.balance.getSubstrate(helper.address.ethToSubstrate(userAddress));
24
25 expect(after < before).to.be.true;
26
27 return before - after;
28}
29
29describe('Add collection admins', () => {30describe('Add collection admins', () => {
30 itWeb3('Add admin by owner', async ({api, web3, privateKeyWrapper}) => {31 let donor: IKeyringPair;
31 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
32 const collectionHelper = evmCollectionHelpers(web3, owner);
3332
34 const result = await collectionHelper.methods33 before(async function() {
35 .createNonfungibleCollection('A', 'B', 'C')34 await usingEthPlaygrounds(async (_helper, privateKey) => {
36 .send({value: Number(2n * UNIQUE)});35 donor = privateKey('//Alice');
37 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);36 });
37 });
3838
39 const newAdmin = createEthAccount(web3);39 itEth('Add admin by owner', async ({helper}) => {
40 const owner = await helper.eth.createAccountWithBalance(donor);
40 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);41 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
42 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
43
44 const newAdmin = helper.eth.createAccount();
45
41 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();46 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
42 const adminList = await api.rpc.unique.adminlist(collectionId);47 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
43 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())48 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())
44 .to.be.eq(newAdmin.toLocaleLowerCase());49 .to.be.eq(newAdmin.toLocaleLowerCase());
45 });50 });
4651
47 // TODO: Temprorary off. Need refactor52 itEth.skip('Add substrate admin by owner', async ({helper}) => {
48 // itWeb3('Add substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {
49 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);53 const owner = await helper.eth.createAccountWithBalance(donor);
50 // const collectionHelper = evmCollectionHelpers(web3, owner);54 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
51
52 // const result = await collectionHelper.methods
53 // .createNonfungibleCollection('A', 'B', 'C')
54 // .send();
55 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);55 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
5656
57 // const newAdmin = privateKeyWrapper('//Alice');57 const [newAdmin] = await helper.arrange.createAccounts([10n], donor);
58 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
59 // await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();58 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();
6059
61 // const adminList = await api.rpc.unique.adminlist(collectionId);60 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
62 // expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())61 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())
63 // .to.be.eq(newAdmin.address.toLocaleLowerCase());62 .to.be.eq(newAdmin.address.toLocaleLowerCase());
64 // });63 });
65
66 itWeb3('Verify owner or admin', async ({api, web3, privateKeyWrapper}) => {
67 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
68 const collectionHelper = evmCollectionHelpers(web3, owner);
69
70 const result = await collectionHelper.methods
71 .createNonfungibleCollection('A', 'B', 'C')
72 .send({value: Number(2n * UNIQUE)});
73 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
7464
75 const newAdmin = createEthAccount(web3);65 itEth('Verify owner or admin', async ({helper}) => {
66 const owner = await helper.eth.createAccountWithBalance(donor);
67 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
68
69 const newAdmin = helper.eth.createAccount();
76 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);70 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
77 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;71 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.false;
78 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();72 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
79 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;73 expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;
80 });74 });
8175
82 itWeb3('(!negative tests!) Add admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {76 itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {
83 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);77 const owner = await helper.eth.createAccountWithBalance(donor);
84 const collectionHelper = evmCollectionHelpers(web3, owner);78 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
85
86 const result = await collectionHelper.methods
87 .createNonfungibleCollection('A', 'B', 'C')
88 .send({value: Number(2n * UNIQUE)});
89 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
9079
91 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);80 const admin = await helper.eth.createAccountWithBalance(donor);
92 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);81 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
93 await collectionEvm.methods.addCollectionAdmin(admin).send();82 await collectionEvm.methods.addCollectionAdmin(admin).send();
94 83
95 const user = createEthAccount(web3);84 const user = helper.eth.createAccount();
96 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))85 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: admin}))
97 .to.be.rejectedWith('NoPermission');86 .to.be.rejectedWith('NoPermission');
9887
99 const adminList = await api.rpc.unique.adminlist(collectionId);88 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
100 expect(adminList.length).to.be.eq(1);89 expect(adminList.length).to.be.eq(1);
101 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())90 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())
102 .to.be.eq(admin.toLocaleLowerCase());91 .to.be.eq(admin.toLocaleLowerCase());
103 });92 });
10493
105 itWeb3('(!negative tests!) Add admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {94 itEth('(!negative tests!) Add admin by USER is not allowed', async ({helper}) => {
106 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);95 const owner = await helper.eth.createAccountWithBalance(donor);
107 const collectionHelper = evmCollectionHelpers(web3, owner);96 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
108
109 const result = await collectionHelper.methods
110 .createNonfungibleCollection('A', 'B', 'C')
111 .send({value: Number(2n * UNIQUE)});
112 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
11397
114 const notAdmin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);98 const notAdmin = await helper.eth.createAccountWithBalance(donor);
115 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);99 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
116 100
117 const user = createEthAccount(web3);101 const user = helper.eth.createAccount();
118 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))102 await expect(collectionEvm.methods.addCollectionAdmin(user).call({from: notAdmin}))
119 .to.be.rejectedWith('NoPermission');103 .to.be.rejectedWith('NoPermission');
120104
121 const adminList = await api.rpc.unique.adminlist(collectionId);105 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
122 expect(adminList.length).to.be.eq(0);106 expect(adminList.length).to.be.eq(0);
123 });107 });
124108
125 // TODO: Temprorary off. Need refactor109 itEth.skip('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({helper}) => {
126 // itWeb3('(!negative tests!) Add substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {
127 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);110 const owner = await helper.eth.createAccountWithBalance(donor);
128 // const collectionHelper = evmCollectionHelpers(web3, owner);111 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
129
130 // const result = await collectionHelper.methods
131 // .createNonfungibleCollection('A', 'B', 'C')
132 // .send();
133 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
134112
135 // const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);113 const admin = await helper.eth.createAccountWithBalance(donor);
136 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);114 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
137 // await collectionEvm.methods.addCollectionAdmin(admin).send();115 await collectionEvm.methods.addCollectionAdmin(admin).send();
138116
139 // const notAdmin = privateKey('//Alice');117 const [notAdmin] = await helper.arrange.createAccounts([10n], donor);
140 // await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))118 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin.addressRaw).call({from: admin}))
141 // .to.be.rejectedWith('NoPermission');119 .to.be.rejectedWith('NoPermission');
142120
143 // const adminList = await api.rpc.unique.adminlist(collectionId);121 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
144 // expect(adminList.length).to.be.eq(1);122 expect(adminList.length).to.be.eq(1);
145 // expect(adminList[0].asEthereum.toString().toLocaleLowerCase())123 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())
146 // .to.be.eq(admin.toLocaleLowerCase());124 .to.be.eq(admin.toLocaleLowerCase());
147 // });125 });
148
149 // TODO: Temprorary off. Need refactor
150 // itWeb3('(!negative tests!) Add substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {
151 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
152 // const collectionHelper = evmCollectionHelpers(web3, owner);
153
154 // const result = await collectionHelper.methods
155 // .createNonfungibleCollection('A', 'B', 'C')
156 // .send();
157 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
158126
159 // const notAdmin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);127 itEth.skip('(!negative tests!) Add substrate admin by USER is not allowed', async ({helper}) => {
160 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
161 // const notAdmin1 = privateKey('//Alice');128 const owner = await helper.eth.createAccountWithBalance(donor);
162 // await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))129 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
163 // .to.be.rejectedWith('NoPermission');
164130
165 // const adminList = await api.rpc.unique.adminlist(collectionId);131 const notAdmin0 = await helper.eth.createAccountWithBalance(donor);
132 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
133 const [notAdmin1] = await helper.arrange.createAccounts([10n], donor);
134 await expect(collectionEvm.methods.addCollectionAdminSubstrate(notAdmin1.addressRaw).call({from: notAdmin0}))
135 .to.be.rejectedWith('NoPermission');
136
137 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
166 // expect(adminList.length).to.be.eq(0);138 expect(adminList.length).to.be.eq(0);
167 // });139 });
168});140});
169141
170describe('Remove collection admins', () => {142describe('Remove collection admins', () => {
171 itWeb3('Remove admin by owner', async ({api, web3, privateKeyWrapper}) => {143 let donor: IKeyringPair;
172 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
173 const collectionHelper = evmCollectionHelpers(web3, owner);
174
175 const result = await collectionHelper.methods
176 .createNonfungibleCollection('A', 'B', 'C')
177 .send({value: Number(2n * UNIQUE)});
178 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
179144
180 const newAdmin = createEthAccount(web3);145 before(async function() {
146 await usingEthPlaygrounds(async (_helper, privateKey) => {
147 donor = privateKey('//Alice');
148 });
149 });
150
151 itEth('Remove admin by owner', async ({helper}) => {
152 const owner = await helper.eth.createAccountWithBalance(donor);
153 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
154
155 const newAdmin = helper.eth.createAccount();
181 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);156 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
182 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();157 await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
158
183 {159 {
184 const adminList = await api.rpc.unique.adminlist(collectionId);160 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
185 expect(adminList.length).to.be.eq(1);161 expect(adminList.length).to.be.eq(1);
186 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())162 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())
187 .to.be.eq(newAdmin.toLocaleLowerCase());163 .to.be.eq(newAdmin.toLocaleLowerCase());
188 }164 }
189165
190 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();166 await collectionEvm.methods.removeCollectionAdmin(newAdmin).send();
191 const adminList = await api.rpc.unique.adminlist(collectionId);167 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
192 expect(adminList.length).to.be.eq(0);168 expect(adminList.length).to.be.eq(0);
193 });169 });
194170
195 // TODO: Temprorary off. Need refactor171 itEth.skip('Remove substrate admin by owner', async ({helper}) => {
196 // itWeb3('Remove substrate admin by owner', async ({api, web3, privateKeyWrapper}) => {
197 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);172 const owner = await helper.eth.createAccountWithBalance(donor);
198 // const collectionHelper = evmCollectionHelpers(web3, owner);173 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
199
200 // const result = await collectionHelper.methods
201 // .createNonfungibleCollection('A', 'B', 'C')
202 // .send();
203 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
204174
205 // const newAdmin = privateKeyWrapper('//Alice');175 const [newAdmin] = await helper.arrange.createAccounts([10n], donor);
206 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);176 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
207 // await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();177 await collectionEvm.methods.addCollectionAdminSubstrate(newAdmin.addressRaw).send();
208 // {178 {
209 // const adminList = await api.rpc.unique.adminlist(collectionId);179 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
210 // expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())180 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())
211 // .to.be.eq(newAdmin.address.toLocaleLowerCase());181 .to.be.eq(newAdmin.address.toLocaleLowerCase());
212 // }182 }
213
214 // await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();
215 // const adminList = await api.rpc.unique.adminlist(collectionId);
216 // expect(adminList.length).to.be.eq(0);
217 // });
218183
219 itWeb3('(!negative tests!) Remove admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {184 await collectionEvm.methods.removeCollectionAdminSubstrate(newAdmin.addressRaw).send();
220 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
221 const collectionHelper = evmCollectionHelpers(web3, owner);
222 185 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
223 const result = await collectionHelper.methods
224 .createNonfungibleCollection('A', 'B', 'C')
225 .send({value: Number(2n * UNIQUE)});186 expect(adminList.length).to.be.eq(0);
226 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);187 });
227188
228 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);189 itEth('(!negative tests!) Remove admin by ADMIN is not allowed', async ({helper}) => {
190 const owner = await helper.eth.createAccountWithBalance(donor);
191 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
229192
230 const admin0 = await createEthAccountWithBalance(api, web3, privateKeyWrapper);193 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
194
195 const admin0 = await helper.eth.createAccountWithBalance(donor);
231 await collectionEvm.methods.addCollectionAdmin(admin0).send();196 await collectionEvm.methods.addCollectionAdmin(admin0).send();
232 const admin1 = createEthAccount(web3);197 const admin1 = await helper.eth.createAccountWithBalance(donor);
233 await collectionEvm.methods.addCollectionAdmin(admin1).send();198 await collectionEvm.methods.addCollectionAdmin(admin1).send();
234199
235 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))200 await expect(collectionEvm.methods.removeCollectionAdmin(admin1).call({from: admin0}))
236 .to.be.rejectedWith('NoPermission');201 .to.be.rejectedWith('NoPermission');
237 {202 {
238 const adminList = await api.rpc.unique.adminlist(collectionId);203 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
239 expect(adminList.length).to.be.eq(2);204 expect(adminList.length).to.be.eq(2);
240 expect(adminList.toString().toLocaleLowerCase())205 expect(adminList.toString().toLocaleLowerCase())
241 .to.be.deep.contains(admin0.toLocaleLowerCase())206 .to.be.deep.contains(admin0.toLocaleLowerCase())
242 .to.be.deep.contains(admin1.toLocaleLowerCase());207 .to.be.deep.contains(admin1.toLocaleLowerCase());
243 }208 }
244 });209 });
245210
246 itWeb3('(!negative tests!) Remove admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {211 itEth('(!negative tests!) Remove admin by USER is not allowed', async ({helper}) => {
247 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);212 const owner = await helper.eth.createAccountWithBalance(donor);
248 const collectionHelper = evmCollectionHelpers(web3, owner);213 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
249
250 const result = await collectionHelper.methods
251 .createNonfungibleCollection('A', 'B', 'C')
252 .send({value: Number(2n * UNIQUE)});
253 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
254214
255 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);215 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
256216
257 const admin = await createEthAccountWithBalance(api, web3, privateKeyWrapper);217 const admin = await helper.eth.createAccountWithBalance(donor);
258 await collectionEvm.methods.addCollectionAdmin(admin).send();218 await collectionEvm.methods.addCollectionAdmin(admin).send();
259 const notAdmin = createEthAccount(web3);219 const notAdmin = helper.eth.createAccount();
260220
261 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))221 await expect(collectionEvm.methods.removeCollectionAdmin(admin).call({from: notAdmin}))
262 .to.be.rejectedWith('NoPermission');222 .to.be.rejectedWith('NoPermission');
263 {223 {
264 const adminList = await api.rpc.unique.adminlist(collectionId);224 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
265 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())225 expect(adminList[0].asEthereum.toString().toLocaleLowerCase())
266 .to.be.eq(admin.toLocaleLowerCase());226 .to.be.eq(admin.toLocaleLowerCase());
267 expect(adminList.length).to.be.eq(1);227 expect(adminList.length).to.be.eq(1);
268 }228 }
269 });229 });
270230
271 // TODO: Temprorary off. Need refactor231 itEth.skip('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({helper}) => {
272 // itWeb3('(!negative tests!) Remove substrate admin by ADMIN is not allowed', async ({api, web3, privateKeyWrapper}) => {
273 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);232 const owner = await helper.eth.createAccountWithBalance(donor);
274 // const collectionHelper = evmCollectionHelpers(web3, owner);233 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
275
276 // const result = await collectionHelper.methods
277 // .createNonfungibleCollection('A', 'B', 'C')
278 // .send();
279 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
280234
281 // const adminSub = privateKeyWrapper('//Alice');235 const [adminSub] = await helper.arrange.createAccounts([10n], donor);
282 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);236 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
283 // await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();237 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();
284 // const adminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);238 const adminEth = await helper.eth.createAccountWithBalance(donor);
285 // await collectionEvm.methods.addCollectionAdmin(adminEth).send();239 await collectionEvm.methods.addCollectionAdmin(adminEth).send();
286240
287 // await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))241 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: adminEth}))
288 // .to.be.rejectedWith('NoPermission');242 .to.be.rejectedWith('NoPermission');
289243
290 // const adminList = await api.rpc.unique.adminlist(collectionId);244 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
291 // expect(adminList.length).to.be.eq(2);245 expect(adminList.length).to.be.eq(2);
292 // expect(adminList.toString().toLocaleLowerCase())246 expect(adminList.toString().toLocaleLowerCase())
293 // .to.be.deep.contains(adminSub.address.toLocaleLowerCase())247 .to.be.deep.contains(adminSub.address.toLocaleLowerCase())
294 // .to.be.deep.contains(adminEth.toLocaleLowerCase());248 .to.be.deep.contains(adminEth.toLocaleLowerCase());
295 // });249 });
296250
297 // TODO: Temprorary off. Need refactor251 itEth.skip('(!negative tests!) Remove substrate admin by USER is not allowed', async ({helper}) => {
298 // itWeb3('(!negative tests!) Remove substrate admin by USER is not allowed', async ({api, web3, privateKeyWrapper}) => {
299 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);252 const owner = await helper.eth.createAccountWithBalance(donor);
300 // const collectionHelper = evmCollectionHelpers(web3, owner);253 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
301
302 // const result = await collectionHelper.methods
303 // .createNonfungibleCollection('A', 'B', 'C')
304 // .send();
305 // const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
306254
307 // const adminSub = privateKeyWrapper('//Alice');255 const [adminSub] = await helper.arrange.createAccounts([10n], donor);
308 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);256 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
309 // await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();257 await collectionEvm.methods.addCollectionAdminSubstrate(adminSub.addressRaw).send();
310 // const notAdminEth = await createEthAccountWithBalance(api, web3, privateKeyWrapper);258 const notAdminEth = await helper.eth.createAccountWithBalance(donor);
311259
312 // await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))260 await expect(collectionEvm.methods.removeCollectionAdminSubstrate(adminSub.addressRaw).call({from: notAdminEth}))
313 // .to.be.rejectedWith('NoPermission');261 .to.be.rejectedWith('NoPermission');
314262
315 // const adminList = await api.rpc.unique.adminlist(collectionId);263 const adminList = await helper.callRpc('api.rpc.unique.adminlist', [collectionId]);
316 // expect(adminList.length).to.be.eq(1);264 expect(adminList.length).to.be.eq(1);
317 // expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())265 expect(adminList[0].asSubstrate.toString().toLocaleLowerCase())
318 // .to.be.eq(adminSub.address.toLocaleLowerCase());266 .to.be.eq(adminSub.address.toLocaleLowerCase());
319 // });267 });
320});268});
321269
322describe('Change owner tests', () => {270describe('Change owner tests', () => {
323 itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {271 let donor: IKeyringPair;
272
273 before(async function() {
274 await usingEthPlaygrounds(async (_helper, privateKey) => {
324 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);275 donor = privateKey('//Alice');
325 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);276 });
277 });
278
279 itEth('Change owner', async ({helper}) => {
326 const collectionHelper = evmCollectionHelpers(web3, owner);280 const owner = await helper.eth.createAccountWithBalance(donor);
327 const result = await collectionHelper.methods281 const newOwner = await helper.eth.createAccountWithBalance(donor);
328 .createNonfungibleCollection('A', 'B', 'C')282 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
329 .send({value: Number(2n * UNIQUE)});
330 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);283 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
331 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);284
332
333 await collectionEvm.methods.setOwner(newOwner).send();285 await collectionEvm.methods.setOwner(newOwner).send();
334 286
335 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;287 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;
336 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;288 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.true;
337 });289 });
338290
339 itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {291 itEth('change owner call fee', async ({helper}) => {
340 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);292 const owner = await helper.eth.createAccountWithBalance(donor);
341 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);293 const newOwner = await helper.eth.createAccountWithBalance(donor);
342 const collectionHelper = evmCollectionHelpers(web3, owner);294 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
343 const result = await collectionHelper.methods
344 .createNonfungibleCollection('A', 'B', 'C')
345 .send({value: Number(2n * UNIQUE)});
346 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);295 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
347 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
348
349 const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwner(newOwner).send());296 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwner(newOwner).send());
350 expect(cost < BigInt(0.2 * Number(UNIQUE)));297 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
351 expect(cost > 0);298 expect(cost > 0);
352 });299 });
353300
354 itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {301 itEth('(!negative tests!) call setOwner by non owner', async ({helper}) => {
355 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);302 const owner = await helper.eth.createAccountWithBalance(donor);
356 const newOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);303 const newOwner = await helper.eth.createAccountWithBalance(donor);
357 const collectionHelper = evmCollectionHelpers(web3, owner);304 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
358 const result = await collectionHelper.methods
359 .createNonfungibleCollection('A', 'B', 'C')
360 .send({value: Number(2n * UNIQUE)});
361 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);305 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
362 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);306
363
364 await expect(collectionEvm.methods.setOwner(newOwner).send({from: newOwner})).to.be.rejected;307 await expect(collectionEvm.methods.setOwner(newOwner).send({from: newOwner})).to.be.rejected;
365 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;308 expect(await collectionEvm.methods.isOwnerOrAdmin(newOwner).call()).to.be.false;
366 });309 });
367});310});
368311
369describe('Change substrate owner tests', () => {312describe('Change substrate owner tests', () => {
370 // TODO: Temprorary off. Need refactor313 let donor: IKeyringPair;
371 // itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {
372 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
373 // const newOwner = privateKeyWrapper('//Alice');
374 // const collectionHelper = evmCollectionHelpers(web3, owner);
375 // const result = await collectionHelper.methods
376 // .createNonfungibleCollection('A', 'B', 'C')
377 // .send();
378 // const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
379 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
380
381 // expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.true;
382 // expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;
383
384 // await collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send();
385
386 // expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;
387 // expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;
388 // });
389314
390 // TODO: Temprorary off. Need refactor315 before(async function() {
391 // itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {
392 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);316 await usingEthPlaygrounds(async (_helper, privateKey) => {
393 // const newOwner = privateKeyWrapper('//Alice');
394 // const collectionHelper = evmCollectionHelpers(web3, owner);317 donor = privateKey('//Alice');
395 // const result = await collectionHelper.methods
396 // .createNonfungibleCollection('A', 'B', 'C')
397 // .send();
398 // const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);318 });
399 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);319 });
400320
401 // const cost = await recordEthFee(api, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());321 itEth.skip('Change owner', async ({helper}) => {
322 const owner = await helper.eth.createAccountWithBalance(donor);
323 const [newOwner] = await helper.arrange.createAccounts([10n], donor);
402 // expect(cost < BigInt(0.2 * Number(UNIQUE)));324 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
403 // expect(cost > 0);325 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
404 // });
405326
406 // TODO: Temprorary off. Need refactor327 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.true;
328 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;
329
407 // itWeb3('(!negative tests!) call setOwner by non owner', async ({api, web3, privateKeyWrapper}) => {330 await collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send();
331
332 expect(await collectionEvm.methods.isOwnerOrAdmin(owner).call()).to.be.false;
333 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;
334 });
335
336 itEth.skip('change owner call fee', async ({helper}) => {
408 // const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);337 const owner = await helper.eth.createAccountWithBalance(donor);
338 const [newOwner] = await helper.arrange.createAccounts([10n], donor);
409 // const otherReceiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);339 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
410 // const newOwner = privateKeyWrapper('//Alice');340 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
341
411 // const collectionHelper = evmCollectionHelpers(web3, owner);342 const cost = await recordEthFee(helper, owner, () => collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send());
412 // const result = await collectionHelper.methods343 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
413 // .createNonfungibleCollection('A', 'B', 'C')344 expect(cost > 0);
345 });
346
347 itEth.skip('(!negative tests!) call setOwner by non owner', async ({helper}) => {
414 // .send();348 const owner = await helper.eth.createAccountWithBalance(donor);
415 // const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);349 const otherReceiver = await helper.eth.createAccountWithBalance(donor);
350 const [newOwner] = await helper.arrange.createAccounts([10n], donor);
351 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
416 // const collectionEvm = evmCollection(web3, owner, collectionIdAddress);352 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
417 353
418 // await expect(collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;354 await expect(collectionEvm.methods.setOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;
419 // expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;355 expect(await collectionEvm.methods.isOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;
420 // });356 });
421});357});
358
modifiedtests/src/eth/collectionProperties.test.tsdiffbeforeafterboth
1import {addCollectionAdminExpectSuccess, createCollectionExpectSuccess} from '../util/helpers';
2import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3} from './util/helpers';1import {itEth, usingEthPlaygrounds, expect} from './util/playgrounds';
3import nonFungibleAbi from './nonFungibleAbi.json';
4import {expect} from 'chai';
5import {executeTransaction} from '../substrate/substrate-api';2import {IKeyringPair} from '@polkadot/types/types';
63
7describe('EVM collection properties', () => {4describe('EVM collection properties', () => {
5 let donor: IKeyringPair;
6 let alice: IKeyringPair;
7
8 before(async function() {
9 await usingEthPlaygrounds(async (_helper, privateKey) => {
10 donor = privateKey('//Alice');
11 [alice] = await _helper.arrange.createAccounts([10n], donor);
12 });
13 });
14
8 itWeb3('Can be set', async({web3, api, privateKeyWrapper}) => {15 itEth('Can be set', async({helper}) => {
9 const alice = privateKeyWrapper('//Alice');
10 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);16 const caller = await helper.eth.createAccountWithBalance(donor);
11 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});17 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test'});
12
13 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});18 await collection.addAdmin(alice, {Ethereum: caller});
1419
15 const address = collectionIdToAddress(collection);20 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
16 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});21 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
1722
18 await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});23 await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send({from: caller});
1924
20 const [{value}] = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toHuman()! as any;25 const raw = (await collection.getData())?.raw;
26
21 expect(value).to.equal('testValue');27 expect(raw.properties[0].value).to.equal('testValue');
22 });28 });
29
23 itWeb3('Can be deleted', async({web3, api, privateKeyWrapper}) => {30 itEth('Can be deleted', async({helper}) => {
24 const alice = privateKeyWrapper('//Alice');
25 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);31 const caller = await helper.eth.createAccountWithBalance(donor);
26 const collection = await createCollectionExpectSuccess({mode: {type: 'NFT'}});32 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});
27
28 await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}]));
2933
30 await addCollectionAdminExpectSuccess(alice, collection, {Ethereum: caller});34 await collection.addAdmin(alice, {Ethereum: caller});
3135
32 const address = collectionIdToAddress(collection);36 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
33 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});37 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
3438
35 await contract.methods.deleteCollectionProperty('testKey').send({from: caller});39 await contract.methods.deleteCollectionProperty('testKey').send({from: caller});
3640
37 const result = (await api.rpc.unique.collectionProperties(collection, ['testKey'])).toJSON()! as any;41 const raw = (await collection.getData())?.raw;
42
38 expect(result.length).to.equal(0);43 expect(raw.properties.length).to.equal(0);
39 });44 });
45
40 itWeb3('Can be read', async({web3, api, privateKeyWrapper}) => {46 itEth('Can be read', async({helper}) => {
41 const alice = privateKeyWrapper('//Alice');
42 const caller = createEthAccount(web3);47 const caller = helper.eth.createAccount();
43 const collection = await createCollectionExpectSuccess({mode: {type:'NFT'}});48 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});
44
45 await executeTransaction(api, alice, api.tx.unique.setCollectionProperties(collection, [{key: 'testKey', value: 'testValue'}]));
4649
47 const address = collectionIdToAddress(collection);50 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
48 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});51 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
4952
50 const value = await contract.methods.collectionProperty('testKey').call();53 const value = await contract.methods.collectionProperty('testKey').call();
51 expect(value).to.equal(web3.utils.toHex('testValue'));54 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));
52 });55 });
53});56});
5457
modifiedtests/src/eth/proxy/fungibleProxy.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {createCollectionExpectSuccess, createFungibleItemExpectSuccess} from '../../util/helpers';
18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';17import {GAS_ARGS, normalizeEvents} from '../util/helpers';
19import fungibleAbi from '../fungibleAbi.json';
20import {expect} from 'chai';18import {expect} from 'chai';
21import {ApiPromise} from '@polkadot/api';
22import Web3 from 'web3';
23import {readFile} from 'fs/promises';19import {readFile} from 'fs/promises';
24import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';
21import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util/playgrounds';
2522
26async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any, privateKeyWrapper: (account: string) => IKeyringPair) {23async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {
27 // Proxy owner has no special privilegies, we don't need to reuse them24 // Proxy owner has no special privilegies, we don't need to reuse them
28 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);25 const owner = await helper.eth.createAccountWithBalance(donor);
26 const web3 = helper.getWeb3();
29 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {27 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueFungibleProxy.abi`)).toString()), undefined, {
30 from: owner,28 from: owner,
31 ...GAS_ARGS,29 ...GAS_ARGS,
35}33}
3634
37describe('Fungible (Via EVM proxy): Information getting', () => {35describe('Fungible (Via EVM proxy): Information getting', () => {
36 let alice: IKeyringPair;
37 let donor: IKeyringPair;
38
39 before(async function() {
40 await usingEthPlaygrounds(async (helper, privateKey) => {
41 donor = privateKey('//Alice');
42 [alice] = await helper.arrange.createAccounts([10n], donor);
43 });
44 });
45
38 itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {46 itEth('totalSupply', async ({helper}) => {
39 const collection = await createCollectionExpectSuccess({47 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
40 name: 'token name',
41 mode: {type: 'Fungible', decimalPoints: 0},
42 });
43 const alice = privateKeyWrapper('//Alice');
44 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);48 const caller = await helper.eth.createAccountWithBalance(donor);
45
46 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});49 await collection.mint(alice, 200n, {Substrate: alice.address});
4750
48 const address = collectionIdToAddress(collection);51 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
52 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
49 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);53 const contract = await proxyWrap(helper, evmCollection, donor);
50 const totalSupply = await contract.methods.totalSupply().call();54 const totalSupply = await contract.methods.totalSupply().call();
5155
52 expect(totalSupply).to.equal('200');56 expect(totalSupply).to.equal('200');
53 });57 });
5458
55 itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {59 itEth('balanceOf', async ({helper}) => {
56 const collection = await createCollectionExpectSuccess({60 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
57 name: 'token name',
58 mode: {type: 'Fungible', decimalPoints: 0},
59 });
60 const alice = privateKeyWrapper('//Alice');
61 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);61 const caller = await helper.eth.createAccountWithBalance(donor);
6262
63 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});63 await collection.mint(alice, 200n, {Ethereum: caller});
6464
65 const address = collectionIdToAddress(collection);65 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
66 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
66 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);67 const contract = await proxyWrap(helper, evmCollection, donor);
67 const balance = await contract.methods.balanceOf(caller).call();68 const balance = await contract.methods.balanceOf(caller).call();
6869
69 expect(balance).to.equal('200');70 expect(balance).to.equal('200');
70 });71 });
71});72});
7273
73describe('Fungible (Via EVM proxy): Plain calls', () => {74describe('Fungible (Via EVM proxy): Plain calls', () => {
75 let alice: IKeyringPair;
76 let donor: IKeyringPair;
77
78 before(async function() {
79 await usingEthPlaygrounds(async (helper, privateKey) => {
80 donor = privateKey('//Alice');
81 [alice] = await helper.arrange.createAccounts([10n], donor);
82 });
83 });
84
74 itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {85 itEth('Can perform approve()', async ({helper}) => {
75 const collection = await createCollectionExpectSuccess({86 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
76 name: 'token name',
77 mode: {type: 'Fungible', decimalPoints: 0},
78 });
79 const alice = privateKeyWrapper('//Alice');87 const caller = await helper.eth.createAccountWithBalance(donor);
80 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);88 const spender = helper.eth.createAccount();
89
81 const spender = createEthAccount(web3);90 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
82
83 const address = collectionIdToAddress(collection);91 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
84 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);92 const contract = await proxyWrap(helper, evmCollection, donor);
85 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: contract.options.address});93 await collection.mint(alice, 200n, {Ethereum: contract.options.address});
8694
87 {95 {
88 const result = await contract.methods.approve(spender, 100).send({from: caller});96 const result = await contract.methods.approve(spender, 100).send({from: caller});
107 }115 }
108 });116 });
109117
110 itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {118 itEth('Can perform transferFrom()', async ({helper}) => {
111 const collection = await createCollectionExpectSuccess({119 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
112 name: 'token name',
113 mode: {type: 'Fungible', decimalPoints: 0},
114 });
115 const alice = privateKeyWrapper('//Alice');
116 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);120 const caller = await helper.eth.createAccountWithBalance(donor);
117 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);121 const owner = await helper.eth.createAccountWithBalance(donor);
118122
119 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});123 await collection.mint(alice, 200n, {Ethereum: owner});
120
121 const receiver = createEthAccount(web3);124 const receiver = helper.eth.createAccount();
122125
123 const address = collectionIdToAddress(collection);126 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
124 const evmCollection = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});127 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
125 const contract = await proxyWrap(api, web3, evmCollection, privateKeyWrapper);128 const contract = await proxyWrap(helper, evmCollection, donor);
126129
127 await evmCollection.methods.approve(contract.options.address, 100).send({from: owner});130 await evmCollection.methods.approve(contract.options.address, 100).send({from: owner});
128131
162 }165 }
163 });166 });
164167
165 itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {168 itEth('Can perform transfer()', async ({helper}) => {
166 const collection = await createCollectionExpectSuccess({169 const collection = await helper.ft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}, 0);
167 name: 'token name',
168 mode: {type: 'Fungible', decimalPoints: 0},
169 });
170 const alice = privateKeyWrapper('//Alice');170 const caller = await helper.eth.createAccountWithBalance(donor);
171 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);171 const receiver = await helper.eth.createAccountWithBalance(donor);
172
172 const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);173 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
173
174 const address = collectionIdToAddress(collection);174 const evmCollection = helper.ethNativeContract.collection(address, 'ft', caller);
175 const contract = await proxyWrap(api, web3, new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);175 const contract = await proxyWrap(helper, evmCollection, donor);
176 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: contract.options.address});176 await collection.mint(alice, 200n, {Ethereum: contract.options.address});
177177
178 {178 {
179 const result = await contract.methods.transfer(receiver, 50).send({from: caller});179 const result = await contract.methods.transfer(receiver, 50).send({from: caller});
modifiedtests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../../util/helpers';17import {GAS_ARGS, itWeb3, normalizeEvents} from '../util/helpers';
18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents} from '../util/helpers';
19import nonFungibleAbi from '../nonFungibleAbi.json';
20import {expect} from 'chai';18import {expect} from 'chai';
21import {submitTransactionAsync} from '../../substrate/substrate-api';
22import Web3 from 'web3';
23import {readFile} from 'fs/promises';19import {readFile} from 'fs/promises';
24import {ApiPromise} from '@polkadot/api';
25import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';
21import {EthUniqueHelper, itEth, usingEthPlaygrounds} from '../util/playgrounds';
2622
27async function proxyWrap(api: ApiPromise, web3: Web3, wrapped: any, privateKeyWrapper: (account: string) => IKeyringPair) {23async function proxyWrap(helper: EthUniqueHelper, wrapped: any, donor: IKeyringPair) {
28 // Proxy owner has no special privilegies, we don't need to reuse them24 // Proxy owner has no special privilegies, we don't need to reuse them
29 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);25 const owner = await helper.eth.createAccountWithBalance(donor);
26 const web3 = helper.getWeb3();
30 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {27 const proxyContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/UniqueNFTProxy.abi`)).toString()), undefined, {
31 from: owner,28 from: owner,
32 ...GAS_ARGS,29 ...GAS_ARGS,
36}33}
3734
38describe('NFT (Via EVM proxy): Information getting', () => {35describe('NFT (Via EVM proxy): Information getting', () => {
39 itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {36 let alice: IKeyringPair;
37 let donor: IKeyringPair;
38
39 before(async function() {
40 await usingEthPlaygrounds(async (helper, privateKey) => {
40 const collection = await createCollectionExpectSuccess({41 donor = privateKey('//Alice');
41 mode: {type: 'NFT'},42 [alice] = await helper.arrange.createAccounts([10n], donor);
42 });43 });
43 const alice = privateKeyWrapper('//Alice');44 });
44 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
4545
46 await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});46 itEth('totalSupply', async ({helper}) => {
47 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
48 const caller = await helper.eth.createAccountWithBalance(donor);
49 await collection.mintToken(alice, {Substrate: alice.address});
4750
48 const address = collectionIdToAddress(collection);51 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
49 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);52 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
53 const contract = await proxyWrap(helper, evmCollection, donor);
50 const totalSupply = await contract.methods.totalSupply().call();54 const totalSupply = await contract.methods.totalSupply().call();
5155
52 expect(totalSupply).to.equal('1');56 expect(totalSupply).to.equal('1');
53 });57 });
5458
55 itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {59 itEth('balanceOf', async ({helper}) => {
56 const collection = await createCollectionExpectSuccess({60 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
57 mode: {type: 'NFT'},
58 });
59 const alice = privateKeyWrapper('//Alice');
6061
61 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);62 const caller = await helper.eth.createAccountWithBalance(donor);
62 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});63 await collection.mintMultipleTokens(alice, [
64 {owner: {Ethereum: caller}},
63 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});65 {owner: {Ethereum: caller}},
64 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});66 {owner: {Ethereum: caller}},
67 ]);
6568
66 const address = collectionIdToAddress(collection);69 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
67 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);70 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
71 const contract = await proxyWrap(helper, evmCollection, donor);
68 const balance = await contract.methods.balanceOf(caller).call();72 const balance = await contract.methods.balanceOf(caller).call();
6973
70 expect(balance).to.equal('3');74 expect(balance).to.equal('3');
71 });75 });
7276
73 itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {77 itEth('ownerOf', async ({helper}) => {
74 const collection = await createCollectionExpectSuccess({78 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
75 mode: {type: 'NFT'},
76 });
77 const alice = privateKeyWrapper('//Alice');
7879
79 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);80 const caller = await helper.eth.createAccountWithBalance(donor);
80 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});81 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});
8182
82 const address = collectionIdToAddress(collection);83 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
83 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);84 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
85 const contract = await proxyWrap(helper, evmCollection, donor);
84 const owner = await contract.methods.ownerOf(tokenId).call();86 const owner = await contract.methods.ownerOf(tokenId).call();
8587
86 expect(owner).to.equal(caller);88 expect(owner).to.equal(caller);
87 });89 });
88});90});
8991
90describe('NFT (Via EVM proxy): Plain calls', () => {92describe('NFT (Via EVM proxy): Plain calls', () => {
91 itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {93 let alice: IKeyringPair;
94 let donor: IKeyringPair;
95
96 before(async function() {
97 await usingEthPlaygrounds(async (helper, privateKey) => {
92 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);98 donor = privateKey('//Alice');
93 const collectionHelper = evmCollectionHelpers(web3, owner);99 [alice] = await helper.arrange.createAccounts([10n], donor);
94 const result = await collectionHelper.methods100 });
101 });
102
95 .createNonfungibleCollection('A', 'A', 'A')103 itEth('Can perform mint()', async ({helper}) => {
96 .send({value: Number(2n * UNIQUE)});104 const owner = await helper.eth.createAccountWithBalance(donor);
97 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);105 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'A', 'A');
98 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);106 const caller = await helper.eth.createAccountWithBalance(donor);
99 const receiver = createEthAccount(web3);107 const receiver = helper.eth.createAccount();
108
100 const collectionEvmOwned = evmCollection(web3, owner, collectionIdAddress);109 const collectionEvmOwned = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
101 const collectionEvm = evmCollection(web3, caller, collectionIdAddress);110 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);
102 const contract = await proxyWrap(api, web3, collectionEvm, privateKeyWrapper);111 const contract = await proxyWrap(helper, collectionEvm, donor);
103 await collectionEvmOwned.methods.addCollectionAdmin(contract.options.address).send();112 await collectionEvmOwned.methods.addCollectionAdmin(contract.options.address).send();
104113
105 {114 {
115124
116 expect(events).to.be.deep.equal([125 expect(events).to.be.deep.equal([
117 {126 {
118 address: collectionIdAddress.toLocaleLowerCase(),127 address: collectionAddress.toLocaleLowerCase(),
119 event: 'Transfer',128 event: 'Transfer',
120 args: {129 args: {
121 from: '0x0000000000000000000000000000000000000000',130 from: '0x0000000000000000000000000000000000000000',
128 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');137 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
129 }138 }
130 });139 });
131 140
132 //TODO: CORE-302 add eth methods141 //TODO: CORE-302 add eth methods
133 itWeb3.skip('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {142 itWeb3.skip('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {
143 /*
134 const collection = await createCollectionExpectSuccess({144 const collection = await createCollectionExpectSuccess({
135 mode: {type: 'NFT'},145 mode: {type: 'NFT'},
136 });146 });
191 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');201 expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
192 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');202 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');
193 }203 }
204 */
194 });205 });
195206
196 itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {207 itEth('Can perform burn()', async ({helper}) => {
197 const collection = await createCollectionExpectSuccess({208 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
198 mode: {type: 'NFT'},
199 });
200 const alice = privateKeyWrapper('//Alice');
201 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);209 const caller = await helper.eth.createAccountWithBalance(donor);
202210
203 const address = collectionIdToAddress(collection);211 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
204 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);212 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
213 const contract = await proxyWrap(helper, evmCollection, donor);
205 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});214 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});
215 await collection.addAdmin(alice, {Ethereum: contract.options.address});
206216
207 const changeAdminTx = api.tx.unique.addCollectionAdmin(collection, {Ethereum: contract.options.address});
208 await submitTransactionAsync(alice, changeAdminTx);
209
210 {217 {
211 const result = await contract.methods.burn(tokenId).send({from: caller});218 const result = await contract.methods.burn(tokenId).send({from: caller});
212 const events = normalizeEvents(result.events);219 const events = normalizeEvents(result.events);
225 }232 }
226 });233 });
227234
228 itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {235 itEth('Can perform approve()', async ({helper}) => {
229 const collection = await createCollectionExpectSuccess({236 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
230 mode: {type: 'NFT'},
231 });
232 const alice = privateKeyWrapper('//Alice');
233 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);237 const caller = await helper.eth.createAccountWithBalance(donor);
234 const spender = createEthAccount(web3);238 const spender = helper.eth.createAccount();
235239
236 const address = collectionIdToAddress(collection);240 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
237 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address), privateKeyWrapper);241 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
242 const contract = await proxyWrap(helper, evmCollection, donor);
238 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});243 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});
239244
240 {245 {
241 const result = await contract.methods.approve(spender, tokenId).send({from: caller, ...GAS_ARGS});246 const result = await contract.methods.approve(spender, tokenId).send({from: caller, ...GAS_ARGS});
255 }260 }
256 });261 });
257262
258 itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {263 itEth('Can perform transferFrom()', async ({helper}) => {
259 const collection = await createCollectionExpectSuccess({264 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
260 mode: {type: 'NFT'},
261 });
262 const alice = privateKeyWrapper('//Alice');
263 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);265 const caller = await helper.eth.createAccountWithBalance(donor);
264 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);266 const owner = await helper.eth.createAccountWithBalance(donor);
265267
266 const receiver = createEthAccount(web3);268 const receiver = helper.eth.createAccount();
267269
268 const address = collectionIdToAddress(collection);270 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
269 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});271 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
270 const contract = await proxyWrap(api, web3, evmCollection, privateKeyWrapper);272 const contract = await proxyWrap(helper, evmCollection, donor);
271 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});273 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});
272274
273 await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});275 await evmCollection.methods.approve(contract.options.address, tokenId).send({from: owner});
274276
299 }301 }
300 });302 });
301303
302 itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {304 itEth('Can perform transfer()', async ({helper}) => {
303 const collection = await createCollectionExpectSuccess({305 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
304 mode: {type: 'NFT'},
305 });
306 const alice = privateKeyWrapper('//Alice');
307 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);306 const caller = await helper.eth.createAccountWithBalance(donor);
308 const receiver = createEthAccount(web3);307 const receiver = helper.eth.createAccount();
309308
310 const address = collectionIdToAddress(collection);309 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
311 const contract = await proxyWrap(api, web3, new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS}), privateKeyWrapper);310 const evmCollection = helper.ethNativeContract.collection(address, 'nft', caller);
311 const contract = await proxyWrap(helper, evmCollection, donor);
312 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});312 const {tokenId} = await collection.mintToken(alice, {Ethereum: contract.options.address});
313313
314 {314 {
315 const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});315 const result = await contract.methods.transfer(receiver, tokenId).send({from: caller});