Skip to content

Commit

Permalink
Update illogical edge cases to return logical results
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBCarter committed Sep 24, 2024
1 parent ab70189 commit cad3526
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ import type { Address } from '@xylabs/hex'
import type { BoundWitness } from '@xyo-network/boundwitness-model'

/**
* Checks if the boundwitness contains any of the addresses
* Checks if the boundwitness contains any of the addresses. If the addresses array
* is empty, it will return true. This is to match the behavior or addressesContainsAll
* which will return true if the addresses array is empty.
* @param bw The boundwitness to check
* @param addresses The addresses to check for
* @returns True if the boundwitness contains all the addresses
* @returns True if the boundwitness contains any of the addresses
*/
export const addressesContainsAny = (bw: BoundWitness, addresses: Address[]): boolean => {
if (addresses.length === 0) return true
return addresses.some(address => bw.addresses?.includes(address))
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ describe('addressesContainsAny', () => {
}
describe('returns true', () => {
const cases: [string, () => WalletInstance[]][] = [
// ['with no wallets', () => []],
['with no wallets', () => []],
['with single wallet', () => oneWallet],
['with multiple wallets', () => twoWallets],
]
it('with no signers and empty addresses supplied', async () => {
const bw = await buildBoundWitness([])
expect(addressesContainsAny(bw, [])).toBeFalse() // No signers and no addresses should return false
expect(addressesContainsAny(bw, [])).toBeTrue() // No signers and no addresses should return true
})
describe.each(cases)('%s', (_, wallets) => {
let addresses: Address[]
Expand All @@ -50,7 +50,7 @@ describe('addressesContainsAny', () => {
})
describe('returns false', () => {
const cases: [string, () => WalletInstance[]][] = [
['with no wallets', () => []],
// ['with no wallets', () => []],
['with single wallet', () => oneWallet],
['with multiple wallets', () => twoWallets],
]
Expand Down

0 comments on commit cad3526

Please sign in to comment.