Skip to content

Commit

Permalink
Merge pull request #1522 from pryzm-finance/fix-gas-price-validation-…
Browse files Browse the repository at this point in the history
…regex

Update validation of GasPrice.fromString to allow using ibc denoms as gas denom
  • Loading branch information
webmaster128 authored Dec 19, 2023
2 parents 55477b5 + a752cd8 commit 62a4ad1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to

## [Unreleased]

### Changed

- @cosmjs/stargate: Update validation of GasPrice.fromString to allow using ibc denoms as gas denom ([#1522])

[#1522]: https://github.com/cosmos/cosmjs/pull/1522

## [0.32.1] - 2023-12-04

### Fixed
Expand Down
4 changes: 4 additions & 0 deletions packages/stargate/src/fee.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ describe("GasPrice", () => {
"0.14ucoin2": { amount: "0.14", denom: "ucoin2" },
// eslint-disable-next-line @typescript-eslint/naming-convention
"0.14FOOBAR": { amount: "0.14", denom: "FOOBAR" },
"0.01ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2": {
amount: "0.01",
denom: "ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2",
},
};
for (const [input, expected] of Object.entries(inputs)) {
const gasPrice = GasPrice.fromString(input);
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/src/fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class GasPrice {
*/
public static fromString(gasPrice: string): GasPrice {
// Use Decimal.fromUserInput and checkDenom for detailed checks and helpful error messages
const matchResult = gasPrice.match(/^([0-9.]+)([a-z][a-z0-9]*)$/i);
const matchResult = gasPrice.match(/^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/);
if (!matchResult) {
throw new Error("Invalid gas price string");
}
Expand Down

0 comments on commit 62a4ad1

Please sign in to comment.