-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9fa28eb
commit 3deb5eb
Showing
3 changed files
with
73 additions
and
2 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
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
71 changes: 71 additions & 0 deletions
71
...kages/boundwitness/packages/validator/src/lib/addresses/spec/addressesContainsAny.spec.ts
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 |
---|---|---|
@@ -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() | ||
}) | ||
}) | ||
}) | ||
}) |