diff --git a/packages/faucet/src/addresses.spec.ts b/packages/faucet/src/addresses.spec.ts new file mode 100644 index 0000000000..639f52970d --- /dev/null +++ b/packages/faucet/src/addresses.spec.ts @@ -0,0 +1,22 @@ +import { isValidAddress } from "./addresses"; + +describe("isValidAddress", () => { + it("accepts account address", () => { + expect(isValidAddress("cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r", "cosmos")).toBe(true); + }); + + it("accepts an ics-27 address", () => { + expect(isValidAddress("osmo1d6em9ea5y3dye6em0awqyss7ssp0a7sgjk792x8cx647cfs7a4msk0fr45", "osmo")).toBe( + true, + ); + }); + + it("rejects an invalid address", () => { + expect(isValidAddress("cosmos1fail", "cosmos")).toBe(false); + }); + + it("requires a prefix argument", () => { + // @ts-expect-error intentionally omitting an argument + expect(isValidAddress("cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r")).toBe(false); + }); +}); diff --git a/packages/faucet/src/addresses.ts b/packages/faucet/src/addresses.ts index 6792a5414d..e336322689 100644 --- a/packages/faucet/src/addresses.ts +++ b/packages/faucet/src/addresses.ts @@ -6,7 +6,7 @@ export function isValidAddress(input: string, requiredPrefix: string): boolean { if (prefix !== requiredPrefix) { return false; } - return data.length === 20; + return data.length >= 20 && data.length <= 32; } catch { return false; }