git.delta.rocks / unique-network / refs/commits / 9ecb329aa0c0

difftreelog

Merge remote-tracking branch 'origin/develop' into feature/NFTPAR-241

kpozdnikin2021-01-18parents: #f4eeb2e #07025d8.patch.diff
in: master
# Conflicts:
#	tests/package.json

16 files changed

modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
1153 }1153 }
11541154
1155 // Reduce approval by transferred amount or remove if remaining approval drops to 01155 // Reduce approval by transferred amount or remove if remaining approval drops to 0
1156 if approval - value > 0 {1156 if approval.checked_sub(value).unwrap_or(0) > 0 {
1157 <Allowances<T>>::insert(collection_id, (item_id, &from, &recipient), approval - value);1157 <Allowances<T>>::insert(collection_id, (item_id, &from, &recipient), approval - value);
1158 }1158 }
1159 else {1159 else {
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
1// Tests to be written here1// Tests to be written here
2use 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}
2929
30fn default_fungible_data () -> CreateFungibleData {30fn default_fungible_data () -> CreateFungibleData {
31 CreateFungibleData { }31 CreateFungibleData { value: 5 }
32}32}
3333
34fn 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());
240240
241 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}
244244
245#[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();
249249
250 create_test_collection(&CollectionMode::Fungible(3), 1);250// create_test_collection(&CollectionMode::Fungible(3), 1);
251251
252 let origin1 = Origin::signed(1);252// let origin1 = Origin::signed(1);
253253
254 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()];
255255
256 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// }
270270
271#[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());
283283
284 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]);
287286
288 // change owner scenario287 // change owner scenario
289 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]);
296292
297 // split item scenario293 // split item scenario
298 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]);
305297
306 // split item and new owner has account scenario298 // split item and new owner has account scenario
307 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}
316306
451 1), Error::<Test>::NoPermission);441 1), Error::<Test>::NoPermission);
452442
453 // do approve443 // do approve
454 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 5
459 approved: 2,
460 amount: 100000000
461 }
462 );449 );
463450
464 assert_ok!(TemplateModule::transfer_from(451 assert_ok!(TemplateModule::transfer_from(
469 1,456 1,
470 1457 1
471 ));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}
475462
505 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));492 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));
506493
507 // do approve494 // do approve
508 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: 100000000
517 }
518 );
519499
520 assert_ok!(TemplateModule::transfer_from(500 assert_ok!(TemplateModule::transfer_from(
521 origin2.clone(),501 origin2.clone(),
525 1,505 1,
526 1506 1
527 ));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}
531511
560 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));540 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, 3));
561541
562 // do approve542 // do approve
563 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: 100000000
572 }
573 );
574547
575 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]);
587560
588 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 900
591 ApprovePermissions {564 );
592 approved: 3,
593 amount: 100000000
594 }
595 );
596 });565 });
597}566}
598567
609 let origin1 = Origin::signed(1);578 let origin1 = Origin::signed(1);
610 let origin2 = Origin::signed(2);579 let origin2 = Origin::signed(2);
611580
612 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]);
614582
615 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));
628596
629 // do approve597 // do approve
630 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 5
637 approved: 2,
638 amount: 100000000
639 }
640 );605 );
641606
642 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 4
649 ));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]);
654617
655 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: 100000000
661 }
662 );
663620
664 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 4
672 ));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]);
677
678 assert_eq!(TemplateModule::approved(1, (1, 1)).len(), 0);
679 });630 });
680}631}
681632
725 assert_eq!(TemplateModule::balance_count(1, 1), 1);676 assert_eq!(TemplateModule::balance_count(1, 1), 1);
726677
727 // burn item678 // burn item
728 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>::TokenNotFound
732 );683 );
733684
749 create_test_item(collection_id, &data.into());700 create_test_item(collection_id, &data.into());
750701
751 // 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);
753704
754 // burn item705 // burn item
755 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>::TokenNotFound
759 );710 );
760711
791 assert_eq!(TemplateModule::balance_count(1, 1), 1000);742 assert_eq!(TemplateModule::balance_count(1, 1), 1000);
792743
793 // burn item744 // burn item
794 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>::TokenNotFound
798 );749 );
799750
875826
876 // 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 // approve
899 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}
903854
914 create_test_item(collection_id, &data.into());865 create_test_item(collection_id, &data.into());
915866
916 // approve867 // approve
917 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);
919870
920 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));
12001151
1201 // do approve1152 // do approve
1202 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);
12041155
1205 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));
12641215
1265 // do approve1216 // do approve
1266 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);
12681219
1269 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::WhiteList
1299 ));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>::AddresNotInWhiteList
1303 );1254 );
1304 });1255 });
13211272
1322 // do approve1273 // do approve
1323 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>::AddresNotInWhiteList
1326 );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));
13751326
1376 // do approve1327 // do approve
1377 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);
13791330
1380 assert_ok!(TemplateModule::transfer_from(1331 assert_ok!(TemplateModule::transfer_from(
1381 origin1.clone(),1332 origin1.clone(),
modifiedtests/package.jsondiffbeforeafterboth
20 "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",20 "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",
21 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",21 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",
22 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",22 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",
23 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",
23 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",24 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",
24 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",25 "testCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",
25 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts"26 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",
27 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",
28 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",
29 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts"
26 },30 },
27 "author": "",31 "author": "",
28 "license": "Apache 2.0",32 "license": "Apache 2.0",
addedtests/src/approve.test.tsdiffbeforeafterboth

no changes

addedtests/src/burnItem.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/confirmSponsorship.test.tsdiffbeforeafterboth
89 });89 });
9090
91 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {91 it('Fungible: Transfer fees are paid by the sponsor after confirmation', async () => {
92 const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});92 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
93 await setCollectionSponsorExpectSuccess(collectionId, bob.address);93 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
94 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');94 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
9595
115 });115 });
116116
117 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {117 it('ReFungible: Transfer fees are paid by the sponsor after confirmation', async () => {
118 const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});118 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});
119 await setCollectionSponsorExpectSuccess(collectionId, bob.address);119 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');120 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
121121
210 });210 });
211211
212 it('Fungible: Sponsoring is rate limited', async () => {212 it('Fungible: Sponsoring is rate limited', async () => {
213 const collectionId = await createCollectionExpectSuccess({mode: 'Fungible'});213 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0 }});
214 await setCollectionSponsorExpectSuccess(collectionId, bob.address);214 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
215 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');215 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
216216
247 });247 });
248248
249 it('ReFungible: Sponsoring is rate limited', async () => {249 it('ReFungible: Sponsoring is rate limited', async () => {
250 const collectionId = await createCollectionExpectSuccess({mode: 'ReFungible'});250 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0 }});
251 await setCollectionSponsorExpectSuccess(collectionId, bob.address);251 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
252 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');252 await confirmSponsorshipExpectSuccess(collectionId, '//Bob');
253253
modifiedtests/src/createCollection.test.tsdiffbeforeafterboth
5 5
6import chai from 'chai'; 6import chai from 'chai';
7import chaiAsPromised from 'chai-as-promised'; 7import chaiAsPromised from 'chai-as-promised';
8import { default as usingApi } from "./substrate/substrate-api"; 8import { default as usingApi } from './substrate/substrate-api';
9import { createCollectionExpectSuccess, createCollectionExpectFailure, CollectionMode } from "./util/helpers"; 9import { createCollectionExpectFailure, createCollectionExpectSuccess } from './util/helpers';
10 10
11chai.use(chaiAsPromised); 11chai.use(chaiAsPromised);
12const expect = chai.expect; 12const expect = chai.expect;
13 13
14describe('integration test: ext. createCollection():', () => { 14describe('integration test: ext. createCollection():', () => {
15 it('Create new NFT collection', async () => { 15 it('Create new NFT collection', async () => {
16 await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'}); 16 await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
17 }); 17 });
18 it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => { 18 it('Create new NFT collection whith collection_name of maximum length (64 bytes)', async () => {
19 await createCollectionExpectSuccess({name: 'A'.repeat(64)}); 19 await createCollectionExpectSuccess({name: 'A'.repeat(64)});
25 await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)}); 25 await createCollectionExpectSuccess({tokenPrefix: 'A'.repeat(16)});
26 }); 26 });
27 it('Create new Fungible collection', async () => { 27 it('Create new Fungible collection', async () => {
28 await createCollectionExpectSuccess({mode: 'Fungible'}); 28 await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
29 }); 29 });
30 it('Create new ReFungible collection', async () => { 30 it('Create new ReFungible collection', async () => {
31 await createCollectionExpectSuccess({mode: 'ReFungible'}); 31 await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
32 }); 32 });
33}); 33});
34 34
35describe('(!negative test!) integration test: ext. createCollection():', () => { 35describe('(!negative test!) integration test: ext. createCollection():', () => {
36 it('(!negative test!) create new NFT collection whith incorrect data (mode)', async () => { 36 it('(!negative test!) create new NFT collection whith incorrect data (mode)', async () => {
37 await usingApi(async (api) => { 37 await usingApi(async (api) => {
38 const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString()); 38 const AcollectionCount = parseInt((await api.query.nft.collectionCount()).toString(), 10);
39 39
40 const badTransaction = async function () { 40 const badTransaction = async () => {
41 await createCollectionExpectSuccess({mode: 'BadMode' as CollectionMode}); 41 await createCollectionExpectSuccess({mode: {type: 'Invalid'}});
42 }; 42 };
43 // tslint:disable-next-line:no-unused-expression
43 expect(badTransaction()).to.be.rejected; 44 expect(badTransaction()).to.be.rejected;
44 45
45 const BcollectionCount = parseInt((await api.query.nft.collectionCount()).toString()); 46 const BcollectionCount = parseInt((await api.query.nft.collectionCount()).toString(), 10);
46 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Incorrect collection created.'); 47 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Incorrect collection created.');
47 }); 48 });
48 }); 49 });
49 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => { 50 it('(!negative test!) create new NFT collection whith incorrect data (collection_name)', async () => {
50 await createCollectionExpectFailure({name: 'A'.repeat(65)}); 51 await createCollectionExpectFailure({ name: 'A'.repeat(65), mode: {type: 'NFT'}});
51 }); 52 });
52 it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => { 53 it('(!negative test!) create new NFT collection whith incorrect data (collection_description)', async () => {
53 await createCollectionExpectFailure({description: 'A'.repeat(257)}); 54 await createCollectionExpectFailure({ description: 'A'.repeat(257), mode: { type: 'NFT' }});
54 }); 55 });
55 it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => { 56 it('(!negative test!) create new NFT collection whith incorrect data (token_prefix)', async () => {
56 await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17)}); 57 await createCollectionExpectFailure({tokenPrefix: 'A'.repeat(17), mode: {type: 'NFT'}});
57 }); 58 });
58}); 59});
5960
modifiedtests/src/createItem.test.tsdiffbeforeafterboth
18 18
19 it('Create new item in NFT collection', async () => { 19 it('Create new item in NFT collection', async () => {
20 const createMode = 'NFT'; 20 const createMode = 'NFT';
21 const newCollectionID = await createCollectionExpectSuccess({mode: createMode}); 21 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode}});
22 await createItemExpectSuccess(alice, newCollectionID, createMode); 22 await createItemExpectSuccess(alice, newCollectionID, createMode);
23 }); 23 });
24 it('Create new item in Fungible collection', async () => { 24 it('Create new item in Fungible collection', async () => {
25 const createMode = 'Fungible'; 25 const createMode = 'Fungible';
26 const newCollectionID = await createCollectionExpectSuccess({mode: createMode}); 26 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
27 await createItemExpectSuccess(alice, newCollectionID, createMode); 27 await createItemExpectSuccess(alice, newCollectionID, createMode);
28 }); 28 });
29 it('Create new item in ReFungible collection', async () => { 29 it('Create new item in ReFungible collection', async () => {
30 const createMode = 'ReFungible'; 30 const createMode = 'ReFungible';
31 const newCollectionID = await createCollectionExpectSuccess({mode: createMode}); 31 const newCollectionID = await createCollectionExpectSuccess({mode: {type: createMode, decimalPoints: 0}});
32 await createItemExpectSuccess(alice, newCollectionID, createMode); 32 await createItemExpectSuccess(alice, newCollectionID, createMode);
33 }); 33 });
34}); 34});
modifiedtests/src/destroyCollection.test.tsdiffbeforeafterboth
14 await destroyCollectionExpectSuccess(collectionId);14 await destroyCollectionExpectSuccess(collectionId);
15 });15 });
16 it('Fungible collection can be destroyed', async () => {16 it('Fungible collection can be destroyed', async () => {
17 const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });17 const collectionId = await createCollectionExpectSuccess({mode: {type: 'Fungible', decimalPoints: 0}});
18 await destroyCollectionExpectSuccess(collectionId);18 await destroyCollectionExpectSuccess(collectionId);
19 });19 });
20 it('ReFungible collection can be destroyed', async () => {20 it('ReFungible collection can be destroyed', async () => {
21 const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });21 const collectionId = await createCollectionExpectSuccess({mode: {type: 'ReFungible', decimalPoints: 0}});
22 await destroyCollectionExpectSuccess(collectionId);22 await destroyCollectionExpectSuccess(collectionId);
23 });23 });
24});24});
addedtests/src/removeCollectionAdmin.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/setCollectionLimits.test.tsdiffbeforeafterboth
32 });32 });
33 it('choose or create collection for testing', async () => {33 it('choose or create collection for testing', async () => {
34 await usingApi(async () => {34 await usingApi(async () => {
35 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});35 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
36 });36 });
37 });37 });
38});38});
modifiedtests/src/setCollectionSponsor.test.tsdiffbeforeafterboth
30 await setCollectionSponsorExpectSuccess(collectionId, bob.address);30 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
31 });31 });
32 it('Set Fungible collection sponsor', async () => {32 it('Set Fungible collection sponsor', async () => {
33 const collectionId = await createCollectionExpectSuccess({ mode: 'Fungible' });33 const collectionId = await createCollectionExpectSuccess({ mode: {type: 'Fungible', decimalPoints: 0} });
34 await setCollectionSponsorExpectSuccess(collectionId, bob.address);34 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
35 });35 });
36 it('Set ReFungible collection sponsor', async () => {36 it('Set ReFungible collection sponsor', async () => {
37 const collectionId = await createCollectionExpectSuccess({ mode: 'ReFungible' });37 const collectionId = await createCollectionExpectSuccess({ mode: {type: 'ReFungible', decimalPoints: 0} });
38 await setCollectionSponsorExpectSuccess(collectionId, bob.address);38 await setCollectionSponsorExpectSuccess(collectionId, bob.address);
39 });39 });
4040
modifiedtests/src/setSchemaVersion.test.tsdiffbeforeafterboth
35 });35 });
36 it('choose or create collection for testing', async () => {36 it('choose or create collection for testing', async () => {
37 await usingApi(async () => {37 await usingApi(async () => {
38 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: 'NFT'});38 collectionIdForTesting = await createCollectionExpectSuccess({name: 'A', description: 'B', tokenPrefix: 'C', mode: {type: 'NFT'}});
39 });39 });
40 });40 });
41});41});
93 const nonExistedCollectionId = collectionCount + 1;93 const nonExistedCollectionId = collectionCount + 1;
94 tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');94 tx = api.tx.nft.setSchemaVersion(nonExistedCollectionId, 'ImageURL');
95 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;95 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
96 /*try {
97 await submitTransactionAsync(alice, tx);
98 } catch (e) {
99 // tslint:disable-next-line:no-unused-expression
100 expect(e).to.be.exist;
101 }*/
102 });96 });
103 });97 });
10498
119 await destroyCollectionExpectSuccess(collectionIdForTesting);113 await destroyCollectionExpectSuccess(collectionIdForTesting);
120 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');114 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
121 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;115 await expect(submitTransactionExpectFailAsync(alice, tx)).to.be.rejected;
122 /*try {
123 tx = api.tx.nft.setSchemaVersion(collectionIdForTesting, 'ImageURL');
124 await submitTransactionAsync(alice, tx);
125 } catch (e) {
126 // tslint:disable-next-line:no-unused-expression
127 expect(e).to.be.exist;
128 }*/
129 });116 });
130 });117 });
131});118});
modifiedtests/src/substrate/substrate-api.tsdiffbeforeafterboth
104 await transaction.signAndSend(sender, ({ events = [], status }) => {103 await transaction.signAndSend(sender, ({ events = [], status }) => {
105 const transactionStatus = getTransactionStatus(events, status);104 const transactionStatus = getTransactionStatus(events, status);
105
106 console.log('transactionStatus', transactionStatus, 'events', events);
106107
107 if (transactionStatus == TransactionStatus.Success) {108 if (transactionStatus == TransactionStatus.Success) {
108 resolve(events);109 resolve(events);
addedtests/src/transferFrom.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/util/helpers.tsdiffbeforeafterboth
3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.
4//4//
55
6import chai from 'chai';6import { ApiPromise, Keyring } from '@polkadot/api';
7import chaiAsPromised from 'chai-as-promised';7import { Enum, Struct } from '@polkadot/types/codec';
8import type { AccountId, EventRecord } from '@polkadot/types/interfaces';8import type { AccountId, EventRecord } from '@polkadot/types/interfaces';
9import { ApiPromise, Keyring } from "@polkadot/api";9import { u128 } from '@polkadot/types/primitive';
10import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from "../substrate/substrate-api";10import { IKeyringPair } from '@polkadot/types/types';
11import privateKey from '../substrate/privateKey';11import { BigNumber } from 'bignumber.js';
12import { alicesPublicKey, nullPublicKey } from "../accounts";12import BN from 'bn.js';
13import { strToUTF16, utf16ToStr, hexToStr } from './util';13import chai from 'chai';
14import { IKeyringPair } from '@polkadot/types/types';14import chaiAsPromised from 'chai-as-promised';
15import { BigNumber } from 'bignumber.js';15import { alicesPublicKey, nullPublicKey } from '../accounts';
16import { Struct, Enum } from '@polkadot/types/codec';16import privateKey from '../substrate/privateKey';
17import { u128 } from '@polkadot/types/primitive';17import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
18import { ICollectionInterface } from '../types';18import { ICollectionInterface } from '../types';
19import BN from "bn.js";19import { hexToStr, strToUTF16, utf16ToStr } from './util';
2020
21chai.use(chaiAsPromised);21chai.use(chaiAsPromised);
22const expect = chai.expect;22const expect = chai.expect;
25 success: boolean,25 success: boolean,
26};26};
2727
28type CreateCollectionResult = {28interface CreateCollectionResult {
29 success: boolean,29 success: boolean;
30 collectionId: number30 collectionId: number;
31};31}
3232
33type CreateItemResult = {33interface CreateItemResult {
34 success: boolean,34 success: boolean;
35 collectionId: number,35 collectionId: number;
36 itemId: number36 itemId: number;
37};37}
38
39interface IReFungibleOwner {
40 Fraction: BN;
41 Owner: number[];
42}
43
44interface ITokenDataType {
45 Owner: number[];
46 ConstData: number[];
47 VariableData: number[];
48}
49
50interface IFungibleTokenDataType {
51 Value: BN;
52}
53
54interface IReFungibleTokenDataType {
55 Owner: IReFungibleOwner[];
56 ConstData: number[];
57 VariableData: number[];
58}
3859
39export function getGenericResult(events: EventRecord[]): GenericResult {60export function getGenericResult(events: EventRecord[]): GenericResult {
40 let result: GenericResult = {61 const result: GenericResult = {
41 success: false62 success: false,
42 }63 };
43 events.forEach(({ phase, event: { data, method, section } }) => {64 events.forEach(({ phase, event: { data, method, section } }) => {
44 // console.log(` ${phase}: ${section}.${method}:: ${data}`);65 // console.log(` ${phase}: ${section}.${method}:: ${data}`);
45 if (method == 'ExtrinsicSuccess') {66 if (method === 'ExtrinsicSuccess') {
46 result.success = true;67 result.success = true;
47 }68 }
48 });69 });
60 collectionId = parseInt(data[0].toString());81 collectionId = parseInt(data[0].toString());
61 }82 }
62 });83 });
63 let result: CreateCollectionResult = {84 const result: CreateCollectionResult = {
64 success,85 success,
65 collectionId86 collectionId,
66 }87 };
67 return result;88 return result;
68}89}
6990
80 itemId = parseInt(data[1].toString());101 itemId = parseInt(data[1].toString());
81 }102 }
82 });103 });
83 let result: CreateItemResult = {104 const result: CreateItemResult = {
84 success,105 success,
85 collectionId,106 collectionId,
86 itemId107 itemId,
87 }108 };
88 return result;109 return result;
89}110}
111
112interface Invalid {
113 type: 'Invalid';
114}
115
116interface Nft {
117 type: 'NFT';
118}
119
120interface Fungible {
121 type: 'Fungible';
122 decimalPoints: number;
123}
124
125interface ReFungible {
126 type: 'ReFungible';
127 decimalPoints: number;
128}
129
130interface Nft {
131 type: 'NFT'
132}
133
134interface Fungible {
135 type: 'Fungible',
136 decimalPoints: number
137}
138
139interface ReFungible {
140 type: 'ReFungible',
141 decimalPoints: number
142}
90143
91export type CollectionMode = 'NFT' | 'Fungible' | 'ReFungible';144type CollectionMode = Nft | Fungible | ReFungible | Invalid;
145
92export type CreateCollectionParams = {146export type CreateCollectionParams = {
93 mode: CollectionMode,147 mode: CollectionMode,
94 name: string,148 name: string,
95 description: string,149 description: string,
96 tokenPrefix: string150 tokenPrefix: string,
97};151};
98152
99const defaultCreateCollectionParams: CreateCollectionParams = {153const defaultCreateCollectionParams: CreateCollectionParams = {
100 name: 'name',
101 description: 'description',154 description: 'description',
102 mode: 'NFT',155 mode: { type: 'NFT' },
156 name: 'name',
103 tokenPrefix: 'prefix'157 tokenPrefix: 'prefix',
104}158}
105159
106export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {160export async function createCollectionExpectSuccess(params: Partial<CreateCollectionParams> = {}): Promise<number> {
109 let collectionId: number = 0;163 let collectionId: number = 0;
110 await usingApi(async (api) => {164 await usingApi(async (api) => {
111 // Get number of collections before the transaction165 // Get number of collections before the transaction
112 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());166 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);
113167
114 // Run the CreateCollection transaction168 // Run the CreateCollection transaction
115 const alicePrivateKey = privateKey('//Alice');169 const alicePrivateKey = privateKey('//Alice');
170
171 let modeprm = {};
172 if (mode.type === 'NFT') {
173 modeprm = {nft: null};
174 } else if (mode.type === 'Fungible') {
175 modeprm = {fungible: mode.decimalPoints};
176 } else if (mode.type === 'ReFungible') {
177 modeprm = {refungible: mode.decimalPoints};
178 } else if (mode.type === 'Invalid') {
179 modeprm = {invalid: null};
180 }
181
116 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), mode);182 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);
117 const events = await submitTransactionAsync(alicePrivateKey, tx);183 const events = await submitTransactionAsync(alicePrivateKey, tx);
118 const result = getCreateCollectionResult(events);184 const result = getCreateCollectionResult(events);
119185
120 // Get number of collections after the transaction186 // Get number of collections after the transaction
121 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());187 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString(), 10);
122188
123 // Get the collection 189 // Get the collection
124 const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();190 const collection: any = (await api.query.nft.collection(result.collectionId)).toJSON();
125191
126 // What to expect192 // What to expect
193 // tslint:disable-next-line:no-unused-expression
127 expect(result.success).to.be.true;194 expect(result.success).to.be.true;
128 expect(result.collectionId).to.be.equal(BcollectionCount);195 expect(result.collectionId).to.be.equal(BcollectionCount);
196 // tslint:disable-next-line:no-unused-expression
129 expect(collection).to.be.not.null;197 expect(collection).to.be.not.null;
130 expect(BcollectionCount).to.be.equal(AcollectionCount+1, 'Error: NFT collection NOT created.');198 expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');
131 expect(collection.Owner).to.be.equal(alicesPublicKey);199 expect(collection.Owner).to.be.equal(alicesPublicKey);
142export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {210export async function createCollectionExpectFailure(params: Partial<CreateCollectionParams> = {}) {
143 const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};211 const {name, description, mode, tokenPrefix } = {...defaultCreateCollectionParams, ...params};
212
213 let modeprm = {};
214 if (mode.type === 'NFT') {
215 modeprm = {nft: null};
216 } else if (mode.type === 'Fungible') {
217 modeprm = {fungible: mode.decimalPoints};
218 } else if (mode.type === 'ReFungible') {
219 modeprm = {refungible: mode.decimalPoints};
220 } else if (mode.type === 'Invalid') {
221 modeprm = {invalid: null};
222 }
144223
145 await usingApi(async (api) => {224 await usingApi(async (api) => {
146 // Get number of collections before the transaction225 // Get number of collections before the transaction
147 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());226 const AcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());
148227
149 // Run the CreateCollection transaction228 // Run the CreateCollection transaction
150 const alicePrivateKey = privateKey('//Alice');229 const alicePrivateKey = privateKey('//Alice');
151 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), mode);230 const tx = api.tx.nft.createCollection(strToUTF16(name), strToUTF16(description), strToUTF16(tokenPrefix), modeprm);
152 const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;231 const events = await expect(submitTransactionExpectFailAsync(alicePrivateKey, tx)).to.be.rejected;
153 const result = getCreateCollectionResult(events);232 const result = getCreateCollectionResult(events);
154233
155 // Get number of collections after the transaction234 // Get number of collections after the transaction
156 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());235 const BcollectionCount = parseInt((await api.query.nft.createdCollectionCount()).toString());
157236
158 // What to expect237 // What to expect
238 // tslint:disable-next-line:no-unused-expression
159 expect(result.success).to.be.false;239 expect(result.success).to.be.false;
160 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');240 expect(BcollectionCount).to.be.equal(AcollectionCount, 'Error: Collection with incorrect data created.');
161 });241 });
201 const events = await submitTransactionAsync(alicePrivateKey, tx);281 const events = await submitTransactionAsync(alicePrivateKey, tx);
202 const result = getDestroyResult(events);282 const result = getDestroyResult(events);
203283
204 // Get the collection 284 // Get the collection
205 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();285 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
206286
207 // What to expect287 // What to expect
220 const events = await submitTransactionAsync(alicePrivateKey, tx);300 const events = await submitTransactionAsync(alicePrivateKey, tx);
221 const result = getGenericResult(events);301 const result = getGenericResult(events);
222302
223 // Get the collection 303 // Get the collection
224 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();304 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
225305
226 // What to expect306 // What to expect
239 const events = await submitTransactionAsync(alicePrivateKey, tx);319 const events = await submitTransactionAsync(alicePrivateKey, tx);
240 const result = getGenericResult(events);320 const result = getGenericResult(events);
241321
242 // Get the collection 322 // Get the collection
243 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();323 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
244324
245 // What to expect325 // What to expect
278 const events = await submitTransactionAsync(sender, tx);358 const events = await submitTransactionAsync(sender, tx);
279 const result = getGenericResult(events);359 const result = getGenericResult(events);
280360
281 // Get the collection 361 // Get the collection
282 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();362 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
283363
284 // What to expect364 // What to expect
300380
301export interface CreateFungibleData extends Struct {381export interface CreateFungibleData extends Struct {
302 readonly value: u128;382 readonly value: u128;
303};383}
304384
305export interface CreateReFungibleData extends Struct {};385export interface CreateReFungibleData extends Struct {}
306export interface CreateNftData extends Struct {};386export interface CreateNftData extends Struct {}
307387
308export interface CreateItemData extends Enum {388export interface CreateItemData extends Enum {
309 NFT: CreateNftData,389 NFT: CreateNftData;
310 Fungible: CreateFungibleData,390 Fungible: CreateFungibleData;
311 ReFungible: CreateReFungibleData391 ReFungible: CreateReFungibleData;
312};392}
393
394export async function
395approveExpectSuccess(collectionId: number,
396 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {
397 await usingApi(async (api: ApiPromise) => {
398 const allowanceBefore =
399 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;
400 const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);
401 const events = await submitTransactionAsync(owner, approveNftTx);
402 const result = getCreateItemResult(events);
403 // tslint:disable-next-line:no-unused-expression
404 expect(result.success).to.be.true;
405 const allowanceAfter =
406 await api.query.nft.allowances(collectionId, [tokenId, owner.address, approved.address]) as unknown as BN;
407 expect(allowanceAfter.toNumber() - allowanceBefore.toNumber()).to.be.equal(amount);
408 });
409}
410
411export async function
412transferFromExpectSuccess(collectionId: number,
413 tokenId: number,
414 accountApproved: IKeyringPair,
415 accountFrom: IKeyringPair,
416 accountTo: IKeyringPair,
417 value: number = 1,
418 type: string = 'NFT') {
419 await usingApi(async (api: ApiPromise) => {
420 let balanceBefore = new BN(0);
421 if (type === 'Fungible') {
422 balanceBefore = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;
423 }
424 const transferFromTx = await api.tx.nft.transferFrom(
425 accountFrom.address, accountTo.address, collectionId, tokenId, value);
426 const events = await submitTransactionAsync(accountFrom, transferFromTx);
427 const result = getCreateItemResult(events);
428 // tslint:disable-next-line:no-unused-expression
429 expect(result.success).to.be.true;
430 if (type === 'NFT') {
431 const nftItemData = await api.query.nft.nftItemList(collectionId, tokenId) as unknown as ITokenDataType;
432 expect(nftItemData.Owner.toString()).to.be.equal(accountTo.address);
433 }
434 if (type === 'Fungible') {
435 const balanceAfter = await api.query.nft.balance(collectionId, accountTo.address) as unknown as BN;
436 expect(balanceAfter.sub(balanceBefore).toNumber()).to.be.equal(value);
437 }
438 if (type === 'ReFungible') {
439 const nftItemData =
440 await api.query.nft.reFungibleItemList(collectionId, tokenId) as unknown as IReFungibleTokenDataType;
441 expect(nftItemData.Owner[0].Owner.toString()).to.be.equal(accountTo.address);
442 expect(nftItemData.Owner[0].Fraction.toNumber()).to.be.equal(value);
443 }
444 });
445}
446
447export async function
448transferFromExpectFail(collectionId: number,
449 tokenId: number,
450 accountApproved: IKeyringPair,
451 accountFrom: IKeyringPair,
452 accountTo: IKeyringPair,
453 value: number = 1) {
454 await usingApi(async (api: ApiPromise) => {
455 const transferFromTx = await api.tx.nft.transferFrom(
456 accountFrom.address, accountTo.address, collectionId, tokenId, value);
457 const events = await expect(submitTransactionExpectFailAsync(accountApproved, transferFromTx)).to.be.rejected;
458 const result = getCreateCollectionResult(events);
459 // tslint:disable-next-line:no-unused-expression
460 expect(result.success).to.be.false;
461 });
462}
463
464export async function
465approveExpectFail(collectionId: number,
466 tokenId: number, owner: IKeyringPair, approved: IKeyringPair, amount: number = 1) {
467 await usingApi(async (api: ApiPromise) => {
468 const approveNftTx = await api.tx.nft.approve(approved.address, collectionId, tokenId, amount);
469 const events = await expect(submitTransactionExpectFailAsync(owner, approveNftTx)).to.be.rejected;
470 const result = getCreateCollectionResult(events);
471 // tslint:disable-next-line:no-unused-expression
472 expect(result.success).to.be.false;
473 });
474}
313475
314export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {476export async function createItemExpectSuccess(sender: IKeyringPair, collectionId: number, createMode: string, owner: string = '') {
315 let newItemId: number = 0;477 let newItemId: number = 0;
316 await usingApi(async (api) => {478 await usingApi(async (api) => {
317 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());479 const AItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);
318 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON(); 480 const Aitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();
319 const AItemBalance = new BigNumber(Aitem.Value);481 const AItemBalance = new BigNumber(Aitem.Value);
320482
321 if (owner === '') owner = sender.address;483 if (owner === '') {
484 owner = sender.address;
485 }
322486
323 let tx;487 let tx;
324 if (createMode == 'Fungible') {488 if (createMode === 'Fungible') {
325 let createData = {fungible: {value: 10}};489 const createData = {fungible: {value: 10}};
326 tx = api.tx.nft.createItem(collectionId, owner, createData);490 tx = api.tx.nft.createItem(collectionId, owner, createData);
327 }491 } else {
328 else {
329 tx = api.tx.nft.createItem(collectionId, owner, createMode);492 tx = api.tx.nft.createItem(collectionId, owner, createMode);
330 }493 }
331 const events = await submitTransactionAsync(sender, tx);494 const events = await submitTransactionAsync(sender, tx);
332 const result = getCreateItemResult(events);495 const result = getCreateItemResult(events);
333496
334 const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString());497 const BItemCount = parseInt((await api.query.nft.itemListIndex(collectionId)).toString(), 10);
335 const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON(); 498 const Bitem: any = (await api.query.nft.fungibleItemList(collectionId, owner)).toJSON();
336 const BItemBalance = new BigNumber(Bitem.Value);499 const BItemBalance = new BigNumber(Bitem.Value);
337500
338 // What to expect501 // What to expect
502 // tslint:disable-next-line:no-unused-expression
339 expect(result.success).to.be.true;503 expect(result.success).to.be.true;
340 if (createMode == 'Fungible') {504 if (createMode === 'Fungible') {
341 expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);505 expect(BItemBalance.minus(AItemBalance).toNumber()).to.be.equal(10);
342 }506 } else {
343 else {
358 const events = await submitTransactionAsync(sender, tx);521 const events = await submitTransactionAsync(sender, tx);
359 const result = getGenericResult(events);522 const result = getGenericResult(events);
360523
361 // Get the collection 524 // Get the collection
362 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();525 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
363526
364 // What to expect527 // What to expect
375 const events = await submitTransactionAsync(sender, tx);538 const events = await submitTransactionAsync(sender, tx);
376 const result = getGenericResult(events);539 const result = getGenericResult(events);
377540
378 // Get the collection 541 // Get the collection
379 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();542 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
380543
381 // What to expect544 // What to expect
392 const events = await submitTransactionAsync(sender, tx);555 const events = await submitTransactionAsync(sender, tx);
393 const result = getGenericResult(events);556 const result = getGenericResult(events);
394557
395 // Get the collection 558 // Get the collection
396 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();559 const collection: any = (await api.query.nft.collection(collectionId)).toJSON();
397560
398 // What to expect561 // What to expect