difftreelog
Style update
in: master
6 files changed
pallets/nft/src/mock.rsdiffbeforeafterboth--- a/pallets/nft/src/mock.rs
+++ b/pallets/nft/src/mock.rs
@@ -98,12 +98,6 @@
type WeightInfo = ();
}
-<<<<<<< HEAD
-type Timestamp = pallet_timestamp::Pallet<Test>;
-type Randomness = pallet_randomness_collective_flip::Pallet<Test>;
-
-=======
->>>>>>> origin/develop
parameter_types! {
pub const CollectionCreationPrice: u32 = 0;
pub TreasuryAccountId: u64 = 1234;
pallets/nft/src/tests.rsdiffbeforeafterboth--- a/pallets/nft/src/tests.rs
+++ b/pallets/nft/src/tests.rs
@@ -2080,206 +2080,210 @@
Error::<Test>::NoPermission
);
-#[test]
-fn collection_transfer_flag_works() {
- new_test_ext().execute_with(|| {
- let origin1 = Origin::signed(1);
+ #[test]
+ fn collection_transfer_flag_works() {
+ new_test_ext().execute_with(|| {
+ let origin1 = Origin::signed(1);
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
- assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));
+ let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ assert_ok!(TemplateModule::set_transfers_enabled_flag(origin1, 1, true));
- let data = default_nft_data();
- create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
- let origin1 = Origin::signed(1);
+ let origin1 = Origin::signed(1);
- // default scenario
- assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
- assert_eq!(TemplateModule::balance_count(1, 1), 0);
- assert_eq!(TemplateModule::balance_count(1, 2), 1);
+ // default scenario
+ assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
+ assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
+ assert_eq!(TemplateModule::balance_count(1, 1), 0);
+ assert_eq!(TemplateModule::balance_count(1, 2), 1);
- assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
- });
-}
+ assert_eq!(TemplateModule::address_tokens(1, 2), [1]);
+ });
+ }
-#[test]
-fn set_variable_meta_data_on_nft_with_admin_flag() {
- new_test_ext().execute_with(|| {
- default_limits();
+ #[test]
+ fn set_variable_meta_data_on_nft_with_admin_flag() {
+ new_test_ext().execute_with(|| {
+ default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
- let origin1 = Origin::signed(1);
- let origin2 = Origin::signed(2);
+ let origin1 = Origin::signed(1);
+ let origin2 = Origin::signed(2);
- assert_ok!(TemplateModule::set_mint_permission(
- origin2.clone(),
- collection_id,
- true
- ));
- assert_ok!(TemplateModule::add_to_white_list(
- origin2.clone(),
- collection_id,
- account(1)
- ));
+ assert_ok!(TemplateModule::set_mint_permission(
+ origin2.clone(),
+ collection_id,
+ true
+ ));
+ assert_ok!(TemplateModule::add_to_white_list(
+ origin2.clone(),
+ collection_id,
+ account(1)
+ ));
- assert_ok!(TemplateModule::add_collection_admin(
- origin2.clone(),
- collection_id,
- account(1)
- ));
+ assert_ok!(TemplateModule::add_collection_admin(
+ origin2.clone(),
+ collection_id,
+ account(1)
+ ));
- let data = default_nft_data();
- create_test_item(1, &data.into());
+ let data = default_nft_data();
+ create_test_item(1, &data.into());
- TemplateModule::set_meta_update_permission_flag(
- origin2.clone(),
- collection_id,
- MetaUpdatePermission::Admin,
- );
+ TemplateModule::set_meta_update_permission_flag(
+ origin2.clone(),
+ collection_id,
+ MetaUpdatePermission::Admin,
+ );
- let variable_data = b"test set_variable_meta_data method.".to_vec();
- assert_ok!(TemplateModule::set_variable_meta_data(
- origin1,
- collection_id,
- 1,
- variable_data.clone()
- ));
+ let variable_data = b"test set_variable_meta_data method.".to_vec();
+ assert_ok!(TemplateModule::set_variable_meta_data(
+ origin1,
+ collection_id,
+ 1,
+ variable_data.clone()
+ ));
- assert_eq!(
- TemplateModule::nft_item_id(collection_id, 1)
- .unwrap()
- .variable_data,
- variable_data
- );
- });
-}
+ assert_eq!(
+ TemplateModule::nft_item_id(collection_id, 1)
+ .unwrap()
+ .variable_data,
+ variable_data
+ );
+ });
+ }
-#[test]
-fn set_variable_meta_data_on_nft_with_admin_flag_neg() {
- new_test_ext().execute_with(|| {
- default_limits();
+ #[test]
+ fn set_variable_meta_data_on_nft_with_admin_flag_neg() {
+ new_test_ext().execute_with(|| {
+ default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
- let origin1 = Origin::signed(1);
- let origin2 = Origin::signed(2);
+ let origin1 = Origin::signed(1);
+ let origin2 = Origin::signed(2);
- assert_ok!(TemplateModule::set_mint_permission(
- origin2.clone(),
- collection_id,
- true
- ));
- assert_ok!(TemplateModule::add_to_white_list(
- origin2.clone(),
- collection_id,
- account(1)
- ));
+ assert_ok!(TemplateModule::set_mint_permission(
+ origin2.clone(),
+ collection_id,
+ true
+ ));
+ assert_ok!(TemplateModule::add_to_white_list(
+ origin2.clone(),
+ collection_id,
+ account(1)
+ ));
- let data = default_nft_data();
- create_test_item(1, &data.into());
+ let data = default_nft_data();
+ create_test_item(1, &data.into());
- TemplateModule::set_meta_update_permission_flag(
- origin2.clone(),
- collection_id,
- MetaUpdatePermission::Admin,
- );
+ TemplateModule::set_meta_update_permission_flag(
+ origin2.clone(),
+ collection_id,
+ MetaUpdatePermission::Admin,
+ );
- let variable_data = b"test set_variable_meta_data method.".to_vec();
- assert_noop!(
- TemplateModule::set_variable_meta_data(
- origin1,
- collection_id,
- 1,
- variable_data.clone()
- ),
- Error::<Test>::NoPermission
- );
- });
-}
+ let variable_data = b"test set_variable_meta_data method.".to_vec();
+ assert_noop!(
+ TemplateModule::set_variable_meta_data(
+ origin1,
+ collection_id,
+ 1,
+ variable_data.clone()
+ ),
+ Error::<Test>::NoPermission
+ );
+ });
+ }
-#[test]
-fn set_variable_meta_flag_after_freeze() {
- new_test_ext().execute_with(|| {
- default_limits();
+ #[test]
+ fn set_variable_meta_flag_after_freeze() {
+ new_test_ext().execute_with(|| {
+ default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 2, 1);
- let origin2 = Origin::signed(2);
+ let origin2 = Origin::signed(2);
- TemplateModule::set_meta_update_permission_flag(
- origin2.clone(),
- collection_id,
- MetaUpdatePermission::None,
- );
- assert_noop!(
- TemplateModule::set_meta_update_permission_flag(
- origin2.clone(),
- collection_id,
- MetaUpdatePermission::Admin
- ),
- Error::<Test>::MetadataFlagFrozen
- );
- });
-}
+ TemplateModule::set_meta_update_permission_flag(
+ origin2.clone(),
+ collection_id,
+ MetaUpdatePermission::None,
+ );
+ assert_noop!(
+ TemplateModule::set_meta_update_permission_flag(
+ origin2.clone(),
+ collection_id,
+ MetaUpdatePermission::Admin
+ ),
+ Error::<Test>::MetadataFlagFrozen
+ );
+ });
+ }
-#[test]
-fn set_variable_meta_data_on_nft_with_none_flag_neg() {
- new_test_ext().execute_with(|| {
- default_limits();
+ #[test]
+ fn set_variable_meta_data_on_nft_with_none_flag_neg() {
+ new_test_ext().execute_with(|| {
+ default_limits();
- let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
- let origin1 = Origin::signed(1);
+ let collection_id = create_test_collection_for_owner(&CollectionMode::NFT, 1, 1);
+ let origin1 = Origin::signed(1);
- let data = default_nft_data();
- create_test_item(1, &data.into());
+ let data = default_nft_data();
+ create_test_item(1, &data.into());
- TemplateModule::set_meta_update_permission_flag(
- origin1.clone(),
- collection_id,
- MetaUpdatePermission::None,
- );
+ TemplateModule::set_meta_update_permission_flag(
+ origin1.clone(),
+ collection_id,
+ MetaUpdatePermission::None,
+ );
- let variable_data = b"test set_variable_meta_data method.".to_vec();
- assert_noop!(
- TemplateModule::set_variable_meta_data(
- origin1.clone(),
- collection_id,
- 1,
- variable_data.clone()
- ),
- Error::<Test>::MetadataUpdateDenied
- );
+ let variable_data = b"test set_variable_meta_data method.".to_vec();
+ assert_noop!(
+ TemplateModule::set_variable_meta_data(
+ origin1.clone(),
+ collection_id,
+ 1,
+ variable_data.clone()
+ ),
+ Error::<Test>::MetadataUpdateDenied
+ );
+ });
+ }
-#[test]
-fn collection_transfer_flag_works_neg() {
- new_test_ext().execute_with(|| {
- let origin1 = Origin::signed(1);
+ #[test]
+ fn collection_transfer_flag_works_neg() {
+ new_test_ext().execute_with(|| {
+ let origin1 = Origin::signed(1);
- let collection_id = create_test_collection(&CollectionMode::NFT, 1);
- assert_ok!(TemplateModule::set_transfers_enabled_flag(
- origin1, 1, false
- ));
+ let collection_id = create_test_collection(&CollectionMode::NFT, 1);
+ assert_ok!(TemplateModule::set_transfers_enabled_flag(
+ origin1, 1, false
+ ));
- let data = default_nft_data();
- create_test_item(collection_id, &data.into());
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ let data = default_nft_data();
+ create_test_item(collection_id, &data.into());
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
- let origin1 = Origin::signed(1);
+ let origin1 = Origin::signed(1);
- // default scenario
- assert_noop!(
- TemplateModule::transfer(origin1, account(2), 1, 1, 1000),
- Error::<Test>::TransferNotAllowed
- );
- assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));
- assert_eq!(TemplateModule::balance_count(1, 1), 1);
- assert_eq!(TemplateModule::balance_count(1, 2), 0);
+ // default scenario
+ assert_noop!(
+ TemplateModule::transfer(origin1, account(2), 1, 1, 1000),
+ Error::<Test>::TransferNotAllowed
+ );
+ assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(1));
+ assert_eq!(TemplateModule::balance_count(1, 1), 1);
+ assert_eq!(TemplateModule::balance_count(1, 2), 0);
- assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
+ });
+ }
});
}
tests/src/addCollectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/addCollectionAdmin.test.ts
+++ b/tests/src/addCollectionAdmin.test.ts
@@ -4,7 +4,6 @@
//
import { ApiPromise } from '@polkadot/api';
-import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from './substrate/privateKey';
tests/src/collision-tests/adminLimitsOff.test.tsdiffbeforeafterboth--- a/tests/src/collision-tests/adminLimitsOff.test.ts
+++ b/tests/src/collision-tests/adminLimitsOff.test.ts
@@ -1,5 +1,4 @@
import { IKeyringPair } from '@polkadot/types/types';
-import BN from 'bn.js';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import privateKey from '../substrate/privateKey';
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import privateKey from '../substrate/privateKey';7import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers';8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';9import { evmToAddress } from '@polkadot/util-crypto';10import nonFungibleAbi from './nonFungibleAbi.json';11import { expect } from 'chai';12import waitNewBlocks from '../substrate/wait-new-blocks';13import { submitTransactionAsync } from '../substrate/substrate-api';1415describe('NFT: Information getting', () => {16 itWeb3('totalSupply', async ({ api, web3 }) => {17 const collection = await createCollectionExpectSuccess({18 mode: { type: 'NFT' },19 });20 const alice = privateKey('//Alice');21 const caller = await createEthAccountWithBalance(api, web3);2223 await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });2425 const address = collectionIdToAddress(collection);26 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});27 const totalSupply = await contract.methods.totalSupply().call();2829 // FIXME: always equals to 0, because this method is not implemented30 expect(totalSupply).to.equal('0');31 });3233 itWeb3('balanceOf', async ({ api, web3 }) => {34 const collection = await createCollectionExpectSuccess({35 mode: { type: 'NFT' },36 });37 const alice = privateKey('//Alice');3839 const caller = await createEthAccountWithBalance(api, web3);40 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });41 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });42 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });4344 const address = collectionIdToAddress(collection);45 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});46 const balance = await contract.methods.balanceOf(caller).call();4748 expect(balance).to.equal('3');49 });5051 itWeb3('ownerOf', async ({ api, web3 }) => {52 const collection = await createCollectionExpectSuccess({53 mode: { type: 'NFT' },54 });55 const alice = privateKey('//Alice');5657 const caller = await createEthAccountWithBalance(api, web3);58 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });5960 const address = collectionIdToAddress(collection);61 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});62 const owner = await contract.methods.ownerOf(tokenId).call();6364 expect(owner).to.equal(caller);65 });66});6768describe('NFT: Plain calls', () => {69 itWeb3('Can perform mint()', async ({ web3, api }) => {70 const collection = await createCollectionExpectSuccess({71 mode: { type: 'NFT' },72 });73 const alice = privateKey('//Alice');7475 const caller = await createEthAccountWithBalance(api, web3);76 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });77 await submitTransactionAsync(alice, changeAdminTx);78 const receiver = createEthAccount(web3);7980 const address = collectionIdToAddress(collection);81 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});8283 {84 const nextTokenId = await contract.methods.nextTokenId().call();85 expect(nextTokenId).to.be.equal('1');86 const result = await contract.methods.mintWithTokenURI(87 receiver,88 nextTokenId,89 'Test URI',90 ).send({from: caller});91 const events = normalizeEvents(result.events);9293 expect(events).to.be.deep.equal([94 {95 address,96 event: 'Transfer',97 args: {98 from: '0x0000000000000000000000000000000000000000',99 to: receiver,100 tokenId: nextTokenId,101 },102 },103 ]);104105 await waitNewBlocks(api, 1);106 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');107 }108 });109110 itWeb3('Can perform burn()', async ({ web3, api }) => {111 const collection = await createCollectionExpectSuccess({112 mode: {type: 'NFT'},113 });114 const alice = privateKey('//Alice');115116 const owner = await createEthAccountWithBalance(api, web3);117118 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });119 120 const address = collectionIdToAddress(collection);121 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});122123 {124 const result = await contract.methods.burn(tokenId).send({ from: owner });125 const events = normalizeEvents(result.events);126 127 expect(events).to.be.deep.equal([128 {129 address,130 event: 'Transfer',131 args: {132 from: owner,133 to: '0x0000000000000000000000000000000000000000',134 tokenId: tokenId.toString(),135 },136 },137 ]);138 }139 });140141 itWeb3('Can perform approve()', async ({ web3, api }) => {142 const collection = await createCollectionExpectSuccess({143 mode: { type: 'NFT' },144 });145 const alice = privateKey('//Alice');146147 const owner = createEthAccount(web3);148 await transferBalanceToEth(api, alice, owner, 999999999999999);149150 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });151152 const spender = createEthAccount(web3);153154 const address = collectionIdToAddress(collection);155 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);156157 {158 const result = await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });159 const events = normalizeEvents(result.events);160161 expect(events).to.be.deep.equal([162 {163 address,164 event: 'Approval',165 args: {166 owner,167 approved: spender,168 tokenId: tokenId.toString(),169 },170 },171 ]);172 }173 });174175 itWeb3('Can perform transferFrom()', async ({ web3, api }) => {176 const collection = await createCollectionExpectSuccess({177 mode: { type: 'NFT' },178 });179 const alice = privateKey('//Alice');180181 const owner = createEthAccount(web3);182 await transferBalanceToEth(api, alice, owner, 999999999999999);183184 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });185186 const spender = createEthAccount(web3);187 await transferBalanceToEth(api, alice, spender, 999999999999999);188189 const receiver = createEthAccount(web3);190191 const address = collectionIdToAddress(collection);192 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});193194 await contract.methods.approve(spender, tokenId).send({ from: owner });195196 {197 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender });198 const events = normalizeEvents(result.events);199 expect(events).to.be.deep.equal([200 {201 address,202 event: 'Transfer',203 args: {204 from: owner,205 to: receiver,206 tokenId: tokenId.toString(),207 },208 },209 ]);210 }211212 {213 const balance = await contract.methods.balanceOf(receiver).call();214 expect(+balance).to.equal(1);215 }216217 {218 const balance = await contract.methods.balanceOf(owner).call();219 expect(+balance).to.equal(0);220 }221 });222223 itWeb3('Can perform transfer()', async ({ web3, api }) => {224 const collection = await createCollectionExpectSuccess({225 mode: { type: 'NFT' },226 });227 const alice = privateKey('//Alice');228229 const owner = createEthAccount(web3);230 await transferBalanceToEth(api, alice, owner, 999999999999999);231232 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });233234 const receiver = createEthAccount(web3);235 await transferBalanceToEth(api, alice, receiver, 999999999999999);236237 const address = collectionIdToAddress(collection);238 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});239240 {241 const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner });242 await waitNewBlocks(api, 1);243 const events = normalizeEvents(result.events);244 expect(events).to.be.deep.equal([245 {246 address,247 event: 'Transfer',248 args: {249 from: owner,250 to: receiver,251 tokenId: tokenId.toString(),252 },253 },254 ]);255 }256257 {258 const balance = await contract.methods.balanceOf(owner).call();259 expect(+balance).to.equal(0);260 }261262 {263 const balance = await contract.methods.balanceOf(receiver).call();264 expect(+balance).to.equal(1);265 }266 });267});268269describe('NFT: Fees', () => {270 itWeb3('approve() call fee is less than 0.2UNQ', async ({ web3, api }) => {271 const collection = await createCollectionExpectSuccess({272 mode: { type: 'NFT' },273 });274 const alice = privateKey('//Alice');275276 const owner = await createEthAccountWithBalance(api, web3);277 const spender = createEthAccount(web3);278279 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });280281 const address = collectionIdToAddress(collection);282 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });283284 const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, tokenId).send({ from: owner }));285 expect(cost < BigInt(0.2 * Number(UNIQUE)));286 });287288 itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({ web3, api }) => {289 const collection = await createCollectionExpectSuccess({290 mode: { type: 'NFT' },291 });292 const alice = privateKey('//Alice');293 294 const owner = await createEthAccountWithBalance(api, web3);295 const spender = await createEthAccountWithBalance(api, web3);296297 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });298299 const address = collectionIdToAddress(collection);300 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });301302 await contract.methods.approve(spender, tokenId).send({ from: owner });303304 const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({ from: spender }));305 expect(cost < BigInt(0.2 * Number(UNIQUE)));306 });307308 itWeb3('transfer() call fee is less than 0.2UNQ', async ({ web3, api }) => {309 const collection = await createCollectionExpectSuccess({310 mode: { type: 'NFT' },311 });312 const alice = privateKey('//Alice');313314 const owner = await createEthAccountWithBalance(api, web3);315 const receiver = createEthAccount(web3);316317 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });318319 const address = collectionIdToAddress(collection);320 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });321322 const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, tokenId).send({ from: owner }));323 expect(cost < BigInt(0.2 * Number(UNIQUE)));324 });325});326327describe('NFT: Substrate calls', () => {328 itWeb3('Events emitted for mint()', async ({ web3 }) => {329 const collection = await createCollectionExpectSuccess({330 mode: { type: 'NFT' },331 });332 const alice = privateKey('//Alice');333334 const address = collectionIdToAddress(collection);335 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);336337 let tokenId: number;338 const events = await recordEvents(contract, async () => {339 tokenId = await createItemExpectSuccess(alice, collection, 'NFT');340 });341342 expect(events).to.be.deep.equal([343 {344 address,345 event: 'Transfer',346 args: {347 from: '0x0000000000000000000000000000000000000000',348 to: subToEth(alice.address),349 tokenId: tokenId!.toString(),350 },351 },352 ]);353 });354355 itWeb3('Events emitted for burn()', async ({ web3 }) => {356 const collection = await createCollectionExpectSuccess({357 mode: { type: 'NFT' },358 });359 const alice = privateKey('//Alice');360361 const address = collectionIdToAddress(collection);362 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);363364 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');365 const events = await recordEvents(contract, async () => {366 await burnItemExpectSuccess(alice, collection, tokenId);367 });368369 expect(events).to.be.deep.equal([370 {371 address,372 event: 'Transfer',373 args: {374 from: subToEth(alice.address),375 to: '0x0000000000000000000000000000000000000000',376 tokenId: tokenId.toString(),377 },378 },379 ]);380 });381382 itWeb3('Events emitted for approve()', async ({ web3 }) => {383 const collection = await createCollectionExpectSuccess({384 mode: { type: 'NFT' },385 });386 const alice = privateKey('//Alice');387388 const receiver = createEthAccount(web3);389390 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');391392 const address = collectionIdToAddress(collection);393 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);394395 const events = await recordEvents(contract, async () => {396 await approveExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1);397 });398399 expect(events).to.be.deep.equal([400 {401 address,402 event: 'Approval',403 args: {404 owner: subToEth(alice.address),405 approved: receiver,406 tokenId: tokenId.toString(),407 },408 },409 ]);410 });411412 itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {413 const collection = await createCollectionExpectSuccess({414 mode: { type: 'NFT' },415 });416 const alice = privateKey('//Alice');417 const bob = privateKey('//Bob');418419 const receiver = createEthAccount(web3);420421 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');422 await approveExpectSuccess(collection, tokenId, alice, bob, 1);423424 const address = collectionIdToAddress(collection);425 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);426427 const events = await recordEvents(contract, async () => {428 await transferFromExpectSuccess(collection, tokenId, bob, alice, { ethereum: receiver }, 1, 'NFT');429 });430431 expect(events).to.be.deep.equal([432 {433 address,434 event: 'Transfer',435 args: {436 from: subToEth(alice.address),437 to: receiver,438 tokenId: tokenId.toString(),439 },440 },441 ]);442 });443444 itWeb3('Events emitted for transfer()', async ({ web3 }) => {445 const collection = await createCollectionExpectSuccess({446 mode: { type: 'NFT' },447 });448 const alice = privateKey('//Alice');449450 const receiver = createEthAccount(web3);451452 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');453454 const address = collectionIdToAddress(collection);455 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);456457 const events = await recordEvents(contract, async () => {458 await transferExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1, 'NFT');459 });460461 expect(events).to.be.deep.equal([462 {463 address,464 event: 'Transfer',465 args: {466 from: subToEth(alice.address),467 to: receiver,468 tokenId: tokenId.toString(),469 },470 },471 ]);472 });473});1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import privateKey from '../substrate/privateKey';7import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers';8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';9import nonFungibleAbi from './nonFungibleAbi.json';10import { expect } from 'chai';11import waitNewBlocks from '../substrate/wait-new-blocks';12import { submitTransactionAsync } from '../substrate/substrate-api';1314describe('NFT: Information getting', () => {15 itWeb3('totalSupply', async ({ api, web3 }) => {16 const collection = await createCollectionExpectSuccess({17 mode: { type: 'NFT' },18 });19 const alice = privateKey('//Alice');20 const caller = await createEthAccountWithBalance(api, web3);2122 await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });2324 const address = collectionIdToAddress(collection);25 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});26 const totalSupply = await contract.methods.totalSupply().call();2728 // FIXME: always equals to 0, because this method is not implemented29 expect(totalSupply).to.equal('0');30 });3132 itWeb3('balanceOf', async ({ api, web3 }) => {33 const collection = await createCollectionExpectSuccess({34 mode: { type: 'NFT' },35 });36 const alice = privateKey('//Alice');3738 const caller = await createEthAccountWithBalance(api, web3);39 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });40 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });41 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });4243 const address = collectionIdToAddress(collection);44 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});45 const balance = await contract.methods.balanceOf(caller).call();4647 expect(balance).to.equal('3');48 });4950 itWeb3('ownerOf', async ({ api, web3 }) => {51 const collection = await createCollectionExpectSuccess({52 mode: { type: 'NFT' },53 });54 const alice = privateKey('//Alice');5556 const caller = await createEthAccountWithBalance(api, web3);57 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });5859 const address = collectionIdToAddress(collection);60 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});61 const owner = await contract.methods.ownerOf(tokenId).call();6263 expect(owner).to.equal(caller);64 });65});6667describe('NFT: Plain calls', () => {68 itWeb3('Can perform mint()', async ({ web3, api }) => {69 const collection = await createCollectionExpectSuccess({70 mode: { type: 'NFT' },71 });72 const alice = privateKey('//Alice');7374 const caller = await createEthAccountWithBalance(api, web3);75 const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });76 await submitTransactionAsync(alice, changeAdminTx);77 const receiver = createEthAccount(web3);7879 const address = collectionIdToAddress(collection);80 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});8182 {83 const nextTokenId = await contract.methods.nextTokenId().call();84 expect(nextTokenId).to.be.equal('1');85 const result = await contract.methods.mintWithTokenURI(86 receiver,87 nextTokenId,88 'Test URI',89 ).send({from: caller});90 const events = normalizeEvents(result.events);9192 expect(events).to.be.deep.equal([93 {94 address,95 event: 'Transfer',96 args: {97 from: '0x0000000000000000000000000000000000000000',98 to: receiver,99 tokenId: nextTokenId,100 },101 },102 ]);103104 await waitNewBlocks(api, 1);105 expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');106 }107 });108109 itWeb3('Can perform burn()', async ({ web3, api }) => {110 const collection = await createCollectionExpectSuccess({111 mode: {type: 'NFT'},112 });113 const alice = privateKey('//Alice');114115 const owner = await createEthAccountWithBalance(api, web3);116117 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });118 119 const address = collectionIdToAddress(collection);120 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});121122 {123 const result = await contract.methods.burn(tokenId).send({ from: owner });124 const events = normalizeEvents(result.events);125 126 expect(events).to.be.deep.equal([127 {128 address,129 event: 'Transfer',130 args: {131 from: owner,132 to: '0x0000000000000000000000000000000000000000',133 tokenId: tokenId.toString(),134 },135 },136 ]);137 }138 });139140 itWeb3('Can perform approve()', async ({ web3, api }) => {141 const collection = await createCollectionExpectSuccess({142 mode: { type: 'NFT' },143 });144 const alice = privateKey('//Alice');145146 const owner = createEthAccount(web3);147 await transferBalanceToEth(api, alice, owner, 999999999999999);148149 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });150151 const spender = createEthAccount(web3);152153 const address = collectionIdToAddress(collection);154 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);155156 {157 const result = await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });158 const events = normalizeEvents(result.events);159160 expect(events).to.be.deep.equal([161 {162 address,163 event: 'Approval',164 args: {165 owner,166 approved: spender,167 tokenId: tokenId.toString(),168 },169 },170 ]);171 }172 });173174 itWeb3('Can perform transferFrom()', async ({ web3, api }) => {175 const collection = await createCollectionExpectSuccess({176 mode: { type: 'NFT' },177 });178 const alice = privateKey('//Alice');179180 const owner = createEthAccount(web3);181 await transferBalanceToEth(api, alice, owner, 999999999999999);182183 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });184185 const spender = createEthAccount(web3);186 await transferBalanceToEth(api, alice, spender, 999999999999999);187188 const receiver = createEthAccount(web3);189190 const address = collectionIdToAddress(collection);191 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});192193 await contract.methods.approve(spender, tokenId).send({ from: owner });194195 {196 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender });197 const events = normalizeEvents(result.events);198 expect(events).to.be.deep.equal([199 {200 address,201 event: 'Transfer',202 args: {203 from: owner,204 to: receiver,205 tokenId: tokenId.toString(),206 },207 },208 ]);209 }210211 {212 const balance = await contract.methods.balanceOf(receiver).call();213 expect(+balance).to.equal(1);214 }215216 {217 const balance = await contract.methods.balanceOf(owner).call();218 expect(+balance).to.equal(0);219 }220 });221222 itWeb3('Can perform transfer()', async ({ web3, api }) => {223 const collection = await createCollectionExpectSuccess({224 mode: { type: 'NFT' },225 });226 const alice = privateKey('//Alice');227228 const owner = createEthAccount(web3);229 await transferBalanceToEth(api, alice, owner, 999999999999999);230231 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });232233 const receiver = createEthAccount(web3);234 await transferBalanceToEth(api, alice, receiver, 999999999999999);235236 const address = collectionIdToAddress(collection);237 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});238239 {240 const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner });241 await waitNewBlocks(api, 1);242 const events = normalizeEvents(result.events);243 expect(events).to.be.deep.equal([244 {245 address,246 event: 'Transfer',247 args: {248 from: owner,249 to: receiver,250 tokenId: tokenId.toString(),251 },252 },253 ]);254 }255256 {257 const balance = await contract.methods.balanceOf(owner).call();258 expect(+balance).to.equal(0);259 }260261 {262 const balance = await contract.methods.balanceOf(receiver).call();263 expect(+balance).to.equal(1);264 }265 });266});267268describe('NFT: Fees', () => {269 itWeb3('approve() call fee is less than 0.2UNQ', async ({ web3, api }) => {270 const collection = await createCollectionExpectSuccess({271 mode: { type: 'NFT' },272 });273 const alice = privateKey('//Alice');274275 const owner = await createEthAccountWithBalance(api, web3);276 const spender = createEthAccount(web3);277278 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });279280 const address = collectionIdToAddress(collection);281 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });282283 const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, tokenId).send({ from: owner }));284 expect(cost < BigInt(0.2 * Number(UNIQUE)));285 });286287 itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({ web3, api }) => {288 const collection = await createCollectionExpectSuccess({289 mode: { type: 'NFT' },290 });291 const alice = privateKey('//Alice');292 293 const owner = await createEthAccountWithBalance(api, web3);294 const spender = await createEthAccountWithBalance(api, web3);295296 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });297298 const address = collectionIdToAddress(collection);299 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });300301 await contract.methods.approve(spender, tokenId).send({ from: owner });302303 const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({ from: spender }));304 expect(cost < BigInt(0.2 * Number(UNIQUE)));305 });306307 itWeb3('transfer() call fee is less than 0.2UNQ', async ({ web3, api }) => {308 const collection = await createCollectionExpectSuccess({309 mode: { type: 'NFT' },310 });311 const alice = privateKey('//Alice');312313 const owner = await createEthAccountWithBalance(api, web3);314 const receiver = createEthAccount(web3);315316 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });317318 const address = collectionIdToAddress(collection);319 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });320321 const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, tokenId).send({ from: owner }));322 expect(cost < BigInt(0.2 * Number(UNIQUE)));323 });324});325326describe('NFT: Substrate calls', () => {327 itWeb3('Events emitted for mint()', async ({ web3 }) => {328 const collection = await createCollectionExpectSuccess({329 mode: { type: 'NFT' },330 });331 const alice = privateKey('//Alice');332333 const address = collectionIdToAddress(collection);334 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);335336 let tokenId: number;337 const events = await recordEvents(contract, async () => {338 tokenId = await createItemExpectSuccess(alice, collection, 'NFT');339 });340341 expect(events).to.be.deep.equal([342 {343 address,344 event: 'Transfer',345 args: {346 from: '0x0000000000000000000000000000000000000000',347 to: subToEth(alice.address),348 tokenId: tokenId!.toString(),349 },350 },351 ]);352 });353354 itWeb3('Events emitted for burn()', async ({ web3 }) => {355 const collection = await createCollectionExpectSuccess({356 mode: { type: 'NFT' },357 });358 const alice = privateKey('//Alice');359360 const address = collectionIdToAddress(collection);361 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);362363 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');364 const events = await recordEvents(contract, async () => {365 await burnItemExpectSuccess(alice, collection, tokenId);366 });367368 expect(events).to.be.deep.equal([369 {370 address,371 event: 'Transfer',372 args: {373 from: subToEth(alice.address),374 to: '0x0000000000000000000000000000000000000000',375 tokenId: tokenId.toString(),376 },377 },378 ]);379 });380381 itWeb3('Events emitted for approve()', async ({ web3 }) => {382 const collection = await createCollectionExpectSuccess({383 mode: { type: 'NFT' },384 });385 const alice = privateKey('//Alice');386387 const receiver = createEthAccount(web3);388389 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');390391 const address = collectionIdToAddress(collection);392 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);393394 const events = await recordEvents(contract, async () => {395 await approveExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1);396 });397398 expect(events).to.be.deep.equal([399 {400 address,401 event: 'Approval',402 args: {403 owner: subToEth(alice.address),404 approved: receiver,405 tokenId: tokenId.toString(),406 },407 },408 ]);409 });410411 itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {412 const collection = await createCollectionExpectSuccess({413 mode: { type: 'NFT' },414 });415 const alice = privateKey('//Alice');416 const bob = privateKey('//Bob');417418 const receiver = createEthAccount(web3);419420 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');421 await approveExpectSuccess(collection, tokenId, alice, bob, 1);422423 const address = collectionIdToAddress(collection);424 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);425426 const events = await recordEvents(contract, async () => {427 await transferFromExpectSuccess(collection, tokenId, bob, alice, { ethereum: receiver }, 1, 'NFT');428 });429430 expect(events).to.be.deep.equal([431 {432 address,433 event: 'Transfer',434 args: {435 from: subToEth(alice.address),436 to: receiver,437 tokenId: tokenId.toString(),438 },439 },440 ]);441 });442443 itWeb3('Events emitted for transfer()', async ({ web3 }) => {444 const collection = await createCollectionExpectSuccess({445 mode: { type: 'NFT' },446 });447 const alice = privateKey('//Alice');448449 const receiver = createEthAccount(web3);450451 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');452453 const address = collectionIdToAddress(collection);454 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);455456 const events = await recordEvents(contract, async () => {457 await transferExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1, 'NFT');458 });459460 expect(events).to.be.deep.equal([461 {462 address,463 event: 'Transfer',464 args: {465 from: subToEth(alice.address),466 to: receiver,467 tokenId: tokenId.toString(),468 },469 },470 ]);471 });472});tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -1084,15 +1084,6 @@
await setMintPermissionExpectSuccess(sender, collectionId, true);
}
-export async function addCollectionAdminExpectSuccess(sender: IKeyringPair, collectionId: number, address: IKeyringPair) {
- await usingApi(async (api) => {
- const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, normalizeAccountId(address.address));
- const events = await submitTransactionAsync(sender, changeAdminTx);
- const result = getCreateCollectionResult(events);
- expect(result.success).to.be.true;
- });
-}
-
export async function setMintPermissionExpectFailure(sender: IKeyringPair, collectionId: number, enabled: boolean) {
await usingApi(async (api) => {
// Run the transaction