Merge pull request #1522 from pryzm-finance/fix-gas-price-validation-regex

Update validation of GasPrice.fromString to allow using ibc denoms as gas denom
This commit is contained in:
Simon Warta 2023-12-19 12:45:25 +01:00 committed by GitHub
commit 62a4ad1b6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 1 deletions

View File

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

View File

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

View File

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