Skip to content

Commit 016eed9

Browse files
committed
fix(faucet): support both account and module addresses
- allow 20-32 byte addresses to validate both standard accounts and module accounts
1 parent f71cdc3 commit 016eed9

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/faucet/src/addresses.spec.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { isValidAddress } from "./addresses";
2+
3+
describe("isValidAddress", () => {
4+
it("accepts account address", () => {
5+
expect(isValidAddress("cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r", "cosmos")).toBe(true);
6+
});
7+
8+
it("accepts an ics-27 address", () => {
9+
expect(isValidAddress("osmo1d6em9ea5y3dye6em0awqyss7ssp0a7sgjk792x8cx647cfs7a4msk0fr45", "osmo")).toBe(
10+
true,
11+
);
12+
});
13+
14+
it("rejects an invalid address", () => {
15+
expect(isValidAddress("cosmos1fail", "cosmos")).toBe(false);
16+
});
17+
18+
it("requires a prefix argument", () => {
19+
// @ts-expect-error intentionally omitting an argument
20+
expect(isValidAddress("cosmos1h806c7khnvmjlywdrkdgk2vrayy2mmvf9rxk2r")).toBe(false);
21+
});
22+
});

packages/faucet/src/addresses.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function isValidAddress(input: string, requiredPrefix: string): boolean {
66
if (prefix !== requiredPrefix) {
77
return false;
88
}
9-
return data.length === 20;
9+
return data.length >= 20 && data.length <= 32;
1010
} catch {
1111
return false;
1212
}

0 commit comments

Comments
 (0)