@@ -8,7 +8,11 @@ import {
8
8
waitForTxReceived ,
9
9
waitTxConfirmed ,
10
10
} from '../helpers/wallet.helper' ;
11
- import { NATIVE_TOKEN_UID , NANO_CONTRACTS_INITIALIZE_METHOD } from '../../../src/constants' ;
11
+ import {
12
+ CREATE_TOKEN_TX_VERSION ,
13
+ NATIVE_TOKEN_UID ,
14
+ NANO_CONTRACTS_INITIALIZE_METHOD ,
15
+ } from '../../../src/constants' ;
12
16
import ncApi from '../../../src/api/nano' ;
13
17
import dateFormatter from '../../../src/utils/date' ;
14
18
import { bufferToHex } from '../../../src/utils/buffer' ;
@@ -327,8 +331,7 @@ describe('full cycle of bet nano contract', () => {
327
331
} ,
328
332
] ) ;
329
333
330
- // Try to withdraw to address 2, success
331
- const txWithdrawal = await wallet . createAndSendNanoContractTransaction ( 'withdraw' , address2 , {
334
+ const withdrawalData = {
332
335
ncId : tx1 . hash ,
333
336
actions : [
334
337
{
@@ -338,13 +341,76 @@ describe('full cycle of bet nano contract', () => {
338
341
address : address2 ,
339
342
} ,
340
343
] ,
341
- } ) ;
344
+ } ;
345
+
346
+ const withdrawalCreateTokenOptions = {
347
+ mintAddress : address0 ,
348
+ name : 'Withdrawal Token' ,
349
+ symbol : 'WTK' ,
350
+ amount : 10000n ,
351
+ changeAddress : null ,
352
+ createMint : false ,
353
+ mintAuthorityAddress : null ,
354
+ createMelt : false ,
355
+ meltAuthorityAddress : null ,
356
+ data : null ,
357
+ isCreateNFT : false ,
358
+ contractPaysTokenDeposit : true ,
359
+ } ;
360
+
361
+ // Error with invalid address
362
+ await expect (
363
+ wallet . createAndSendNanoContractCreateTokenTransaction (
364
+ 'withdraw' ,
365
+ 'abc' ,
366
+ withdrawalData ,
367
+ withdrawalCreateTokenOptions
368
+ )
369
+ ) . rejects . toThrow ( NanoContractTransactionError ) ;
370
+
371
+ // Error with invalid mint authority address
372
+ await expect (
373
+ wallet . createAndSendNanoContractCreateTokenTransaction ( 'withdraw' , address2 , withdrawalData , {
374
+ ...withdrawalCreateTokenOptions ,
375
+ mintAuthorityAddress : 'abc' ,
376
+ } )
377
+ ) . rejects . toThrow ( NanoContractTransactionError ) ;
378
+
379
+ // Error with invalid melt authority address
380
+ await expect (
381
+ wallet . createAndSendNanoContractCreateTokenTransaction ( 'withdraw' , address2 , withdrawalData , {
382
+ ...withdrawalCreateTokenOptions ,
383
+ meltAuthorityAddress : 'abc' ,
384
+ } )
385
+ ) . rejects . toThrow ( NanoContractTransactionError ) ;
386
+
387
+ // Try to withdraw to address 2, success
388
+ const txWithdrawal = await wallet . createAndSendNanoContractCreateTokenTransaction (
389
+ 'withdraw' ,
390
+ address2 ,
391
+ withdrawalData ,
392
+ withdrawalCreateTokenOptions
393
+ ) ;
342
394
await checkTxValid ( wallet , txWithdrawal ) ;
343
395
txIds . push ( txWithdrawal . hash ) ;
344
396
345
397
const txWithdrawalData = await wallet . getFullTxById ( txWithdrawal . hash ) ;
346
398
expect ( isNanoContractCreateTx ( txWithdrawalData ) ) . toBe ( false ) ;
347
399
400
+ expect ( txWithdrawalData . tx . nc_id ) . toBe ( tx1 . hash ) ;
401
+ expect ( txWithdrawalData . tx . nc_method ) . toBe ( 'withdraw' ) ;
402
+ expect ( txWithdrawalData . tx . version ) . toBe ( CREATE_TOKEN_TX_VERSION ) ;
403
+ expect ( txWithdrawalData . tx . token_name ) . toBe ( 'Withdrawal Token' ) ;
404
+ expect ( txWithdrawalData . tx . token_symbol ) . toBe ( 'WTK' ) ;
405
+ expect ( txWithdrawalData . tx . outputs . length ) . toBe ( 2 ) ;
406
+ // First the created token output with 10000n amount
407
+ expect ( txWithdrawalData . tx . outputs [ 0 ] . value ) . toBe ( 10000n ) ;
408
+ expect ( txWithdrawalData . tx . outputs [ 0 ] . token_data ) . toBe ( 1 ) ;
409
+ // Then what's left of the withdrawal, after paying 100n
410
+ // in deposit fee for the token creation
411
+ expect ( txWithdrawalData . tx . outputs [ 1 ] . value ) . toBe ( 200n ) ;
412
+ expect ( txWithdrawalData . tx . outputs [ 1 ] . token_data ) . toBe ( 0 ) ;
413
+
348
414
// We must have two transactions in the address2
349
415
const address2Meta2 = await wallet . storage . store . getAddressMeta ( address2 ) ;
350
416
expect ( address2Meta2 . numTransactions ) . toBe ( 2 ) ;
@@ -646,6 +712,19 @@ describe('full cycle of bet nano contract', () => {
646
712
} )
647
713
) . rejects . toThrow ( NanoContractTransactionError ) ;
648
714
715
+ // If we remove the pin from the wallet object, it should throw error
716
+ const oldPin = hWallet . pinCode ;
717
+ hWallet . pinCode = '' ;
718
+ await expect (
719
+ hWallet . createAndSendNanoContractTransaction ( 'withdraw' , address2 , { } )
720
+ ) . rejects . toThrow ( PinRequiredError ) ;
721
+
722
+ await expect (
723
+ hWallet . createAndSendNanoContractCreateTokenTransaction ( 'withdraw' , address2 , { } , { } )
724
+ ) . rejects . toThrow ( PinRequiredError ) ;
725
+ // Add the pin back for the other tests
726
+ hWallet . pinCode = oldPin ;
727
+
649
728
// Test ocb errors
650
729
const { seed } = WALLET_CONSTANTS . ocb ;
651
730
const ocbWallet = await generateWalletHelper ( { seed } ) ;
@@ -657,13 +736,13 @@ describe('full cycle of bet nano contract', () => {
657
736
) . rejects . toThrow ( NanoContractTransactionError ) ;
658
737
659
738
// If we remove the pin from the wallet object, it should throw error
660
- const oldPin = ocbWallet . pinCode ;
739
+ const oldOcbPin = ocbWallet . pinCode ;
661
740
ocbWallet . pinCode = '' ;
662
741
await expect (
663
742
ocbWallet . createAndSendOnChainBlueprintTransaction ( code , address0 )
664
743
) . rejects . toThrow ( PinRequiredError ) ;
665
744
666
745
// Add the pin back in case there are more tests here
667
- ocbWallet . pinCode = oldPin ;
746
+ ocbWallet . pinCode = oldOcbPin ;
668
747
} ) ;
669
748
} ) ;
0 commit comments