|
| 1 | +import * as assert from 'assert'; |
| 2 | + |
| 3 | +import * as utxolib from '@bitgo/utxo-lib'; |
| 4 | + |
| 5 | +import { extractAddressBufferFromPayGoAttestationProof } from '../src/ExtractAddressPayGoAttestation'; |
| 6 | + |
| 7 | +const addressFromPubKeyBase58 = 'bitgoAddressToExtract'; |
| 8 | +const bufferAddressPubKeyB58 = Buffer.from(addressFromPubKeyBase58); |
| 9 | + |
| 10 | +describe('extractAddressBufferFromPayGoAttestationProof', () => { |
| 11 | + it('should extractAddressBufferFromPayGoAttestationProof properly', () => { |
| 12 | + const paygoAttestationProof = utxolib.testutil.generatePayGoAttestationProof( |
| 13 | + '00000000-0000-0000-0000-000000000000', |
| 14 | + bufferAddressPubKeyB58 |
| 15 | + ); |
| 16 | + const addressFromProof = extractAddressBufferFromPayGoAttestationProof(paygoAttestationProof); |
| 17 | + assert.deepStrictEqual(Buffer.compare(addressFromProof, bufferAddressPubKeyB58), 0); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should extract the paygo address paygo attestation proof given a non nilUUID', () => { |
| 21 | + const paygoAttestationProof = utxolib.testutil.generatePayGoAttestationProof( |
| 22 | + '12345678-1234-4567-6890-231928472123', |
| 23 | + bufferAddressPubKeyB58 |
| 24 | + ); |
| 25 | + const addressFromProof = extractAddressBufferFromPayGoAttestationProof(paygoAttestationProof); |
| 26 | + assert.deepStrictEqual(Buffer.compare(addressFromProof, bufferAddressPubKeyB58), 0); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should not extract the correct address given a uuid of wrong format', () => { |
| 30 | + const paygoAttestationProof = utxolib.testutil.generatePayGoAttestationProof( |
| 31 | + '000000000000000-000000-0000000-000000-0000000000000000', |
| 32 | + bufferAddressPubKeyB58 |
| 33 | + ); |
| 34 | + const addressFromProof = extractAddressBufferFromPayGoAttestationProof(paygoAttestationProof); |
| 35 | + assert.notDeepStrictEqual(Buffer.compare(addressFromProof, bufferAddressPubKeyB58), 0); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should throw an error if the paygo attestation proof is too short', () => { |
| 39 | + assert.throws( |
| 40 | + () => extractAddressBufferFromPayGoAttestationProof(Buffer.from('shortproof-shrug')), |
| 41 | + 'PayGo attestation proof is too short to contain a valid address.' |
| 42 | + ); |
| 43 | + }); |
| 44 | +}); |
0 commit comments