Skip to content

Commit

Permalink
Added unit tests for toBitcoinJsLibNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszslabon committed Sep 27, 2023
1 parent bfb593a commit 96c204a
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions typescript/test/bitcoin-network.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { expect } from "chai"
import { BitcoinNetwork, toBcoinNetwork } from "../src/bitcoin-network"
import {
BitcoinNetwork,
toBcoinNetwork,
toBitcoinJsLibNetwork,
} from "../src/bitcoin-network"
import { TransactionHash } from "../src/bitcoin"
import { networks } from "bitcoinjs-lib"

describe("BitcoinNetwork", () => {
const testData = [
Expand All @@ -10,6 +15,7 @@ describe("BitcoinNetwork", () => {
// any value that doesn't match other supported networks
genesisHash: TransactionHash.from("0x00010203"),
expectedToBcoinResult: new Error("network not supported"),
expectedToBitcoinJsLibResult: new Error("network not supported"),
},
{
enumKey: BitcoinNetwork.Testnet,
Expand All @@ -18,6 +24,7 @@ describe("BitcoinNetwork", () => {
"0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"
),
expectedToBcoinResult: "testnet",
expectedToBitcoinJsLibResult: networks.testnet,
},
{
enumKey: BitcoinNetwork.Mainnet,
Expand All @@ -26,11 +33,18 @@ describe("BitcoinNetwork", () => {
"000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"
),
expectedToBcoinResult: "main",
expectedToBitcoinJsLibResult: networks.bitcoin,
},
]

testData.forEach(
({ enumKey, enumValue, genesisHash, expectedToBcoinResult }) => {
({
enumKey,
enumValue,
genesisHash,
expectedToBcoinResult,
expectedToBitcoinJsLibResult,
}) => {
context(enumKey, async () => {
describe(`toString`, async () => {
it(`should return correct value`, async () => {
Expand Down Expand Up @@ -59,6 +73,22 @@ describe("BitcoinNetwork", () => {
})
}
})

describe(`toBitcoinJsLibNetwork`, async () => {
if (expectedToBitcoinJsLibResult instanceof Error) {
it(`should throw an error`, async () => {
expect(() => toBitcoinJsLibNetwork(enumKey)).to.throw(
expectedToBitcoinJsLibResult.message
)
})
} else {
it(`should return ${expectedToBitcoinJsLibResult}`, async () => {
expect(toBitcoinJsLibNetwork(enumKey)).to.be.equal(
expectedToBitcoinJsLibResult
)
})
}
})
})
}
)
Expand Down

0 comments on commit 96c204a

Please sign in to comment.