Add type instance check tests
This commit is contained in:
parent
14eeb309df
commit
51133c8051
3 changed files with 42 additions and 5 deletions
10
src/psbt.js
10
src/psbt.js
|
@ -143,7 +143,10 @@ class Psbt extends bip174_1.Psbt {
|
|||
});
|
||||
return self.__TX.toBuffer();
|
||||
};
|
||||
return super.addInput(inputData, inputAdder);
|
||||
super.addInput(inputData, inputAdder);
|
||||
this.__FEE_RATE = undefined;
|
||||
this.__EXTRACTED_TX = undefined;
|
||||
return this;
|
||||
}
|
||||
addOutput(outputData) {
|
||||
checkInputsForPartialSig(this.inputs, 'addOutput');
|
||||
|
@ -170,7 +173,10 @@ class Psbt extends bip174_1.Psbt {
|
|||
});
|
||||
return self.__TX.toBuffer();
|
||||
};
|
||||
return super.addOutput(outputData, true, outputAdder);
|
||||
super.addOutput(outputData, true, outputAdder);
|
||||
this.__FEE_RATE = undefined;
|
||||
this.__EXTRACTED_TX = undefined;
|
||||
return this;
|
||||
}
|
||||
addNonWitnessUtxoToInput(inputIndex, nonWitnessUtxo) {
|
||||
super.addNonWitnessUtxoToInput(inputIndex, nonWitnessUtxo);
|
||||
|
|
27
test/psbt.js
27
test/psbt.js
|
@ -158,7 +158,7 @@ describe(`Psbt`, () => {
|
|||
ECPair.fromWIF(f.shouldSign.WIF),
|
||||
)
|
||||
})
|
||||
|
||||
|
||||
const psbtThatShouldThrow = Psbt.fromBase64(f.shouldThrow.psbt)
|
||||
assert.throws(() => {
|
||||
psbtThatShouldThrow.signInput(
|
||||
|
@ -224,4 +224,29 @@ describe(`Psbt`, () => {
|
|||
}, {message: 'Input index too high'})
|
||||
})
|
||||
})
|
||||
|
||||
describe('Method return types', () => {
|
||||
it('fromTransaction returns Psbt type (not base class)', () => {
|
||||
const psbt = Psbt.fromTransaction(Buffer.from([2,0,0,0,0,0,0,0,0,0]));
|
||||
assert.strictEqual(psbt instanceof Psbt, true);
|
||||
assert.ok(psbt.__TX);
|
||||
})
|
||||
it('fromBuffer returns Psbt type (not base class)', () => {
|
||||
const psbt = Psbt.fromBuffer(Buffer.from(
|
||||
'70736274ff01000a01000000000000000000000000', 'hex' //cHNidP8BAAoBAAAAAAAAAAAAAAAA
|
||||
));
|
||||
assert.strictEqual(psbt instanceof Psbt, true);
|
||||
assert.ok(psbt.__TX);
|
||||
})
|
||||
it('fromBase64 returns Psbt type (not base class)', () => {
|
||||
const psbt = Psbt.fromBase64('cHNidP8BAAoBAAAAAAAAAAAAAAAA');
|
||||
assert.strictEqual(psbt instanceof Psbt, true);
|
||||
assert.ok(psbt.__TX);
|
||||
})
|
||||
it('fromHex returns Psbt type (not base class)', () => {
|
||||
const psbt = Psbt.fromHex('70736274ff01000a01000000000000000000000000');
|
||||
assert.strictEqual(psbt instanceof Psbt, true);
|
||||
assert.ok(psbt.__TX);
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -180,7 +180,10 @@ export class Psbt extends PsbtBase {
|
|||
});
|
||||
return self.__TX.toBuffer();
|
||||
};
|
||||
return super.addInput(inputData, inputAdder);
|
||||
super.addInput(inputData, inputAdder);
|
||||
this.__FEE_RATE = undefined;
|
||||
this.__EXTRACTED_TX = undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
addOutput(outputData: TransactionOutput): this {
|
||||
|
@ -211,7 +214,10 @@ export class Psbt extends PsbtBase {
|
|||
});
|
||||
return self.__TX.toBuffer();
|
||||
};
|
||||
return super.addOutput(outputData, true, outputAdder);
|
||||
super.addOutput(outputData, true, outputAdder);
|
||||
this.__FEE_RATE = undefined;
|
||||
this.__EXTRACTED_TX = undefined;
|
||||
return this;
|
||||
}
|
||||
|
||||
addNonWitnessUtxoToInput(
|
||||
|
|
Loading…
Reference in a new issue