2026-08-25 20:30:24 -07:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
// A fake wallet that records every broadcast attempt and can be made to fail.
|
|
|
|
|
// It satisfies the small adapter surface the Memo action modules need:
|
|
|
|
|
// walletInfo, getUtxos(), sendOpReturn(). Set `wallet.failWith` to make
|
|
|
|
|
// sendOpReturn throw.
|
|
|
|
|
function fakeWallet ({
|
|
|
|
|
cashAddress = 'bitcoincash:qqlrzp23w08434twmvr4fxw672whkjy0py26r63g3d',
|
2026-08-26 06:14:01 -07:00
|
|
|
utxos = [{ txid: 'utxo1', value: 100000 }],
|
2026-08-25 20:30:24 -07:00
|
|
|
txid = 'fake-txid'
|
|
|
|
|
} = {}) {
|
|
|
|
|
const broadcasts = []
|
2026-08-26 06:14:01 -07:00
|
|
|
const sends = []
|
2026-08-25 20:30:24 -07:00
|
|
|
const wallet = {
|
|
|
|
|
walletInfo: { cashAddress },
|
2026-08-26 06:14:01 -07:00
|
|
|
utxos,
|
2026-08-25 20:30:24 -07:00
|
|
|
getUtxos: async () => utxos,
|
2026-08-26 06:14:01 -07:00
|
|
|
sendOpReturn: async function (msg, prefix, bchOutput = []) {
|
|
|
|
|
broadcasts.push({ msg, prefix, bchOutput })
|
|
|
|
|
if (this.failWith) throw new Error(this.failWith)
|
|
|
|
|
return txid
|
|
|
|
|
},
|
|
|
|
|
send: async function (receivers) {
|
|
|
|
|
sends.push(receivers)
|
2026-08-25 20:30:24 -07:00
|
|
|
if (this.failWith) throw new Error(this.failWith)
|
|
|
|
|
return txid
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
wallet.broadcasts = broadcasts
|
2026-08-26 06:14:01 -07:00
|
|
|
wallet.sends = sends
|
2026-08-25 20:30:24 -07:00
|
|
|
return wallet
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = { fakeWallet }
|