diff --git a/typescript/test/bitcoin.test.ts b/typescript/test/bitcoin.test.ts index c8a243f87..0bcc335ba 100644 --- a/typescript/test/bitcoin.test.ts +++ b/typescript/test/bitcoin.test.ts @@ -17,6 +17,10 @@ import { readCompactSizeUint, computeHash160, computeHash256, + isP2PKHScript, + isP2WPKHScript, + isP2SHScript, + isP2WSHScript, } from "../src/bitcoin" import { calculateDepositRefundLocktime } from "../src/deposit" import { BitcoinNetwork } from "../src/bitcoin-network" @@ -596,4 +600,57 @@ describe("Bitcoin", () => { }) }) }) + + describe("Bitcoin Script Type", () => { + const testData = [ + { + testFunction: isP2PKHScript, + validScript: Buffer.from( + "76a9148db50eb52063ea9d98b3eac91489a90f738986f688ac", + "hex" + ), + name: "P2PKH", + }, + { + testFunction: isP2WPKHScript, + validScript: Buffer.from( + "00148db50eb52063ea9d98b3eac91489a90f738986f6", + "hex" + ), + name: "P2WPKH", + }, + { + testFunction: isP2SHScript, + validScript: Buffer.from( + "a914a9a5f97d5d3c4687a52e90718168270005b369c487", + "hex" + ), + name: "P2SH", + }, + { + testFunction: isP2WSHScript, + validScript: Buffer.from( + "0020b1f83e226979dc9fe74e87f6d303dbb08a27a1c7ce91664033f34c7f2d214cd7", + "hex" + ), + name: "P2WSH", + }, + ] + + testData.forEach(({ testFunction, validScript, name }) => { + describe(`is${name}Script`, () => { + it(`should return true for a valid ${name} script`, () => { + expect(testFunction(validScript)).to.be.true + }) + + it("should return false for other scripts", () => { + testData.forEach((data) => { + if (data.name !== name) { + expect(testFunction(data.validScript)).to.be.false + } + }) + }) + }) + }) + }) })