@@ -6,8 +6,10 @@ import {
66 decodeTimelock ,
77 encodeTimelock ,
88 parseCoreDaoOpReturnOutputScript ,
9+ toString ,
910} from '../../src' ;
1011import { testutil } from '@bitgo/utxo-lib' ;
12+ import { getFixture } from './utils' ;
1113
1214describe ( '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