Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update SDK's listAddressTransaction #259

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 157 additions & 105 deletions src/client/api.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/coinbase/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class Address {
}: ListTransactionsOptions): Promise<ListTransactionsResult> {
const txnList: Transaction[] = [];

const response = await Coinbase.apiClients.externalAddress!.listAddressTransactions(
const response = await Coinbase.apiClients.transactionHistory!.listAddressTransactions(
this.getNetworkId(),
this.getId(),
limit ? limit : undefined,
Expand Down
6 changes: 6 additions & 0 deletions src/coinbase/coinbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ContractInvocationsApiFactory,
BalanceHistoryApiFactory,
SmartContractsApiFactory,
TransactionHistoryApiFactory,
} from "../client";
import { BASE_PATH } from "./../client/base";
import { Configuration } from "./../client/configuration";
Expand Down Expand Up @@ -148,6 +149,11 @@ export class Coinbase {
Coinbase.apiClients.balanceHistory = BalanceHistoryApiFactory(config, basePath, axiosInstance);
Coinbase.apiClients.contractEvent = ContractEventsApiFactory(config, basePath, axiosInstance);
Coinbase.apiClients.smartContract = SmartContractsApiFactory(config, basePath, axiosInstance);
Coinbase.apiClients.transactionHistory = TransactionHistoryApiFactory(
config,
basePath,
axiosInstance,
);
Coinbase.apiKeyPrivateKey = privateKey;
Coinbase.useServerSigner = useServerSigner;
}
Expand Down
40 changes: 21 additions & 19 deletions src/coinbase/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,25 +407,6 @@ export type ExternalAddressAPIClient = {
options?: RawAxiosRequestConfig,
): AxiosPromise<Balance>;

/**
* List the transactions of a specific address.
*
* @summary Get address transactions
* @param networkId - The ID of the blockchain network
* @param addressId - The ID of the address to fetch transactions for.
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
* @param page - A cursor for pagination across multiple pages of results. Don\&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
* @param options - Override http request option.
* @throws {RequiredError}
*/
listAddressTransactions(
networkId: string,
addressId: string,
limit?: number,
page?: string,
options?: RawAxiosRequestConfig,
): AxiosPromise<AddressTransactionList>;

/**
* Request faucet funds to be sent to external address.
*
Expand Down Expand Up @@ -727,6 +708,7 @@ export type ApiClients = {
contractEvent?: ExternalSmartContractAPIClient;
contractInvocation?: ContractInvocationAPIClient;
balanceHistory?: BalanceHistoryApiClient;
transactionHistory?: TransactionHistoryApiClient;
smartContract?: SmartContractAPIClient;
};

Expand Down Expand Up @@ -1105,6 +1087,26 @@ export interface BalanceHistoryApiClient {
): AxiosPromise<AddressHistoricalBalanceList>;
}

export interface TransactionHistoryApiClient {
/**
* List the transactions of a specific address.
*
* @summary Get address transactions
* @param networkId - The ID of the blockchain network
* @param addressId - The ID of the address to fetch transactions for.
* @param limit - A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 10.
* @param page - A cursor for pagination across multiple pages of results. Don\&#39;t include this parameter on the first call. Use the next_page value returned in a previous response to request subsequent results.
* @param options - Override http request option.
* @throws {RequiredError}
*/
listAddressTransactions(
networkId: string,
addressId: string,
limit?: number,
page?: string,
options?: RawAxiosRequestConfig,
): AxiosPromise<AddressTransactionList>;
}
/**
* The domain for an EIP-712 typed data message payload.
*/
Expand Down
22 changes: 11 additions & 11 deletions src/tests/address_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
VALID_ADDRESS_MODEL,
mockReturnValue,
newAddressModel,
externalAddressApiMock,
balanceHistoryApiMock,
transactionHistoryApiMock,
} from "./utils";
import Decimal from "decimal.js";
import { randomUUID } from "crypto";
Expand Down Expand Up @@ -61,17 +61,17 @@ describe("Address", () => {
has_more: true,
next_page: "pageToken",
};
Coinbase.apiClients.externalAddress = externalAddressApiMock;
Coinbase.apiClients.externalAddress!.listAddressTransactions =
Coinbase.apiClients.transactionHistory = transactionHistoryApiMock;
Coinbase.apiClients.transactionHistory!.listAddressTransactions =
mockReturnValue(mockTransactionsResponse);
});

it("should return results with param", async () => {
const result = await address.listTransactions({ limit: 2, page: "page" });
expect(result.transactions.length).toEqual(2);
expect(result.transactions[0].blockHeight()).toEqual("12345");
expect(Coinbase.apiClients.externalAddress!.listAddressTransactions).toHaveBeenCalledTimes(1);
expect(Coinbase.apiClients.externalAddress!.listAddressTransactions).toHaveBeenCalledWith(
expect(Coinbase.apiClients.transactionHistory!.listAddressTransactions).toHaveBeenCalledTimes(1);
expect(Coinbase.apiClients.transactionHistory!.listAddressTransactions).toHaveBeenCalledWith(
address.getNetworkId(),
address.getId(),
2,
Expand All @@ -81,7 +81,7 @@ describe("Address", () => {
});

it("should return results without param", async () => {
Coinbase.apiClients.externalAddress!.listAddressTransactions = mockReturnValue({
Coinbase.apiClients.transactionHistory!.listAddressTransactions = mockReturnValue({
data: [
{
network_id: "base-sepolia",
Expand All @@ -98,8 +98,8 @@ describe("Address", () => {
const result = await address.listTransactions({});
expect(result.transactions.length).toEqual(1);
expect(result.transactions[0].blockHeight()).toEqual("12348");
expect(Coinbase.apiClients.externalAddress!.listAddressTransactions).toHaveBeenCalledTimes(1);
expect(Coinbase.apiClients.externalAddress!.listAddressTransactions).toHaveBeenCalledWith(
expect(Coinbase.apiClients.transactionHistory!.listAddressTransactions).toHaveBeenCalledTimes(1);
expect(Coinbase.apiClients.transactionHistory!.listAddressTransactions).toHaveBeenCalledWith(
address.getNetworkId(),
address.getId(),
undefined,
Expand All @@ -109,15 +109,15 @@ describe("Address", () => {
});

it("should return empty if no transactions found", async () => {
Coinbase.apiClients.externalAddress!.listAddressTransactions = mockReturnValue({
Coinbase.apiClients.transactionHistory!.listAddressTransactions = mockReturnValue({
data: [],
has_more: false,
next_page: "",
});
const result = await address.listTransactions({});
expect(result.transactions.length).toEqual(0);
expect(Coinbase.apiClients.externalAddress!.listAddressTransactions).toHaveBeenCalledTimes(1);
expect(Coinbase.apiClients.externalAddress!.listAddressTransactions).toHaveBeenCalledWith(
expect(Coinbase.apiClients.transactionHistory!.listAddressTransactions).toHaveBeenCalledTimes(1);
expect(Coinbase.apiClients.transactionHistory!.listAddressTransactions).toHaveBeenCalledWith(
address.getNetworkId(),
address.getId(),
undefined,
Expand Down
4 changes: 4 additions & 0 deletions src/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,10 @@ export const balanceHistoryApiMock = {
listAddressHistoricalBalance: jest.fn(),
};

export const transactionHistoryApiMock = {
listAddressTransactions: jest.fn(),
};

export const serverSignersApiMock = {
listServerSigners: jest.fn(),
};
Expand Down
Loading