From bbe1b9537c466cd0a9b2465fab86d41c3f3510de Mon Sep 17 00:00:00 2001 From: Gonzalo D'elia Date: Mon, 30 Dec 2024 18:08:09 -0300 Subject: [PATCH] Add some utils/bitcoin test --- webapp/test/utils/bitcoin.test.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/webapp/test/utils/bitcoin.test.ts b/webapp/test/utils/bitcoin.test.ts index 8a6a5c5d..d57a80c5 100644 --- a/webapp/test/utils/bitcoin.test.ts +++ b/webapp/test/utils/bitcoin.test.ts @@ -1,7 +1,25 @@ -import { getBitcoinTimestamp } from 'utils/bitcoin' +import { calculateDepositAmount, getBitcoinTimestamp } from 'utils/bitcoin' import { describe, expect, it, vi } from 'vitest' describe('utils/bitcoin', function () { + describe('calculateDepositAmount', function () { + it('calculate the deposit amount of a bitcoin deposit transaction', function () { + const userAddress = 'tb1qmynr0k2fuvc24rg2j0xq2wztjvwuqnkdjxvky6' + const bitcoinCustodyAddress = 'tb1qvs632vkezddhuahgdqmwjapm4raprsx0nvyq2q' + + const utxos = [ + // amount sent to the custody address + { value: 10000, scriptpubkeyAddress: bitcoinCustodyAddress }, + // OP_RETURN + { value: 0 }, + // change + { value: 300000, scriptpubkeyAddress: userAddress }, + ] + + expect(calculateDepositAmount(utxos, bitcoinCustodyAddress)).toBe(10000) + }) + }) + describe('getBitcoinTimestamp', function () { it('should return the block time if is prior to the current time', function () { // using 5 minutes ago