diff --git a/src/common/io.ts b/src/common/io.ts index 3c38ecec..e1b91bd0 100644 --- a/src/common/io.ts +++ b/src/common/io.ts @@ -26,6 +26,8 @@ import { AoGatewayWithAddress, AoJoinNetworkParams, AoMessageResult, + AoPrimaryName, + AoPrimaryNameRequest, AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoWeightedObserver, @@ -58,7 +60,11 @@ import { } from '../types/io.js'; import { AoSigner, mIOToken } from '../types/token.js'; import { createAoSigner } from '../utils/ao.js'; -import { getCurrentBlockUnixTimestampMs, pruneTags } from '../utils/arweave.js'; +import { + getCurrentBlockUnixTimestampMs, + paginationParamsToTags, + pruneTags, +} from '../utils/arweave.js'; import { defaultArweave } from './arweave.js'; import { AOProcess } from './contracts/ao-process.js'; import { InvalidContractConfigurationError } from './error.js'; @@ -200,16 +206,11 @@ export class IOReadable implements AoIORead { async getArNSRecords( params?: PaginationParams, ): Promise> { - const allTags = [ - { name: 'Action', value: 'Paginated-Records' }, - { name: 'Cursor', value: params?.cursor?.toString() }, - { name: 'Limit', value: params?.limit?.toString() }, - { name: 'Sort-By', value: params?.sortBy }, - { name: 'Sort-Order', value: params?.sortOrder }, - ]; - return this.process.read>({ - tags: pruneTags(allTags), + tags: [ + { name: 'Action', value: 'Paginated-Records' }, + ...paginationParamsToTags(params), + ], }); } @@ -246,16 +247,11 @@ export class IOReadable implements AoIORead { async getBalances( params?: PaginationParams, ): Promise> { - const allTags = [ - { name: 'Action', value: 'Paginated-Balances' }, - { name: 'Cursor', value: params?.cursor?.toString() }, - { name: 'Limit', value: params?.limit?.toString() }, - { name: 'Sort-By', value: params?.sortBy }, - { name: 'Sort-Order', value: params?.sortOrder }, - ]; - return this.process.read>({ - tags: pruneTags(allTags), + tags: [ + { name: 'Action', value: 'Paginated-Balances' }, + ...paginationParamsToTags(params), + ], }); } @@ -278,16 +274,11 @@ export class IOReadable implements AoIORead { async getVaults( params?: PaginationParams, ): Promise> { - const allTags = [ - { name: 'Action', value: 'Paginated-Vaults' }, - { name: 'Cursor', value: params?.cursor?.toString() }, - { name: 'Limit', value: params?.limit?.toString() }, - { name: 'Sort-By', value: params?.sortBy }, - { name: 'Sort-Order', value: params?.sortOrder }, - ]; - return this.process.read>({ - tags: pruneTags(allTags), + tags: [ + { name: 'Action', value: 'Paginated-Vaults' }, + ...paginationParamsToTags(params), + ], }); } @@ -308,17 +299,12 @@ export class IOReadable implements AoIORead { address, ...pageParams }): Promise> { - const allTags = [ - { name: 'Action', value: 'Paginated-Delegates' }, - { name: 'Address', value: address }, - { name: 'Cursor', value: pageParams?.cursor?.toString() }, - { name: 'Limit', value: pageParams?.limit?.toString() }, - { name: 'Sort-By', value: pageParams?.sortBy }, - { name: 'Sort-Order', value: pageParams?.sortOrder }, - ]; - return this.process.read>({ - tags: pruneTags(allTags), + tags: [ + { name: 'Action', value: 'Paginated-Delegates' }, + { name: 'Address', value: address }, + ...paginationParamsToTags(pageParams), + ], }); } @@ -330,33 +316,23 @@ export class IOReadable implements AoIORead { } & PaginationParams): Promise< PaginationResult > { - const allTags = [ - { name: 'Action', value: 'Paginated-Allowed-Delegates' }, - { name: 'Address', value: address }, - { name: 'Cursor', value: pageParams?.cursor?.toString() }, - { name: 'Limit', value: pageParams?.limit?.toString() }, - { name: 'Sort-Order', value: pageParams?.sortOrder }, - // note: sortBy is omitted because it's not supported for this action as table is an of addresses - ]; - return this.process.read>({ - tags: pruneTags(allTags), + tags: [ + { name: 'Action', value: 'Paginated-Allowed-Delegates' }, + { name: 'Address', value: address }, + ...paginationParamsToTags(pageParams), + ], }); } async getGateways( pageParams?: PaginationParams, ): Promise> { - const allTags = [ - { name: 'Action', value: 'Paginated-Gateways' }, - { name: 'Cursor', value: pageParams?.cursor?.toString() }, - { name: 'Limit', value: pageParams?.limit?.toString() }, - { name: 'Sort-By', value: pageParams?.sortBy }, - { name: 'Sort-Order', value: pageParams?.sortOrder }, - ]; - return this.process.read>({ - tags: pruneTags(allTags), + tags: [ + { name: 'Action', value: 'Paginated-Gateways' }, + ...paginationParamsToTags(pageParams), + ], }); } @@ -430,16 +406,7 @@ export class IOReadable implements AoIORead { name: 'Timestamp', value: (epoch as { timestamp?: number })?.timestamp?.toString() ?? - ( - await this.arweave.blocks - .getCurrent() - .then((block) => { - return { timestamp: block.timestamp * 1000 }; - }) - .catch(() => { - return { timestamp: `${Date.now()}` }; // fallback to current time - }) - ).timestamp.toString(), + (await getCurrentBlockUnixTimestampMs(this.arweave)).toString(), }, { name: 'Epoch-Index', @@ -559,16 +526,11 @@ export class IOReadable implements AoIORead { async getArNSAuctions( params?: PaginationParams, ): Promise> { - const allTags = [ - { name: 'Action', value: 'Auctions' }, - { name: 'Cursor', value: params?.cursor?.toString() }, - { name: 'Limit', value: params?.limit?.toString() }, - { name: 'Sort-By', value: params?.sortBy }, - { name: 'Sort-Order', value: params?.sortOrder }, - ]; - return this.process.read>({ - tags: pruneTags(allTags), + tags: [ + { name: 'Action', value: 'Auctions' }, + ...paginationParamsToTags(params), + ], }); } @@ -644,16 +606,76 @@ export class IOReadable implements AoIORead { ): Promise> { const allTags = [ { name: 'Action', value: 'Paginated-Delegations' }, - { name: 'Cursor', value: params.cursor?.toString() }, - { name: 'Limit', value: params.limit?.toString() }, - { name: 'Sort-By', value: params.sortBy }, - { name: 'Sort-Order', value: params.sortOrder }, { name: 'Address', value: params.address }, + ...paginationParamsToTags(params), ]; + return this.process.read>({ tags: pruneTags(allTags), }); } + + async getPrimaryNameRequest( + params: + | { + initiator: WalletAddress; + } + | { + name: string; + }, + ): Promise { + const allTags = [ + { name: 'Action', value: 'Primary-Name-Request' }, + { name: 'Name', value: (params as { name: string }).name }, + { + name: 'Initiator', + value: (params as { initiator: WalletAddress }).initiator, + }, + ]; + + return this.process.read({ + tags: allTags, + }); + } + + async getPrimaryNameRequests( + params: PaginationParams, + ): Promise> { + return this.process.read>({ + tags: [ + { name: 'Action', value: 'Primary-Name-Requests' }, + ...paginationParamsToTags(params), + ], + }); + } + + async getPrimaryName( + params: { address: WalletAddress } | { name: string }, + ): Promise { + const allTags = [ + { name: 'Action', value: 'Primary-Name' }, + { + name: 'Address', + value: (params as { address: WalletAddress })?.address, + }, + { name: 'Name', value: (params as { name: string })?.name }, + ]; + + return this.process.read({ + tags: pruneTags(allTags), + }); + } + + async getPrimaryNames( + params: PaginationParams, + ): Promise> { + return this.process.read>({ + tags: [ + { name: 'Action', value: 'Primary-Names' }, + ...paginationParamsToTags(params), + ], + }); + } } export class IOWriteable extends IOReadable implements AoIOWrite { @@ -1142,4 +1164,14 @@ export class IOWriteable extends IOReadable implements AoIOWrite { tags: pruneTags(allTags), }); } + + async requestPrimaryName(params: { name: string }): Promise { + return this.process.send({ + signer: this.signer, + tags: [ + { name: 'Action', value: 'Primary-Name-Request' }, + { name: 'Name', value: params.name }, + ], + }); + } } diff --git a/src/types/common.ts b/src/types/common.ts index f2fde650..546beeed 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -57,6 +57,18 @@ export type WriteParameters = WithSigner< export type AoMessageResult = { id: string }; +export type AoPrimaryNameRequest = { + name: string; + startTimestamp: Timestamp; + endTimestamp: Timestamp; +}; + +export type AoPrimaryName = { + owner: WalletAddress; + name: string; + startTimestamp: Timestamp; +}; + // Utility type to require at least one of the fields export type AtLeastOne< T, diff --git a/src/types/io.ts b/src/types/io.ts index 4576dd1b..7ba31750 100644 --- a/src/types/io.ts +++ b/src/types/io.ts @@ -17,6 +17,8 @@ import { AOProcess } from '../common/index.js'; import { validateArweaveId } from '../utils/arweave.js'; import { AoMessageResult, + AoPrimaryName, + AoPrimaryNameRequest, AtLeastOne, BlockHeight, ProcessId, @@ -433,6 +435,20 @@ export interface AoIORead { address: WalletAddress; vaultId: string; }): Promise; + getPrimaryNameRequest( + params: { initiator: WalletAddress } | { name: string }, + ): Promise; + getPrimaryNameRequests( + params: PaginationParams & { + initiator?: WalletAddress; + }, + ): Promise>; + getPrimaryName( + params: { address: WalletAddress } | { name: string }, + ): Promise; + getPrimaryNames( + params?: PaginationParams, + ): Promise>; } export interface AoIOWrite extends AoIORead { @@ -545,6 +561,7 @@ export interface AoIOWrite extends AoIORead { }, options?: WriteOptions, ): Promise; + requestPrimaryName(params: { name: string }): Promise; } // Typeguard functions diff --git a/src/utils/arweave.ts b/src/utils/arweave.ts index 36ed72ce..972847d7 100644 --- a/src/utils/arweave.ts +++ b/src/utils/arweave.ts @@ -17,6 +17,7 @@ import Arweave from 'arweave'; import { ARWEAVE_TX_REGEX } from '../constants.js'; import { BlockHeight, Timestamp } from '../types/common.js'; +import { PaginationParams } from '../types/io.js'; export const validateArweaveId = (id: string): boolean => { return ARWEAVE_TX_REGEX.test(id); @@ -49,3 +50,16 @@ export const getCurrentBlockUnixTimestampMs = async ( return Date.now(); // fallback to current time }); }; + +export const paginationParamsToTags = ( + params?: PaginationParams, +): { name: string; value: string }[] => { + const tags = [ + { name: 'Cursor', value: params?.cursor?.toString() }, + { name: 'Limit', value: params?.limit?.toString() }, + { name: 'Sort-By', value: params?.sortBy?.toString() }, + { name: 'Sort-Order', value: params?.sortOrder?.toString() }, + ]; + + return pruneTags(tags); +}; diff --git a/tests/e2e/cjs/index.test.js b/tests/e2e/cjs/index.test.js index 7af75f4b..52d3a393 100644 --- a/tests/e2e/cjs/index.test.js +++ b/tests/e2e/cjs/index.test.js @@ -1,11 +1,15 @@ -const { describe, it, before, after } = require('node:test'); -const { DockerComposeEnvironment, Wait } = require('testcontainers'); -const assert = require('node:assert/strict'); -const fs = require('node:fs'); /** + * + * NOTE: these tests are just to validate the clients load with a CJS configuration. + * + * They only need to be extended when new clients or signers are introduced. + * * Ensure that npm link has been ran prior to running these tests * (simply running npm run test:integration will ensure npm link is ran) */ +const { describe, it } = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); const { IO, ioDevnetProcessId, @@ -16,11 +20,12 @@ const { IOWriteable, AoANTWriteable, AoANTRegistryWriteable, + AoANTRegistryReadable, + AoANTReadable, AOProcess, + IOReadable, } = require('@ar.io/sdk'); -const { connect } = require('@permaweb/aoconnect'); -const projectRootPath = process.cwd(); const testWalletJSON = fs.readFileSync('../test-wallet.json', { encoding: 'utf-8', }); @@ -29,383 +34,59 @@ const signers = [ new ArweaveSigner(testWallet), createAoSigner(new ArweaveSigner(testWallet)), ]; - -const aoClient = connect({ - CU_URL: 'http://localhost:6363', -}); - -const io = IO.init({ - process: new AOProcess({ - processId: process.env.IO_PROCESS_ID || ioDevnetProcessId, - ao: aoClient, - }), -}); - describe('e2e cjs tests', async () => { - describe('IO', async () => { - let compose; - before(async () => { - compose = await new DockerComposeEnvironment( - projectRootPath, - '../docker-compose.test.yml', - ) - .withBuild() - .withWaitStrategy('ao-cu-1', Wait.forHttp('/', 6363)) - .up(['ao-cu']); - }); - - after(async () => { - await compose.down(); - }); - it('should be able to get the process information', async () => { - const epoch = await io.getInfo(); - assert.ok(epoch); - }); - - it('should be able to get the total token supply', async () => { - const tokenSupply = await io.getTokenSupply(); - assert.ok(tokenSupply); - }); - - it('should be able to get first set of arns records', async () => { - const records = await io.getArNSRecords(); - assert.ok(records); - assert(records.limit === 100); - assert(records.sortOrder === 'desc'); - assert(records.sortBy === 'startTimestamp'); - assert(typeof records.totalItems === 'number'); - assert(typeof records.sortBy === 'string'); - assert(typeof records.sortOrder === 'string'); - assert(typeof records.limit === 'number'); - assert(typeof records.hasMore === 'boolean'); - if (records.nextCursor) { - assert(typeof records.nextCursor === 'string'); - } - assert(Array.isArray(records.items)); - records.items.forEach((record) => { - assert(typeof record.processId === 'string'); - assert(typeof record.name === 'string'); - assert(typeof record.startTimestamp === 'number'); - assert(['lease', 'permabuy'].includes(record.type)); - assert(typeof record.undernameLimit === 'number'); - }); - }); - - it('should be able to return a specific page of arns records', async () => { - const records = await io.getArNSRecords({ - cursor: 'ardrive', - limit: 5, - sortOrder: 'desc', - sortBy: 'name', - }); - assert.ok(records); - assert(records.limit === 5); - assert(records.sortOrder === 'desc'); - assert(records.sortBy === 'name'); - assert(typeof records.totalItems === 'number'); - assert(typeof records.sortBy === 'string'); - assert(typeof records.sortOrder === 'string'); - assert(typeof records.limit === 'number'); - assert(typeof records.hasMore === 'boolean'); - if (records.nextCursor) { - assert(typeof records.nextCursor === 'string'); - } - assert(Array.isArray(records.items)); - records.items.forEach((record) => { - assert(typeof record.processId === 'string'); - assert(typeof record.name === 'string'); - assert(typeof record.startTimestamp === 'number'); - assert(['lease', 'permabuy'].includes(record.type)); - assert(typeof record.undernameLimit === 'number'); - }); - }); - it('should be able to get a single arns record', async () => { - const arns = await io.getArNSRecord({ name: 'ardrive' }); - assert.ok(arns); - }); - - it('should be able to get the current epoch using getCurrentEpoch', async () => { - const epoch = await io.getCurrentEpoch(); - assert.ok(epoch); - }); - - it('should be able to get the current epoch using getEpoch', async () => { - const epoch = await io.getEpoch({ epochIndex: 0 }); - assert.ok(epoch); - }); - - it('should be able to get epoch-settings', async () => { - const epochSettings = await io.getEpochSettings(); - assert.ok(epochSettings); - }); - - it('should be able to get reserved names', async () => { - const reservedNames = await io.getArNSReservedNames(); - assert.ok(reservedNames); - }); - - it('should be able to get a single reserved name', async () => { - const reservedNames = await io.getArNSReservedNames({ name: 'www ' }); - assert.ok(reservedNames); - }); - - it('should be able to get first page of gateways', async () => { - const gateways = await io.getGateways(); - assert.ok(gateways); - assert(gateways.limit === 100); - assert(gateways.sortOrder === 'desc'); - assert(gateways.sortBy === 'startTimestamp'); - assert(typeof gateways.totalItems === 'number'); - assert(typeof gateways.sortBy === 'string'); - assert(typeof gateways.sortOrder === 'string'); - assert(typeof gateways.limit === 'number'); - assert(typeof gateways.hasMore === 'boolean'); - if (gateways.nextCursor) { - assert(typeof gateways.nextCursor === 'string'); - } - assert(Array.isArray(gateways.items)); - gateways.items.forEach((gateway) => { - assert(typeof gateway.gatewayAddress === 'string'); - assert(typeof gateway.observerAddress === 'string'); - assert(typeof gateway.startTimestamp === 'number'); - assert(typeof gateway.operatorStake === 'number'); - assert(typeof gateway.totalDelegatedStake === 'number'); - assert(typeof gateway.settings === 'object'); - assert(typeof gateway.weights === 'object'); - assert(typeof gateway.weights.normalizedCompositeWeight === 'number'); - assert(typeof gateway.weights.compositeWeight === 'number'); - assert(typeof gateway.weights.stakeWeight === 'number'); - assert(typeof gateway.weights.tenureWeight === 'number'); - assert(typeof gateway.weights.observerRewardRatioWeight === 'number'); - assert(typeof gateway.weights.gatewayRewardRatioWeight === 'number'); - }); - }); - - it('should be able to get a specific page of gateways', async () => { - const gateways = await io.getGateways({ - cursor: 1000000, - limit: 1, - sortBy: 'operatorStake', - sortOrder: 'desc', - }); - assert.ok(gateways); - assert(gateways.limit === 1); - assert(gateways.sortOrder === 'desc'); - assert(gateways.sortBy === 'operatorStake'); - assert(typeof gateways.totalItems === 'number'); - assert(typeof gateways.sortBy === 'string'); - assert(typeof gateways.sortOrder === 'string'); - assert(typeof gateways.limit === 'number'); - assert(typeof gateways.hasMore === 'boolean'); - if (gateways.nextCursor) { - assert(typeof gateways.nextCursor === 'string'); - } - assert(Array.isArray(gateways.items)); - gateways.items.forEach((gateway) => { - assert(typeof gateway.gatewayAddress === 'string'); - assert(typeof gateway.observerAddress === 'string'); - assert(typeof gateway.startTimestamp === 'number'); - assert(typeof gateway.operatorStake === 'number'); - assert(typeof gateway.totalDelegatedStake === 'number'); - assert(typeof gateway.settings === 'object'); - assert(typeof gateway.weights === 'object'); - assert(typeof gateway.weights.normalizedCompositeWeight === 'number'); - assert(typeof gateway.weights.compositeWeight === 'number'); - assert(typeof gateway.weights.stakeWeight === 'number'); - assert(typeof gateway.weights.tenureWeight === 'number'); - assert(typeof gateway.weights.observerRewardRatioWeight === 'number'); - assert(typeof gateway.weights.gatewayRewardRatioWeight === 'number'); - }); - }); - - it('should be able to get a single gateway', async () => { - const gateways = await io.getGateway({ - address: 'QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ', - }); - assert.ok(gateways); - }); - - it('should be able to get balances, defaulting to first page', async () => { - const balances = await io.getBalances(); - assert.ok(balances); - assert(balances.limit === 100); - assert(balances.sortOrder === 'desc'); - assert(balances.sortBy === 'balance'); - assert(typeof balances.totalItems === 'number'); - assert(typeof balances.sortBy === 'string'); - assert(typeof balances.sortOrder === 'string'); - assert(typeof balances.limit === 'number'); - assert(typeof balances.hasMore === 'boolean'); - if (balances.nextCursor) { - assert(typeof gateways.nextCursor === 'string'); - } - assert(Array.isArray(balances.items)); - balances.items.forEach((wallet) => { - assert(typeof wallet.address === 'string'); - assert(typeof wallet.balance === 'number'); - }); - }); - - it('should be able to get balances of a specific to first page', async () => { - const balances = await io.getBalances({ - cursor: 1000000, - limit: 1, - sortBy: 'address', - sortOrder: 'asc', - }); - assert.ok(balances); - assert(balances.limit === 1); - assert(balances.sortOrder === 'asc'); - assert(balances.sortBy === 'address'); - assert(typeof balances.totalItems === 'number'); - assert(typeof balances.sortBy === 'string'); - assert(typeof balances.sortOrder === 'string'); - assert(typeof balances.limit === 'number'); - assert(typeof balances.hasMore === 'boolean'); - if (balances.nextCursor) { - assert(typeof balances.nextCursor === 'string'); - } - assert(Array.isArray(balances.items)); - balances.items.forEach((wallet) => { - assert(typeof wallet.address === 'string'); - assert(typeof wallet.balance === 'number'); - }); - }); - - it('should be able to get a single balance', async () => { - const balances = await io.getBalance({ - address: 'QGWqtJdLLgm2ehFWiiPzMaoFLD50CnGuzZIPEdoDRGQ', - }); - assert.ok(balances); - }); - - it('should be able to get prescribed names', async () => { - const prescribedNames = await io.getPrescribedNames(); - assert.ok(prescribedNames); - }); - - it('should return the prescribed observers for a given epoch', async () => { - const observers = await io.getPrescribedObservers(); - assert.ok(observers); - for (const observer of observers) { - assert(typeof observer.gatewayAddress === 'string'); - assert(typeof observer.observerAddress === 'string'); - assert(typeof observer.stake === 'number'); - assert(typeof observer.startTimestamp === 'number'); - assert(typeof observer.stakeWeight === 'number'); - assert(typeof observer.tenureWeight === 'number'); - assert(typeof observer.gatewayRewardRatioWeight === 'number'); - assert(typeof observer.observerRewardRatioWeight === 'number'); - assert(typeof observer.compositeWeight === 'number'); - } - }); - - it('should be able to get token cost for leasing a name', async () => { - const tokenCost = await io.getTokenCost({ - intent: 'Buy-Record', - name: 'new-name', - years: 1, - }); - assert.ok(tokenCost); - }); - - it('should be able to get token cost for buying a name name', async () => { - const tokenCost = await io.getTokenCost({ - intent: 'Buy-Record', - name: 'new-name', - type: 'permabuy', + describe('IO client works ', async () => { + it('should able to instantiate IOReadable', async () => { + const io = IO.init({ + process: new AOProcess({ + processId: process.env.IO_PROCESS_ID || ioDevnetProcessId, + }), }); - assert.ok(tokenCost); - }); - - it('should be able to get registration fees', async () => { - const registrationFees = await io.getRegistrationFees(); - assert(registrationFees); - assert.equal(Object.keys(registrationFees).length, 51); - for (const nameLength of Object.keys(registrationFees)) { - // assert lease is length of 5 - assert(registrationFees[nameLength]['lease']['1'] > 0); - assert(registrationFees[nameLength]['lease']['2'] > 0); - assert(registrationFees[nameLength]['lease']['3'] > 0); - assert(registrationFees[nameLength]['lease']['4'] > 0); - assert(registrationFees[nameLength]['lease']['5'] > 0); - assert(registrationFees[nameLength]['permabuy'] > 0); - } + assert(io instanceof IOReadable); }); - it('should be able to create IOWriteable with valid signers', async () => { - for (const signer of signers) { - const io = IO.init({ signer }); + for (const signer of signers) { + it(`should be able to instantiate IOWriteable with ${signer.constructor.name}`, async () => { + const io = IO.init({ + process: new AOProcess({ + processId: process.env.IO_PROCESS_ID || ioDevnetProcessId, + }), + signer, + }); assert(io instanceof IOWriteable); - } - }); - - it('should be able to get paginated vaults', async () => { - const vaults = await io.getVaults(); - assert.ok(vaults); - assert(vaults.limit === 100); - assert(vaults.sortOrder === 'desc'); - assert(vaults.sortBy === 'address'); - assert(typeof vaults.totalItems === 'number'); - assert(typeof vaults.sortBy === 'string'); - assert(typeof vaults.sortOrder === 'string'); - assert(typeof vaults.limit === 'number'); - assert(typeof vaults.hasMore === 'boolean'); - if (vaults.nextCursor) { - assert(typeof vaults.nextCursor === 'string'); - } - assert(Array.isArray(vaults.items)); - vaults.items.forEach( - ({ address, vaultId, balance, endTimestamp, startTimestamp }) => { - assert(typeof address === 'string'); - assert(typeof balance === 'number'); - assert(typeof startTimestamp === 'number'); - assert(typeof endTimestamp === 'number'); - assert(typeof vaultId === 'string'); - }, - ); - }); + }); + } }); describe('ANTRegistry', async () => { - const registry = ANTRegistry.init(); - const address = '7waR8v4STuwPnTck1zFVkQqJh5K9q9Zik4Y5-5dV7nk'; - - it('should retrieve ids from registry', async () => { - const affiliatedAnts = await registry.accessControlList({ address }); - assert(Array.isArray(affiliatedAnts.Owned)); - assert(Array.isArray(affiliatedAnts.Controlled)); + it('should be able to instantiate AoANTRegistryWriteable', async () => { + for (const signer of signers) { + const registry = ANTRegistry.init({ signer }); + assert(registry instanceof AoANTRegistryWriteable); + } }); - it('should be able to create AoANTRegistryWriteable with valid signers', async () => { + it('should be able to instantiate AoANTRegistryReadable', async () => { for (const signer of signers) { - const registry = ANTRegistry.init({ - signer, - }); - assert(registry instanceof AoANTRegistryWriteable); + const registry = ANTRegistry.init(); + assert(registry instanceof AoANTRegistryReadable); } }); }); describe('ANT', async () => { const processId = 'YcxE5IbqZYK72H64ELoysxiJ-0wb36deYPv55wgl8xo'; - it('should be able to create ANTWriteable with valid signers', async () => { + it('should be able to instantiate AoANTWriteable', async () => { for (const signer of signers) { - const ant = ANT.init({ - processId, - signer, - strict: true, - ao: aoClient, - }); - const strictAnt = ANT.init({ - processId, - signer, - strict: true, - ao: aoClient, - }); - + const ant = ANT.init({ processId, signer }); assert(ant instanceof AoANTWriteable); - assert(strictAnt instanceof AoANTWriteable); + } + }); + + it('should be able to instantiate AoANTReadable', async () => { + for (const signer of signers) { + const ant = ANT.init({ processId }); + assert(ant instanceof AoANTReadable); } }); }); diff --git a/tests/e2e/esm/index.test.js b/tests/e2e/esm/index.test.js index c43bb067..e428190c 100644 --- a/tests/e2e/esm/index.test.js +++ b/tests/e2e/esm/index.test.js @@ -1,3 +1,7 @@ +/** + * Ensure that npm link has been ran prior to running these tests + * (simply running npm run test:integration will ensure npm link is ran) + */ import { ANT, ANTRegistry, @@ -28,11 +32,6 @@ const signers = [ createAoSigner(new ArweaveSigner(testWallet)), ]; -/** - * Ensure that npm link has been ran prior to running these tests - * (simply running npm run test:integration will ensure npm link is ran) - */ - const aoClient = connect({ CU_URL: 'http://localhost:6363', }); @@ -596,6 +595,38 @@ describe('e2e esm tests', async () => { }, ); }); + + it('should be able to get paginated primary names', async () => { + const primaryNames = await io.getPrimaryNames(); + assert.ok(primaryNames); + }); + + it('should be able to get paginated primary names with custom sort', async () => { + const primaryNames = await io.getPrimaryNames({ + sortBy: 'startTimestamp', + sortOrder: 'desc', + }); + assert.ok(primaryNames); + }); + + it('should be able to get a specific primary name', async () => { + const primaryName = await io.getPrimaryName({ + address: 'N4h8M9A9hasa3tF47qQyNvcKjm4APBKuFs7vqUVm-SI', + }); + assert.ok(primaryName); + }); + + it('should be able to get a specific primary name by name', async () => { + const primaryName = await io.getPrimaryName({ + name: 'new-name', + }); + assert.ok(primaryName); + }); + + it('should be able to get paginated primary name requests', async () => { + const primaryNameRequests = await io.getPrimaryNameRequests(); + assert.ok(primaryNameRequests); + }); }); describe('ANTRegistry', async () => {