Skip to content

Commit

Permalink
Change ANS queries return types (#343)
Browse files Browse the repository at this point in the history
change ans queries return types
  • Loading branch information
0xmaayan authored Mar 28, 2024
1 parent 7ff9aea commit 7d257b7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ All notable changes to the Aptos TypeScript SDK will be captured in this file. T

# Unreleased

- [`Breaking`] Change `getOwnerAddress` and `getTargetAddress` return type to `AccountAddress`

# 1.11.0 (2024-03-26)

- Use indexer API via API Gateway
Expand Down
12 changes: 6 additions & 6 deletions src/api/ans.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Account, AccountAddressInput } from "../core";
import { Account, AccountAddress, AccountAddressInput } from "../core";
import {
RegisterNameParameters,
getExpiration,
Expand All @@ -22,7 +22,7 @@ import {
getDomainSubdomains,
GetDomainSubdomainsArgs,
} from "../internal/ans";
import { GetANSNameResponse, MoveAddressType } from "../types";
import { GetANSNameResponse } from "../types";
import { InputGenerateTransactionOptions, SimpleTransaction } from "../transactions/types";
import { AptosConfig } from "./aptosConfig";

Expand All @@ -43,9 +43,9 @@ export class ANS {
*
* @param args.name - A string of the name to retrieve
*
* @returns MoveAddressType if the name is owned, undefined otherwise
* @returns AccountAddress if the name is owned, undefined otherwise
*/
async getOwnerAddress(args: { name: string }): Promise<MoveAddressType | undefined> {
async getOwnerAddress(args: { name: string }): Promise<AccountAddress | undefined> {
return getOwnerAddress({ aptosConfig: this.config, ...args });
}

Expand Down Expand Up @@ -78,9 +78,9 @@ export class ANS {
*
* @param args.name - A string of the name: primary, primary.apt, secondary.primary, secondary.primary.apt, etc.
*
* @returns MoveAddressType if the name has a target, undefined otherwise
* @returns AccountAddress if the name has a target, undefined otherwise
*/
async getTargetAddress(args: { name: string }): Promise<MoveAddressType | undefined> {
async getTargetAddress(args: { name: string }): Promise<AccountAddress | undefined> {
return getTargetAddress({ aptosConfig: this.config, ...args });
}

Expand Down
11 changes: 7 additions & 4 deletions src/internal/ans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ const unwrapOption = <T>(option: any): T | undefined => {
return undefined;
};

export async function getOwnerAddress(args: { aptosConfig: AptosConfig; name: string }): Promise<string | undefined> {
export async function getOwnerAddress(args: {
aptosConfig: AptosConfig;
name: string;
}): Promise<AccountAddress | undefined> {
const { aptosConfig, name } = args;
const routerAddress = getRouterAddress(aptosConfig);
const { domainName, subdomainName } = isValidANSName(name);
Expand All @@ -109,7 +112,7 @@ export async function getOwnerAddress(args: { aptosConfig: AptosConfig; name: st

const owner = unwrapOption<MoveAddressType>(res[0]);

return owner ? AccountAddress.from(owner).toString() : undefined;
return owner ? AccountAddress.from(owner) : undefined;
}

export interface RegisterNameParameters {
Expand Down Expand Up @@ -289,7 +292,7 @@ export async function setPrimaryName(args: {
export async function getTargetAddress(args: {
aptosConfig: AptosConfig;
name: string;
}): Promise<MoveAddressType | undefined> {
}): Promise<AccountAddress | undefined> {
const { aptosConfig, name } = args;
const routerAddress = getRouterAddress(aptosConfig);
const { domainName, subdomainName } = isValidANSName(name);
Expand All @@ -303,7 +306,7 @@ export async function getTargetAddress(args: {
});

const target = unwrapOption<MoveAddressType>(res[0]);
return target ? AccountAddress.from(target).toString() : undefined;
return target ? AccountAddress.from(target) : undefined;
}

export async function setTargetAddress(args: {
Expand Down
29 changes: 19 additions & 10 deletions tests/e2e/ans/ans.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
// Copyright © Aptos Foundation
// SPDX-License-Identifier: Apache-2.0

import { Aptos, Network, Account, AnyRawTransaction, U8, AptosConfig, GetANSNameResponse } from "../../../src";
import {
Aptos,
Network,
Account,
AnyRawTransaction,
U8,
AptosConfig,
GetANSNameResponse,
AccountAddress,
} from "../../../src";
import { isValidANSName } from "../../../src/internal/ans";
import { generateTransaction } from "../../../src/internal/transactionSubmission";
import { publishAnsContract } from "./publishANSContracts";
Expand Down Expand Up @@ -212,7 +221,7 @@ describe("ANS", () => {
);

const owner = await aptos.getOwnerAddress({ name });
expect(owner).toEqual(alice.accountAddress.toString());
expect(owner?.toString()).toEqual(alice.accountAddress.toString());
});

test("it mints a domain name and gives it to the specified address", async () => {
Expand All @@ -230,7 +239,7 @@ describe("ANS", () => {
);

const owner = await aptos.getOwnerAddress({ name });
expect(owner).toEqual(bob.accountAddress.toString());
expect(owner?.toString()).toEqual(bob.accountAddress.toString());
});

test("it mints a subdomain name and gives it to the sender", async () => {
Expand All @@ -254,7 +263,7 @@ describe("ANS", () => {
);

const owner = await aptos.getOwnerAddress({ name: `${subdomainName}.${domainName}` });
expect(owner).toEqual(alice.accountAddress.toString());
expect(owner?.toString()).toEqual(alice.accountAddress.toString());
});

test("it mints a subdomain name and gives it to the specified address", async () => {
Expand Down Expand Up @@ -284,7 +293,7 @@ describe("ANS", () => {
);

const owner = await aptos.getOwnerAddress({ name: `${subdomainName}.${domainName}` });
expect(owner).toEqual(bob.accountAddress.toString());
expect(owner?.toString()).toEqual(bob.accountAddress.toString());
});
});

Expand All @@ -293,7 +302,7 @@ describe("ANS", () => {
let bob: Account;
let domainName: string;
let subdomainName: string;
let addr: string | undefined;
let addr: AccountAddress | undefined;

beforeEach(async () => {
alice = Account.generate();
Expand Down Expand Up @@ -327,7 +336,7 @@ describe("ANS", () => {
);

addr = await aptos.getTargetAddress({ name });
expect(addr).toEqual(alice.accountAddress.toString());
expect(addr?.toString()).toEqual(alice.accountAddress.toString());

await signAndSubmit(
alice,
Expand All @@ -338,7 +347,7 @@ describe("ANS", () => {
}),
);
addr = await aptos.getTargetAddress({ name });
expect(addr).toEqual(bob.accountAddress.toString());
expect(addr?.toString()).toEqual(bob.accountAddress.toString());
});

test("it sets and gets the target address for a subdomain", async () => {
Expand All @@ -363,7 +372,7 @@ describe("ANS", () => {
);

addr = await aptos.getTargetAddress({ name });
expect(addr).toEqual(alice.accountAddress.toString());
expect(addr?.toString()).toEqual(alice.accountAddress.toString());

await signAndSubmit(
alice,
Expand All @@ -374,7 +383,7 @@ describe("ANS", () => {
}),
);
addr = await aptos.getTargetAddress({ name });
expect(addr).toEqual(bob.accountAddress.toString());
expect(addr?.toString()).toEqual(bob.accountAddress.toString());
});
});

Expand Down

0 comments on commit 7d257b7

Please sign in to comment.