Skip to content

Commit 87c8773

Browse files
test(utxo-coredao): add fixtures from testnet3
TICKET: BTC-1578
1 parent e0b09a5 commit 87c8773

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

modules/utxo-coredao/src/opReturn.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,15 @@ export function parseCoreDaoOpReturnOutputScript(script: Buffer): OpReturnParams
194194
return { ...baseParams, redeemScript: Buffer.from(dataBuffer.subarray(offset)) };
195195
}
196196
}
197+
198+
export function toString(params: OpReturnParams): string {
199+
return JSON.stringify({
200+
version: params.version,
201+
chainId: params.chainId.toString('hex'),
202+
delegator: params.delegator.toString('hex'),
203+
validator: params.validator.toString('hex'),
204+
fee: params.fee,
205+
...('redeemScript' in params ? { redeemScript: params.redeemScript.toString('hex') } : {}),
206+
...('timelock' in params ? { timelock: params.timelock } : {}),
207+
});
208+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"version": 1,
3+
"chainId": "045b",
4+
"delegator": "2dda5d5d3bec673033b5f21ca07c77695404f491",
5+
"validator": "2953559db5cc88ab20b1960faa9793803d070337",
6+
"fee": 0,
7+
"timelock": 1725503428
8+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6a345341542b01045b2dda5d5d3bec673033b5f21ca07c77695404f4912953559db5cc88ab20b1960faa9793803d07033700c417d966

modules/utxo-coredao/test/unit/opReturn.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import {
66
decodeTimelock,
77
encodeTimelock,
88
parseCoreDaoOpReturnOutputScript,
9+
toString,
910
} from '../../src';
1011
import { testutil } from '@bitgo/utxo-lib';
12+
import { getFixture } from './utils';
1113

1214
describe('OP_RETURN', function () {
1315
const validVersion = 2;
@@ -246,6 +248,16 @@ describe('OP_RETURN', function () {
246248
assert.deepStrictEqual(parsed.redeemScript, validRedeemScript);
247249
});
248250

251+
it('should parse valid opreturn script from testnet', async function () {
252+
// Source: https://mempool.space/testnet/tx/66ed4cea26a410248a6d87f14b2bca514f33920c54d4af63ed46a903793115d5
253+
const baseFixturePath = 'test/fixtures/opReturn/66ed4cea26a410248a6d87f14b2bca514f33920c54d4af63ed46a903793115d5';
254+
const opReturnHex = await getFixture(baseFixturePath + '.txt', undefined);
255+
assert(typeof opReturnHex === 'string');
256+
const parsed = parseCoreDaoOpReturnOutputScript(Buffer.from(opReturnHex, 'hex'));
257+
const parsedFixture = await getFixture(baseFixturePath + '.json', JSON.parse(toString(parsed)));
258+
assert.deepStrictEqual(toString(parsed), JSON.stringify(parsedFixture));
259+
});
260+
249261
it('should fail if there is an invalid op-return', function () {
250262
const script = defaultScript.replace('6a4c50', '6b4c50');
251263
assert.throws(() => parseCoreDaoOpReturnOutputScript(Buffer.from(script, 'hex')));

0 commit comments

Comments
 (0)