Skip to content

Commit d023d2f

Browse files
committed
Merge branch 'master' into feat/missing-wallet-service-methods
2 parents a800665 + eee0c35 commit d023d2f

File tree

6 files changed

+554
-103
lines changed

6 files changed

+554
-103
lines changed

__tests__/integration/hathorwallet_facade.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ describe('start', () => {
644644
await expect(hWallet.createAndSendNanoContractTransaction()).rejects.toThrow(
645645
WalletFromXPubGuard
646646
);
647+
await expect(hWallet.createAndSendNanoContractCreateTokenTransaction()).rejects.toThrow(
648+
WalletFromXPubGuard
649+
);
647650
await expect(hWallet.getPrivateKeyFromAddress()).rejects.toThrow(WalletFromXPubGuard);
648651
await expect(hWallet.createOnChainBlueprintTransaction()).rejects.toThrow(WalletFromXPubGuard);
649652

__tests__/integration/nanocontracts/bet.test.ts

Lines changed: 85 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
waitForTxReceived,
99
waitTxConfirmed,
1010
} 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';
1216
import ncApi from '../../../src/api/nano';
1317
import dateFormatter from '../../../src/utils/date';
1418
import { bufferToHex } from '../../../src/utils/buffer';
@@ -327,8 +331,7 @@ describe('full cycle of bet nano contract', () => {
327331
},
328332
]);
329333

330-
// Try to withdraw to address 2, success
331-
const txWithdrawal = await wallet.createAndSendNanoContractTransaction('withdraw', address2, {
334+
const withdrawalData = {
332335
ncId: tx1.hash,
333336
actions: [
334337
{
@@ -338,13 +341,76 @@ describe('full cycle of bet nano contract', () => {
338341
address: address2,
339342
},
340343
],
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+
);
342394
await checkTxValid(wallet, txWithdrawal);
343395
txIds.push(txWithdrawal.hash);
344396

345397
const txWithdrawalData = await wallet.getFullTxById(txWithdrawal.hash);
346398
expect(isNanoContractCreateTx(txWithdrawalData)).toBe(false);
347399

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+
348414
// We must have two transactions in the address2
349415
const address2Meta2 = await wallet.storage.store.getAddressMeta(address2);
350416
expect(address2Meta2.numTransactions).toBe(2);
@@ -646,6 +712,19 @@ describe('full cycle of bet nano contract', () => {
646712
})
647713
).rejects.toThrow(NanoContractTransactionError);
648714

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+
649728
// Test ocb errors
650729
const { seed } = WALLET_CONSTANTS.ocb;
651730
const ocbWallet = await generateWalletHelper({ seed });
@@ -657,13 +736,13 @@ describe('full cycle of bet nano contract', () => {
657736
).rejects.toThrow(NanoContractTransactionError);
658737

659738
// If we remove the pin from the wallet object, it should throw error
660-
const oldPin = ocbWallet.pinCode;
739+
const oldOcbPin = ocbWallet.pinCode;
661740
ocbWallet.pinCode = '';
662741
await expect(
663742
ocbWallet.createAndSendOnChainBlueprintTransaction(code, address0)
664743
).rejects.toThrow(PinRequiredError);
665744

666745
// Add the pin back in case there are more tests here
667-
ocbWallet.pinCode = oldPin;
746+
ocbWallet.pinCode = oldOcbPin;
668747
});
669748
});

0 commit comments

Comments
 (0)