-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(braid): allow for regtest braids
- Loading branch information
Showing
3 changed files
with
31 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,75 @@ | ||
import { validateAddress } from './addresses'; | ||
import { P2SH, P2WSH, } from './multisig'; | ||
import { NETWORKS } from './networks'; | ||
import { validateAddress } from "./addresses"; | ||
import { P2SH, P2WSH } from "./multisig"; | ||
import { NETWORKS } from "./networks"; | ||
|
||
const P2PKH = "P2PKH"; | ||
|
||
let ADDRESSES = {}; | ||
ADDRESSES[NETWORKS.MAINNET] = {}; | ||
ADDRESSES[NETWORKS.MAINNET][P2PKH] = ["1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH"]; | ||
ADDRESSES[NETWORKS.MAINNET][P2SH] = ["3LRW7jeCvQCRdPF8S3yUCfRAx4eqXFmdcr"]; | ||
ADDRESSES[NETWORKS.MAINNET][P2WSH] = ["bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4", "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx"]; | ||
ADDRESSES[NETWORKS.MAINNET][P2WSH] = [ | ||
"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4", | ||
"bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx", | ||
]; | ||
|
||
ADDRESSES[NETWORKS.TESTNET] = {}; | ||
ADDRESSES[NETWORKS.TESTNET][P2PKH] = ["mrCDrCybB6J1vRfbwM5hemdJz73FwDBC8r"]; | ||
ADDRESSES[NETWORKS.TESTNET][P2SH] = ["2NByiBUaEXrhmqAsg7BbLpcQSAQs1EDwt5w"]; | ||
ADDRESSES[NETWORKS.TESTNET][P2WSH] = ["tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7"]; | ||
ADDRESSES[NETWORKS.TESTNET][P2WSH] = [ | ||
"tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7", | ||
]; | ||
|
||
const ADDRESS_TYPES = [P2PKH, P2SH, P2WSH]; | ||
|
||
describe('addresses', () => { | ||
|
||
describe('validateAddress', () => { | ||
|
||
describe("addresses", () => { | ||
describe("validateAddress", () => { | ||
const invalidAddress = /must start with.+followed by letters or digits/i; | ||
|
||
it("returns an error message on blank addresses", () => { | ||
it("returns an error message on blank addresses", () => { | ||
Object.values(NETWORKS).forEach((network) => { | ||
expect(validateAddress("", network)).toMatch(/cannot be blank/i); | ||
expect(validateAddress(" ", network)).toMatch(/cannot be blank/i); | ||
}); | ||
}); | ||
|
||
it("returns an error message on an invalid address", () => { | ||
Object.values(NETWORKS).forEach((network) => { | ||
expect(validateAddress("f", network)).toMatch(invalidAddress); | ||
expect(validateAddress("--", network)).toMatch(invalidAddress); | ||
}); | ||
|
||
expect(validateAddress("1asdf", NETWORKS.MAINNET)).toMatch(/address is invalid/i); | ||
expect(validateAddress("masdf", NETWORKS.TESTNET)).toMatch(/address is invalid/i); | ||
expect(validateAddress("1asdf", NETWORKS.MAINNET)).toMatch( | ||
/address is invalid/i | ||
); | ||
expect(validateAddress("masdf", NETWORKS.TESTNET)).toMatch( | ||
/address is invalid/i | ||
); | ||
}); | ||
|
||
it("returns an error message when an address doesn't match the network", () => { | ||
it("returns an error message when an address doesn't match the network", () => { | ||
ADDRESS_TYPES.forEach((addressType) => { | ||
ADDRESSES[NETWORKS.MAINNET][addressType].forEach((address) => { | ||
expect(validateAddress(address, NETWORKS.TESTNET)).toMatch(invalidAddress); | ||
expect(validateAddress(address, NETWORKS.TESTNET)).toMatch( | ||
invalidAddress | ||
); | ||
}); | ||
ADDRESSES[NETWORKS.TESTNET][addressType].forEach((address) => { | ||
expect(validateAddress(address, NETWORKS.MAINNET)).toMatch(invalidAddress); | ||
expect(validateAddress(address, NETWORKS.MAINNET)).toMatch( | ||
invalidAddress | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
it("returns an empty string when the address is valid", () => { | ||
Object.values(NETWORKS).forEach((network) => { | ||
it("returns an empty string when the address is valid", () => { | ||
[NETWORKS.MAINNET, NETWORKS.TESTNET].forEach((network) => { | ||
ADDRESS_TYPES.forEach((addressType) => { | ||
ADDRESSES[network][addressType].forEach((address) => { | ||
expect(validateAddress(address, network)).toEqual(""); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters