Skip to content

Commit 52ff0c1

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

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6a4c505341542b01045bde60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1a9e209f5ea0036c8c2f41078a3cebee57d8a47d501041f5e0e66b17576a914c4b8ae927ff2b9ce218e20bf06d425d6b68424fd88ac

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

Lines changed: 20 additions & 4 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;
@@ -18,9 +20,14 @@ describe('OP_RETURN', function () {
1820
const validFee = 1;
1921
const validRedeemScript = Buffer.from('522103a8295453660d5e212d55556666666666666666666666666666666666', 'hex');
2022
const validTimelock = 800800;
21-
// https://docs.coredao.org/docs/Learn/products/btc-staking/design#op_return-output-1
22-
const defaultScript =
23-
'6a4c505341542b01045bde60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1a9e209f5ea0036c8c2f41078a3cebee57d8a47d501041f5e0e66b17576a914c4b8ae927ff2b9ce218e20bf06d425d6b68424fd88ac';
23+
let defaultScript: string;
24+
25+
before(async function () {
26+
// https://docs.coredao.org/docs/Learn/products/btc-staking/design#op_return-output-1
27+
const script = await getFixture('test/fixtures/opReturn/documentation.txt', undefined);
28+
assert(typeof script === 'string');
29+
defaultScript = script;
30+
});
2431

2532
describe('createCoreDaoOpReturnOutputScript', function () {
2633
it('should throw if invalid parameters are passed', function () {
@@ -201,7 +208,6 @@ describe('OP_RETURN', function () {
201208
fee: 1,
202209
redeemScript: Buffer.from('041f5e0e66b17576a914c4b8ae927ff2b9ce218e20bf06d425d6b68424fd88ac', 'hex'),
203210
}).toString('hex'),
204-
// Source: https://docs.coredao.org/docs/Learn/products/btc-staking/design#op_return-output-1
205211
defaultScript
206212
);
207213
});
@@ -246,6 +252,16 @@ describe('OP_RETURN', function () {
246252
assert.deepStrictEqual(parsed.redeemScript, validRedeemScript);
247253
});
248254

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

0 commit comments

Comments
 (0)