From 7d257b76730e54b524fc3bc3d163d6f6a55af7ed Mon Sep 17 00:00:00 2001 From: Maayan Date: Thu, 28 Mar 2024 17:57:21 -0400 Subject: [PATCH] Change ANS queries return types (#343) change ans queries return types --- CHANGELOG.md | 2 ++ src/api/ans.ts | 12 ++++++------ src/internal/ans.ts | 11 +++++++---- tests/e2e/ans/ans.test.ts | 29 +++++++++++++++++++---------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ecd0884b..a58ce73ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/api/ans.ts b/src/api/ans.ts index 87803747e..55a5a0b0a 100644 --- a/src/api/ans.ts +++ b/src/api/ans.ts @@ -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, @@ -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"; @@ -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 { + async getOwnerAddress(args: { name: string }): Promise { return getOwnerAddress({ aptosConfig: this.config, ...args }); } @@ -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 { + async getTargetAddress(args: { name: string }): Promise { return getTargetAddress({ aptosConfig: this.config, ...args }); } diff --git a/src/internal/ans.ts b/src/internal/ans.ts index 212d1c842..dd268f0c8 100644 --- a/src/internal/ans.ts +++ b/src/internal/ans.ts @@ -94,7 +94,10 @@ const unwrapOption = (option: any): T | undefined => { return undefined; }; -export async function getOwnerAddress(args: { aptosConfig: AptosConfig; name: string }): Promise { +export async function getOwnerAddress(args: { + aptosConfig: AptosConfig; + name: string; +}): Promise { const { aptosConfig, name } = args; const routerAddress = getRouterAddress(aptosConfig); const { domainName, subdomainName } = isValidANSName(name); @@ -109,7 +112,7 @@ export async function getOwnerAddress(args: { aptosConfig: AptosConfig; name: st const owner = unwrapOption(res[0]); - return owner ? AccountAddress.from(owner).toString() : undefined; + return owner ? AccountAddress.from(owner) : undefined; } export interface RegisterNameParameters { @@ -289,7 +292,7 @@ export async function setPrimaryName(args: { export async function getTargetAddress(args: { aptosConfig: AptosConfig; name: string; -}): Promise { +}): Promise { const { aptosConfig, name } = args; const routerAddress = getRouterAddress(aptosConfig); const { domainName, subdomainName } = isValidANSName(name); @@ -303,7 +306,7 @@ export async function getTargetAddress(args: { }); const target = unwrapOption(res[0]); - return target ? AccountAddress.from(target).toString() : undefined; + return target ? AccountAddress.from(target) : undefined; } export async function setTargetAddress(args: { diff --git a/tests/e2e/ans/ans.test.ts b/tests/e2e/ans/ans.test.ts index 4c227c4a4..f4c05ad82 100644 --- a/tests/e2e/ans/ans.test.ts +++ b/tests/e2e/ans/ans.test.ts @@ -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"; @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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()); }); }); @@ -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(); @@ -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, @@ -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 () => { @@ -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, @@ -374,7 +383,7 @@ describe("ANS", () => { }), ); addr = await aptos.getTargetAddress({ name }); - expect(addr).toEqual(bob.accountAddress.toString()); + expect(addr?.toString()).toEqual(bob.accountAddress.toString()); }); });