|
| 1 | +import assert from 'node:assert/strict'; |
| 2 | + |
| 3 | +import { BitGoAPI } from '@bitgo/sdk-api'; |
| 4 | +import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test'; |
| 5 | +import * as utxolib from '@bitgo/utxo-lib'; |
| 6 | + |
| 7 | +import { AbstractUtxoCoin } from '../../../../../src/abstractUtxoCoin'; |
| 8 | +import { Pearl, Tpearl } from '../../../../../src/impl/pearl'; |
| 9 | + |
| 10 | +describe('Pearl', function () { |
| 11 | + let bitgo: TestBitGoAPI; |
| 12 | + |
| 13 | + /** `bitgo.coin()` is typed as BaseCoin; these are registered as AbstractUtxoCoin */ |
| 14 | + function getCoin(coinName: 'pearl' | 'tpearl'): AbstractUtxoCoin { |
| 15 | + return bitgo.coin(coinName) as unknown as AbstractUtxoCoin; |
| 16 | + } |
| 17 | + |
| 18 | + before(function () { |
| 19 | + bitgo = TestBitGo.decorate(BitGoAPI, { |
| 20 | + env: 'mock', |
| 21 | + }); |
| 22 | + bitgo.initializeTestVars(); |
| 23 | + bitgo.safeRegister('pearl', Pearl.createInstance); |
| 24 | + bitgo.safeRegister('tpearl', Tpearl.createInstance); |
| 25 | + }); |
| 26 | + |
| 27 | + it('should instantiate the coin', function () { |
| 28 | + assert.ok(bitgo.coin('pearl') instanceof Pearl); |
| 29 | + assert.ok(bitgo.coin('tpearl') instanceof Tpearl); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should return the chain', function () { |
| 33 | + assert.strictEqual(bitgo.coin('pearl').getChain(), 'pearl'); |
| 34 | + assert.strictEqual(bitgo.coin('tpearl').getChain(), 'tpearl'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should return full name', function () { |
| 38 | + assert.strictEqual(bitgo.coin('pearl').getFullName(), 'Pearl'); |
| 39 | + assert.strictEqual(bitgo.coin('tpearl').getFullName(), 'Testnet Pearl'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should have tpearl as the testnet variant of pearl', function () { |
| 43 | + assert.ok(bitgo.coin('tpearl') instanceof Pearl); |
| 44 | + }); |
| 45 | + |
| 46 | + /** |
| 47 | + * Pearl is taproot-only. This is not enforced by an override here - it comes from |
| 48 | + * `supportsAddressType` delegating to wasm-utxo, which reports only the taproot |
| 49 | + * script types for this coin. Pinned so a regression in either layer is caught. |
| 50 | + */ |
| 51 | + it('should support only the taproot script types', function () { |
| 52 | + for (const coinName of ['pearl', 'tpearl'] as const) { |
| 53 | + const coin = getCoin(coinName); |
| 54 | + assert.strictEqual(coin.supportsAddressType('p2tr'), true); |
| 55 | + assert.strictEqual(coin.supportsAddressType('p2trMusig2'), true); |
| 56 | + assert.strictEqual(coin.supportsAddressType('p2sh'), false); |
| 57 | + assert.strictEqual(coin.supportsAddressType('p2shP2wsh'), false); |
| 58 | + assert.strictEqual(coin.supportsAddressType('p2wsh'), false); |
| 59 | + } |
| 60 | + }); |
| 61 | + |
| 62 | + it('should support only the taproot address chains', function () { |
| 63 | + for (const coinName of ['pearl', 'tpearl'] as const) { |
| 64 | + const coin = getCoin(coinName); |
| 65 | + // 30/31 = p2tr, 40/41 = p2trMusig2 |
| 66 | + for (const chain of [30, 31, 40, 41]) { |
| 67 | + assert.strictEqual(coin.supportsAddressChain(chain), true, `chain ${chain} should be supported`); |
| 68 | + } |
| 69 | + // 0/1 = p2sh, 10/11 = p2shP2wsh, 20/21 = p2wsh |
| 70 | + for (const chain of [0, 1, 10, 11, 20, 21]) { |
| 71 | + assert.strictEqual(coin.supportsAddressChain(chain), false, `chain ${chain} should not be supported`); |
| 72 | + } |
| 73 | + } |
| 74 | + }); |
| 75 | + |
| 76 | + /** |
| 77 | + * Pearl is served through @bitgo/wasm-utxo and is deliberately absent from |
| 78 | + * @bitgo/utxo-lib. No other checked-in coin has this profile, so it cannot be |
| 79 | + * inferred from an existing coin - assert it explicitly. |
| 80 | + */ |
| 81 | + it('should have no utxo-lib network registration', function () { |
| 82 | + assert.ok(!('pearl' in utxolib.networks)); |
| 83 | + assert.ok(!('tpearl' in utxolib.networks)); |
| 84 | + }); |
| 85 | +}); |
0 commit comments