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

Expose toAddressId() method on Transaction class #158

Merged
merged 2 commits into from
Aug 15, 2024
Merged
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# Coinbase Node.js SDK Changelog

## [0.1.0]
## Unreleased

### Added

- Add historical_balances function for wallet: listing historical balances for default address of the wallet.
- Add toAddressId() method to Transaction class
- Remove "pending" status from StakingOperationStatusEnum

## [0.0.16] - 2024-08-14

Expand Down
1 change: 0 additions & 1 deletion src/client/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,6 @@ export interface StakingOperation {

export const StakingOperationStatusEnum = {
Initialized: 'initialized',
Pending: 'pending',
Complete: 'complete',
Failed: 'failed',
Unspecified: 'unspecified'
Expand Down
9 changes: 9 additions & 0 deletions src/coinbase/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ export class Transaction {
return this.model.from_address_id;
}

/**
* Returns the To Address ID for the Transaction if it's available.
*
* @returns The To Address ID
*/
toAddressId(): string | undefined {
return this.model.to_address_id;
}

/**
* Returns whether the Transaction is in a terminal State.
*
Expand Down
6 changes: 2 additions & 4 deletions src/tests/external_address_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ import {
externalAddressApiMock,
generateRandomHash,
getAssetMock,
mockEthereumValidator,
mockReturnValue,
newAddressModel,
stakeApiMock,
VALID_ACTIVE_VALIDATOR_LIST,
VALID_ADDRESS_MODEL,
validatorApiMock,
} from "./utils";
import {
Expand All @@ -21,6 +18,7 @@ import {
StakingOperation as StakingOperationModel,
StakingRewardFormat,
StakingRewardStateEnum,
StakingOperationStatusEnum,
} from "../client";
import Decimal from "decimal.js";
import { ExternalAddress } from "../coinbase/address/external_address";
Expand Down Expand Up @@ -70,7 +68,7 @@ describe("ExternalAddress", () => {
id: randomUUID(),
network_id: Coinbase.networks.EthereumHolesky,
address_id: "0x1234567890",
status: "pending",
status: StakingOperationStatusEnum.Initialized,
transactions: [
{
from_address_id: address.getId(),
Expand Down
7 changes: 5 additions & 2 deletions src/tests/staking_operation_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ describe("StakingOperation", () => {
it("return the the array of transactions", () => {
const op = new StakingOperation(VALID_STAKING_OPERATION_MODEL);
expect(op.getTransactions().length).toEqual(1);
expect(op.getStatus()).toEqual(StakingOperationStatusEnum.Pending);
expect(op.getTransactions()[0].toAddressId()).toEqual("dummy-to-address-id");
expect(op.getTransactions()[0].fromAddressId()).toEqual("dummy-from-address-id");
expect(op.getTransactions()[0].getTransactionHash()).toEqual("0xdummy-transaction-hash");
expect(op.getStatus()).toEqual(StakingOperationStatusEnum.Initialized);
});
});

Expand Down Expand Up @@ -123,7 +126,7 @@ describe("StakingOperation", () => {
it("all getters should work", async () => {
const stakingOperation = new StakingOperation(VALID_STAKING_OPERATION_MODEL);
expect(stakingOperation.getID()).toBe("some-id");
expect(stakingOperation.getStatus()).toBe(StakingOperationStatusEnum.Pending);
expect(stakingOperation.getStatus()).toBe(StakingOperationStatusEnum.Initialized);
expect(stakingOperation.isTerminalState()).toBe(false);
expect(stakingOperation.getTransactions().length).toBe(1);
expect(stakingOperation.getSignedVoluntaryExitMessages().length).toBe(0);
Expand Down
7 changes: 4 additions & 3 deletions src/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ export const VALID_STAKING_OPERATION_MODEL: StakingOperationModel = {
id: "some-id",
network_id: Coinbase.networks.EthereumHolesky,
address_id: "some-address-id",
status: "pending",
status: StakingOperationStatusEnum.Initialized,
transactions: [
{
network_id: Coinbase.networks.EthereumHolesky,
from_address_id: "0xdeadbeef",
from_address_id: "dummy-from-address-id",
to_address_id: "dummy-to-address-id",
unsigned_payload:
"7b2274797065223a22307832222c22636861696e4964223a2230783134613334222c226e6f6e63" +
"65223a22307830222c22746f223a22307834643965346633663464316138623566346637623166" +
Expand All @@ -188,7 +189,7 @@ export const VALID_STAKING_OPERATION_MODEL: StakingOperationModel = {
"2c2273223a22307830222c2279506172697479223a22307830222c2268617368223a2230783664" +
"633334306534643663323633653363396561396135656438646561346332383966613861363966" +
"3031653635393462333732386230386138323335333433227d",
transaction_hash: "0xdeadbeef",
transaction_hash: "0xdummy-transaction-hash",
transaction_link: "https://sepolia.basescan.org/tx/0xdeadbeef",
status: "pending",
},
Expand Down
Loading