@@ -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' ;
@@ -364,8 +368,7 @@ describe('full cycle of bet nano contract', () => {
364
368
) . toMatchBuffer ( inputData ) ;
365
369
expect ( ( txSetResultParser . parsedArgs [ 0 ] . value as NanoContractSignedData ) . value ) . toEqual ( result ) ;
366
370
367
- // Try to withdraw to address 2, success
368
- const txWithdrawal = await wallet . createAndSendNanoContractTransaction ( 'withdraw' , address2 , {
371
+ const withdrawalData = {
369
372
ncId : tx1 . hash ,
370
373
actions : [
371
374
{
@@ -375,13 +378,76 @@ describe('full cycle of bet nano contract', () => {
375
378
address : address2 ,
376
379
} ,
377
380
] ,
378
- } ) ;
381
+ } ;
382
+
383
+ const withdrawalCreateTokenOptions = {
384
+ mintAddress : address0 ,
385
+ name : 'Withdrawal Token' ,
386
+ symbol : 'WTK' ,
387
+ amount : 10000n ,
388
+ changeAddress : null ,
389
+ createMint : false ,
390
+ mintAuthorityAddress : null ,
391
+ createMelt : false ,
392
+ meltAuthorityAddress : null ,
393
+ data : null ,
394
+ isCreateNFT : false ,
395
+ contractPaysTokenDeposit : true ,
396
+ } ;
397
+
398
+ // Error with invalid address
399
+ await expect (
400
+ wallet . createAndSendNanoContractCreateTokenTransaction (
401
+ 'withdraw' ,
402
+ 'abc' ,
403
+ withdrawalData ,
404
+ withdrawalCreateTokenOptions
405
+ )
406
+ ) . rejects . toThrow ( NanoContractTransactionError ) ;
407
+
408
+ // Error with invalid mint authority address
409
+ await expect (
410
+ wallet . createAndSendNanoContractCreateTokenTransaction ( 'withdraw' , address2 , withdrawalData , {
411
+ ...withdrawalCreateTokenOptions ,
412
+ mintAuthorityAddress : 'abc' ,
413
+ } )
414
+ ) . rejects . toThrow ( NanoContractTransactionError ) ;
415
+
416
+ // Error with invalid melt authority address
417
+ await expect (
418
+ wallet . createAndSendNanoContractCreateTokenTransaction ( 'withdraw' , address2 , withdrawalData , {
419
+ ...withdrawalCreateTokenOptions ,
420
+ meltAuthorityAddress : 'abc' ,
421
+ } )
422
+ ) . rejects . toThrow ( NanoContractTransactionError ) ;
423
+
424
+ // Try to withdraw to address 2, success
425
+ const txWithdrawal = await wallet . createAndSendNanoContractCreateTokenTransaction (
426
+ 'withdraw' ,
427
+ address2 ,
428
+ withdrawalData ,
429
+ withdrawalCreateTokenOptions
430
+ ) ;
379
431
await checkTxValid ( wallet , txWithdrawal ) ;
380
432
txIds . push ( txWithdrawal . hash ) ;
381
433
382
434
const txWithdrawalData = await wallet . getFullTxById ( txWithdrawal . hash ) ;
383
435
expect ( isNanoContractCreateTx ( txWithdrawalData ) ) . toBe ( false ) ;
384
436
437
+ expect ( txWithdrawalData . tx . nc_id ) . toBe ( tx1 . hash ) ;
438
+ expect ( txWithdrawalData . tx . nc_method ) . toBe ( 'withdraw' ) ;
439
+ expect ( txWithdrawalData . tx . version ) . toBe ( CREATE_TOKEN_TX_VERSION ) ;
440
+ expect ( txWithdrawalData . tx . token_name ) . toBe ( 'Withdrawal Token' ) ;
441
+ expect ( txWithdrawalData . tx . token_symbol ) . toBe ( 'WTK' ) ;
442
+ expect ( txWithdrawalData . tx . outputs . length ) . toBe ( 2 ) ;
443
+ // First the created token output with 10000n amount
444
+ expect ( txWithdrawalData . tx . outputs [ 0 ] . value ) . toBe ( 10000n ) ;
445
+ expect ( txWithdrawalData . tx . outputs [ 0 ] . token_data ) . toBe ( 1 ) ;
446
+ // Then what's left of the withdrawal, after paying 100n
447
+ // in deposit fee for the token creation
448
+ expect ( txWithdrawalData . tx . outputs [ 1 ] . value ) . toBe ( 200n ) ;
449
+ expect ( txWithdrawalData . tx . outputs [ 1 ] . token_data ) . toBe ( 0 ) ;
450
+
385
451
// We must have two transactions in the address2
386
452
const address2Meta2 = await wallet . storage . store . getAddressMeta ( address2 ) ;
387
453
expect ( address2Meta2 . numTransactions ) . toBe ( 2 ) ;
@@ -683,6 +749,19 @@ describe('full cycle of bet nano contract', () => {
683
749
} )
684
750
) . rejects . toThrow ( NanoContractTransactionError ) ;
685
751
752
+ // If we remove the pin from the wallet object, it should throw error
753
+ const oldPin = hWallet . pinCode ;
754
+ hWallet . pinCode = '' ;
755
+ await expect (
756
+ hWallet . createAndSendNanoContractTransaction ( 'withdraw' , address2 , { } )
757
+ ) . rejects . toThrow ( PinRequiredError ) ;
758
+
759
+ await expect (
760
+ hWallet . createAndSendNanoContractCreateTokenTransaction ( 'withdraw' , address2 , { } , { } )
761
+ ) . rejects . toThrow ( PinRequiredError ) ;
762
+ // Add the pin back for the other tests
763
+ hWallet . pinCode = oldPin ;
764
+
686
765
// Test ocb errors
687
766
const { seed } = WALLET_CONSTANTS . ocb ;
688
767
const ocbWallet = await generateWalletHelper ( { seed } ) ;
@@ -694,13 +773,13 @@ describe('full cycle of bet nano contract', () => {
694
773
) . rejects . toThrow ( NanoContractTransactionError ) ;
695
774
696
775
// If we remove the pin from the wallet object, it should throw error
697
- const oldPin = ocbWallet . pinCode ;
776
+ const oldOcbPin = ocbWallet . pinCode ;
698
777
ocbWallet . pinCode = '' ;
699
778
await expect (
700
779
ocbWallet . createAndSendOnChainBlueprintTransaction ( code , address0 )
701
780
) . rejects . toThrow ( PinRequiredError ) ;
702
781
703
782
// Add the pin back in case there are more tests here
704
- ocbWallet . pinCode = oldPin ;
783
+ ocbWallet . pinCode = oldOcbPin ;
705
784
} ) ;
706
785
} ) ;
0 commit comments