Skip to content

Commit

Permalink
fix(faucet): support both account and module addresses
Browse files Browse the repository at this point in the history
- allow 20-32 byte addresses to validate both standard accounts and module accounts
  • Loading branch information
0xpatrickdev committed Jun 26, 2024
1 parent f71cdc3 commit 016eed9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/faucet/src/addresses.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
2 changes: 1 addition & 1 deletion packages/faucet/src/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 016eed9

Please sign in to comment.