diff --git a/cashtab/package-lock.json b/cashtab/package-lock.json --- a/cashtab/package-lock.json +++ b/cashtab/package-lock.json @@ -1,12 +1,12 @@ { "name": "cashtab", - "version": "2.40.4", + "version": "2.40.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cashtab", - "version": "2.40.4", + "version": "2.40.5", "dependencies": { "@bitgo/utxo-lib": "^9.33.0", "@zxing/browser": "^0.1.4", diff --git a/cashtab/package.json b/cashtab/package.json --- a/cashtab/package.json +++ b/cashtab/package.json @@ -1,6 +1,6 @@ { "name": "cashtab", - "version": "2.40.4", + "version": "2.40.5", "private": true, "scripts": { "start": "node scripts/start.js", diff --git a/cashtab/src/opreturn/__tests__/index.test.js b/cashtab/src/opreturn/__tests__/index.test.js --- a/cashtab/src/opreturn/__tests__/index.test.js +++ b/cashtab/src/opreturn/__tests__/index.test.js @@ -19,14 +19,10 @@ // Successfully created targetOutputs expectedReturns.forEach(expectedReturn => { - const { description, cashtabMsg, outputScriptHex } = expectedReturn; + const { description, cashtabMsg, returned } = expectedReturn; it(`getCashtabMsgTargetOutput: ${description}`, () => { - const targetOutput = getCashtabMsgTargetOutput(cashtabMsg); - // Output value should be zero for OP_RETURN - expect(targetOutput.value).toStrictEqual(0); - // Test vs hex string as cannot store buffer type in vectors - expect(targetOutput.script.toString('hex')).toStrictEqual( - outputScriptHex, + expect(getCashtabMsgTargetOutput(cashtabMsg)).toStrictEqual( + returned, ); }); }); @@ -46,19 +42,12 @@ // Successfully created targetOutputs expectedReturns.forEach(expectedReturn => { - const { description, tokenId, airdropMsg, outputScriptHex } = + const { description, tokenId, airdropMsg, returned } = expectedReturn; it(`${description}`, () => { - const targetOutput = getAirdropTargetOutput( - tokenId, - airdropMsg, - ); - // Output value should be zero for OP_RETURN - expect(targetOutput.value).toStrictEqual(0); - // Test vs hex string as cannot store buffer type in vectors - expect(targetOutput.script.toString('hex')).toStrictEqual( - outputScriptHex, - ); + expect( + getAirdropTargetOutput(tokenId, airdropMsg), + ).toStrictEqual(returned); }); }); // Error cases @@ -79,15 +68,10 @@ // Successfully created targetOutputs expectedReturns.forEach(expectedReturn => { - const { description, alias, address, outputScriptHex } = - expectedReturn; + const { description, alias, address, returned } = expectedReturn; it(`getAliasTargetOutput: ${description}`, () => { - const targetOutput = getAliasTargetOutput(alias, address); - // Output value should be zero for OP_RETURN - expect(targetOutput.value).toStrictEqual(0); - // Test vs hex string as cannot store buffer type in vectors - expect(targetOutput.script.toString('hex')).toStrictEqual( - outputScriptHex, + expect(getAliasTargetOutput(alias, address)).toStrictEqual( + returned, ); }); }); @@ -150,17 +134,11 @@ // Successfully created targetOutputs expectedReturns.forEach(expectedReturn => { - const { description, opreturnParam, outputScriptHex } = - expectedReturn; + const { description, opreturnParam, returned } = expectedReturn; it(`getOpreturnParamTargetOutput: ${description}`, () => { - const targetOutput = - getOpreturnParamTargetOutput(opreturnParam); - // Output value should be zero for OP_RETURN - expect(targetOutput.value).toStrictEqual(0); - // Test vs hex string as cannot store buffer type in vectors - expect(targetOutput.script.toString('hex')).toStrictEqual( - outputScriptHex, - ); + expect( + getOpreturnParamTargetOutput(opreturnParam), + ).toStrictEqual(returned); }); }); // Error cases diff --git a/cashtab/src/opreturn/fixtures/vectors.js b/cashtab/src/opreturn/fixtures/vectors.js --- a/cashtab/src/opreturn/fixtures/vectors.js +++ b/cashtab/src/opreturn/fixtures/vectors.js @@ -12,21 +12,36 @@ { description: 'Alphanumeric string', cashtabMsg: 'This is a Cashtab Msg', - outputScriptHex: - '6a0400746162155468697320697320612043617368746162204d7367', + returned: { + value: 0, + script: Buffer.from( + '6a0400746162155468697320697320612043617368746162204d7367', + 'hex', + ), + }, }, { description: 'String with emojis', cashtabMsg: 'ππ¬π«‘ππ΅οΈπππͺππ―', - outputScriptHex: - '6a04007461622bf09f998ff09f93acf09faba1f09f9180f09f95b5efb88ff09f9191f09f8e83f09faa96f09f908bf09f8eaf', + returned: { + value: 0, + script: Buffer.from( + '6a04007461622bf09f998ff09f93acf09faba1f09f9180f09f95b5efb88ff09f9191f09f8e83f09faa96f09f908bf09f8eaf', + 'hex', + ), + }, }, { description: 'String of max length for Cashtab Msg', cashtabMsg: '00000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000112345', - outputScriptHex: - '6a04007461624cd73030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313132333435', + returned: { + value: 0, + script: Buffer.from( + '6a04007461624cd73030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313132333435', + 'hex', + ), + }, }, ], expectedErrors: [ @@ -56,8 +71,13 @@ tokenId: '50d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', airdropMsg: '', - outputScriptHex: - '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', + returned: { + value: 0, + script: Buffer.from( + '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', + 'hex', + ), + }, }, { description: @@ -65,16 +85,26 @@ tokenId: '50d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', airdropMsg: ' ', - outputScriptHex: - '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', + returned: { + value: 0, + script: Buffer.from( + '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', + 'hex', + ), + }, }, { description: 'Airdrop with optional alphanumeric msg', tokenId: '50d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', airdropMsg: 'Test airdrop msg', - outputScriptHex: - '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e10546573742061697264726f70206d7367', + returned: { + value: 0, + script: Buffer.from( + '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e10546573742061697264726f70206d7367', + 'hex', + ), + }, }, { description: @@ -83,8 +113,13 @@ '50d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', airdropMsg: '30~40 νλ‘ μμΉμΌλ‘ λ§μ‘±λͺ»νκ² μΌλ 300~400νλ‘ νν ν¨ κ°μ¦μ~ μ체λ°λκ³ ~π€', - outputScriptHex: - '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e4c6833307e343020ed9484eba19c20ec8381ec8ab9ec9cbceba19c20eba78ceca1b1ebaabbed9598eab2a0ec9cbceb8b88203330307e343030ed9484eba19c20ed8e8ced959120ed95a820eab080eca688ec95847e20ec8b9cecb2b4ebb0adeb8498eab3a07ef09fa494', + returned: { + value: 0, + script: Buffer.from( + '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e4c6833307e343020ed9484eba19c20ec8381ec8ab9ec9cbceba19c20eba78ceca1b1ebaabbed9598eab2a0ec9cbceb8b88203330307e343030ed9484eba19c20ed8e8ced959120ed95a820eab080eca688ec95847e20ec8b9cecb2b4ebb0adeb8498eab3a07ef09fa494', + 'hex', + ), + }, }, { description: @@ -93,8 +128,13 @@ '50d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e', airdropMsg: '00000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000100000000010000000001000000000112', - outputScriptHex: - '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e4cb63030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313132', + returned: { + value: 0, + script: Buffer.from( + '6a0464726f702050d8292c6255cda7afc6c8566fed3cf42a2794e9619740fe8f4c95431271410e4cb63030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313132', + 'hex', + ), + }, }, ], expectedErrors: [ @@ -131,15 +171,25 @@ description: 'Valid alias to p2pkh address', alias: 'test', address: 'ecash:qz2708636snqhsxu8wnlka78h6fdp77ar59jrf5035', - outputScriptHex: - '6a042e786563000474657374150095e79f51d4260bc0dc3ba7fb77c7be92d0fbdd1d', + returned: { + value: 0, + script: Buffer.from( + '6a042e786563000474657374150095e79f51d4260bc0dc3ba7fb77c7be92d0fbdd1d', + 'hex', + ), + }, }, { description: 'Valid alias to p2sh address', alias: 'testtwo', address: 'ecash:prfhcnyqnl5cgrnmlfmms675w93ld7mvvqd0y8lz07', - outputScriptHex: - '6a042e78656300077465737474776f1508d37c4c809fe9840e7bfa77b86bd47163f6fb6c60', + returned: { + value: 0, + script: Buffer.from( + '6a042e78656300077465737474776f1508d37c4c809fe9840e7bfa77b86bd47163f6fb6c60', + 'hex', + ), + }, }, ], expectedErrors: [ @@ -259,15 +309,25 @@ description: 'Valid opreturn param input', opreturnParam: '0400746162155468697320697320612043617368746162204d7367', - outputScriptHex: - '6a0400746162155468697320697320612043617368746162204d7367', + returned: { + value: 0, + script: Buffer.from( + '6a0400746162155468697320697320612043617368746162204d7367', + 'hex', + ), + }, }, { description: 'Max length for opreturn param', opreturnParam: '04007461624cd73030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313132333435', - outputScriptHex: - '6a04007461624cd73030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313132333435', + returned: { + value: 0, + script: Buffer.from( + '6a04007461624cd73030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313030303030303030303130303030303030303031303030303030303030313132333435', + 'hex', + ), + }, }, ], expectedErrors: [