Skip to content

Commit

Permalink
Update test readability
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Sep 24, 2024
1 parent b4a2c09 commit c3768bb
Showing 1 changed file with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,65 +5,69 @@ import { BoundWitnessBuilder } from '@xyo-network/boundwitness-builder'

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

describe('BoundWitnessValidator', () => {
describe('addressesContainsAll', () => {
const payload = { schema: 'network.xyo.test', value: Date.now() }
const oneWallet: WalletInstance[] = []
const twoWallets: WalletInstance[] = []
let oneWallet: WalletInstance[] = []
let twoWallets: WalletInstance[] = []

beforeAll(async () => {
oneWallet.push(await HDWallet.random())
twoWallets.push(await HDWallet.random(), await HDWallet.random())
oneWallet = [await HDWallet.random()]
twoWallets = [await HDWallet.random(), await HDWallet.random()]
})

const buildBoundWitness = async (signers: WalletInstance[]) => {
const [bw] = await new BoundWitnessBuilder().signers(signers).payload(payload).build()
return bw
}

describe('returns true', () => {
const cases: [string, () => WalletInstance[]][] = [
['with no signer', () => []],
['with single signer', () => oneWallet],
['with multiple signer', () => twoWallets],
['with no wallets', () => []],
['with single wallet', () => oneWallet],
['with multiple wallets', () => twoWallets],
]
describe.each(cases)('%s when all sign', (_, signers) => {
describe.each(cases)('%s', (_, wallets) => {
let addresses: Address[]
beforeAll(() => {
addresses = signers().map(x => x.address)
addresses = wallets().map(x => x.address)
})
it('addresses empty', async () => {
const all = signers()
const [bw] = await new BoundWitnessBuilder().signers(all).payload(payload).build()
it('with no signers and empty addresses supplied', async () => {
const bw = await buildBoundWitness(wallets())
expect(addressesContainsAll(bw, [])).toBeTrue()
})
it('all addresses present in boundwitness addresses', async () => {
const all = signers()
const [bw] = await new BoundWitnessBuilder().signers(all).payload(payload).build()
it('with all wallets as signers and all wallet addresses supplied', async () => {
const bw = await buildBoundWitness(wallets())
expect(addressesContainsAll(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()
it('with all wallets (and extra wallets) as signers and all wallet addresses supplied', async () => {
const extraSigners = [...wallets(), await HDWallet.random()]
const bw = await buildBoundWitness(extraSigners)
expect(addressesContainsAll(bw, addresses)).toBeTrue()
})
})
})
describe('returns false', () => {
const cases: [string, () => WalletInstance[]][] = [
// ['for no wallet', () => []], // This case intentionally skipped because empty addresses will always return true
['for single wallet', () => oneWallet],
['for multiple wallets', () => twoWallets],
['with single wallet', () => oneWallet],
['with multiple wallets', () => twoWallets],
]
describe.each(cases)('%s', (_, signers) => {
describe.each(cases)('%s', (_, wallets) => {
let addresses: Address[]
beforeAll(() => {
addresses = signers().map(x => x.address)
addresses = wallets().map(x => x.address)
})
it('with no signers', async () => {
it('with no signers and all wallet addresses supplied', async () => {
const [bw] = await new BoundWitnessBuilder().payload(payload).build()
expect(addressesContainsAll(bw, addresses)).toBeFalse()
})
it('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()
it('with all signers except one and all wallet addresses supplied', async () => {
const lessSigners = [...wallets().slice(0, -1), await HDWallet.random()]
const bw = await buildBoundWitness(lessSigners)
expect(addressesContainsAll(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()
it('with all different signers and all wallet addresses supplied', async () => {
const differentSigners = [await HDWallet.random(), await HDWallet.random()]
const bw = await buildBoundWitness(differentSigners)
expect(addressesContainsAll(bw, addresses)).toBeFalse()
})
})
Expand Down

0 comments on commit c3768bb

Please sign in to comment.