Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Sep 24, 2024
1 parent 9fa28eb commit 3deb5eb
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"--run",
"--inspect-brk",
"--no-file-parallelism",
"packages/protocol/packages/boundwitness/packages/validator/src/lib/addresses/spec/addressesContainsAll.spec.ts"
"packages/protocol/packages/boundwitness/packages/validator/src/lib/addresses/spec/addressesContainsAny.spec.ts"
],
"sourceMaps": true,
"resolveSourceMapLocations": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('BoundWitnessValidator', () => {
beforeAll(() => {
addresses = signers().map(x => x.address)
})
it('addresses empty', async () => {
it.skip('addresses empty', async () => {
const all = signers()
const [bw] = await new BoundWitnessBuilder().signers(all).payload(payload).build()
expect(addressesContainsAll(bw, [])).toBeTrue()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type { Address } from '@xylabs/hex'
import type { WalletInstance } from '@xyo-network/account'
import { HDWallet } from '@xyo-network/account'
import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'

import { addressesContainsAny } from '../addressesContainsAny.ts'

describe('BoundWitnessValidator', () => {
const payload = { schema: 'network.xyo.test', value: Date.now() }
const oneWallet: WalletInstance[] = []
const twoWallets: WalletInstance[] = []
beforeAll(async () => {
oneWallet.push(await HDWallet.random())
twoWallets.push(await HDWallet.random(), await HDWallet.random())
})
describe('returns true', () => {
const cases: [string, () => WalletInstance[]][] = [
// ['for no wallet', () => []], // This case intentionally skipped because empty addresses will always return false
['for single wallet', () => oneWallet],
['for multiple wallets', () => twoWallets],
]
describe.each(cases)('%s when all sign', (_, signers) => {
let addresses: Address[]
beforeAll(() => {
addresses = signers().map(x => x.address)
})
// it('addresses empty', async () => {
// const all = signers()
// const [bw] = await new BoundWitnessBuilder().signers(all).payload(payload).build()
// expect(addressesContainsAny(bw, [])).toBeTrue()
// })
it('all addresses present in boundwitness addresses', async () => {
const all = signers()
const [bw] = await new BoundWitnessBuilder().signers(all).payload(payload).build()
expect(addressesContainsAny(bw, addresses)).toBeTrue()
})
it('with extra signers and all addresses present in boundwitness addresses', async () => {
const extra = [...signers(), await HDWallet.random()]
const [bw] = await new BoundWitnessBuilder().signers(extra).payload(payload).build()
expect(addressesContainsAny(bw, addresses)).toBeTrue()
})
})
})
describe('returns false', () => {
const cases: [string, () => WalletInstance[]][] = [
// ['for no wallet', () => []],
// ['for single wallet', () => oneWallet],
['for multiple wallets', () => twoWallets],
]
describe.each(cases)('%s', (_, signers) => {
let addresses: Address[]
beforeAll(() => {
addresses = signers().map(x => x.address)
})
it('with no signers', async () => {
const [bw] = await new BoundWitnessBuilder().payload(payload).build()
expect(addressesContainsAny(bw, addresses)).toBeFalse()
})
it.only('with all signers but one', async () => {
const less = [...signers().slice(0, -1), await HDWallet.random()]
const [bw] = await new BoundWitnessBuilder().signers(less).payload(payload).build()
expect(addressesContainsAny(bw, addresses)).toBeFalse()
})
it('with all different signers', async () => {
const none = [await HDWallet.random(), await HDWallet.random()]
const [bw] = await new BoundWitnessBuilder().signers(none).payload(payload).build()
expect(addressesContainsAny(bw, addresses)).toBeFalse()
})
})
})
})

0 comments on commit 3deb5eb

Please sign in to comment.