Skip to content

Commit

Permalink
Address.isAddress
Browse files Browse the repository at this point in the history
Signed-off-by: bennett <[email protected]>
  • Loading branch information
bmzig committed Feb 28, 2025
1 parent 3a453f1 commit 3ce3868
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/utils/AddressUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export class Address {
return isSvmAddress(this.toBase58());
}

// Checks if the object is an address by looking at whether it has an Address constructor.
static isAddress(obj: Record<string, unknown>): boolean {
return obj instanceof Address;
}

// Converts the input address to a 32-byte hex data string.
toString(): string {
return this.toBytes32();
Expand Down
5 changes: 4 additions & 1 deletion test/SpokePoolClient.ValidateFill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
DepositSearchResult,
getBlockRangeForDepositId,
EvmAddress,
Address,
} from "../src/utils";
import { ZERO_BYTES } from "../src/constants";
import { CHAIN_ID_TEST_LIST, originChainId, destinationChainId, repaymentChainId } from "./constants";
Expand Down Expand Up @@ -152,9 +153,11 @@ describe("SpokePoolClient: Fill Validation", function () {
// For each RelayData field, toggle the value to produce an invalid fill. Verify that it's rejected.
const fields = Object.keys(fill).filter((field) => !ignoredFields.includes(field));
for (const field of fields) {
let val: BigNumber | string | number;
let val: BigNumber | string | number | Address;
if (BigNumber.isBigNumber(fill[field])) {
val = fill[field].add(bnOne);
} else if (Address.isAddress(fill[field])) {
val = Address.fromHex(fill[field].toAddress() + "1234");
} else if (typeof fill[field] === "string") {
val = fill[field] + "1234";
} else {
Expand Down

0 comments on commit 3ce3868

Please sign in to comment.