fix(faucet): support both account and module addresses

- allow 20-32 byte addresses to validate both standard accounts and module accounts
This commit is contained in:
0xPatrick 2024-06-07 00:38:34 -04:00
parent f71cdc35a8
commit 016eed9fdb
2 changed files with 23 additions and 1 deletions

View File

@ -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);
});
});

View File

@ -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;
}