diff --git a/modules/abstract-utxo/test/unit/recovery/mock.ts b/modules/abstract-utxo/test/unit/recovery/mock.ts index 244211dc6e..6c4e93ffbe 100644 --- a/modules/abstract-utxo/test/unit/recovery/mock.ts +++ b/modules/abstract-utxo/test/unit/recovery/mock.ts @@ -1,20 +1,18 @@ -import { bitgo } from '@bitgo/utxo-lib'; import { AddressInfo, TransactionIO } from '@bitgo/blockapis'; -import * as utxolib from '@bitgo/utxo-lib'; import { address as wasmAddress, AddressFormat } from '@bitgo/wasm-utxo'; import { AbstractUtxoCoin, RecoveryProvider } from '../../../src'; import { Bch } from '../../../src/impl/bch'; import { Bsv } from '../../../src/impl/bsv'; -import type { Unspent, UnspentWithPrevTx, WalletUnspent } from '../../../src/unspent'; +import { parseOutputId, type Unspent, type UnspentWithPrevTx, type WalletUnspent } from '../../../src/unspent'; export class MockRecoveryProvider implements RecoveryProvider { public unspents: Unspent[]; private prevTxCache: Record = {}; constructor(unspents: Unspent[]) { this.unspents = unspents; this.unspents.forEach((u) => { - if (utxolib.bitgo.isUnspentWithPrevTx(u)) { - const { txid } = bitgo.parseOutputId(u.id); + if ('prevTx' in u) { + const { txid } = parseOutputId(u.id); this.prevTxCache[txid] = (u as UnspentWithPrevTx).prevTx.toString('hex'); } }); @@ -49,72 +47,6 @@ export class MockRecoveryProvider implements RecoveryProvider { throw new Error(`not implemented`); } } -export class MockCrossChainRecoveryProvider implements RecoveryProvider { - private addressVersion: 'cashaddr' | 'base58'; - private addressFormat: AddressFormat; - constructor( - public coin: AbstractUtxoCoin, - public unspents: Unspent[], - public tx: utxolib.bitgo.UtxoTransaction - ) { - // this is how blockchair will return the data, as a cashaddr for BCH like coins - // BSV supports cashaddr, but at the time of writing the SDK does not support cashaddr for bsv - this.addressFormat = this.coin instanceof Bch && !(this.coin instanceof Bsv) ? 'cashaddr' : 'default'; - this.addressVersion = this.coin instanceof Bch && !(this.coin instanceof Bsv) ? 'cashaddr' : 'base58'; - } - - async getUnspentsForAddresses(addresses: string[]): Promise { - return this.tx.outs.map((o, vout: number) => { - let address = wasmAddress.fromOutputScriptWithCoin(o.script, this.coin.name, this.addressFormat); - if (address.includes(':')) { - [, address] = address.split(':'); - } - return { - id: `${this.tx?.getId()}:${vout}`, - address, - value: Number(o.value), - ...(this.coin.amountType === 'bigint' ? { valueString: o.value.toString() } : {}), - }; - }); - } - - async getTransactionIO(txid: string): Promise { - const payload: TransactionIO = { - inputs: this.unspents.map((u) => { - // imitate how blockchair returns data - let address = this.coin.canonicalAddress(u.address, this.addressVersion); - if (address.includes(':')) { - [, address] = address.split(':'); - } - return { - address, - }; - }), - outputs: this.tx.outs.map((o) => { - let address = wasmAddress.fromOutputScriptWithCoin(o.script, this.coin.name, this.addressFormat); - if (address.includes(':')) { - [, address] = address.split(':'); - } - return { - address, - }; - }), - }; - return payload; - } - - async getAddressInfo(address: string): Promise { - throw new Error(`not implemented`); - } - - async getTransactionHex(txid: string): Promise { - throw new Error(`not implemented`); - } - - getTransactionInputs(txid: string): Promise[]> { - throw new Error(`not implemented`); - } -} /** * Cross-chain recovery mock provider using wasm-utxo only (no utxolib dependency).