Skip to content

Commit

Permalink
chore: test reach coinbase tx
Browse files Browse the repository at this point in the history
  • Loading branch information
slavastartsev committed Jan 2, 2025
1 parent c84713c commit c46d43d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions sdk/test/utxo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
);
});

0 comments on commit c46d43d

Please sign in to comment.