-
Notifications
You must be signed in to change notification settings - Fork 5
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
70c81d7
commit 2bf31d1
Showing
7 changed files
with
399 additions
and
167 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { z } from 'zod'; | ||
|
||
const bnsV2NameSchema = z.object({ | ||
full_name: z.string(), | ||
name_string: z.string(), | ||
namespace_string: z.string(), | ||
owner: z.string(), | ||
registered_at: z.string(), | ||
renewal_height: z.string(), | ||
stx_burn: z.string(), | ||
revoked: z.boolean(), | ||
}); | ||
|
||
export const bnsV2NamesByAddressSchema = z.object({ | ||
total: z.number(), | ||
current_burn_block: z.number(), | ||
limit: z.number(), | ||
offset: z.number(), | ||
names: z.array(bnsV2NameSchema), | ||
}); |
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,57 @@ | ||
import axios from 'axios'; | ||
import { getPrimaryName } from 'bns-v2-sdk'; | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { fetchNamesForAddress } from './bns.utils'; | ||
|
||
vi.mock('axios'); | ||
vi.mock('bns-v2-sdk'); | ||
|
||
describe('bns.utils', () => { | ||
describe('fetchNamesForAddress', () => { | ||
const mockAddress = 'ST123'; | ||
const mockSignal = new AbortController().signal; | ||
|
||
it('returns single name without fetching primary name', async () => { | ||
vi.mocked(axios.get).mockResolvedValueOnce({ | ||
data: { names: [{ full_name: 'test.btc' }] }, | ||
}); | ||
|
||
const result = await fetchNamesForAddress({ | ||
address: mockAddress, | ||
signal: mockSignal, | ||
network: 'mainnet', | ||
}); | ||
|
||
expect(result).toEqual({ names: ['test.btc'] }); | ||
expect(getPrimaryName).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('orders primary name first when multiple names exist', async () => { | ||
vi.mocked(axios.get).mockResolvedValueOnce({ | ||
data: { | ||
names: [ | ||
{ full_name: 'secondary.btc' }, | ||
{ full_name: 'primary.btc' }, | ||
{ full_name: 'another.btc' }, | ||
], | ||
}, | ||
}); | ||
|
||
vi.mocked(getPrimaryName).mockResolvedValueOnce({ | ||
name: 'primary', | ||
namespace: 'btc', | ||
}); | ||
|
||
const result = await fetchNamesForAddress({ | ||
address: mockAddress, | ||
signal: mockSignal, | ||
network: 'mainnet', | ||
}); | ||
|
||
expect(result).toEqual({ | ||
names: ['primary.btc', 'secondary.btc', 'another.btc'], | ||
}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.