|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | + |
| 3 | +import { testutil } from '@bitgo/utxo-lib'; |
| 4 | + |
| 5 | +import { explainPsbt } from '../../../../src/transaction/fixedScript'; |
| 6 | + |
| 7 | +function describeTransactionWith(acidTest: testutil.AcidTest) { |
| 8 | + describe(`explainPsbt ${acidTest.name}`, function () { |
| 9 | + it('should explain the transaction', function () { |
| 10 | + const psbt = acidTest.createPsbt(); |
| 11 | + const explanation = explainPsbt( |
| 12 | + psbt, |
| 13 | + { pubs: acidTest.rootWalletKeys.triple.map((k) => k.toBase58()) }, |
| 14 | + acidTest.network, |
| 15 | + { strict: true } |
| 16 | + ); |
| 17 | + assert.strictEqual(explanation.outputs.length, 3); |
| 18 | + assert.strictEqual(explanation.outputAmount, '2700'); |
| 19 | + assert.strictEqual(explanation.changeOutputs.length, acidTest.outputs.length - 3); |
| 20 | + explanation.changeOutputs.forEach((change) => { |
| 21 | + assert.strictEqual(change.amount, '900'); |
| 22 | + assert.strictEqual(typeof change.address, 'string'); |
| 23 | + }); |
| 24 | + assert.strictEqual(explanation.inputSignatures.length, acidTest.inputs.length); |
| 25 | + explanation.inputSignatures.forEach((signature, i) => { |
| 26 | + if (acidTest.inputs[i].scriptType === 'p2shP2pk') { |
| 27 | + return; |
| 28 | + } |
| 29 | + if (acidTest.signStage === 'unsigned') { |
| 30 | + assert.strictEqual(signature, 0); |
| 31 | + } else if (acidTest.signStage === 'halfsigned') { |
| 32 | + assert.strictEqual(signature, 1); |
| 33 | + } else if (acidTest.signStage === 'fullsigned') { |
| 34 | + assert.strictEqual(signature, 2); |
| 35 | + } |
| 36 | + }); |
| 37 | + }); |
| 38 | + }); |
| 39 | +} |
| 40 | + |
| 41 | +testutil.AcidTest.suite().forEach((test) => describeTransactionWith(test)); |
0 commit comments