difftreelog
tests(eth): NFT, RFT, FT tests refactored for playgrounds
in: master
6 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -87,8 +87,11 @@
"testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",
"testEthCreateNFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createNFTCollection.test.ts",
"testEthCreateRFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createRFTCollection.test.ts",
+ "testEthNFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/nonFungible.test.ts",
"testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",
+ "testEthRFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/reFungible.test.ts ./**/eth/reFungibleToken.test.ts",
"testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",
+ "testEthFT": "mocha --timeout 9999999 -r ts-node/register ./**/eth/fungible.test.ts",
"testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",
"testPromotion": "mocha --timeout 9999999 -r ts-node/register ./**/app-promotion.test.ts",
"polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -14,204 +14,132 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import {approveExpectSuccess, createCollection, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';
-import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';
-import fungibleAbi from './fungibleAbi.json';
-import {expect} from 'chai';
-import {submitTransactionAsync} from '../substrate/substrate-api';
+import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {IKeyringPair} from '@polkadot/types/types';
describe('Fungible: Information getting', () => {
- itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: {type: 'Fungible', decimalPoints: 0},
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([20n], donor);
});
- const alice = privateKeyWrapper('//Alice');
+ });
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ itEth('totalSupply', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n);
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});
-
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+ const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
const totalSupply = await contract.methods.totalSupply().call();
-
expect(totalSupply).to.equal('200');
});
- itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: {type: 'Fungible', decimalPoints: 0},
- });
- const alice = privateKeyWrapper('//Alice');
+ itEth('balanceOf', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: caller});
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});
-
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+ const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
const balance = await contract.methods.balanceOf(caller).call();
-
expect(balance).to.equal('200');
});
});
describe('Fungible: Plain calls', () => {
- itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
- const collection = await createCollection(api, alice, {
- name: 'token name',
- mode: {type: 'Fungible', decimalPoints: 0},
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([20n], donor);
});
+ });
- const receiver = createEthAccount(web3);
+ itEth('Can perform mint()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.addAdmin(alice, {Ethereum: owner});
- const collectionIdAddress = collectionIdToAddress(collection.collectionId);
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const changeAdminTx = api.tx.unique.addCollectionAdmin(collection.collectionId, {Ethereum: owner});
- await submitTransactionAsync(alice, changeAdminTx);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
- const collectionContract = evmCollection(web3, owner, collectionIdAddress, {type: 'Fungible', decimalPoints: 0});
- const result = await collectionContract.methods.mint(receiver, 100).send();
- const events = normalizeEvents(result.events);
+ const result = await contract.methods.mint(receiver, 100).send();
- expect(events).to.be.deep.equal([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver,
- value: '100',
- },
- },
- ]);
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.value).to.equal('100');
});
-
- itWeb3('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
- const collection = await createCollection(api, alice, {
- name: 'token name',
- mode: {type: 'Fungible', decimalPoints: 0},
- });
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const receiver1 = createEthAccount(web3);
- const receiver2 = createEthAccount(web3);
- const receiver3 = createEthAccount(web3);
-
- const collectionIdAddress = collectionIdToAddress(collection.collectionId);
- const changeAdminTx = api.tx.unique.addCollectionAdmin(collection.collectionId, {Ethereum: owner});
- await submitTransactionAsync(alice, changeAdminTx);
+ itEth('Can perform mintBulk()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const bulkSize = 3;
+ const receivers = [...new Array(bulkSize)].map(() => helper.eth.createAccount());
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.addAdmin(alice, {Ethereum: owner});
- const collectionContract = evmCollection(web3, owner, collectionIdAddress, {type: 'Fungible', decimalPoints: 0});
- const result = await collectionContract.methods.mintBulk([
- [receiver1, 10],
- [receiver2, 20],
- [receiver3, 30],
- ]).send();
- const events = normalizeEvents(result.events);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
- expect(events).to.be.deep.contain({
- address:collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver1,
- value: '10',
- },
- });
-
- expect(events).to.be.deep.contain({
- address:collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver2,
- value: '20',
- },
- });
-
- expect(events).to.be.deep.contain({
- address:collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver3,
- value: '30',
- },
- });
+ const result = await contract.methods.mintBulk(Array.from({length: bulkSize}, (_, i) => (
+ [receivers[i], (i + 1) * 10]
+ ))).send();
+ const events = result.events.Transfer.sort((a: any, b: any) => +a.returnValues.value - b.returnValues.value);
+ for (let i = 0; i < bulkSize; i++) {
+ const event = events[i];
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receivers[i]);
+ expect(event.returnValues.value).to.equal(String(10 * (i + 1)));
+ }
});
- itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
- const collection = await createCollection(api, alice, {
- name: 'token name',
- mode: {type: 'Fungible', decimalPoints: 0},
- });
-
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const changeAdminTx = api.tx.unique.addCollectionAdmin(collection.collectionId, {Ethereum: owner});
- await submitTransactionAsync(alice, changeAdminTx);
- const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ itEth('Can perform burn()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.addAdmin(alice, {Ethereum: owner});
- const collectionIdAddress = collectionIdToAddress(collection.collectionId);
- const collectionContract = evmCollection(web3, owner, collectionIdAddress, {type: 'Fungible', decimalPoints: 0});
- await collectionContract.methods.mint(receiver, 100).send();
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
+ await contract.methods.mint(receiver, 100).send();
- const result = await collectionContract.methods.burnFrom(receiver, 49).send({from: receiver});
+ const result = await contract.methods.burnFrom(receiver, 49).send({from: receiver});
- const events = normalizeEvents(result.events);
-
- expect(events).to.be.deep.equal([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: receiver,
- to: '0x0000000000000000000000000000000000000000',
- value: '49',
- },
- },
- ]);
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal(receiver);
+ expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.value).to.equal('49');
- const balance = await collectionContract.methods.balanceOf(receiver).call();
+ const balance = await contract.methods.balanceOf(receiver).call();
expect(balance).to.equal('51');
});
- itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: {type: 'Fungible', decimalPoints: 0},
- });
- const alice = privateKeyWrapper('//Alice');
+ itEth('Can perform approve()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = helper.eth.createAccount();
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
-
- const spender = createEthAccount(web3);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
-
{
const result = await contract.methods.approve(spender, 100).send({from: owner});
- const events = normalizeEvents(result.events);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Approval',
- args: {
- owner,
- spender,
- value: '100',
- },
- },
- ]);
+ const event = result.events.Approval;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(spender);
+ expect(event.returnValues.value).to.be.equal('100');
}
{
@@ -220,51 +148,32 @@
}
});
- itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: {type: 'Fungible', decimalPoints: 0},
- });
- const alice = privateKeyWrapper('//Alice');
-
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner);
-
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
-
- const spender = createEthAccount(web3);
- await transferBalanceToEth(api, alice, spender);
-
- const receiver = createEthAccount(web3);
+ itEth('Can perform transferFrom()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
await contract.methods.approve(spender, 100).send();
{
const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});
- const events = normalizeEvents(result.events);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: owner,
- to: receiver,
- value: '49',
- },
- },
- {
- address,
- event: 'Approval',
- args: {
- owner,
- spender,
- value: '51',
- },
- },
- ]);
+
+ let event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal(owner);
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('49');
+
+ event = result.events.Approval;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(spender);
+ expect(event.returnValues.value).to.be.equal('51');
}
{
@@ -278,38 +187,23 @@
}
});
- itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: {type: 'Fungible', decimalPoints: 0},
- });
- const alice = privateKeyWrapper('//Alice');
-
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner);
-
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
-
- const receiver = createEthAccount(web3);
- await transferBalanceToEth(api, alice, receiver);
+ itEth('Can perform transfer()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
{
const result = await contract.methods.transfer(receiver, 50).send({from: owner});
- const events = normalizeEvents(result.events);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: owner,
- to: receiver,
- value: '50',
- },
- },
- ]);
+
+ const event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal(owner);
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('50');
}
{
@@ -325,162 +219,141 @@
});
describe('Fungible: Fees', () => {
- itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- mode: {type: 'Fungible', decimalPoints: 0},
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([20n], donor);
});
- const alice = privateKeyWrapper('//Alice');
+ });
+
+ itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = helper.eth.createAccount();
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const spender = createEthAccount(web3);
-
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
-
- const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));
- expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));
+ expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
- itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- mode: {type: 'Fungible', decimalPoints: 0},
- });
- const alice = privateKeyWrapper('//Alice');
-
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const spender = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
+ itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
await contract.methods.approve(spender, 100).send({from: owner});
- const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));
- expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));
+ expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
-
- itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- mode: {type: 'Fungible', decimalPoints: 0},
- });
- const alice = privateKeyWrapper('//Alice');
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const receiver = createEthAccount(web3);
-
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
+ itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n, {Ethereum: owner});
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
- const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));
- expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));
+ expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
});
describe('Fungible: Substrate calls', () => {
- itWeb3('Events emitted for approve()', async ({web3, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- mode: {type: 'Fungible', decimalPoints: 0},
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([20n], donor);
});
- const alice = privateKeyWrapper('//Alice');
+ });
- const receiver = createEthAccount(web3);
+ itEth('Events emitted for approve()', async ({helper}) => {
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n);
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
-
- const events = await recordEvents(contract, async () => {
- await approveExpectSuccess(collection, 0, alice, {Ethereum: receiver}, 100);
+ const events: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ events.push(event);
});
+ await collection.approveTokens(alice, {Ethereum: receiver}, 100n);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Approval',
- args: {
- owner: subToEth(alice.address),
- spender: receiver,
- value: '100',
- },
- },
- ]);
+ const event = events[0];
+ expect(event.event).to.be.equal('Approval');
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
+ expect(event.returnValues.spender).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('100');
});
- itWeb3('Events emitted for transferFrom()', async ({web3, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- mode: {type: 'Fungible', decimalPoints: 0},
- });
- const alice = privateKeyWrapper('//Alice');
- const bob = privateKeyWrapper('//Bob');
+ itEth('Events emitted for transferFrom()', async ({helper}) => {
+ const [bob] = await helper.arrange.createAccounts([10n], donor);
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n);
+ await collection.approveTokens(alice, {Substrate: bob.address}, 100n);
- const receiver = createEthAccount(web3);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});
- await approveExpectSuccess(collection, 0, alice, bob.address, 100);
+ const events: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ events.push(event);
+ });
+ await collection.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n);
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
+ let event = events[0];
+ expect(event.event).to.be.equal('Transfer');
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('51');
- const events = await recordEvents(contract, async () => {
- await transferFromExpectSuccess(collection, 0, bob, alice, {Ethereum: receiver}, 51, 'Fungible');
- });
-
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: subToEth(alice.address),
- to: receiver,
- value: '51',
- },
- },
- {
- address,
- event: 'Approval',
- args: {
- owner: subToEth(alice.address),
- spender: subToEth(bob.address),
- value: '49',
- },
- },
- ]);
+ event = events[1];
+ expect(event.event).to.be.equal('Approval');
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
+ expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));
+ expect(event.returnValues.value).to.be.equal('49');
});
- itWeb3('Events emitted for transfer()', async ({web3, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- mode: {type: 'Fungible', decimalPoints: 0},
- });
- const alice = privateKeyWrapper('//Alice');
+ itEth('Events emitted for transfer()', async ({helper}) => {
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.ft.mintCollection(alice);
+ await collection.mint(alice, 200n);
- const receiver = createEthAccount(web3);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'ft');
- await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});
-
- const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
-
- const events = await recordEvents(contract, async () => {
- await transferExpectSuccess(collection, 0, alice, {Ethereum:receiver}, 51, 'Fungible');
+ const events: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ events.push(event);
});
+ await collection.transfer(alice, {Ethereum:receiver}, 51n);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: subToEth(alice.address),
- to: receiver,
- value: '51',
- },
- },
- ]);
+ const event = events[0];
+ expect(event.event).to.be.equal('Transfer');
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('51');
});
});
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// 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/>.161617import {approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util/playgrounds';18import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';18import {IKeyringPair} from '@polkadot/types/types';19import nonFungibleAbi from './nonFungibleAbi.json';19import {Contract} from 'web3-eth-contract';20import {expect} from 'chai';21import {submitTransactionAsync} from '../substrate/substrate-api';222023describe('NFT: Information getting', () => {21describe('NFT: Information getting', () => {24 itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {22 let donor: IKeyringPair;23 let alice: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (helper, privateKey) => {25 const collection = await createCollectionExpectSuccess({27 donor = privateKey('//Alice');26 mode: {type: 'NFT'},28 [alice] = await helper.arrange.createAccounts([10n], donor);27 });29 });28 const alice = privateKeyWrapper('//Alice');30 });31 32 itEth('totalSupply', async ({helper}) => {29 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);33 const collection = await helper.nft.mintCollection(alice, {});34 await collection.mintToken(alice);303531 await createItemExpectSuccess(alice, collection, 'NFT', {Substrate: alice.address});36 const caller = await helper.eth.createAccountWithBalance(donor);323733 const address = collectionIdToAddress(collection);38 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);34 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});35 const totalSupply = await contract.methods.totalSupply().call();39 const totalSupply = await contract.methods.totalSupply().call();364037 expect(totalSupply).to.equal('1');41 expect(totalSupply).to.equal('1');38 });42 });394340 itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {44 itEth('balanceOf', async ({helper}) => {41 const collection = await createCollectionExpectSuccess({45 const collection = await helper.nft.mintCollection(alice, {});42 mode: {type: 'NFT'},43 });44 const alice = privateKeyWrapper('//Alice');46 const caller = await helper.eth.createAccountWithBalance(donor);454746 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);48 await collection.mintToken(alice, {Ethereum: caller});47 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum:caller});48 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});49 await collection.mintToken(alice, {Ethereum: caller});49 await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});50 await collection.mintToken(alice, {Ethereum: caller});505151 const address = collectionIdToAddress(collection);52 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);52 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});53 const balance = await contract.methods.balanceOf(caller).call();53 const balance = await contract.methods.balanceOf(caller).call();545455 expect(balance).to.equal('3');55 expect(balance).to.equal('3');56 });56 });575758 itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {58 itEth('ownerOf', async ({helper}) => {59 const collection = await createCollectionExpectSuccess({59 const collection = await helper.nft.mintCollection(alice, {});60 mode: {type: 'NFT'},61 });62 const alice = privateKeyWrapper('//Alice');60 const caller = await helper.eth.createAccountWithBalance(donor);636164 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);62 const token = await collection.mintToken(alice, {Ethereum: caller});65 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});666367 const address = collectionIdToAddress(collection);64 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);68 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});69 const owner = await contract.methods.ownerOf(tokenId).call();706566 const owner = await contract.methods.ownerOf(token.tokenId).call();6771 expect(owner).to.equal(caller);68 expect(owner).to.equal(caller);72 });69 });73});70});747175describe('Check ERC721 token URI for NFT', () => {72describe('Check ERC721 token URI for NFT', () => {76 itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {73 let donor: IKeyringPair;7475 before(async function() {76 await usingEthPlaygrounds(async (_helper, privateKey) => {77 donor = privateKey('//Alice');78 });79 });8081 async function setup(helper: EthUniqueHelper, tokenPrefix: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {77 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);82 const owner = await helper.eth.createAccountWithBalance(donor);83 const receiver = helper.eth.createAccount();8478 const helper = evmCollectionHelpers(web3, owner);85 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);79 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', '').send();86 let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send();80 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);87 const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);81 const receiver = createEthAccount(web3);88 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);82 const contract = evmCollection(web3, owner, collectionIdAddress);83 89 84 const nextTokenId = await contract.methods.nextTokenId().call();90 const nextTokenId = await contract.methods.nextTokenId().call();85 expect(nextTokenId).to.be.equal('1');91 expect(nextTokenId).to.be.equal('1');88 nextTokenId,94 nextTokenId,89 ).send();95 ).send();909691 const events = normalizeEvents(result.events);97 if (propertyKey && propertyValue) {92 const address = collectionIdToAddress(collectionId);98 // Set URL or suffix99 await contract.methods.setProperty(nextTokenId, propertyKey, Buffer.from(propertyValue)).send();100 }9310194 expect(events).to.be.deep.equal([102 const event = result.events.Transfer;103 expect(event.address).to.be.equal(collectionAddress);95 {104 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');96 address,97 event: 'Transfer',98 args: {99 from: '0x0000000000000000000000000000000000000000',100 to: receiver,105 expect(event.returnValues.to).to.be.equal(receiver);101 tokenId: nextTokenId,106 expect(event.returnValues.tokenId).to.be.equal(nextTokenId);102 },103 },104 ]);105107108 return {contract, nextTokenId};109 }110111 itEth('Empty tokenURI', async ({helper}) => {112 const {contract, nextTokenId} = await setup(helper, '');106 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');113 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');107 });114 });108115109 itWeb3('TokenURI from url', async ({web3, api, privateKeyWrapper}) => {116 itEth('TokenURI from url', async ({helper}) => {110 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);117 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'url', 'Token URI');111 const helper = evmCollectionHelpers(web3, owner);112 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();113 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);114 const receiver = createEthAccount(web3);115 const contract = evmCollection(web3, owner, collectionIdAddress);116 117 const nextTokenId = await contract.methods.nextTokenId().call();118 expect(nextTokenId).to.be.equal('1');119 result = await contract.methods.mint(120 receiver,121 nextTokenId,122 ).send();123 124 // Set URL125 await contract.methods.setProperty(nextTokenId, 'url', Buffer.from('Token URI')).send();126 127 const events = normalizeEvents(result.events);128 const address = collectionIdToAddress(collectionId);129130 expect(events).to.be.deep.equal([131 {132 address,133 event: 'Transfer',134 args: {135 from: '0x0000000000000000000000000000000000000000',136 to: receiver,137 tokenId: nextTokenId,138 },139 },140 ]);141142 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');118 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');143 });119 });144120145 itWeb3('TokenURI from baseURI + tokenId', async ({web3, api, privateKeyWrapper}) => {121 itEth('TokenURI from baseURI + tokenId', async ({helper}) => {146 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);122 const {contract, nextTokenId} = await setup(helper, 'BaseURI_');147 const helper = evmCollectionHelpers(web3, owner);148 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();149 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);150 const receiver = createEthAccount(web3);151 const contract = evmCollection(web3, owner, collectionIdAddress);152 153 const nextTokenId = await contract.methods.nextTokenId().call();154 expect(nextTokenId).to.be.equal('1');155 result = await contract.methods.mint(156 receiver,157 nextTokenId,158 ).send();159 160 const events = normalizeEvents(result.events);161 const address = collectionIdToAddress(collectionId);162163 expect(events).to.be.deep.equal([164 {165 address,166 event: 'Transfer',167 args: {168 from: '0x0000000000000000000000000000000000000000',169 to: receiver,170 tokenId: nextTokenId,171 },172 },173 ]);174175 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);123 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);176 });124 });177125178 itWeb3('TokenURI from baseURI + suffix', async ({web3, api, privateKeyWrapper}) => {126 itEth('TokenURI from baseURI + suffix', async ({helper}) => {179 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);180 const helper = evmCollectionHelpers(web3, owner);181 let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();182 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);183 const receiver = createEthAccount(web3);184 const contract = evmCollection(web3, owner, collectionIdAddress);185 186 const nextTokenId = await contract.methods.nextTokenId().call();187 expect(nextTokenId).to.be.equal('1');188 result = await contract.methods.mint(189 receiver,190 nextTokenId,191 ).send();192 193 // Set suffix194 const suffix = '/some/suffix';127 const suffix = '/some/suffix';195 await contract.methods.setProperty(nextTokenId, 'suffix', Buffer.from(suffix)).send();128 const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'suffix', suffix);196197 const events = normalizeEvents(result.events);198 const address = collectionIdToAddress(collectionId);199200 expect(events).to.be.deep.equal([201 {202 address,203 event: 'Transfer',204 args: {205 from: '0x0000000000000000000000000000000000000000',206 to: receiver,207 tokenId: nextTokenId,208 },209 },210 ]);211212 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);129 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);213 });130 });214});131});215132216describe('NFT: Plain calls', () => {133describe('NFT: Plain calls', () => {217 itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {134 let donor: IKeyringPair;135 let alice: IKeyringPair;136137 before(async function() {138 await usingEthPlaygrounds(async (helper, privateKey) => {218 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);139 donor = privateKey('//Alice');219 const helper = evmCollectionHelpers(web3, owner);140 [alice] = await helper.arrange.createAccounts([10n], donor);220 let result = await helper.methods.createNonfungibleCollection('Mint collection', '6', '6').send();141 });142 });143144 itEth('Can perform mint()', async ({helper}) => {221 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);145 const owner = await helper.eth.createAccountWithBalance(donor);222 const receiver = createEthAccount(web3);146 const receiver = helper.eth.createAccount();147223 const contract = evmCollection(web3, owner, collectionIdAddress);148 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'Minty', '6', '6');149 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);224 const nextTokenId = await contract.methods.nextTokenId().call();150 const nextTokenId = await contract.methods.nextTokenId().call();225151226 expect(nextTokenId).to.be.equal('1');152 expect(nextTokenId).to.be.equal('1');227 result = await contract.methods.mintWithTokenURI(153 const result = await contract.methods.mintWithTokenURI(228 receiver,154 receiver,229 nextTokenId,155 nextTokenId,230 'Test URI',156 'Test URI',231 ).send();157 ).send();232158233 const events = normalizeEvents(result.events);159 const event = result.events.Transfer;160 expect(event.address).to.be.equal(collectionAddress);234 const address = collectionIdToAddress(collectionId);161 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');162 expect(event.returnValues.to).to.be.equal(receiver);163 expect(event.returnValues.tokenId).to.be.equal(nextTokenId);235164236 expect(events).to.be.deep.equal([237 {238 address,239 event: 'Transfer',240 args: {241 from: '0x0000000000000000000000000000000000000000',242 to: receiver,243 tokenId: nextTokenId,244 },245 },246 ]);247248 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');165 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');249166250 // TODO: this wont work right now, need release 919000 first167 // TODO: this wont work right now, need release 919000 first254 });171 });255172256 //TODO: CORE-302 add eth methods173 //TODO: CORE-302 add eth methods257 itWeb3.skip('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {174 /* todo:playgrounds skipped test!175 itWeb3.skip('Can perform mintBulk()', async ({helper}) => {258 const collection = await createCollectionExpectSuccess({176 const collection = await createCollectionExpectSuccess({259 mode: {type: 'NFT'},177 mode: {type: 'NFT'},260 });178 });316 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');234 expect(await contract.methods.tokenURI(+nextTokenId + 2).call()).to.be.equal('Test URI 2');317 }235 }318 });236 });237 */319238320 itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {239 itEth('Can perform burn()', async ({helper}) => {321 const collection = await createCollectionExpectSuccess({240 const caller = await helper.eth.createAccountWithBalance(donor);322 mode: {type: 'NFT'},323 });324 const alice = privateKeyWrapper('//Alice');325241326 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);242 const collection = await helper.nft.mintCollection(alice, {});243 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});327244328 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});245 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);246 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', caller);329247330 const address = collectionIdToAddress(collection);331 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});332333 {248 {334 const result = await contract.methods.burn(tokenId).send({from: owner});249 const result = await contract.methods.burn(tokenId).send({from: caller});335 const events = normalizeEvents(result.events);250 336251 const event = result.events.Transfer;337 expect(events).to.be.deep.equal([252 expect(event.address).to.be.equal(collectionAddress);338 {253 expect(event.returnValues.from).to.be.equal(caller);339 address,340 event: 'Transfer',341 args: {342 from: owner,343 to: '0x0000000000000000000000000000000000000000',254 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');344 tokenId: tokenId.toString(),255 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);345 },346 },347 ]);348 }256 }349 });257 });350258351 itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {259 itEth('Can perform approve()', async ({helper}) => {352 const collection = await createCollectionExpectSuccess({260 const owner = await helper.eth.createAccountWithBalance(donor);353 mode: {type: 'NFT'},354 });355 const alice = privateKeyWrapper('//Alice');261 const spender = helper.eth.createAccount();356262357 const owner = createEthAccount(web3);263 const collection = await helper.nft.mintCollection(alice, {});358 await transferBalanceToEth(api, alice, owner);264 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});359265360 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});266 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);267 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);361268362 const spender = createEthAccount(web3);363364 const address = collectionIdToAddress(collection);365 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);366367 {269 {368 const result = await contract.methods.approve(spender, tokenId).send({from: owner, ...GAS_ARGS});270 const result = await contract.methods.approve(spender, tokenId).send({from: owner});369 const events = normalizeEvents(result.events);370271371 expect(events).to.be.deep.equal([272 const event = result.events.Approval;372 {373 address,273 expect(event.address).to.be.equal(collectionAddress);374 event: 'Approval',274 expect(event.returnValues.owner).to.be.equal(owner);375 args: {376 owner,377 approved: spender,275 expect(event.returnValues.approved).to.be.equal(spender);378 tokenId: tokenId.toString(),276 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);379 },380 },381 ]);382 }277 }383 });278 });384279385 itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {280 itEth('Can perform transferFrom()', async ({helper}) => {386 const collection = await createCollectionExpectSuccess({281 const owner = await helper.eth.createAccountWithBalance(donor);387 mode: {type: 'NFT'},282 const spender = await helper.eth.createAccountWithBalance(donor);388 });389 const alice = privateKeyWrapper('//Alice');283 const receiver = helper.eth.createAccount();390284391 const owner = createEthAccount(web3);285 const collection = await helper.nft.mintCollection(alice, {});392 await transferBalanceToEth(api, alice, owner);286 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});393287394 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});288 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);289 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);395290396 const spender = createEthAccount(web3);397 await transferBalanceToEth(api, alice, spender);398399 const receiver = createEthAccount(web3);400401 const address = collectionIdToAddress(collection);402 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});403404 await contract.methods.approve(spender, tokenId).send({from: owner});291 await contract.methods.approve(spender, tokenId).send({from: owner});405292406 {293 {407 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});294 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({from: spender});295408 const events = normalizeEvents(result.events);296 const event = result.events.Transfer;409 expect(events).to.be.deep.equal([297 expect(event.address).to.be.equal(collectionAddress);410 {298 expect(event.returnValues.from).to.be.equal(owner);411 address,412 event: 'Transfer',413 args: {414 from: owner,415 to: receiver,299 expect(event.returnValues.to).to.be.equal(receiver);416 tokenId: tokenId.toString(),300 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);417 },418 },419 ]);420 }301 }421302422 {303 {430 }311 }431 });312 });432313433 itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {314 itEth('Can perform transfer()', async ({helper}) => {434 const collection = await createCollectionExpectSuccess({315 const collection = await helper.nft.mintCollection(alice, {});435 mode: {type: 'NFT'},316 const owner = await helper.eth.createAccountWithBalance(donor);436 });437 const alice = privateKeyWrapper('//Alice');317 const receiver = helper.eth.createAccount();438318439 const owner = createEthAccount(web3);319 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});440 await transferBalanceToEth(api, alice, owner);441320442 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});321 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);322 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);443323444 const receiver = createEthAccount(web3);445 await transferBalanceToEth(api, alice, receiver);446447 const address = collectionIdToAddress(collection);448 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});449450 {324 {451 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});325 const result = await contract.methods.transfer(receiver, tokenId).send({from: owner});326452 const events = normalizeEvents(result.events);327 const event = result.events.Transfer;453 expect(events).to.be.deep.equal([328 expect(event.address).to.be.equal(collectionAddress);454 {329 expect(event.returnValues.from).to.be.equal(owner);455 address,456 event: 'Transfer',457 args: {458 from: owner,459 to: receiver,330 expect(event.returnValues.to).to.be.equal(receiver);460 tokenId: tokenId.toString(),331 expect(event.returnValues.tokenId).to.be.equal(`${tokenId}`);461 },462 },463 ]);464 }332 }465333466 {334 {476});344});477345478describe('NFT: Fees', () => {346describe('NFT: Fees', () => {479 itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {347 let donor: IKeyringPair;348 let alice: IKeyringPair;349350 before(async function() {351 await usingEthPlaygrounds(async (helper, privateKey) => {480 const collection = await createCollectionExpectSuccess({352 donor = privateKey('//Alice');481 mode: {type: 'NFT'},353 [alice] = await helper.arrange.createAccounts([10n], donor);482 });354 });483 const alice = privateKeyWrapper('//Alice');355 });356 357 itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {358 const owner = await helper.eth.createAccountWithBalance(donor);359 const spender = helper.eth.createAccount();484360485 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);361 const collection = await helper.nft.mintCollection(alice, {});486 const spender = createEthAccount(web3);362 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});487363488 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});364 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);489365490 const address = collectionIdToAddress(collection);366 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));491 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});492493 const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, tokenId).send({from: owner}));494 expect(cost < BigInt(0.2 * Number(UNIQUE)));367 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));495 });368 });496369497 itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {370 itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {498 const collection = await createCollectionExpectSuccess({371 const owner = await helper.eth.createAccountWithBalance(donor);499 mode: {type: 'NFT'},500 });501 const alice = privateKeyWrapper('//Alice');372 const spender = await helper.eth.createAccountWithBalance(donor);502373503 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);374 const collection = await helper.nft.mintCollection(alice, {});504 const spender = await createEthAccountWithBalance(api, web3, privateKeyWrapper);375 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});505376506 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});377 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);507378508 const address = collectionIdToAddress(collection);509 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});510511 await contract.methods.approve(spender, tokenId).send({from: owner});379 await contract.methods.approve(spender, tokenId).send({from: owner});512380513 const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));381 const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({from: spender}));514 expect(cost < BigInt(0.2 * Number(UNIQUE)));382 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));515 });383 });516384517 itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {385 itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {518 const collection = await createCollectionExpectSuccess({386 const owner = await helper.eth.createAccountWithBalance(donor);519 mode: {type: 'NFT'},520 });521 const alice = privateKeyWrapper('//Alice');387 const receiver = helper.eth.createAccount();522388523 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);389 const collection = await helper.nft.mintCollection(alice, {});524 const receiver = createEthAccount(web3);390 const {tokenId} = await collection.mintToken(alice, {Ethereum: owner});525391526 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});392 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', owner);527393528 const address = collectionIdToAddress(collection);394 const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));529 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});530531 const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, tokenId).send({from: owner}));532 expect(cost < BigInt(0.2 * Number(UNIQUE)));395 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));533 });396 });534});397});535398536describe('NFT: Substrate calls', () => {399describe('NFT: Substrate calls', () => {537 itWeb3('Events emitted for mint()', async ({web3, privateKeyWrapper}) => {400 let donor: IKeyringPair;538 const collection = await createCollectionExpectSuccess({539 mode: {type: 'NFT'},540 });541 const alice = privateKeyWrapper('//Alice');401 let alice: IKeyringPair;542402543 const address = collectionIdToAddress(collection);403 before(async function() {544 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);404 await usingEthPlaygrounds(async (helper, privateKey) => {545546 let tokenId: number;547 const events = await recordEvents(contract, async () => {405 donor = privateKey('//Alice');548 tokenId = await createItemExpectSuccess(alice, collection, 'NFT');406 [alice] = await helper.arrange.createAccounts([20n], donor);549 });407 });550551 expect(events).to.be.deep.equal([552 {553 address,554 event: 'Transfer',555 args: {556 from: '0x0000000000000000000000000000000000000000',557 to: subToEth(alice.address),558 tokenId: tokenId!.toString(),559 },560 },561 ]);562 });408 });563409564 itWeb3('Events emitted for burn()', async ({web3, privateKeyWrapper}) => {410 itEth('Events emitted for mint()', async ({helper}) => {565 const collection = await createCollectionExpectSuccess({411 const collection = await helper.nft.mintCollection(alice, {});566 mode: {type: 'NFT'},412 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);567 });568 const alice = privateKeyWrapper('//Alice');413 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');569414570 const address = collectionIdToAddress(collection);415 const events: any = [];571 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);416 contract.events.allEvents((_: any, event: any) => {572573 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');574 const events = await recordEvents(contract, async () => {575 await burnItemExpectSuccess(alice, collection, tokenId);417 events.push(event);576 });418 });419 const {tokenId} = await collection.mintToken(alice);577420578 expect(events).to.be.deep.equal([421 const event = events[0];579 {580 address,581 event: 'Transfer',422 expect(event.event).to.be.equal('Transfer');582 args: {423 expect(event.address).to.be.equal(collectionAddress);583 from: subToEth(alice.address),584 to: '0x0000000000000000000000000000000000000000',424 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');585 tokenId: tokenId.toString(),425 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(alice.address));586 },587 },588 ]);426 expect(event.returnValues.tokenId).to.be.equal(tokenId.toString());589 });427 });590428591 itWeb3('Events emitted for approve()', async ({web3, privateKeyWrapper}) => {429 itEth('Events emitted for burn()', async ({helper}) => {592 const collection = await createCollectionExpectSuccess({430 const collection = await helper.nft.mintCollection(alice, {});593 mode: {type: 'NFT'},431 const token = await collection.mintToken(alice);432433 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);434 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');435 436 const events: any = [];437 contract.events.allEvents((_: any, event: any) => {438 events.push(event);594 });439 });595 const alice = privateKeyWrapper('//Alice');596440597 const receiver = createEthAccount(web3);441 await token.burn(alice);598442599 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');443 const event = events[0];444 expect(event.event).to.be.equal('Transfer');445 expect(event.address).to.be.equal(collectionAddress);446 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));447 expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');448 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());449 });600450601 const address = collectionIdToAddress(collection);451 itEth('Events emitted for approve()', async ({helper}) => {602 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);452 const receiver = helper.eth.createAccount();603453604 const events = await recordEvents(contract, async () => {454 const collection = await helper.nft.mintCollection(alice, {});605 await approveExpectSuccess(collection, tokenId, alice, {Ethereum: receiver}, 1);455 const token = await collection.mintToken(alice);606 });607456608 expect(events).to.be.deep.equal([457 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);609 {458 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');610 address,611 event: 'Approval',612 args: {613 owner: subToEth(alice.address),614 approved: receiver,459 615 tokenId: tokenId.toString(),460 const events: any = [];616 },617 },618 ]);619 });461 contract.events.allEvents((_: any, event: any) => {620621 itWeb3('Events emitted for transferFrom()', async ({web3, privateKeyWrapper}) => {622 const collection = await createCollectionExpectSuccess({462 events.push(event);623 mode: {type: 'NFT'},624 });463 });625 const alice = privateKeyWrapper('//Alice');626 const bob = privateKeyWrapper('//Bob');627464628 const receiver = createEthAccount(web3);465 await token.approve(alice, {Ethereum: receiver});629466630 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');467 const event = events[0];468 expect(event.event).to.be.equal('Approval');631 await approveExpectSuccess(collection, tokenId, alice, bob.address, 1);469 expect(event.address).to.be.equal(collectionAddress);470 expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));471 expect(event.returnValues.approved).to.be.equal(receiver);472 expect(event.returnValues.tokenId).to.be.equal(token.tokenId.toString());473 });632474633 const address = collectionIdToAddress(collection);475 itEth('Events emitted for transferFrom()', async ({helper}) => {476 const [bob] = await helper.arrange.createAccounts([10n], donor);634 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);477 const receiver = helper.eth.createAccount();635478636 const events = await recordEvents(contract, async () => {479 const collection = await helper.nft.mintCollection(alice, {});480 const token = await collection.mintToken(alice);481 await token.approve(alice, {Substrate: bob.address});482637 await transferFromExpectSuccess(collection, tokenId, bob, alice, {Ethereum: receiver}, 1, 'NFT');483 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);484 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');485 486 const events: any = [];487 contract.events.allEvents((_: any, event: any) => {488 events.push(event);638 });489 });639490640 expect(events).to.be.deep.equal([491 await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver});641 {642 address,643 event: 'Transfer',492 644 args: {493 const event = events[0];645 from: subToEth(alice.address),494 expect(event.address).to.be.equal(collectionAddress);495 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));646 to: receiver,496 expect(event.returnValues.to).to.be.equal(receiver);647 tokenId: tokenId.toString(),497 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);648 },649 },650 ]);651 });498 });652499653 itWeb3('Events emitted for transfer()', async ({web3, privateKeyWrapper}) => {500 itEth('Events emitted for transfer()', async ({helper}) => {654 const collection = await createCollectionExpectSuccess({501 const receiver = helper.eth.createAccount();655 mode: {type: 'NFT'},656 });657 const alice = privateKeyWrapper('//Alice');658502659 const receiver = createEthAccount(web3);503 const collection = await helper.nft.mintCollection(alice, {});504 const token = await collection.mintToken(alice);660505661 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');506 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);662663 const address = collectionIdToAddress(collection);507 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft');664 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);508 665509 const events: any = [];666 const events = await recordEvents(contract, async () => {510 contract.events.allEvents((_: any, event: any) => {667 await transferExpectSuccess(collection, tokenId, alice, {Ethereum: receiver}, 1, 'NFT');511 events.push(event);668 });512 });669513670 expect(events).to.be.deep.equal([514 await token.transfer(alice, {Ethereum: receiver});671 {515 672 address,516 const event = events[0];673 event: 'Transfer',517 expect(event.address).to.be.equal(collectionAddress);674 args: {518 expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));675 from: subToEth(alice.address),676 to: receiver,519 expect(event.returnValues.to).to.be.equal(receiver);677 tokenId: tokenId.toString(),520 expect(event.returnValues.tokenId).to.be.equal(`${token.tokenId}`);678 },679 },680 ]);681 });521 });682});522});683523684describe('Common metadata', () => {524describe('Common metadata', () => {685 itWeb3('Returns collection name', async ({api, web3, privateKeyWrapper}) => {525 let donor: IKeyringPair;526 let alice: IKeyringPair;527528 before(async function() {686 const collection = await createCollectionExpectSuccess({529 await usingEthPlaygrounds(async (helper, privateKey) => {687 name: 'token name',530 donor = privateKey('//Alice');688 mode: {type: 'NFT'},531 [alice] = await helper.arrange.createAccounts([20n], donor);689 });532 });690 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);533 });691534692 const address = collectionIdToAddress(collection);535 itEth('Returns collection name', async ({helper}) => {693 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});536 const caller = await helper.eth.createAccountWithBalance(donor);694 const name = await contract.methods.name().call();537 const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE'});695538696 expect(name).to.equal('token name');539 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);540 const name = await contract.methods.name().call();541 expect(name).to.equal('oh River');697 });542 });698543699 itWeb3('Returns symbol name', async ({api, web3, privateKeyWrapper}) => {544 itEth('Returns symbol name', async ({helper}) => {700 const collection = await createCollectionExpectSuccess({545 const caller = await helper.eth.createAccountWithBalance(donor);701 tokenPrefix: 'TOK',702 mode: {type: 'NFT'},703 });704 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);546 const collection = await helper.nft.mintCollection(alice, {name: 'oh River', tokenPrefix: 'CHANGE'});705547706 const address = collectionIdToAddress(collection);548 const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);707 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});708 const symbol = await contract.methods.symbol().call();549 const symbol = await contract.methods.symbol().call();709710 expect(symbol).to.equal('TOK');550 expect(symbol).to.equal('CHANGE');711 });551 });712});552});tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -14,33 +14,35 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import {createCollectionExpectSuccess, UNIQUE, requirePallets, Pallets} from '../util/helpers';
-import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, tokenIdToAddress, uniqueRefungibleToken} from './util/helpers';
-import {expect} from 'chai';
+import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';
+import {expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {IKeyringPair} from '@polkadot/types/types';
describe('Refungible: Information getting', () => {
+ let donor: IKeyringPair;
+
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = privateKey('//Alice');
+ });
});
- itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('totalSupply', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'TotalSupply', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const nextTokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, nextTokenId).send();
const totalSupply = await contract.methods.totalSupply().call();
expect(totalSupply).to.equal('1');
});
- itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('balanceOf', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'BalanceOf', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
{
const nextTokenId = await contract.methods.nextTokenId().call();
@@ -56,38 +58,30 @@
}
const balance = await contract.methods.balanceOf(caller).call();
-
expect(balance).to.equal('3');
});
- itWeb3('ownerOf', async ({api, web3, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('ownerOf', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'OwnerOf', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
const owner = await contract.methods.ownerOf(tokenId).call();
-
expect(owner).to.equal(caller);
});
- itWeb3('ownerOf after burn', async ({api, web3, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const receiver = createEthAccount(web3);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('ownerOf after burn', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'OwnerOf-AfterBurn', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
-
- const tokenAddress = tokenIdToAddress(collectionId, tokenId);
- const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
+ const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
await tokenContract.methods.repartition(2).send();
await tokenContract.methods.transfer(receiver, 1).send();
@@ -95,80 +89,67 @@
await tokenContract.methods.burnFrom(caller, 1).send();
const owner = await contract.methods.ownerOf(tokenId).call();
-
expect(owner).to.equal(receiver);
});
- itWeb3('ownerOf for partial ownership', async ({api, web3, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const receiver = createEthAccount(web3);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('ownerOf for partial ownership', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Partial-OwnerOf', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
-
- const tokenAddress = tokenIdToAddress(collectionId, tokenId);
- const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
+ const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
await tokenContract.methods.repartition(2).send();
await tokenContract.methods.transfer(receiver, 1).send();
const owner = await contract.methods.ownerOf(tokenId).call();
-
expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
});
});
describe('Refungible: Plain calls', () => {
+ let donor: IKeyringPair;
+
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = privateKey('//Alice');
+ });
});
- itWeb3('Can perform mint()', async ({web3, api, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, owner);
- let result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const receiver = createEthAccount(web3);
- const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
+ itEth('Can perform mint()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Minty', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+
const nextTokenId = await contract.methods.nextTokenId().call();
-
expect(nextTokenId).to.be.equal('1');
- result = await contract.methods.mintWithTokenURI(
+ const result = await contract.methods.mintWithTokenURI(
receiver,
nextTokenId,
'Test URI',
).send();
- const events = normalizeEvents(result.events);
-
- expect(events).to.include.deep.members([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver,
- tokenId: nextTokenId,
- },
- },
- ]);
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.tokenId).to.equal(nextTokenId);
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
});
- itWeb3('Can perform mintBulk()', async ({web3, api, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('Can perform mintBulk()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'MintBulky', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
- const receiver = createEthAccount(web3);
-
{
const nextTokenId = await contract.methods.nextTokenId().call();
expect(nextTokenId).to.be.equal('1');
@@ -180,37 +161,15 @@
[+nextTokenId + 2, 'Test URI 2'],
],
).send();
- const events = normalizeEvents(result.events);
- expect(events).to.include.deep.members([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver,
- tokenId: nextTokenId,
- },
- },
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver,
- tokenId: String(+nextTokenId + 1),
- },
- },
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver,
- tokenId: String(+nextTokenId + 2),
- },
- },
- ]);
+ const events = result.events.Transfer;
+ for (let i = 0; i < 2; i++) {
+ const event = events[i];
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.tokenId).to.equal(String(+nextTokenId + i));
+ }
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI 0');
expect(await contract.methods.tokenURI(+nextTokenId + 1).call()).to.be.equal('Test URI 1');
@@ -218,76 +177,54 @@
}
});
- itWeb3('Can perform burn()', async ({web3, api, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('Can perform burn()', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Burny', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
{
const result = await contract.methods.burn(tokenId).send();
- const events = normalizeEvents(result.events);
- expect(events).to.include.deep.members([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: caller,
- to: '0x0000000000000000000000000000000000000000',
- tokenId: tokenId.toString(),
- },
- },
- ]);
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal(caller);
+ expect(event.returnValues.to).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.tokenId).to.equal(tokenId.toString());
}
});
- itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
-
- const receiver = createEthAccount(web3);
+ itEth('Can perform transferFrom()', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'TransferFromy', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
+ const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);
await contract.methods.mint(caller, tokenId).send();
- const address = tokenIdToAddress(collectionId, tokenId);
- const tokenContract = uniqueRefungibleToken(web3, address, caller);
+ const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);
await tokenContract.methods.repartition(15).send();
{
- const erc20Events = await recordEvents(tokenContract, async () => {
- const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();
- const events = normalizeEvents(result.events);
- expect(events).to.include.deep.members([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: caller,
- to: receiver,
- tokenId: tokenId.toString(),
- },
- },
- ]);
+ const tokenEvents: any = [];
+ tokenContract.events.allEvents((_: any, event: any) => {
+ tokenEvents.push(event);
});
+ const result = await contract.methods.transferFrom(caller, receiver, tokenId).send();
+
+ let event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal(caller);
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.tokenId).to.equal(tokenId.toString());
- expect(erc20Events).to.include.deep.members([
- {
- address,
- event: 'Transfer',
- args: {
- from: caller,
- to: receiver,
- value: '15',
- },
- },
- ]);
+ event = tokenEvents[0];
+ expect(event.address).to.equal(tokenAddress);
+ expect(event.returnValues.from).to.equal(caller);
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.value).to.equal('15');
}
{
@@ -301,32 +238,23 @@
}
});
- itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
-
- const receiver = createEthAccount(web3);
+ itEth('Can perform transfer()', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Transferry', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
{
const result = await contract.methods.transfer(receiver, tokenId).send();
- const events = normalizeEvents(result.events);
- expect(events).to.include.deep.members([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: caller,
- to: receiver,
- tokenId: tokenId.toString(),
- },
- },
- ]);
+
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal(caller);
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.tokenId).to.equal(tokenId.toString());
}
{
@@ -340,141 +268,127 @@
}
});
- itWeb3('transfer event on transfer from partial ownership to full ownership', async ({api, web3, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const receiver = createEthAccount(web3);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('transfer event on transfer from partial ownership to full ownership', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Transferry-Partial-to-Full', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
- const tokenAddress = tokenIdToAddress(collectionId, tokenId);
- const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
+ const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
await tokenContract.methods.repartition(2).send();
await tokenContract.methods.transfer(receiver, 1).send();
- const events = await recordEvents(contract, async () =>
- await tokenContract.methods.transfer(receiver, 1).send());
- expect(events).to.deep.equal([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',
- to: receiver,
- tokenId: tokenId.toString(),
- },
- },
- ]);
+ const events: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ events.push(event);
+ });
+ await tokenContract.methods.transfer(receiver, 1).send();
+
+ const event = events[0];
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
+ expect(event.returnValues.to).to.equal(receiver);
+ expect(event.returnValues.tokenId).to.equal(tokenId.toString());
});
- itWeb3('transfer event on transfer from full ownership to partial ownership', async ({api, web3, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const receiver = createEthAccount(web3);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('transfer event on transfer from full ownership to partial ownership', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Transferry-Full-to-Partial', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
- const tokenAddress = tokenIdToAddress(collectionId, tokenId);
- const tokenContract = uniqueRefungibleToken(web3, tokenAddress, caller);
+ const tokenContract = helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
await tokenContract.methods.repartition(2).send();
- const events = await recordEvents(contract, async () =>
- await tokenContract.methods.transfer(receiver, 1).send());
+ const events: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ events.push(event);
+ });
+ await tokenContract.methods.transfer(receiver, 1).send();
- expect(events).to.deep.equal([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: caller,
- to: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',
- tokenId: tokenId.toString(),
- },
- },
- ]);
+ const event = events[0];
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal(caller);
+ expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
+ expect(event.returnValues.tokenId).to.equal(tokenId.toString());
});
});
describe('RFT: Fees', () => {
+ let donor: IKeyringPair;
+
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = privateKey('//Alice');
+ });
});
- itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
-
- const receiver = createEthAccount(web3);
+ itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Feeful-Transfer-From', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
- const cost = await recordEthFee(api, caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());
- expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transferFrom(caller, receiver, tokenId).send());
+ expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
expect(cost > 0n);
});
- itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
-
- const receiver = createEthAccount(web3);
+ itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Feeful-Transfer', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
- const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, tokenId).send());
- expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ const cost = await helper.eth.recordCallFee(caller, () => contract.methods.transfer(receiver, tokenId).send());
+ expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
expect(cost > 0n);
});
});
describe('Common metadata', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
- });
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- itWeb3('Returns collection name', async ({api, web3, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- name: 'token name',
- mode: {type: 'ReFungible'},
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([20n], donor);
});
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ });
- const address = collectionIdToAddress(collection);
- const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});
+ itEth('Returns collection name', async ({helper}) => {
+ const caller = helper.eth.createAccount();
+ const collection = await helper.rft.mintCollection(alice, {name: 'Leviathan', tokenPrefix: '11'});
+
+ const contract = helper.ethNativeContract.collectionById(collection.collectionId, 'rft', caller);
const name = await contract.methods.name().call();
-
- expect(name).to.equal('token name');
+ expect(name).to.equal('Leviathan');
});
- itWeb3('Returns symbol name', async ({api, web3, privateKeyWrapper}) => {
- const collection = await createCollectionExpectSuccess({
- tokenPrefix: 'TOK',
- mode: {type: 'ReFungible'},
- });
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const address = collectionIdToAddress(collection);
- const contract = evmCollection(web3, caller, address, {type: 'ReFungible'});
+ itEth('Returns symbol name', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Leviathan', '', '12');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const symbol = await contract.methods.symbol().call();
-
- expect(symbol).to.equal('TOK');
+ expect(symbol).to.equal('12');
});
});
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -14,82 +14,76 @@
// You should have received a copy of the GNU General Public License
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-import {approve, createCollection, createRefungibleToken, transfer, transferFrom, UNIQUE, requirePallets, Pallets} from '../util/helpers';
-import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, createRFTCollection, evmCollection, evmCollectionHelpers, getCollectionAddressFromResult, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, tokenIdToAddress, transferBalanceToEth, uniqueRefungible, uniqueRefungibleToken} from './util/helpers';
+import {Pallets, requirePalletsOrSkip} from '../util/playgrounds';
+import {EthUniqueHelper, expect, itEth, usingEthPlaygrounds} from './util/playgrounds';
+import {IKeyringPair} from '@polkadot/types/types';
+import {Contract} from 'web3-eth-contract';
-import chai from 'chai';
-import chaiAsPromised from 'chai-as-promised';
-chai.use(chaiAsPromised);
-const expect = chai.expect;
+describe('Refungible token: Information getting', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
-describe('Refungible token: Information getting', () => {
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
- });
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- itWeb3('totalSupply', async ({api, web3, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
-
- const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
-
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([20n], donor);
+ });
+ });
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
+ itEth('totalSupply', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
+ const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, caller);
+ const contract = helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
const totalSupply = await contract.methods.totalSupply().call();
-
expect(totalSupply).to.equal('200');
});
- itWeb3('balanceOf', async ({api, web3, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
-
- const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
+ itEth('balanceOf', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
+ const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
-
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, caller);
+ const contract = helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
const balance = await contract.methods.balanceOf(caller).call();
-
expect(balance).to.equal('200');
});
- itWeb3('decimals', async ({api, web3, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
+ itEth('decimals', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
+ const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
- const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
-
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: caller})).itemId;
-
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, caller);
+ const contract = helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
const decimals = await contract.methods.decimals().call();
-
expect(decimals).to.equal('0');
});
});
// FIXME: Need erc721 for ReFubgible.
describe('Check ERC721 token URI for ReFungible', () => {
+ let donor: IKeyringPair;
+
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = privateKey('//Alice');
+ });
});
- itWeb3('Empty tokenURI', async ({web3, api, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, owner);
- let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', '').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const receiver = createEthAccount(web3);
- const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
+ async function setup(helper: EthUniqueHelper, tokenPrefix: string, propertyKey?: string, propertyValue?: string): Promise<{contract: Contract, nextTokenId: string}> {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
+ let result = await collectionHelper.methods.createERC721MetadataCompatibleCollection('Mint collection', 'a', 'b', tokenPrefix).send();
+ const collectionAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+
const nextTokenId = await contract.methods.nextTokenId().call();
expect(nextTokenId).to.be.equal('1');
result = await contract.methods.mint(
@@ -97,166 +91,71 @@
nextTokenId,
).send();
- const events = normalizeEvents(result.events);
- const address = collectionIdToAddress(collectionId);
+ if (propertyKey && propertyValue) {
+ // Set URL or suffix
+ await contract.methods.setProperty(nextTokenId, propertyKey, Buffer.from(propertyValue)).send();
+ }
+
+ const event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.tokenId).to.be.equal(nextTokenId);
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver,
- tokenId: nextTokenId,
- },
- },
- ]);
+ return {contract, nextTokenId};
+ }
+ itEth('Empty tokenURI', async ({helper}) => {
+ const {contract, nextTokenId} = await setup(helper, '');
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('');
});
-
- itWeb3('TokenURI from url', async ({web3, api, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, owner);
- let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const receiver = createEthAccount(web3);
- const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
- const nextTokenId = await contract.methods.nextTokenId().call();
- expect(nextTokenId).to.be.equal('1');
- result = await contract.methods.mint(
- receiver,
- nextTokenId,
- ).send();
-
- // Set URL
- await contract.methods.setProperty(nextTokenId, 'url', Buffer.from('Token URI')).send();
-
- const events = normalizeEvents(result.events);
- const address = collectionIdToAddress(collectionId);
-
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver,
- tokenId: nextTokenId,
- },
- },
- ]);
-
+ itEth('TokenURI from url', async ({helper}) => {
+ const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'url', 'Token URI');
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Token URI');
});
-
- itWeb3('TokenURI from baseURI + tokenId', async ({web3, api, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, owner);
- let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const receiver = createEthAccount(web3);
- const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
- const nextTokenId = await contract.methods.nextTokenId().call();
- expect(nextTokenId).to.be.equal('1');
- result = await contract.methods.mint(
- receiver,
- nextTokenId,
- ).send();
-
- const events = normalizeEvents(result.events);
- const address = collectionIdToAddress(collectionId);
-
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver,
- tokenId: nextTokenId,
- },
- },
- ]);
-
+ itEth('TokenURI from baseURI + tokenId', async ({helper}) => {
+ const {contract, nextTokenId} = await setup(helper, 'BaseURI_');
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + nextTokenId);
});
- itWeb3('TokenURI from baseURI + suffix', async ({web3, api, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, owner);
- let result = await helper.methods.createERC721MetadataCompatibleCollection('Mint collection', '1', '1', 'BaseURI_').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const receiver = createEthAccount(web3);
- const contract = evmCollection(web3, owner, collectionIdAddress, {type: 'ReFungible'});
-
- const nextTokenId = await contract.methods.nextTokenId().call();
- expect(nextTokenId).to.be.equal('1');
- result = await contract.methods.mint(
- receiver,
- nextTokenId,
- ).send();
-
- // Set suffix
+ itEth('TokenURI from baseURI + suffix', async ({helper}) => {
const suffix = '/some/suffix';
- await contract.methods.setProperty(nextTokenId, 'suffix', Buffer.from(suffix)).send();
-
- const events = normalizeEvents(result.events);
- const address = collectionIdToAddress(collectionId);
-
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: receiver,
- tokenId: nextTokenId,
- },
- },
- ]);
-
+ const {contract, nextTokenId} = await setup(helper, 'BaseURI_', 'suffix', suffix);
expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('BaseURI_' + suffix);
});
});
describe('Refungible: Plain calls', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([50n], donor);
+ });
});
- itWeb3('Can perform approve()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
+ itEth('Can perform approve()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = helper.eth.createAccount();
+ const collection = await helper.rft.mintCollection(alice);
+ const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});
- const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
-
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
-
- const address = tokenIdToAddress(collectionId, tokenId);
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);
- const spender = createEthAccount(web3);
-
- const contract = uniqueRefungibleToken(web3, address, owner);
-
{
const result = await contract.methods.approve(spender, 100).send({from: owner});
- const events = normalizeEvents(result.events);
-
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Approval',
- args: {
- owner,
- spender,
- value: '100',
- },
- },
- ]);
+ const event = result.events.Approval;
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(spender);
+ expect(event.returnValues.value).to.be.equal('100');
}
{
@@ -265,49 +164,31 @@
}
});
- itWeb3('Can perform transferFrom()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
-
- const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
+ itEth('Can perform transferFrom()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.rft.mintCollection(alice);
+ const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
-
- const spender = createEthAccount(web3);
- await transferBalanceToEth(api, alice, spender);
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);
- const receiver = createEthAccount(web3);
-
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, owner);
-
await contract.methods.approve(spender, 100).send();
{
const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});
- const events = normalizeEvents(result.events);
- expect(events).to.include.deep.members([
- {
- address,
- event: 'Transfer',
- args: {
- from: owner,
- to: receiver,
- value: '49',
- },
- },
- {
- address,
- event: 'Approval',
- args: {
- owner,
- spender,
- value: '51',
- },
- },
- ]);
+ let event = result.events.Transfer;
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.from).to.be.equal(owner);
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('49');
+
+ event = result.events.Approval;
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.owner).to.be.equal(owner);
+ expect(event.returnValues.spender).to.be.equal(spender);
+ expect(event.returnValues.value).to.be.equal('51');
}
{
@@ -321,36 +202,22 @@
}
});
- itWeb3('Can perform transfer()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
+ itEth('Can perform transfer()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.rft.mintCollection(alice);
+ const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});
- const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
-
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
-
- const receiver = createEthAccount(web3);
- await transferBalanceToEth(api, alice, receiver);
-
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, owner);
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);
{
const result = await contract.methods.transfer(receiver, 50).send({from: owner});
- const events = normalizeEvents(result.events);
- expect(events).to.include.deep.members([
- {
- address,
- event: 'Transfer',
- args: {
- from: owner,
- to: receiver,
- value: '50',
- },
- },
- ]);
+ const event = result.events.Transfer;
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.from).to.be.equal(owner);
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('50');
}
{
@@ -364,311 +231,262 @@
}
});
- itWeb3('Can perform repartition()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
-
- const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
+ itEth('Can perform repartition()', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice);
+ const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner);
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);
- const receiver = createEthAccount(web3);
- await transferBalanceToEth(api, alice, receiver);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
-
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, owner);
-
await contract.methods.repartition(200).send({from: owner});
expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(200);
await contract.methods.transfer(receiver, 110).send({from: owner});
expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(90);
expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(110);
- await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected;
+ await expect(contract.methods.repartition(80).send({from: owner})).to.eventually.be.rejected; // Transaction is reverted
await contract.methods.transfer(receiver, 90).send({from: owner});
expect(+await contract.methods.balanceOf(owner).call()).to.be.equal(0);
expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(200);
await contract.methods.repartition(150).send({from: receiver});
- await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected;
+ await expect(contract.methods.transfer(owner, 160).send({from: receiver})).to.eventually.be.rejected; // Transaction is reverted
expect(+await contract.methods.balanceOf(receiver).call()).to.be.equal(150);
});
- itWeb3('Can repartition with increased amount', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
-
- const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
-
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
+ itEth('Can repartition with increased amount', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice);
+ const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, owner);
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);
const result = await contract.methods.repartition(200).send();
- const events = normalizeEvents(result.events);
- expect(events).to.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: owner,
- value: '100',
- },
- },
- ]);
+ const event = result.events.Transfer;
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(owner);
+ expect(event.returnValues.value).to.be.equal('100');
});
- itWeb3('Can repartition with decreased amount', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
+ itEth('Can repartition with decreased amount', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice);
+ const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});
- const collectionId = (await createCollection(api, alice, {name: 'token name', mode: {type: 'ReFungible'}})).collectionId;
-
- const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 100n, {Ethereum: owner})).itemId;
-
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, owner);
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);
const result = await contract.methods.repartition(50).send();
- const events = normalizeEvents(result.events);
- expect(events).to.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: owner,
- to: '0x0000000000000000000000000000000000000000',
- value: '50',
- },
- },
- ]);
+ const event = result.events.Transfer;
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.from).to.be.equal(owner);
+ expect(event.returnValues.to).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.value).to.be.equal('50');
});
- itWeb3('Receiving Transfer event on burning into full ownership', async ({web3, api, privateKeyWrapper}) => {
- const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const receiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const helper = evmCollectionHelpers(web3, caller);
- const result = await helper.methods.createRFTCollection('Mint collection', '6', '6').send();
- const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
- const contract = evmCollection(web3, caller, collectionIdAddress, {type: 'ReFungible'});
+ itEth('Receiving Transfer event on burning into full ownership', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = await helper.eth.createAccountWithBalance(donor);
+ const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(caller, 'Devastation', '6', '6');
+ const contract = helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
const tokenId = await contract.methods.nextTokenId().call();
await contract.methods.mint(caller, tokenId).send();
+ const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);
+ const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, caller);
- const address = tokenIdToAddress(collectionId, tokenId);
-
- const tokenContract = uniqueRefungibleToken(web3, address, caller);
await tokenContract.methods.repartition(2).send();
await tokenContract.methods.transfer(receiver, 1).send();
- const events = await recordEvents(contract, async () =>
- await tokenContract.methods.burnFrom(caller, 1).send());
- expect(events).to.deep.equal([
- {
- address: collectionIdAddress,
- event: 'Transfer',
- args: {
- from: '0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF',
- to: receiver,
- tokenId,
- },
- },
- ]);
+ const events: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ events.push(event);
+ });
+ await tokenContract.methods.burnFrom(caller, 1).send();
+
+ const event = events[0];
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.tokenId).to.be.equal(tokenId);
});
});
describe('Refungible: Fees', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([50n], donor);
+ });
});
- itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
+ itEth('approve() call fee is less than 0.2UNQ', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = helper.eth.createAccount();
+ const collection = await helper.rft.mintCollection(alice);
+ const {tokenId} = await collection.mintToken(alice, 100n, {Ethereum: owner});
- const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const spender = createEthAccount(web3);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
-
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, owner);
-
- const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));
- expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ const cost = await helper.eth.recordCallFee(owner, () => contract.methods.approve(spender, 100).send({from: owner}));
+ expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
- itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
-
- const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const spender = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
+ itEth('transferFrom() call fee is less than 0.2UNQ', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const spender = await helper.eth.createAccountWithBalance(donor);
+ const collection = await helper.rft.mintCollection(alice);
+ const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, owner);
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);
await contract.methods.approve(spender, 100).send({from: owner});
- const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));
- expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ const cost = await helper.eth.recordCallFee(spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));
+ expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
- itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
+ itEth('transfer() call fee is less than 0.2UNQ', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.rft.mintCollection(alice);
+ const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner});
- const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress, owner);
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
- const receiver = createEthAccount(web3);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n, {Ethereum: owner})).itemId;
-
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address, owner);
-
- const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));
- expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ const cost = await helper.eth.recordCallFee(owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));
+ expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
});
describe('Refungible: Substrate calls', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
- });
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- itWeb3('Events emitted for approve()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
-
- const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
-
- const receiver = createEthAccount(web3);
+ donor = privateKey('//Alice');
+ [alice] = await helper.arrange.createAccounts([50n], donor);
+ });
+ });
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;
+ itEth('Events emitted for approve()', async ({helper}) => {
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.rft.mintCollection(alice);
+ const token = await collection.mintToken(alice, 200n);
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address);
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress);
- const events = await recordEvents(contract, async () => {
- expect(await approve(api, collectionId, tokenId, alice, {Ethereum: receiver}, 100n)).to.be.true;
+ const events: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ events.push(event);
});
+ expect(await token.approve(alice, {Ethereum: receiver}, 100n)).to.be.true;
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Approval',
- args: {
- owner: subToEth(alice.address),
- spender: receiver,
- value: '100',
- },
- },
- ]);
+ const event = events[0];
+ expect(event.event).to.be.equal('Approval');
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
+ expect(event.returnValues.spender).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('100');
});
- itWeb3('Events emitted for transferFrom()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
+ itEth('Events emitted for transferFrom()', async ({helper}) => {
+ const [bob] = await helper.arrange.createAccounts([10n], donor);
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.rft.mintCollection(alice);
+ const token = await collection.mintToken(alice, 200n);
+ await token.approve(alice, {Substrate: bob.address}, 100n);
- const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
- const bob = privateKeyWrapper('//Bob');
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress);
- const receiver = createEthAccount(web3);
+ const events: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ events.push(event);
+ });
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;
- expect(await approve(api, collectionId, tokenId, alice, bob.address, 100n)).to.be.true;
+ expect(await token.transferFrom(bob, {Substrate: alice.address}, {Ethereum: receiver}, 51n)).to.be.true;
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address);
+ let event = events[0];
+ expect(event.event).to.be.equal('Transfer');
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('51');
- const events = await recordEvents(contract, async () => {
- expect(await transferFrom(api, collectionId, tokenId, bob, alice, {Ethereum: receiver}, 51n)).to.be.true;
- });
-
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: subToEth(alice.address),
- to: receiver,
- value: '51',
- },
- },
- {
- address,
- event: 'Approval',
- args: {
- owner: subToEth(alice.address),
- spender: subToEth(bob.address),
- value: '49',
- },
- },
- ]);
+ event = events[1];
+ expect(event.event).to.be.equal('Approval');
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.owner).to.be.equal(helper.address.substrateToEth(alice.address));
+ expect(event.returnValues.spender).to.be.equal(helper.address.substrateToEth(bob.address));
+ expect(event.returnValues.value).to.be.equal('49');
});
- itWeb3('Events emitted for transfer()', async ({web3, api, privateKeyWrapper}) => {
- const alice = privateKeyWrapper('//Alice');
+ itEth('Events emitted for transfer()', async ({helper}) => {
+ const receiver = helper.eth.createAccount();
+ const collection = await helper.rft.mintCollection(alice);
+ const token = await collection.mintToken(alice, 200n);
- const collectionId = (await createCollection(api, alice, {mode: {type: 'ReFungible'}})).collectionId;
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, token.tokenId);
+ const contract = helper.ethNativeContract.rftToken(tokenAddress);
- const receiver = createEthAccount(web3);
-
- const tokenId = (await createRefungibleToken(api, alice, collectionId, 200n)).itemId;
+ const events: any = [];
+ contract.events.allEvents((_: any, event: any) => {
+ events.push(event);
+ });
- const address = tokenIdToAddress(collectionId, tokenId);
- const contract = uniqueRefungibleToken(web3, address);
+ expect(await token.transfer(alice, {Ethereum: receiver}, 51n)).to.be.true;
- const events = await recordEvents(contract, async () => {
- expect(await transfer(api, collectionId, tokenId, alice, {Ethereum: receiver}, 51n)).to.be.true;
- });
-
- expect(events).to.be.deep.equal([
- {
- address,
- event: 'Transfer',
- args: {
- from: subToEth(alice.address),
- to: receiver,
- value: '51',
- },
- },
- ]);
+ const event = events[0];
+ expect(event.event).to.be.equal('Transfer');
+ expect(event.address).to.be.equal(tokenAddress);
+ expect(event.returnValues.from).to.be.equal(helper.address.substrateToEth(alice.address));
+ expect(event.returnValues.to).to.be.equal(receiver);
+ expect(event.returnValues.value).to.be.equal('51');
});
});
describe('ERC 1633 implementation', () => {
+ let donor: IKeyringPair;
+
before(async function() {
- await requirePallets(this, [Pallets.ReFungible]);
- });
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
- itWeb3('Default parent token address and id', async ({api, web3, privateKeyWrapper}) => {
- const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ donor = privateKey('//Alice');
+ });
+ });
- const {collectionIdAddress, collectionId} = await createRFTCollection(api, web3, owner);
- const refungibleContract = uniqueRefungible(web3, collectionIdAddress, owner);
- const refungibleTokenId = await refungibleContract.methods.nextTokenId().call();
- await refungibleContract.methods.mint(owner, refungibleTokenId).send();
+ itEth('Default parent token address and id', async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
- const rftTokenAddress = tokenIdToAddress(collectionId, refungibleTokenId);
- const refungibleTokenContract = uniqueRefungibleToken(web3, rftTokenAddress, owner);
+ const {collectionId, collectionAddress} = await helper.eth.createRefungibleCollection(owner, 'Sands', '', 'GRAIN');
+ const collectionContract = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
+
+ const tokenId = await collectionContract.methods.nextTokenId().call();
+ await collectionContract.methods.mint(owner, tokenId).send();
+ const tokenAddress = helper.ethAddress.fromTokenId(collectionId, tokenId);
+ const tokenContract = helper.ethNativeContract.rftToken(tokenAddress, owner);
- const tokenAddress = await refungibleTokenContract.methods.parentToken().call();
- const tokenId = await refungibleTokenContract.methods.parentTokenId().call();
- expect(tokenAddress).to.be.equal(collectionIdAddress);
- expect(tokenId).to.be.equal(refungibleTokenId);
+ expect(await tokenContract.methods.parentToken().call()).to.be.equal(collectionAddress);
+ expect(await tokenContract.methods.parentTokenId().call()).to.be.equal(tokenId);
});
});
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -116,13 +116,17 @@
return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});
}
- rftTokenByAddress(address: string, caller?: string): Contract {
+ collectionById(collectionId: number, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {
+ return this.collection(this.helper.ethAddress.fromCollectionId(collectionId), mode, caller);
+ }
+
+ rftToken(address: string, caller?: string): Contract {
const web3 = this.helper.getWeb3();
return new web3.eth.Contract(refungibleTokenAbi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});
}
- rftToken(collectionId: number, tokenId: number, caller?: string): Contract {
- return this.rftTokenByAddress(this.helper.ethAddress.fromTokenId(collectionId, tokenId), caller);
+ rftTokenById(collectionId: number, tokenId: number, caller?: string): Contract {
+ return this.rftToken(this.helper.ethAddress.fromTokenId(collectionId, tokenId), caller);
}
}
@@ -171,6 +175,17 @@
return {collectionId, collectionAddress};
}
+ async createRefungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {
+ const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);
+
+ const result = await collectionHelper.methods.createRFTCollection(name, description, tokenPrefix).send();
+
+ const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
+ const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
+
+ return {collectionId, collectionAddress};
+ }
+
async deployCollectorContract(signer: string): Promise<Contract> {
return await this.helper.ethContract.deployByCode(signer, 'Collector', `
// SPDX-License-Identifier: UNLICENSED
@@ -215,6 +230,16 @@
}
`);
}
+
+ async recordCallFee(user: string, call: () => Promise<any>): Promise<bigint> {
+ const before = await this.helper.balance.getEthereum(user);
+ await call();
+ // In dev mode, the transaction might not finish processing in time
+ await this.helper.wait.newBlocks(1);
+ const after = await this.helper.balance.getEthereum(user);
+
+ return before - after;
+ }
}
class EthAddressGroup extends EthGroupBase {