Skip to content

Commit

Permalink
Added unit tests for script type functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Sep 27, 2023
1 parent 96c204a commit a5ef9e8
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions typescript/test/bitcoin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
})
})
})
})
})
})

0 comments on commit a5ef9e8

Please sign in to comment.