Skip to content

Commit 4da473a

Browse files
refactor(utxo-core): refactored tests
Ticket: BTC-2235 TICKET: BTC-2235
1 parent b164136 commit 4da473a

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

modules/utxo-core/test/paygo/psbt/payGoAddressProof.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { generatePayGoAttestationProof } from '../../../src/testutil/generatePayGoAttestationProof.utils';
1616
import { trimMessagePrefix } from '../../../src/paygo/trimMessagePrefix';
1717
import { signMessage } from '../../../src/bip32utils';
18-
import { NIL_UUID } from '../../../src/paygo/attestation';
18+
import { createPayGoAttestationBuffer, NIL_UUID } from '../../../src/paygo/attestation';
1919
import { parsePayGoAttestation } from '../../../src/paygo';
2020

2121
// To construct our PSBTs
@@ -138,11 +138,33 @@ describe('getPaygoAddressProofIndex', () => {
138138
// Small test to verify, leave in this test file
139139
describe('trimMessagePrefix', function () {
140140
it('should be the same proof constructed consistently', function () {
141-
const reconstructedProof = Buffer.concat([
141+
const psbt = getTestPsbt();
142+
psbt.addOutput({ script: utxolib.address.toOutputScript(addressToVerify, network), value: BigInt(10000) });
143+
const outputIndex = psbt.data.outputs.length - 1;
144+
addPayGoAddressProof(psbt, outputIndex, sig, addressProofEntropy);
145+
// manually check without the verify function to see if the entropy being stored
146+
// in the psbt is the same as the entropy being extracted and trimmed.
147+
const psbtOutputs = checkForOutput(psbt.data.outputs, outputIndex);
148+
const stored = utxolib.bitgo.getProprietaryKeyValuesFromUnknownKeyValues(psbtOutputs, {
149+
identifier: utxolib.bitgo.PSBT_PROPRIETARY_IDENTIFIER,
150+
subtype: utxolib.bitgo.ProprietaryKeySubtype.PAYGO_ADDRESS_ATTESTATION_PROOF,
151+
});
152+
153+
assert(stored[0].key.keydata.equals(payGoAttestationProofComponents.entropy));
154+
assert(stored[0].value.equals(sig));
155+
156+
const reconstructedProofFromComponents = Buffer.concat([
142157
payGoAttestationProofComponents.entropy,
143158
payGoAttestationProofComponents.address,
144159
payGoAttestationProofComponents.uuid,
145160
]);
146-
assert(addressProofMsgBuffer.equals(reconstructedProof));
161+
const verifyConstructedProof = createPayGoAttestationBuffer(
162+
addressToVerify,
163+
stored[0].key.keydata,
164+
utxolib.networks.bitcoin
165+
);
166+
167+
assert(addressProofMsgBuffer.equals(reconstructedProofFromComponents));
168+
assert(verifyConstructedProof.equals(reconstructedProofFromComponents));
147169
});
148170
});

0 commit comments

Comments
 (0)