@@ -3,16 +3,15 @@ use core::convert::TryFrom;
33use codec:: { Encode } ;
44
55use frame_support:: { assert_noop, assert_ok, BoundedVec } ;
6- use sp_runtime:: Permill ;
76
87pub struct ExtBuilder ;
98
109// helper function to set BoundedVec
11- macro_rules! bvec {
12- ( $( $x: tt ) * ) => {
13- vec![ $( $x ) * ] . try_into( ) . unwrap( )
14- }
15- }
10+ // macro_rules! bvec {
11+ // ($( $x:tt )*) => {
12+ // vec![$( $x )*].try_into().unwrap()
13+ // }
14+ // }
1615
1716impl Default for ExtBuilder {
1817 fn default ( ) -> Self {
@@ -46,10 +45,11 @@ fn dummy_attributes() -> Vec<(BoundedVec<u8, KeyLimit>, BoundedVec<u8, ValueLimi
4645 ) ]
4746}
4847
49- fn dummy_value ( ) -> Permill {
50- Permill :: from_percent ( 50 )
48+ fn dummy_empty_attributes ( ) -> Vec < ( BoundedVec < u8 , KeyLimit > , BoundedVec < u8 , ValueLimit > ) > {
49+ vec ! [ ]
5150}
5251
52+
5353#[ test]
5454fn create_collection_works ( ) {
5555 ExtBuilder :: default ( ) . build ( ) . execute_with ( || {
@@ -63,98 +63,38 @@ fn spawn_extrinsic_works() {
6363 // A collection must be created before spawning an NFT
6464 assert_noop ! ( Fruniques :: spawn( Origin :: signed( 1 ) , 0 , None , None ) , Error :: <Test >:: CollectionNotFound ) ;
6565
66+ // Create a collection
6667 assert_ok ! ( Fruniques :: create_collection( Origin :: signed( 1 ) , Some ( dummy_description( ) ) ) ) ;
68+
69+ // The first item can not be a child
70+ assert_noop ! ( Fruniques :: spawn( Origin :: signed( 1 ) , 0 , Some ( ( 0 , false , 10 ) ) , None ) , Error :: <Test >:: ParentNotFound ) ;
71+
6772 // A NFT can be created with empty data
6873 assert_ok ! ( Fruniques :: spawn( Origin :: signed( 1 ) , 0 , None , None ) ) ;
6974 // A NFT can be created with attributes
7075 assert_ok ! ( Fruniques :: spawn( Origin :: signed( 1 ) , 0 , None , Some ( dummy_attributes( ) ) ) ) ;
7176 // A NFT can be hierarchical
7277 assert_ok ! ( Fruniques :: spawn( Origin :: signed( 1 ) , 0 , Some ( ( 0 , false , 10 ) ) , None ) ) ;
73-
78+ // The parent must exist
79+ assert_noop ! ( Fruniques :: spawn( Origin :: signed( 1 ) , 0 , Some ( ( 100 , false , 10 ) ) , None ) , Error :: <Test >:: ParentNotFound ) ;
7480 } )
7581}
7682
77- // #[test]
78- // fn create_frunique_works() {
79- // // Create a frunique
80- // ExtBuilder::default().build().execute_with(|| {
81- // assert_ok!(Fruniques::create(Origin::signed(1), 1, 0, Some(Permill::from_percent(50)), 1));
82- // });
83- // }
8483
85- // #[test]
86- // fn create_frunique_with_attributes_should_work() {
87- // // Create a frunique with attributes
88- // ExtBuilder::default().build().execute_with(|| {
89- // assert_noop!(
90- // Fruniques::create_with_attributes(
91- // Origin::signed(1),
92- // 1,
93- // 0,
94- // Some(Permill::from_percent(50)),
95- // 1,
96- // vec![]
97- // ),
98- // Error::<Test>::AttributesEmpty
99- // );
100-
101- // assert_ok!(Fruniques::create_with_attributes(
102- // Origin::signed(1),
103- // 1,
104- // 0,
105- // Some(Permill::from_percent(50)),
106- // 1,
107- // vec![(bvec![0], bvec![0])],
108- // ));
109- // });
110- // }
84+ #[ test]
85+ fn set_attributes_works ( ) {
86+ ExtBuilder :: default ( ) . build ( ) . execute_with ( || {
87+ // A collection must be created before spawning an NFT
88+ assert_noop ! ( Fruniques :: spawn( Origin :: signed( 1 ) , 0 , None , None ) , Error :: <Test >:: CollectionNotFound ) ;
11189
112- // this test is failing for some reason...
113- /*---- tests::spawn_extrinsic_works stdout ----
114- thread 'tests::spawn_extrinsic_works' panicked at 'Expected Ok(_). Got Err(
115- Module(
116- ModuleError {
117- index: 1,
118- error: [
119- 1,
120- 0,
121- 0,
122- 0,
123- ],
124- message: Some(
125- "UnknownCollection",
126- ),
127- },
128- ),
129- )', pallets/fruniques/src/tests.rs:41:9
130- note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
131- */
132- // #[test]
133- // fn spawn_extrinsic_works() {
134- // ExtBuilder::default().build().execute_with(|| {
135- // assert_ok!(Fruniques::create(Origin::signed(1), 1, 0, Some(Permill::from_percent(50)), 1));
136- // assert_ok!(Fruniques::spawn(
137- // Origin::signed(1),
138- // 1,
139- // 255,
140- // true,
141- // Permill::from_float(20.525),
142- // 1
143- // ));
144- // //Fruniques::spawn(Origin::signed(1),1,255,true,Permill::from_float(20.525),1 );
145- // assert_ok!(Fruniques::spawn(Origin::signed(1), 1, 1, true, Permill::from_float(20.525), 1));
146- // assert_ok!(Fruniques::instance_exists(Origin::signed(1), 1, 1));
147- // });
148- // }
90+ // Create a collection
91+ assert_ok ! ( Fruniques :: create_collection( Origin :: signed( 1 ) , Some ( dummy_description( ) ) ) ) ;
92+ // Attributes can be added only to existing NFTs
93+ assert_noop ! ( Fruniques :: set_attributes( Origin :: signed( 1 ) , 0 , 0 , dummy_attributes( ) ) , Error :: <Test >:: FruniqueNotFound ) ;
94+ // A NFT can be created with empty data
95+ assert_ok ! ( Fruniques :: spawn( Origin :: signed( 1 ) , 0 , None , None ) ) ;
96+ // Attributes can not be empty
97+ assert_noop ! ( Fruniques :: set_attributes( Origin :: signed( 1 ) , 0 , 0 , dummy_empty_attributes( ) ) , Error :: <Test >:: AttributesEmpty ) ;
14998
150- // #[test]
151- // fn set_attributes_should_work() {
152- // ExtBuilder::default().build().execute_with(|| {
153- // assert_ok!(Fruniques::create(Origin::signed(1), 0, 0, Some(Permill::from_percent(50)), 1));
154- // assert_noop!(
155- // Fruniques::set_attributes(Origin::signed(1), 0, 0, vec![]),
156- // Error::<Test>::AttributesEmpty
157- // );
158- // assert_ok!(Fruniques::set_attributes(Origin::signed(1), 0, 0, vec![(bvec![0], bvec![0])]));
159- // });
160- // }
99+ } )
100+ }
0 commit comments