@@ -16,18 +16,24 @@ import {
1616} from "./util/contracthelpers" ;
1717
1818import {
19+ addToWhiteListExpectSuccess ,
20+ approveExpectSuccess ,
1921 createCollectionExpectSuccess ,
2022 createItemExpectSuccess ,
23+ enablePublicMintingExpectSuccess ,
24+ enableWhiteListExpectSuccess ,
2125 getGenericResult ,
22- normalizeAccountId
26+ normalizeAccountId ,
27+ isWhitelisted ,
28+ transferFromExpectSuccess
2329} from "./util/helpers" ;
2430
2531
2632chai . use ( chaiAsPromised ) ;
2733const expect = chai . expect ;
2834
2935const value = 0 ;
30- const gasLimit = 3000n * 1000000n ;
36+ const gasLimit = 9000n * 1000000n ;
3137const marketContractAddress = '5CYN9j3YvRkqxewoxeSvRbhAym4465C57uMmX5j4yz99L5H6' ;
3238
3339describe ( 'Contracts' , ( ) => {
@@ -54,8 +60,10 @@ describe('Contracts', () => {
5460 expect ( newContractInstance . address . toString ( ) ) . to . equal ( marketContractAddress ) ;
5561 } ) ;
5662 } ) ;
63+ } ) ;
5764
58- it ( 'Can transfer NFT using smart contract.' , async ( ) => {
65+ describe . only ( 'Chain extensions' , ( ) => {
66+ it ( 'Transfer CE' , async ( ) => {
5967 await usingApi ( async api => {
6068 const alice = privateKey ( "//Alice" ) ;
6169 const bob = privateKey ( "//Bob" ) ;
@@ -64,6 +72,9 @@ describe('Contracts', () => {
6472 const collectionId = await createCollectionExpectSuccess ( ) ;
6573 const tokenId = await createItemExpectSuccess ( alice , collectionId , 'NFT' ) ;
6674 const [ contract , deployer ] = await deployTransferContract ( api ) ;
75+ const changeAdminTx = api . tx . nft . addCollectionAdmin ( collectionId , contract . address ) ;
76+ await submitTransactionAsync ( alice , changeAdminTx ) ;
77+
6778 const tokenBefore : any = ( await api . query . nft . nftItemList ( collectionId , tokenId ) as any ) . toJSON ( ) ;
6879
6980 // Transfer
@@ -78,4 +89,165 @@ describe('Contracts', () => {
7889 expect ( tokenAfter . Owner ) . to . be . deep . equal ( normalizeAccountId ( bob . address ) ) ;
7990 } ) ;
8091 } ) ;
92+
93+ it ( 'Mint CE' , async ( ) => {
94+ await usingApi ( async api => {
95+ const alice = privateKey ( '//Alice' ) ;
96+ const bob = privateKey ( '//Bob' ) ;
97+
98+ const collectionId = await createCollectionExpectSuccess ( ) ;
99+ const [ contract , deployer ] = await deployTransferContract ( api ) ;
100+ await enablePublicMintingExpectSuccess ( alice , collectionId ) ;
101+ await enableWhiteListExpectSuccess ( alice , collectionId ) ;
102+ await addToWhiteListExpectSuccess ( alice , collectionId , contract . address ) ;
103+ await addToWhiteListExpectSuccess ( alice , collectionId , bob . address ) ;
104+
105+ const transferTx = contract . tx . createItem ( value , gasLimit , bob . address , collectionId , { Nft : { const_data : '0x010203' , variable_data : '0x020304' } } ) ;
106+ const events = await submitTransactionAsync ( alice , transferTx ) ;
107+ const result = getGenericResult ( events ) ;
108+ expect ( result . success ) . to . be . true ;
109+
110+ const tokensAfter : any = ( await api . query . nft . nftItemList . entries ( collectionId ) as any ) . map ( ( kv : any ) => kv [ 1 ] . toJSON ( ) ) ;
111+ expect ( tokensAfter ) . to . be . deep . equal ( [
112+ {
113+ Owner : bob . address ,
114+ ConstData : '0x010203' ,
115+ VariableData : '0x020304' ,
116+ } ,
117+ ] ) ;
118+ } ) ;
119+ } ) ;
120+
121+ it ( 'Bulk mint CE' , async ( ) => {
122+ await usingApi ( async api => {
123+ const alice = privateKey ( '//Alice' ) ;
124+ const bob = privateKey ( '//Bob' ) ;
125+
126+ const collectionId = await createCollectionExpectSuccess ( ) ;
127+ const [ contract , deployer ] = await deployTransferContract ( api ) ;
128+ await enablePublicMintingExpectSuccess ( alice , collectionId ) ;
129+ await enableWhiteListExpectSuccess ( alice , collectionId ) ;
130+ await addToWhiteListExpectSuccess ( alice , collectionId , contract . address ) ;
131+ await addToWhiteListExpectSuccess ( alice , collectionId , bob . address ) ;
132+
133+ const transferTx = contract . tx . createMultipleItems ( value , gasLimit , bob . address , collectionId , [
134+ { Nft : { const_data : '0x010203' , variable_data : '0x020304' } } ,
135+ { Nft : { const_data : '0x010204' , variable_data : '0x020305' } } ,
136+ { Nft : { const_data : '0x010205' , variable_data : '0x020306' } }
137+ ] ) ;
138+ const events = await submitTransactionAsync ( alice , transferTx ) ;
139+ const result = getGenericResult ( events ) ;
140+ expect ( result . success ) . to . be . true ;
141+
142+ const tokensAfter : any = ( await api . query . nft . nftItemList . entries ( collectionId ) as any )
143+ . map ( ( kv : any ) => kv [ 1 ] . toJSON ( ) )
144+ . sort ( ( a : any , b : any ) => a . ConstData . localeCompare ( b . ConstData ) ) ;
145+ expect ( tokensAfter ) . to . be . deep . equal ( [
146+ {
147+ Owner : bob . address ,
148+ ConstData : '0x010203' ,
149+ VariableData : '0x020304' ,
150+ } ,
151+ {
152+ Owner : bob . address ,
153+ ConstData : '0x010204' ,
154+ VariableData : '0x020305' ,
155+ } ,
156+ {
157+ Owner : bob . address ,
158+ ConstData : '0x010205' ,
159+ VariableData : '0x020306' ,
160+ } ,
161+ ] ) ;
162+ } ) ;
163+ } ) ;
164+
165+ it ( 'Approve CE' , async ( ) => {
166+ await usingApi ( async api => {
167+ const alice = privateKey ( '//Alice' ) ;
168+ const bob = privateKey ( '//Bob' ) ;
169+ const charlie = privateKey ( '//Charlie' ) ;
170+
171+ const collectionId = await createCollectionExpectSuccess ( ) ;
172+ const [ contract , deployer ] = await deployTransferContract ( api ) ;
173+ const tokenId = await createItemExpectSuccess ( alice , collectionId , 'NFT' , contract . address . toString ( ) ) ;
174+
175+ const transferTx = contract . tx . approve ( value , gasLimit , bob . address , collectionId , tokenId , 1 ) ;
176+ const events = await submitTransactionAsync ( alice , transferTx ) ;
177+ const result = getGenericResult ( events ) ;
178+ expect ( result . success ) . to . be . true ;
179+
180+ await transferFromExpectSuccess ( collectionId , tokenId , bob , contract . address . toString ( ) , charlie , 1 , 'NFT' ) ;
181+ } ) ;
182+ } ) ;
183+
184+ it ( 'TransferFrom CE' , async ( ) => {
185+ await usingApi ( async api => {
186+ const alice = privateKey ( '//Alice' ) ;
187+ const bob = privateKey ( '//Bob' ) ;
188+ const charlie = privateKey ( '//Charlie' ) ;
189+
190+ const collectionId = await createCollectionExpectSuccess ( ) ;
191+ const [ contract , deployer ] = await deployTransferContract ( api ) ;
192+ const tokenId = await createItemExpectSuccess ( alice , collectionId , 'NFT' , bob . address ) ;
193+ await approveExpectSuccess ( collectionId , tokenId , bob , contract . address . toString ( ) , 1 ) ;
194+
195+ const transferTx = contract . tx . transferFrom ( value , gasLimit , bob . address , charlie . address , collectionId , tokenId , 1 ) ;
196+ const events = await submitTransactionAsync ( alice , transferTx ) ;
197+ const result = getGenericResult ( events ) ;
198+ expect ( result . success ) . to . be . true ;
199+
200+ const token : any = ( await api . query . nft . nftItemList ( collectionId , tokenId ) as any ) . unwrap ( )
201+ expect ( token . Owner . toString ( ) ) . to . be . equal ( charlie . address ) ;
202+ } ) ;
203+ } ) ;
204+
205+ it ( 'SetVariableMetaData CE' , async ( ) => {
206+ await usingApi ( async api => {
207+ const alice = privateKey ( '//Alice' ) ;
208+
209+ const collectionId = await createCollectionExpectSuccess ( ) ;
210+ const [ contract , deployer ] = await deployTransferContract ( api ) ;
211+ const tokenId = await createItemExpectSuccess ( alice , collectionId , 'NFT' , contract . address . toString ( ) ) ;
212+
213+ const transferTx = contract . tx . setVariableMetaData ( value , gasLimit , collectionId , tokenId , '0x121314' ) ;
214+ const events = await submitTransactionAsync ( alice , transferTx ) ;
215+ const result = getGenericResult ( events ) ;
216+ expect ( result . success ) . to . be . true ;
217+
218+ const token : any = ( await api . query . nft . nftItemList ( collectionId , tokenId ) as any ) . unwrap ( )
219+ expect ( token . VariableData . toString ( ) ) . to . be . equal ( '0x121314' ) ;
220+ } ) ;
221+ } ) ;
222+
223+ it ( 'ToggleWhiteList CE' , async ( ) => {
224+ await usingApi ( async api => {
225+ const alice = privateKey ( '//Alice' ) ;
226+ const bob = privateKey ( '//Bob' ) ;
227+
228+ const collectionId = await createCollectionExpectSuccess ( ) ;
229+ const [ contract , deployer ] = await deployTransferContract ( api ) ;
230+ const changeAdminTx = api . tx . nft . addCollectionAdmin ( collectionId , contract . address ) ;
231+ await submitTransactionAsync ( alice , changeAdminTx ) ;
232+
233+ expect ( await isWhitelisted ( collectionId , bob . address ) ) . to . be . false ;
234+
235+ {
236+ const transferTx = contract . tx . toggleWhiteList ( value , gasLimit , collectionId , bob . address , true ) ;
237+ const events = await submitTransactionAsync ( alice , transferTx ) ;
238+ const result = getGenericResult ( events ) ;
239+ expect ( result . success ) . to . be . true ;
240+
241+ expect ( await isWhitelisted ( collectionId , bob . address ) ) . to . be . true ;
242+ }
243+ {
244+ const transferTx = contract . tx . toggleWhiteList ( value , gasLimit , collectionId , bob . address , false ) ;
245+ const events = await submitTransactionAsync ( alice , transferTx ) ;
246+ const result = getGenericResult ( events ) ;
247+ expect ( result . success ) . to . be . true ;
248+
249+ expect ( await isWhitelisted ( collectionId , bob . address ) ) . to . be . false ;
250+ }
251+ } ) ;
252+ } ) ;
81253} ) ;
0 commit comments