From c46d43d4a130d1f6bb408adbf32661136f858063 Mon Sep 17 00:00:00 2001 From: Slava Date: Thu, 2 Jan 2025 23:51:02 +0300 Subject: [PATCH] chore: test reach coinbase tx --- sdk/test/utxo.test.ts | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/sdk/test/utxo.test.ts b/sdk/test/utxo.test.ts index 6cd5c890..fbc48fe6 100644 --- a/sdk/test/utxo.test.ts +++ b/sdk/test/utxo.test.ts @@ -522,4 +522,50 @@ describe('UTXO Tests', () => { expect(balanceData.confirmed).toBeLessThan(BigInt(confirmed)); } ); + + // coinbase reached + it( + 'outputs could be spent if not confirmed by ord service, not indexed and does not contain runes or inscriptions', + { timeout: 50000 }, + async () => { + const taprootAddress = 'bc1peqr5a5kfufvsl66444jm9y8qq0s87ph0zv4lfkcs7h40ew02uvsqkhjav0'; + + const esploraClient = new EsploraClient('mainnet'); + + const outputs = await esploraClient.getAddressUtxos(taprootAddress); + + const total = outputs.reduce((acc, output) => acc + output.value, 0); + + const confirmed = outputs.reduce((acc, output) => { + if (output.confirmed) { + return acc + output.value; + } + + return acc; + }, 0); + + // mock half of the UTXOs contain inscriptions or runes + (OrdinalsClient.prototype.getOutputsFromAddress as Mock).mockResolvedValueOnce( + outputs.slice(Math.ceil(outputs.length / 2)).map((output) => { + const outpoint = OutPoint.toString(output); + + return { outpoint }; + }) + ); + // mark every requested output as not indexed and not containing inscriptions or runes + (OrdinalsClient.prototype.getOutputsFromOutPoints as Mock).mockResolvedValue( + Array.from(outputs, () => ({ indexed: false, inscriptions: [], runes: {} })) + ); + + // no inputs otherwise will loop infinitely + (EsploraClient.prototype.getTransaction as Mock).mockResolvedValue({ + vin: [], + }); + + const balanceData = await getBalance(taprootAddress); + + expect(balanceData.total).toEqual(BigInt(total)); + expect(balanceData.confirmed).toBeLessThan(BigInt(confirmed)); + } + ); });