-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddresses.test.ts
39 lines (31 loc) · 1.19 KB
/
addresses.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { describe, expect, it } from 'bun:test'
import { zeroAddress } from 'viem'
import { unprefixAddress, splitPrefixedAddress } from './addresses'
import { PrefixedAddress } from './types'
describe('splitPrefixedAddress', () => {
it('correctly splits a prefixed address with a chain shortName', () => {
expect(splitPrefixedAddress(`eth:${zeroAddress}`)).toEqual([1, zeroAddress])
})
it('correctly splits a prefixed address with eoa', () => {
expect(splitPrefixedAddress(`eoa:${zeroAddress}`)).toEqual([
undefined,
zeroAddress,
])
})
it('throws error when prefix chain shortName is unknown', () => {
expect(() =>
splitPrefixedAddress(`abc:${zeroAddress}` as PrefixedAddress)
).toThrow()
})
it('correctly splits a simple address', () => {
expect(splitPrefixedAddress(zeroAddress)).toEqual([undefined, zeroAddress])
})
})
describe('parsePrefixedAddress', () => {
it('returns the address part of a prefixed address', () => {
expect(unprefixAddress(`eth:${zeroAddress}`)).toEqual(zeroAddress)
})
it('is the identify function when the input is already an address', () => {
expect(unprefixAddress(zeroAddress)).toEqual(zeroAddress)
})
})