difftreelog
Merge remote-tracking branch 'origin/develop' into feature/NFTPAR-235-258
in: master
# Conflicts: # tests/src/createCollection.test.ts # tests/src/util/helpers.ts
13 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -1153,7 +1153,7 @@
}
// Reduce approval by transferred amount or remove if remaining approval drops to 0
- if approval - value > 0 {
+ if approval.checked_sub(value).unwrap_or(0) > 0 {
<Allowances<T>>::insert(collection_id, (item_id, &from, &recipient), approval - value);
}
else {
pallets/nft/src/tests.rsdiffbeforeafterboth1// Tests to be written here1// Tests to be written here2use super::*;2use super::*;3use crate::mock::*;3use crate::mock::*;4use crate::{AccessMode, ApprovePermissions, CollectionMode,4use crate::{AccessMode, CollectionMode,5 Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData,5 Ownership, ChainLimits, CreateItemData, CreateNftData, CreateFungibleData, CreateReFungibleData,6 CollectionId, TokenId, MAX_DECIMAL_POINTS};6 CollectionId, TokenId, MAX_DECIMAL_POINTS};7use frame_support::{assert_noop, assert_ok};7use frame_support::{assert_noop, assert_ok};28}28}292930fn default_fungible_data () -> CreateFungibleData {30fn default_fungible_data () -> CreateFungibleData {31 CreateFungibleData { }31 CreateFungibleData { value: 5 }32}32}333334fn default_re_fungible_data () -> CreateReFungibleData {34fn default_re_fungible_data () -> CreateReFungibleData {238 let data = default_fungible_data();238 let data = default_fungible_data();239 create_test_item(collection_id, &data.into());239 create_test_item(collection_id, &data.into());240240241 assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).owner, 1);241 assert_eq!(TemplateModule::fungible_item_id(collection_id, 1).value, 5);242 });242 });243}243}244244245#[test]245//#[test]246fn create_multiple_fungible_items() {246// fn create_multiple_fungible_items() {247 new_test_ext().execute_with(|| {247// new_test_ext().execute_with(|| {248 default_limits();248// default_limits();249249250 create_test_collection(&CollectionMode::Fungible(3), 1);250// create_test_collection(&CollectionMode::Fungible(3), 1);251251252 let origin1 = Origin::signed(1);252// let origin1 = Origin::signed(1);253253254 let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];254// let items_data = vec![default_fungible_data(), default_fungible_data(), default_fungible_data()];255255256 assert_ok!(TemplateModule::create_multiple_items(256// assert_ok!(TemplateModule::create_multiple_items(257 origin1.clone(),257// origin1.clone(),258 1,258// 1,259 1,259// 1,260 items_data.clone().into_iter().map(|d| { d.into() }).collect()260// items_data.clone().into_iter().map(|d| { d.into() }).collect()261 ));261// ));262 262 263 for (index, _) in items_data.iter().enumerate() {263// for (index, _) in items_data.iter().enumerate() {264 assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).owner, 1);264// assert_eq!(TemplateModule::fungible_item_id(1, (index + 1) as TokenId).value, 5);265 }265// }266 assert_eq!(TemplateModule::balance_count(1, 1), 3000);266// assert_eq!(TemplateModule::balance_count(1, 1), 3000);267 assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);267// assert_eq!(TemplateModule::address_tokens(1, 1), [1, 2, 3]);268 });268// });269}269// }270270271#[test]271#[test]272fn transfer_fungible_item() {272fn transfer_fungible_item() {281 let data = default_fungible_data();281 let data = default_fungible_data();282 create_test_item(collection_id, &data.into());282 create_test_item(collection_id, &data.into());283283284 assert_eq!(TemplateModule::fungible_item_id(1, 1).owner, 1);284 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 5);285 assert_eq!(TemplateModule::balance_count(1, 1), 1000);285 assert_eq!(TemplateModule::balance_count(1, 1), 5);286 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);287286288 // change owner scenario287 // change owner scenario289 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 1000));288 assert_ok!(TemplateModule::transfer(origin1.clone(), 2, 1, 1, 5));290 assert_eq!(TemplateModule::fungible_item_id(1, 1).owner, 2);291 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 1000);289 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);292 assert_eq!(TemplateModule::balance_count(1, 1), 0);290 assert_eq!(TemplateModule::balance_count(1, 1), 0);293 assert_eq!(TemplateModule::balance_count(1, 2), 1000);291 assert_eq!(TemplateModule::balance_count(1, 2), 5);294 // assert_eq!(TemplateModule::address_tokens(1, 1), []);295 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);296292297 // split item scenario293 // split item scenario298 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 500));294 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 3));299 assert_eq!(TemplateModule::fungible_item_id(1, 1).owner, 2);300 assert_eq!(TemplateModule::fungible_item_id(1, 2).owner, 3);301 assert_eq!(TemplateModule::balance_count(1, 2), 500);295 assert_eq!(TemplateModule::balance_count(1, 2), 2);302 assert_eq!(TemplateModule::balance_count(1, 3), 500);296 assert_eq!(TemplateModule::balance_count(1, 3), 3);303 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);304 assert_eq!(TemplateModule::address_tokens(1, 3), [2]);305297306 // split item and new owner has account scenario298 // split item and new owner has account scenario307 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 200));299 assert_ok!(TemplateModule::transfer(origin2.clone(), 3, 1, 1, 1));308 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 300);300 assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);309 assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 700);301 assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);310 assert_eq!(TemplateModule::balance_count(1, 2), 300);302 assert_eq!(TemplateModule::balance_count(1, 2), 1);311 assert_eq!(TemplateModule::balance_count(1, 3), 700);303 assert_eq!(TemplateModule::balance_count(1, 3), 4);312 assert_eq!(TemplateModule::address_tokens(1, 2), [1]);313 assert_eq!(TemplateModule::address_tokens(1, 3), [2]);314 });304 });315}305}316306451 1), Error::<Test>::NoPermission);441 1), Error::<Test>::NoPermission);452442453 // do approve443 // do approve454 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));444 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));455 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);445 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);456 assert_eq!(446 assert_eq!(457 TemplateModule::approved(1, (1, 1))[0],447 TemplateModule::approved(1, (1, 1, 2)),458 ApprovePermissions {448 5459 approved: 2,460 amount: 100000000461 }462 );449 );463450464 assert_ok!(TemplateModule::transfer_from(451 assert_ok!(TemplateModule::transfer_from(469 1,456 1,470 1457 1471 ));458 ));472 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);459 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 4);473 });460 });474}461}475462505 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));492 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));506493507 // do approve494 // do approve508 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));495 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));509 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);496 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);510 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1));497 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));511 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 2);498 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);512 assert_eq!(513 TemplateModule::approved(1, (1, 1))[0],514 ApprovePermissions {515 approved: 2,516 amount: 100000000517 }518 );519499520 assert_ok!(TemplateModule::transfer_from(500 assert_ok!(TemplateModule::transfer_from(521 origin2.clone(),501 origin2.clone(),525 1,505 1,526 1506 1527 ));507 ));528 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);508 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 4);529 });509 });530}510}531511560 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));540 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));561541562 // do approve542 // do approve563 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));543 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));564 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);544 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);565 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1));545 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 1000));566 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 2);546 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1000);567 assert_eq!(568 TemplateModule::approved(1, (1, 1))[0],569 ApprovePermissions {570 approved: 2,571 amount: 100000000572 }573 );574547575 assert_ok!(TemplateModule::transfer_from(548 assert_ok!(TemplateModule::transfer_from(576 origin2.clone(),549 origin2.clone(),585 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);558 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);586 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);559 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);587560588 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);561 assert_eq!(589 assert_eq!(562 TemplateModule::approved(1, (1, 1, 3)),590 TemplateModule::approved(1, (1, 1))[0],563 900591 ApprovePermissions {564 );592 approved: 3,593 amount: 100000000594 }595 );596 });565 });597}566}598567609 let origin1 = Origin::signed(1);578 let origin1 = Origin::signed(1);610 let origin2 = Origin::signed(2);579 let origin2 = Origin::signed(2);611580612 assert_eq!(TemplateModule::balance_count(1, 1), 1000);581 assert_eq!(TemplateModule::balance_count(1, 1), 5);613 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);614582615 assert_ok!(TemplateModule::set_mint_permission(583 assert_ok!(TemplateModule::set_mint_permission(616 origin1.clone(),584 origin1.clone(),627 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));595 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));628596629 // do approve597 // do approve630 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));598 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));631 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);599 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);632 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1));600 assert_ok!(TemplateModule::approve(origin1.clone(), 3, 1, 1, 5));633 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 2);601 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);634 assert_eq!(602 assert_eq!(635 TemplateModule::approved(1, (1, 1))[0],603 TemplateModule::approved(1, (1, 1, 2)),636 ApprovePermissions {604 5637 approved: 2,638 amount: 100000000639 }640 );605 );641606642 assert_ok!(TemplateModule::transfer_from(607 assert_ok!(TemplateModule::transfer_from(645 3,610 3,646 1,611 1,647 1,612 1,648 100613 4649 ));614 ));650 assert_eq!(TemplateModule::balance_count(1, 1), 900);615 assert_eq!(TemplateModule::balance_count(1, 1), 1);651 assert_eq!(TemplateModule::balance_count(1, 3), 100);616 assert_eq!(TemplateModule::balance_count(1, 3), 4);652 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);653 assert_eq!(TemplateModule::address_tokens(1, 3), [2]);654617655 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);618 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);656 assert_eq!(619 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 1);657 TemplateModule::approved(1, (1, 1))[0],658 ApprovePermissions {659 approved: 3,660 amount: 100000000661 }662 );663620664 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));621 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 5));665 assert_ok!(TemplateModule::transfer_from(622 assert_noop!(TemplateModule::transfer_from(666 origin2.clone(),623 origin2.clone(),667 1,624 1,668 3,625 3,669 1,626 1,670 1,627 1,671 900628 4672 ));629 ), Error::<Test>::TokenValueNotEnough);673 assert_eq!(TemplateModule::balance_count(1, 1), 0);674 assert_eq!(TemplateModule::balance_count(1, 3), 1000);675 // assert_eq!(TemplateModule::address_tokens(1, 1), []);676 assert_eq!(TemplateModule::address_tokens(1, 3), [2]);677678 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);679 });630 });680}631}681632725 assert_eq!(TemplateModule::balance_count(1, 1), 1);676 assert_eq!(TemplateModule::balance_count(1, 1), 1);726677727 // burn item678 // burn item728 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));679 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));729 assert_noop!(680 assert_noop!(730 TemplateModule::burn_item(origin1.clone(), 1, 1),681 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),731 Error::<Test>::TokenNotFound682 Error::<Test>::TokenNotFound732 );683 );733684749 create_test_item(collection_id, &data.into());700 create_test_item(collection_id, &data.into());750701751 // check balance (collection with id = 1, user id = 1)702 // check balance (collection with id = 1, user id = 1)752 assert_eq!(TemplateModule::balance_count(1, 1), 1000);703 assert_eq!(TemplateModule::balance_count(1, 1), 5);753704754 // burn item705 // burn item755 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));706 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));756 assert_noop!(707 assert_noop!(757 TemplateModule::burn_item(origin1.clone(), 1, 1),708 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),758 Error::<Test>::TokenNotFound709 Error::<Test>::TokenNotFound759 );710 );760711791 assert_eq!(TemplateModule::balance_count(1, 1), 1000);742 assert_eq!(TemplateModule::balance_count(1, 1), 1000);792743793 // burn item744 // burn item794 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1));745 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1000));795 assert_noop!(746 assert_noop!(796 TemplateModule::burn_item(origin1.clone(), 1, 1),747 TemplateModule::burn_item(origin1.clone(), 1, 1, 1000),797 Error::<Test>::TokenNotFound748 Error::<Test>::TokenNotFound798 );749 );799750875826876 // check balance (collection with id = 1, user id = 1)827 // check balance (collection with id = 1, user id = 1)877 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);828 assert_eq!(TemplateModule::balance_count(nft_collection_id, 1), 1);878 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 1000);829 assert_eq!(TemplateModule::balance_count(fungible_collection_id, 1), 5);879 assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 1000);830 assert_eq!(TemplateModule::balance_count(re_fungible_collection_id, 1), 1000);880 assert_eq!(TemplateModule::nft_item_id(nft_collection_id, 1).owner, 1);831 assert_eq!(TemplateModule::nft_item_id(nft_collection_id, 1).owner, 1);881 assert_eq!(TemplateModule::fungible_item_id(fungible_collection_id, 1).owner, 1);832 assert_eq!(TemplateModule::fungible_item_id(fungible_collection_id, 1).value, 5);882 assert_eq!(TemplateModule::refungible_item_id(re_fungible_collection_id, 1).owner[0].owner, 1);833 assert_eq!(TemplateModule::refungible_item_id(re_fungible_collection_id, 1).owner[0].owner, 1);883 });834 });884}835}896 let origin1 = Origin::signed(1);847 let origin1 = Origin::signed(1);897 848 898 // approve849 // approve899 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));850 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1));900 assert_eq!(TemplateModule::approved(1, (1, 1))[0].approved, 2);851 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);901 });852 });902}853}903854914 create_test_item(collection_id, &data.into());865 create_test_item(collection_id, &data.into());915866916 // approve867 // approve917 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1));868 assert_ok!(TemplateModule::approve(origin1.clone(), 2, 1, 1, 1));918 assert_eq!(TemplateModule::approved(1, (1, 1))[0].approved, 2);869 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);919870920 assert_ok!(TemplateModule::set_mint_permission(871 assert_ok!(TemplateModule::set_mint_permission(921 origin1.clone(),872 origin1.clone(),1199 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));1150 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 2));120011511201 // do approve1152 // do approve1202 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1));1153 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 1));1203 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);1154 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);120411551205 assert_ok!(TemplateModule::remove_from_white_list(1156 assert_ok!(TemplateModule::remove_from_white_list(1206 origin1.clone(),1157 origin1.clone(),1263 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));1214 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));126412151265 // do approve1216 // do approve1266 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1));1217 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 1));1267 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);1218 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 1);126812191269 assert_ok!(TemplateModule::remove_from_white_list(1220 assert_ok!(TemplateModule::remove_from_white_list(1270 origin1.clone(),1221 origin1.clone(),1298 AccessMode::WhiteList1249 AccessMode::WhiteList1299 ));1250 ));1300 assert_noop!(1251 assert_noop!(1301 TemplateModule::burn_item(origin1.clone(), 1, 1),1252 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1302 Error::<Test>::AddresNotInWhiteList1253 Error::<Test>::AddresNotInWhiteList1303 );1254 );1304 });1255 });132112721322 // do approve1273 // do approve1323 assert_noop!(1274 assert_noop!(1324 TemplateModule::approve(origin1.clone(), 1, 1, 1),1275 TemplateModule::approve(origin1.clone(), 1, 1, 1, 5),1325 Error::<Test>::AddresNotInWhiteList1276 Error::<Test>::AddresNotInWhiteList1326 );1277 );1327 });1278 });1374 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));1325 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, 2));137513261376 // do approve1327 // do approve1377 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1));1328 assert_ok!(TemplateModule::approve(origin1.clone(), 1, 1, 1, 5));1378 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 1);1329 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);137913301380 assert_ok!(TemplateModule::transfer_from(1331 assert_ok!(TemplateModule::transfer_from(1381 origin1.clone(),1332 origin1.clone(),tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -20,6 +20,7 @@
"load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",
"testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
"testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
+ "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
"testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
"testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
"testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
tests/src/burnItem.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/burnItem.test.ts
@@ -0,0 +1,237 @@
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import { Keyring } from "@polkadot/api";
+import { IKeyringPair } from "@polkadot/types/types";
+import {
+ createCollectionExpectSuccess,
+ createItemExpectSuccess,
+ getGenericResult,
+ destroyCollectionExpectSuccess
+} from './util/helpers';
+import { nullPublicKey } from "./accounts";
+
+import chai from 'chai';
+import chaiAsPromised from 'chai-as-promised';
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+
+describe('integration test: ext. burnItem():', () => {
+ before(async () => {
+ await usingApi(async (api) => {
+ const keyring = new Keyring({ type: 'sr25519' });
+ alice = keyring.addFromUri(`//Alice`);
+ bob = keyring.addFromUri(`//Bob`);
+ });
+ });
+
+ it('Burn item in NFT collection', async () => {
+ const createMode = 'NFT';
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode}});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const events = await submitTransactionAsync(alice, tx);
+ const result = getGenericResult(events);
+
+ // Get the item
+ const item: any = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON();
+
+ // What to expect
+ expect(result.success).to.be.true;
+ expect(item).to.be.not.null;
+ expect(item.Owner).to.be.equal(nullPublicKey);
+ });
+
+ });
+ it('Burn item in Fungible collection', async () => {
+ const createMode = 'Fungible';
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});
+ await createItemExpectSuccess(alice, collectionId, createMode); // Helper creates 10 fungible tokens
+ const tokenId = 0; // ignored
+
+ await usingApi(async (api) => {
+ // Destroy 1 of 10
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
+ const events = await submitTransactionAsync(alice, tx);
+ const result = getGenericResult(events);
+
+ // Get alice balance
+ const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();
+
+ // What to expect
+ expect(result.success).to.be.true;
+ expect(balance).to.be.not.null;
+ expect(balance.Value).to.be.equal(9);
+ });
+
+ });
+ it('Burn item in ReFungible collection', async () => {
+ const createMode = 'ReFungible';
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 1);
+ const events = await submitTransactionAsync(alice, tx);
+ const result = getGenericResult(events);
+
+ // Get alice balance
+ const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+
+ // What to expect
+ expect(result.success).to.be.true;
+ expect(balance).to.be.not.null;
+ expect(balance.Owner.length).to.be.equal(0);
+ });
+
+ });
+
+ it('Burn owned portion of item in ReFungible collection', async () => {
+ const createMode = 'ReFungible';
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 2 }});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+ await usingApi(async (api) => {
+ // Transfer 1/100 of the token to Bob
+ const transfertx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 1);
+ const events1 = await submitTransactionAsync(alice, transfertx);
+ const result1 = getGenericResult(events1);
+
+ // Get balances
+ const balanceBefore: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+
+ // Bob burns his portion
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const events2 = await submitTransactionAsync(bob, tx);
+ const result2 = getGenericResult(events2);
+
+ // Get balances
+ const balance: any = (await api.query.nft.reFungibleItemList(collectionId, tokenId)).toJSON();
+ // console.log(balance);
+
+ // What to expect before burning
+ expect(result1.success).to.be.true;
+ expect(balanceBefore).to.be.not.null;
+ expect(balanceBefore.Owner.length).to.be.equal(2);
+ expect(balanceBefore.Owner[0].Owner).to.be.equal(alice.address);
+ expect(balanceBefore.Owner[0].Fraction).to.be.equal(99);
+ expect(balanceBefore.Owner[1].Owner).to.be.equal(bob.address);
+ expect(balanceBefore.Owner[1].Fraction).to.be.equal(1);
+
+ // What to expect after burning
+ expect(result2.success).to.be.true;
+ expect(balance).to.be.not.null;
+ expect(balance.Owner.length).to.be.equal(1);
+ expect(balance.Owner[0].Fraction).to.be.equal(99);
+ expect(balance.Owner[0].Owner).to.be.equal(alice.address);
+ });
+
+ });
+
+});
+
+describe('Negative integration test: ext. burnItem():', () => {
+ before(async () => {
+ await usingApi(async (api) => {
+ const keyring = new Keyring({ type: 'sr25519' });
+ alice = keyring.addFromUri(`//Alice`);
+ bob = keyring.addFromUri(`//Bob`);
+ });
+ });
+
+ it('Burn a token in a destroyed collection', async () => {
+ const createMode = 'NFT';
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+ await destroyCollectionExpectSuccess(collectionId);
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const badTransaction = async function () {
+ await submitTransactionExpectFailAsync(alice, tx);
+ };
+ await expect(badTransaction()).to.be.rejected;
+ });
+
+ });
+
+ it('Burn a token that was never created', async () => {
+ const createMode = 'NFT';
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const tokenId = 10;
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const badTransaction = async function () {
+ await submitTransactionExpectFailAsync(alice, tx);
+ };
+ await expect(badTransaction()).to.be.rejected;
+ });
+
+ });
+
+ it('Burn a token using the address that does not own it', async () => {
+ const createMode = 'NFT';
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+ await usingApi(async (api) => {
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const badTransaction = async function () {
+ await submitTransactionExpectFailAsync(bob, tx);
+ };
+ await expect(badTransaction()).to.be.rejected;
+ });
+
+ });
+
+ it('Transfer a burned a token', async () => {
+ const createMode = 'NFT';
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode }});
+ const tokenId = await createItemExpectSuccess(alice, collectionId, createMode);
+
+ await usingApi(async (api) => {
+
+ const burntx = api.tx.nft.burnItem(collectionId, tokenId, 0);
+ const events1 = await submitTransactionAsync(alice, burntx);
+ const result1 = getGenericResult(events1);
+ expect(result1.success).to.be.true;
+
+ const tx = api.tx.nft.transfer(bob.address, collectionId, tokenId, 0);
+ const badTransaction = async function () {
+ await submitTransactionExpectFailAsync(alice, tx);
+ };
+ await expect(badTransaction()).to.be.rejected;
+ });
+
+ });
+
+ it('Burn more than owned in Fungible collection', async () => {
+ const createMode = 'Fungible';
+ const collectionId = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0 }});
+ // Helper creates 10 fungible tokens
+ await createItemExpectSuccess(alice, collectionId, createMode);
+ const tokenId = 0; // ignored
+
+ await usingApi(async (api) => {
+ // Destroy 11 of 10
+ const tx = api.tx.nft.burnItem(collectionId, tokenId, 11);
+ const badTransaction = async function () {
+ await submitTransactionExpectFailAsync(alice, tx);
+ };
+ await expect(badTransaction()).to.be.rejected;
+
+ // Get alice balance
+ const balance: any = (await api.query.nft.fungibleItemList(collectionId, alice.address)).toJSON();
+
+ // What to expect
+ expect(balance).to.be.not.null;
+ expect(balance.Value).to.be.equal(10);
+ });
+
+ });
+
+});
tests/src/confirmSponsorship.test.tsdiffbeforeafterboth--- a/tests/src/confirmSponsorship.test.ts
+++ b/tests/src/confirmSponsorship.test.ts
@@ -89,7 +89,7 @@
});
it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -115,7 +115,7 @@
});
it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -210,7 +210,7 @@
});
it('Fungible: Sponsoring is rate limited', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
@@ -247,7 +247,7 @@
});
it('ReFungible: Sponsoring is rate limited', async () => {
- const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
tests/src/createCollection.test.tsdiffbeforeafterboth--- a/tests/src/createCollection.test.ts
+++ b/tests/src/createCollection.test.ts
@@ -37,7 +37,9 @@
await usingApi(async (api) => {
const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString(), 10);
- const badTransaction = async () => await createCollectionExpectSuccess({mode: {type: 'Invalid'}});
+ const badTransaction = async () => {
+ await createCollectionExpectSuccess({mode: {type: 'Invalid'}});
+ };
// tslint:disable-next-line:no-unused-expression
expect(badTransaction()).to.be.rejected;
tests/src/createItem.test.tsdiffbeforeafterboth--- a/tests/src/createItem.test.ts
+++ b/tests/src/createItem.test.ts
@@ -18,17 +18,17 @@
it('Create new item in NFT collection', async () => {
const createMode = 'NFT';
- const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
+ const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
await createItemExpectSuccess(alice, newCollectionID, createMode);
});
it('Create new item in Fungible collection', async () => {
const createMode = 'Fungible';
- const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
+ const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
await createItemExpectSuccess(alice, newCollectionID, createMode);
});
it('Create new item in ReFungible collection', async () => {
const createMode = 'ReFungible';
- const newCollectionID = await createCollectionExpectSuccess({mode: createMode});
+ const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
await createItemExpectSuccess(alice, newCollectionID, createMode);
});
});
tests/src/destroyCollection.test.tsdiffbeforeafterboth--- a/tests/src/destroyCollection.test.ts
+++ b/tests/src/destroyCollection.test.ts
@@ -14,11 +14,11 @@
await destroyCollectionExpectSuccess(collectionId);
});
it('Fungible collection can be destroyed', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
await destroyCollectionExpectSuccess(collectionId);
});
it('ReFungible collection can be destroyed', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });
+ const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
await destroyCollectionExpectSuccess(collectionId);
});
});
tests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/removeCollectionAdmin.test.ts
@@ -0,0 +1,82 @@
+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';
+import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from './substrate/substrate-api';
+import {createCollectionExpectSuccess, destroyCollectionExpectSuccess} from './util/helpers';
+
+chai.use(chaiAsPromised);
+const expect = chai.expect;
+
+describe('Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
+ it('Remove collection admin.', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ const collectionId = await createCollectionExpectSuccess();
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+ const collection: any = (await api.query.nft.collection(collectionId));
+ expect(collection.Owner.toString()).to.be.eq(Alice.address);
+ // first - add collection admin Bob
+ const addAdminTx = api.tx.nft.addCollectionAdmin(collectionId, Bob.address);
+ await submitTransactionAsync(Alice, addAdminTx);
+
+ const adminListAfterAddAdmin: any = (await api.query.nft.adminList(collectionId));
+ expect(adminListAfterAddAdmin).to.be.contains(Bob.address);
+
+ // then remove bob from admins of collection
+ const removeAdminTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);
+ await submitTransactionAsync(Alice, removeAdminTx);
+
+ const adminListAfterRemoveAdmin: any = (await api.query.nft.adminList(collectionId));
+ expect(adminListAfterRemoveAdmin).not.to.be.contains(Bob.address);
+ });
+ });
+});
+
+describe('Negative Integration Test removeCollectionAdmin(collection_id, account_id):', () => {
+ it('Can\'t remove collection admin from not existing collection', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = (1 << 32) - 1;
+ const alice = privateKey('//Alice');
+ const bob = privateKey('//Bob');
+
+ const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, bob.address);
+ await expect(submitTransactionExpectFailAsync(alice, changeOwnerTx)).to.be.rejected;
+
+ // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
+ await createCollectionExpectSuccess();
+ });
+ });
+
+ it('Can\'t remove collection admin from deleted collection', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ // tslint:disable-next-line: no-bitwise
+ const collectionId = await createCollectionExpectSuccess();
+ const Alice = privateKey('//Alice');
+ const Bob = privateKey('//Bob');
+
+ await destroyCollectionExpectSuccess(collectionId);
+
+ const changeOwnerTx = api.tx.nft.removeCollectionAdmin(collectionId, Bob.address);
+ await expect(submitTransactionExpectFailAsync(Alice, changeOwnerTx)).to.be.rejected;
+
+ // Verifying that nothing bad happened (network is live, new collections can be created, etc.)
+ await createCollectionExpectSuccess();
+ });
+ });
+
+ it('Remove admin from collection that has no admins', async () => {
+ await usingApi(async (api: ApiPromise) => {
+ const Alice = privateKey('//Alice');
+ const collectionId = await createCollectionExpectSuccess();
+
+ const adminListBeforeAddAdmin: any = (await api.query.nft.adminList(collectionId));
+ expect(adminListBeforeAddAdmin).to.have.lengthOf(0);
+
+ const tx = api.tx.nft.removeCollectionAdmin(collectionId, Alice.address);
+ await expect(submitTransactionExpectFailAsync(Alice, tx)).to.be.rejected;
+ });
+ });
+});
tests/src/setCollectionLimits.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionLimits.test.ts
+++ b/tests/src/setCollectionLimits.test.ts
@@ -32,7 +32,7 @@
});
it('choose or create collection for testing', async () => {
await usingApi(async () => {
- collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});
+ collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
});
});
});
tests/src/setCollectionSponsor.test.tsdiffbeforeafterboth--- a/tests/src/setCollectionSponsor.test.ts
+++ b/tests/src/setCollectionSponsor.test.ts
@@ -30,11 +30,11 @@
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
it('Set Fungible collection sponsor', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });
+ const collectionId = await createCollectionExpectSuccess({ mode: {type: 'Fungible', decimalPoints: 0} });
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
it('Set ReFungible collection sponsor', async () => {
- const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });
+ const collectionId = await createCollectionExpectSuccess({ mode: {type: 'ReFungible', decimalPoints: 0} });
await setCollectionSponsorExpectSuccess(collectionId, bob.address);
});
tests/src/setSchemaVersion.test.tsdiffbeforeafterboth--- a/tests/src/setSchemaVersion.test.ts
+++ b/tests/src/setSchemaVersion.test.ts
@@ -35,7 +35,7 @@
});
it('choose or create collection for testing', async () => {
await usingApi(async () => {
- collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});
+ collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
});
});
});
@@ -93,12 +93,6 @@
const nonExistedCollectionId = collectionCount + 1;
tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
- /*try {
- await submitTransactionAsync(alice, tx);
- } catch (e) {
- // tslint:disable-next-line:no-unused-expression
- expect(e).to.be.exist;
- }*/
});
});
@@ -119,13 +113,6 @@
await destroyCollectionExpectSuccess(collectionIdForTesting);
tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
- /*try {
- tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
- await submitTransactionAsync(alice, tx);
- } catch (e) {
- // tslint:disable-next-line:no-unused-expression
- expect(e).to.be.exist;
- }*/
});
});
});
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -112,6 +112,20 @@
decimalPoints: number;
}
+interface Nft {
+ type: 'NFT'
+}
+
+interface Fungible {
+ type: 'Fungible',
+ decimalPoints: number
+}
+
+interface ReFungible {
+ type: 'ReFungible',
+ decimalPoints: number
+}
+
type CollectionMode = Nft | Fungible | ReFungible | Invalid;
export type CreateCollectionParams = {