diff --git a/packages/sdk/src/mintlayer-connect-sdk.ts b/packages/sdk/src/mintlayer-connect-sdk.ts index b2f145a..4268fc7 100644 --- a/packages/sdk/src/mintlayer-connect-sdk.ts +++ b/packages/sdk/src/mintlayer-connect-sdk.ts @@ -66,7 +66,7 @@ function stringToUint8Array(str: string): Uint8Array { return new TextEncoder().encode(str); } -function atomsToDecimal(atoms: string | number, decimals: number): string { +export function atomsToDecimal(atoms: string | number, decimals: number): string { const atomsStr = atoms.toString(); const atomsLength = atomsStr.length; @@ -87,6 +87,13 @@ function atomsToDecimal(atoms: string | number, decimals: number): string { return fractionalPart === '' ? integerPart : `${integerPart}.${fractionalPart}`; } +export function decimalsToAtoms(value: string | number, decimals: number): bigint { + const [intPart, fracPart = ""] = value.toString().split("."); + const paddedFrac = (fracPart + "0".repeat(decimals)).slice(0, decimals); + const full = intPart + paddedFrac; + return BigInt(full); +} + type Address = { [key: string]: { receiving: string[]; @@ -1355,12 +1362,12 @@ class Client { fee = token_change_authority_fee(block_height, this.network === 'mainnet' ? Network.Mainnet : Network.Testnet); return BigInt(fee.atoms()); case 'ChangeMetadataUri': - return BigInt(50 * Math.pow(10, 11)); + return decimalsToAtoms(50, 11); case 'FreezeToken': fee = token_freeze_fee(block_height, this.network === 'mainnet' ? Network.Mainnet : Network.Testnet); return BigInt(fee.atoms()); case 'UnfreezeToken': - return BigInt(50 * Math.pow(10, 11)); + return decimalsToAtoms(50, 11); case 'DataDeposit': fee = data_deposit_fee(block_height, this.network === 'mainnet' ? Network.Mainnet : Network.Testnet); return BigInt(fee.atoms()); @@ -1396,13 +1403,13 @@ class Client { const { token_id, token_details } = params; if (token_details) { - input_amount_token_req += BigInt(params.amount! * Math.pow(10, token_details.number_of_decimals)); + input_amount_token_req += decimalsToAtoms(params.amount!,token_details.number_of_decimals); send_token = { token_id, number_of_decimals: token_details.number_of_decimals, }; } else { - input_amount_coin_req += BigInt(params.amount! * Math.pow(10, 11)); + input_amount_coin_req += decimalsToAtoms(params.amount!, 11); } outputs.push({ @@ -1418,13 +1425,13 @@ class Client { ? { amount: { decimal: params.amount!.toString(), - atoms: (params.amount! * Math.pow(10, token_details.number_of_decimals)).toString(), + atoms: decimalsToAtoms(params.amount!, token_details.number_of_decimals).toString(), }, } : { amount: { decimal: params.amount!.toString(), - atoms: (params.amount! * Math.pow(10, 11)).toString(), + atoms: decimalsToAtoms(params.amount!, 11).toString(), }, }), }, @@ -1435,13 +1442,13 @@ class Client { const { token_id, token_details } = params; if (token_details) { - input_amount_token_req += BigInt(params.amount! * Math.pow(10, token_details.number_of_decimals)); + input_amount_token_req += decimalsToAtoms(params.amount!, token_details.number_of_decimals); send_token = { token_id, number_of_decimals: token_details.number_of_decimals, }; } else { - input_amount_coin_req += BigInt(params.amount! * Math.pow(10, 11)); + input_amount_coin_req += decimalsToAtoms(params.amount!,11); } outputs.push({ @@ -1455,7 +1462,7 @@ class Client { }), amount: { decimal: params.amount!.toString(), - atoms: (params.amount! * Math.pow(10, 11)).toString(), + atoms: decimalsToAtoms(params.amount!, 11).toString(), }, }, }); @@ -1472,7 +1479,7 @@ class Client { total_supply = { type: 'Fixed', amount: { - atoms: (params.supply_amount! * Math.pow(10, params.number_of_decimals!)).toString(), + atoms: decimalsToAtoms(params.supply_amount!, params.number_of_decimals!).toString(), decimal: params.supply_amount!.toString(), }, }; @@ -1538,7 +1545,7 @@ class Client { if (type === 'MintToken') { const amount = { - atoms: (params.amount! * Math.pow(10, params.token_details!.number_of_decimals)).toString(), + atoms: decimalsToAtoms(params.amount!, params.token_details!.number_of_decimals).toString(), decimal: params.amount!.toString(), }; @@ -1573,7 +1580,7 @@ class Client { const token_id = params.token_id; const token_details = params.token_details; - input_amount_token_req += BigInt(params.amount! * Math.pow(10, token_details!.number_of_decimals)); + input_amount_token_req += decimalsToAtoms(params.amount!, token_details!.number_of_decimals); send_token = { token_id, number_of_decimals: token_details!.number_of_decimals, @@ -1693,8 +1700,8 @@ class Client { if (type === 'DelegateStaking') { const { delegation_id, amount } = params; - const amount_atoms = amount! * Math.pow(10, 11); - input_amount_coin_req += BigInt(amount! * Math.pow(10, 11)); + const amount_atoms = decimalsToAtoms(amount!, 11); + input_amount_coin_req += decimalsToAtoms(amount!, 11); outputs.push({ type: 'DelegateStaking', @@ -1709,7 +1716,7 @@ class Client { if (type === 'DelegationWithdraw') { const { delegation_id, amount, delegation_details } = params; - const amount_atoms = amount! * Math.pow(10, 11); + const amount_atoms = decimalsToAtoms(amount!, 11); inputs.push({ input: { @@ -1753,9 +1760,9 @@ class Client { } = params; if (give_token === 'Coin') { - input_amount_coin_req += BigInt(give_amount! * Math.pow(10, 11)); + input_amount_coin_req += decimalsToAtoms(give_amount!, 11); } else if (give_token_details) { - input_amount_token_req += BigInt(give_amount! * Math.pow(10, give_token_details.number_of_decimals)); + input_amount_token_req += decimalsToAtoms(give_amount!, give_token_details.number_of_decimals); send_token = { token_id: give_token, number_of_decimals: give_token_details.number_of_decimals, @@ -1770,27 +1777,27 @@ class Client { ask_currency: ask_token === 'Coin' ? { type: 'Coin' } : { token_id: ask_token, type: 'TokenV1' }, ask_balance: { atoms: ask_token_details - ? (ask_amount! * Math.pow(10, ask_token_details.number_of_decimals)).toString() - : (ask_amount! * Math.pow(10, 11)).toString(), + ? decimalsToAtoms(ask_amount!, ask_token_details.number_of_decimals).toString() + : decimalsToAtoms(ask_amount!, 11).toString(), decimal: ask_amount!.toString(), }, initially_asked: { atoms: ask_token_details - ? (ask_amount! * Math.pow(10, ask_token_details.number_of_decimals)).toString() - : (ask_amount! * Math.pow(10, 11)).toString(), + ? decimalsToAtoms(ask_amount!, ask_token_details.number_of_decimals).toString() + : decimalsToAtoms(ask_amount!, 11).toString(), decimal: ask_amount!.toString(), }, give_currency: give_token === 'Coin' ? { type: 'Coin' } : { token_id: give_token, type: 'TokenV1' }, give_balance: { atoms: give_token_details - ? (give_amount! * Math.pow(10, give_token_details.number_of_decimals)).toString() - : (give_amount! * Math.pow(10, 11)).toString(), + ? decimalsToAtoms(give_amount!, give_token_details.number_of_decimals).toString() + : decimalsToAtoms(give_amount!, 11).toString(), decimal: give_amount!.toString(), }, initially_given: { atoms: give_token_details - ? (give_amount! * Math.pow(10, give_token_details.number_of_decimals)).toString() - : (give_amount! * Math.pow(10, 11)).toString(), + ? decimalsToAtoms(give_amount!, give_token_details.number_of_decimals).toString() + : decimalsToAtoms(give_amount!, 11).toString(), decimal: give_amount!.toString(), }, }); @@ -1860,8 +1867,8 @@ class Client { const give_amount = amount; // Amount to fill in the order. Give _to_ order as counterpart of ask const give_amount_atoms = order_details.ask_currency.type === 'Token' - ? give_amount! * Math.pow(10, ask_token_details!.number_of_decimals) - : give_amount! * Math.pow(10, 11); // Coin decimal + ? decimalsToAtoms(give_amount!, ask_token_details!.number_of_decimals) + : decimalsToAtoms(give_amount!, 11); // Coin decimal if (order_details.ask_currency.type === 'Coin') { input_amount_coin_req += BigInt(give_amount_atoms); } else if (ask_token_details) { @@ -1872,9 +1879,15 @@ class Client { }; } + const asked = BigInt(order_details.initially_asked.atoms); + const given = BigInt(order_details.initially_given.atoms); + + const give_atoms = BigInt(give_amount_atoms); + const ask_amount_atoms_bigint = (give_atoms * given) / asked; + const rate = parseInt(order_details.initially_asked.atoms) / parseInt(order_details.initially_given.atoms); - const ask_amount_atoms = Math.floor(give_amount_atoms / rate); + const ask_amount_atoms = ask_amount_atoms_bigint.toString(); const ask_amount = order_details.give_currency.type === 'Token' ? atomsToDecimal(ask_amount_atoms, give_token_details!.number_of_decimals) @@ -1993,7 +2006,7 @@ class Client { type: 'Coin', amount: { atoms: changeAmountCoin.toString(), - decimal: (Number(changeAmountCoin) / 1e11).toString(), + decimal: atomsToDecimal(changeAmountCoin.toString(), 11).toString(), }, }, destination: currentAddress.change[0], @@ -2009,7 +2022,7 @@ class Client { token_id: send_token.token_id, amount: { atoms: changeAmountToken.toString(), - decimal: (Number(changeAmountToken) / Math.pow(10, decimals)).toString(), + decimal: atomsToDecimal(changeAmountToken.toString(), decimals).toString(), }, }, destination: currentAddress.change[0], diff --git a/packages/sdk/tests/__snapshots__/transfer.test.ts.snap b/packages/sdk/tests/__snapshots__/transfer.test.ts.snap index c25c7ce..4906484 100644 --- a/packages/sdk/tests/__snapshots__/transfer.test.ts.snap +++ b/packages/sdk/tests/__snapshots__/transfer.test.ts.snap @@ -169,3 +169,683 @@ exports[`buildTransaction for transfer - snapshot 1`] = ` "transaction_id": "95d91b8b3c9cd5973e85a397a86a803ab2b8ba8b8ad1b875c85b5c8ae7e4fc7d", } `; + +exports[`buildTransaction for transfer, decimal test 1 1`] = ` +{ + "BINRepresentation": { + "inputs": [ + Uint8Array [ + 0, + 0, + 175, + 59, + 95, + 173, + 32, + 246, + 249, + 126, + 178, + 16, + 147, + 78, + 148, + 33, + 118, + 247, + 247, + 208, + 247, + 4, + 35, + 89, + 6, + 89, + 238, + 14, + 2, + 23, + 5, + 58, + 124, + 171, + 1, + 0, + 0, + 0, + ], + ], + "outputs": [ + Uint8Array [ + 0, + 0, + 7, + 0, + 16, + 165, + 212, + 232, + 1, + 118, + 148, + 121, + 186, + 231, + 213, + 53, + 208, + 151, + 222, + 253, + 255, + 15, + 78, + 113, + 1, + 102, + 157, + 74, + 25, + ], + Uint8Array [ + 0, + 0, + 15, + 224, + 246, + 133, + 212, + 32, + 12, + 6, + 1, + 134, + 236, + 69, + 4, + 87, + 208, + 154, + 217, + 128, + 115, + 147, + 216, + 156, + 236, + 156, + 113, + 214, + 32, + 96, + 33, + ], + ], + "transactionsize": 206, + }, + "HEXRepresentation_unsigned": "0100040000af3b5fad20f6f97eb210934e942176f7f7d0f70423590659ee0e0217053a7cab01000000080000070010a5d4e801769479bae7d535d097defdff0f4e7101669d4a1900000fe0f685d4200c060186ec450457d09ad9807393d89cec9c71d6206021", + "JSONRepresentation": { + "fee": { + "atoms": "20600000000", + "decimal": "0.206", + }, + "id": "95d91b8b3c9cd5973e85a397a86a803ab2b8ba8b8ad1b875c85b5c8ae7e4fc7d", + "inputs": [ + { + "input": { + "index": 1, + "input_type": "UTXO", + "source_id": "af3b5fad20f6f97eb210934e942176f7f7d0f70423590659ee0e0217053a7cab", + "source_type": "Transaction", + }, + "utxo": { + "destination": "tmt1qxrwc3gy2lgf4kvqwwfa388vn3cavgrqyyrgswe6", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1703205604300000", + "decimal": "17032.056043", + }, + "type": "Coin", + }, + }, + }, + ], + "outputs": [ + { + "destination": "tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1000000000000", + "decimal": "10", + }, + "type": "Coin", + }, + }, + { + "destination": "tmt1qxrwc3gy2lgf4kvqwwfa388vn3cavgrqyyrgswe6", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1702185004300000", + "decimal": "17021.850043", + }, + "type": "Coin", + }, + }, + ], + }, + "transaction_id": "95d91b8b3c9cd5973e85a397a86a803ab2b8ba8b8ad1b875c85b5c8ae7e4fc7d", +} +`; + +exports[`buildTransaction for transfer, decimal test 2 1`] = ` +{ + "BINRepresentation": { + "inputs": [ + Uint8Array [ + 0, + 0, + 175, + 59, + 95, + 173, + 32, + 246, + 249, + 126, + 178, + 16, + 147, + 78, + 148, + 33, + 118, + 247, + 247, + 208, + 247, + 4, + 35, + 89, + 6, + 89, + 238, + 14, + 2, + 23, + 5, + 58, + 124, + 171, + 1, + 0, + 0, + 0, + ], + ], + "outputs": [ + Uint8Array [ + 0, + 0, + 7, + 0, + 16, + 165, + 212, + 232, + 1, + 118, + 148, + 121, + 186, + 231, + 213, + 53, + 208, + 151, + 222, + 253, + 255, + 15, + 78, + 113, + 1, + 102, + 157, + 74, + 25, + ], + Uint8Array [ + 0, + 0, + 15, + 224, + 246, + 133, + 212, + 32, + 12, + 6, + 1, + 134, + 236, + 69, + 4, + 87, + 208, + 154, + 217, + 128, + 115, + 147, + 216, + 156, + 236, + 156, + 113, + 214, + 32, + 96, + 33, + ], + ], + "transactionsize": 206, + }, + "HEXRepresentation_unsigned": "0100040000af3b5fad20f6f97eb210934e942176f7f7d0f70423590659ee0e0217053a7cab01000000080000070010a5d4e801769479bae7d535d097defdff0f4e7101669d4a1900000fe0f685d4200c060186ec450457d09ad9807393d89cec9c71d6206021", + "JSONRepresentation": { + "fee": { + "atoms": "20600000000", + "decimal": "0.206", + }, + "id": "95d91b8b3c9cd5973e85a397a86a803ab2b8ba8b8ad1b875c85b5c8ae7e4fc7d", + "inputs": [ + { + "input": { + "index": 1, + "input_type": "UTXO", + "source_id": "af3b5fad20f6f97eb210934e942176f7f7d0f70423590659ee0e0217053a7cab", + "source_type": "Transaction", + }, + "utxo": { + "destination": "tmt1qxrwc3gy2lgf4kvqwwfa388vn3cavgrqyyrgswe6", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1703205604300000", + "decimal": "17032.056043", + }, + "type": "Coin", + }, + }, + }, + ], + "outputs": [ + { + "destination": "tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1000000000000", + "decimal": "10", + }, + "type": "Coin", + }, + }, + { + "destination": "tmt1qxrwc3gy2lgf4kvqwwfa388vn3cavgrqyyrgswe6", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1702185004300000", + "decimal": "17021.850043", + }, + "type": "Coin", + }, + }, + ], + }, + "transaction_id": "95d91b8b3c9cd5973e85a397a86a803ab2b8ba8b8ad1b875c85b5c8ae7e4fc7d", +} +`; + +exports[`buildTransaction for transfer, decimal test 3 1`] = ` +{ + "BINRepresentation": { + "inputs": [ + Uint8Array [ + 0, + 0, + 175, + 59, + 95, + 173, + 32, + 246, + 249, + 126, + 178, + 16, + 147, + 78, + 148, + 33, + 118, + 247, + 247, + 208, + 247, + 4, + 35, + 89, + 6, + 89, + 238, + 14, + 2, + 23, + 5, + 58, + 124, + 171, + 1, + 0, + 0, + 0, + ], + ], + "outputs": [ + Uint8Array [ + 0, + 0, + 7, + 0, + 16, + 165, + 212, + 232, + 1, + 118, + 148, + 121, + 186, + 231, + 213, + 53, + 208, + 151, + 222, + 253, + 255, + 15, + 78, + 113, + 1, + 102, + 157, + 74, + 25, + ], + Uint8Array [ + 0, + 0, + 15, + 224, + 246, + 133, + 212, + 32, + 12, + 6, + 1, + 134, + 236, + 69, + 4, + 87, + 208, + 154, + 217, + 128, + 115, + 147, + 216, + 156, + 236, + 156, + 113, + 214, + 32, + 96, + 33, + ], + ], + "transactionsize": 206, + }, + "HEXRepresentation_unsigned": "0100040000af3b5fad20f6f97eb210934e942176f7f7d0f70423590659ee0e0217053a7cab01000000080000070010a5d4e801769479bae7d535d097defdff0f4e7101669d4a1900000fe0f685d4200c060186ec450457d09ad9807393d89cec9c71d6206021", + "JSONRepresentation": { + "fee": { + "atoms": "20600000000", + "decimal": "0.206", + }, + "id": "95d91b8b3c9cd5973e85a397a86a803ab2b8ba8b8ad1b875c85b5c8ae7e4fc7d", + "inputs": [ + { + "input": { + "index": 1, + "input_type": "UTXO", + "source_id": "af3b5fad20f6f97eb210934e942176f7f7d0f70423590659ee0e0217053a7cab", + "source_type": "Transaction", + }, + "utxo": { + "destination": "tmt1qxrwc3gy2lgf4kvqwwfa388vn3cavgrqyyrgswe6", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1703205604300000", + "decimal": "17032.056043", + }, + "type": "Coin", + }, + }, + }, + ], + "outputs": [ + { + "destination": "tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1000000000000", + "decimal": "10", + }, + "type": "Coin", + }, + }, + { + "destination": "tmt1qxrwc3gy2lgf4kvqwwfa388vn3cavgrqyyrgswe6", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1702185004300000", + "decimal": "17021.850043", + }, + "type": "Coin", + }, + }, + ], + }, + "transaction_id": "95d91b8b3c9cd5973e85a397a86a803ab2b8ba8b8ad1b875c85b5c8ae7e4fc7d", +} +`; + +exports[`buildTransaction for transfer, decimal test 4 1`] = ` +{ + "BINRepresentation": { + "inputs": [ + Uint8Array [ + 0, + 0, + 175, + 59, + 95, + 173, + 32, + 246, + 249, + 126, + 178, + 16, + 147, + 78, + 148, + 33, + 118, + 247, + 247, + 208, + 247, + 4, + 35, + 89, + 6, + 89, + 238, + 14, + 2, + 23, + 5, + 58, + 124, + 171, + 1, + 0, + 0, + 0, + ], + ], + "outputs": [ + Uint8Array [ + 0, + 0, + 7, + 0, + 16, + 165, + 212, + 232, + 1, + 118, + 148, + 121, + 186, + 231, + 213, + 53, + 208, + 151, + 222, + 253, + 255, + 15, + 78, + 113, + 1, + 102, + 157, + 74, + 25, + ], + Uint8Array [ + 0, + 0, + 15, + 224, + 246, + 133, + 212, + 32, + 12, + 6, + 1, + 134, + 236, + 69, + 4, + 87, + 208, + 154, + 217, + 128, + 115, + 147, + 216, + 156, + 236, + 156, + 113, + 214, + 32, + 96, + 33, + ], + ], + "transactionsize": 206, + }, + "HEXRepresentation_unsigned": "0100040000af3b5fad20f6f97eb210934e942176f7f7d0f70423590659ee0e0217053a7cab01000000080000070010a5d4e801769479bae7d535d097defdff0f4e7101669d4a1900000fe0f685d4200c060186ec450457d09ad9807393d89cec9c71d6206021", + "JSONRepresentation": { + "fee": { + "atoms": "20600000000", + "decimal": "0.206", + }, + "id": "95d91b8b3c9cd5973e85a397a86a803ab2b8ba8b8ad1b875c85b5c8ae7e4fc7d", + "inputs": [ + { + "input": { + "index": 1, + "input_type": "UTXO", + "source_id": "af3b5fad20f6f97eb210934e942176f7f7d0f70423590659ee0e0217053a7cab", + "source_type": "Transaction", + }, + "utxo": { + "destination": "tmt1qxrwc3gy2lgf4kvqwwfa388vn3cavgrqyyrgswe6", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1703205604300000", + "decimal": "17032.056043", + }, + "type": "Coin", + }, + }, + }, + ], + "outputs": [ + { + "destination": "tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1000000000000", + "decimal": "10", + }, + "type": "Coin", + }, + }, + { + "destination": "tmt1qxrwc3gy2lgf4kvqwwfa388vn3cavgrqyyrgswe6", + "type": "Transfer", + "value": { + "amount": { + "atoms": "1702185004300000", + "decimal": "17021.850043", + }, + "type": "Coin", + }, + }, + ], + }, + "transaction_id": "95d91b8b3c9cd5973e85a397a86a803ab2b8ba8b8ad1b875c85b5c8ae7e4fc7d", +} +`; diff --git a/packages/sdk/tests/numbers.test.ts b/packages/sdk/tests/numbers.test.ts new file mode 100644 index 0000000..90fd6dd --- /dev/null +++ b/packages/sdk/tests/numbers.test.ts @@ -0,0 +1,8 @@ +import { decimalsToAtoms, atomsToDecimal } from '../src/mintlayer-connect-sdk'; + +test('decimalsToAtoms', async () => { + // @ts-ignore + expect(decimalsToAtoms(1, 11)).toEqual(100000000000n); + // @ts-ignore + expect(decimalsToAtoms(1.005, 11)).toEqual(100500000000n); +}); diff --git a/packages/sdk/tests/transfer.test.ts b/packages/sdk/tests/transfer.test.ts index 6b6b642..b35098f 100644 --- a/packages/sdk/tests/transfer.test.ts +++ b/packages/sdk/tests/transfer.test.ts @@ -185,3 +185,70 @@ test('transfer transfer fee precise', async () => { decimal: "0.206" }); }); + +test('buildTransaction for transfer, decimal test 1', async () => { + const client = await Client.create({ network: 'testnet', autoRestore: false }); + + const spy = jest.spyOn(Client.prototype as any, 'buildTransaction'); + + await client.connect(); + + await client.transfer({ + to: 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc', + amount: 0.009, + }); + + const result = await spy.mock.results[0]?.value; + + expect(result).toMatchSnapshot(); +}); + +test('buildTransaction for transfer, decimal test 2', async () => { + const client = await Client.create({ network: 'testnet', autoRestore: false }); + + const spy = jest.spyOn(Client.prototype as any, 'buildTransaction'); + + await client.connect(); + + await client.transfer({ + to: 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc', + amount: 1.005, + }); + + const result = await spy.mock.results[0]?.value; + expect(result).toMatchSnapshot(); +}); + +test('buildTransaction for transfer, decimal test 3', async () => { + const client = await Client.create({ network: 'testnet', autoRestore: false }); + + const spy = jest.spyOn(Client.prototype as any, 'buildTransaction'); + + await client.connect(); + + await client.transfer({ + to: 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc', + amount: 0.00001, + }); + + const result = await spy.mock.results[0]?.value; + + expect(result).toMatchSnapshot(); +}); + +test('buildTransaction for transfer, decimal test 4', async () => { + const client = await Client.create({ network: 'testnet', autoRestore: false }); + + const spy = jest.spyOn(Client.prototype as any, 'buildTransaction'); + + await client.connect(); + + await client.transfer({ + to: 'tmt1q9mfg7d6ul2nt5yhmm7l7r6wwyqkd822rymr83uc', + amount: 0.1, + }); + + const result = await spy.mock.results[0]?.value; + + expect(result).toMatchSnapshot(); +});