-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: extract correct account sequence for injective
- Loading branch information
Showing
5 changed files
with
54 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "cosmes", | ||
"version": "0.0.45", | ||
"version": "0.0.46", | ||
"private": false, | ||
"packageManager": "[email protected]", | ||
"sideEffects": false, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { extractExpectedAccountSequence } from "./sequence"; | ||
|
||
describe("extractExpectedAccountSequence", () => { | ||
it("should extract expected account sequence numbers from valid errors", () => { | ||
// Older cosmos sdk chains | ||
const err1 = new Error( | ||
`account sequence mismatch, expected 10, got 11: incorrect account sequence: invalid request` | ||
); | ||
expect(extractExpectedAccountSequence(err1)).toBe(10n); | ||
|
||
// Newer cosmos sdk chains (0.45+) | ||
const err2 = new Error( | ||
`rpc error: code = Unknown desc = account sequence mismatch, expected 10, got 11: ......` | ||
); | ||
expect(extractExpectedAccountSequence(err2)).toBe(10n); | ||
|
||
// Injective | ||
const err3 = new Error( | ||
`[reason]:"incorrect account sequence" metadata:{key:"ABCICode" value:"32"} ...... rpc error: code = Unknown desc = account sequence mismatch, expected 10, got 11: ......` | ||
); | ||
expect(extractExpectedAccountSequence(err3)).toBe(10n); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Extracts and returns the expected account sequence number from an error. If | ||
* the error is not related to an account sequence mismatch, `null` is returned. | ||
*/ | ||
export function extractExpectedAccountSequence(err: Error): bigint | null { | ||
const matches = err.message.match( | ||
// This regex is intentionally kept as strict as possible | ||
/account sequence mismatch, expected (\d+), got (\d+):/ | ||
); | ||
if (!matches || matches.length < 3) { | ||
return null; | ||
} | ||
return BigInt(matches[1]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters