Account: allow negative sequence number#948
Conversation
|
Size Change: -283 B (-0.02%) Total Size: 1.75 MB
|
There was a problem hiding this comment.
Pull request overview
This PR updates the Account constructor to permit negative sequence numbers, enabling workflows that need to construct transactions with sequence "0" (e.g., by starting from "-1" and relying on TransactionBuilder’s increment-on-build behavior).
Changes:
- Removed the
Accountconstructor check that rejected negative sequence numbers. - Updated unit tests by removing the expectation that negative sequences throw, and added an eslint suppression for an invalid-type test case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/account.ts |
Removes the “non-negative sequence” validation to allow negative sequence inputs. |
test/unit/account.test.ts |
Removes the negative-sequence rejection test and adds an eslint suppression for an invalid-type test. |
Comments suppressed due to low confidence (1)
test/unit/account.test.ts:33
- This PR changes the contract to allow negative sequence numbers, but the unit tests no longer assert the new behavior. Add a test that
new Account(ACCOUNT, "-1")succeeds (and ideally thatTransactionBuilderbuilt from it produces a tx sequence of "0" / increments the source to "0"), so the intended SEP-10-style use case stays covered.
it("fails to create Account object from an empty string sequence", () => {
expect(() => new Account(ACCOUNT, "")).toThrow(
/sequence is not a valid number/,
);
});
it("creates an Account object", () => {
const account = new Account(ACCOUNT, "100");
expect(account.accountId()).toBe(ACCOUNT);
expect(account.sequenceNumber()).toBe("100");
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Shaptic
left a comment
There was a problem hiding this comment.
This doesn't seem like a good idea to me tbh, I think any valid use-case should be able to use a sequence number of zero, instead 🤔
|
@Shaptic , should we update |
|
@quietbits we should definitely change that code to not rely on a negative value (seqnum of 0 is enough as an "invalid" check if that's the purpose), and we can re-introduce "no negative numbers" later to avoid the "breaking" (arguably a bugfix) change. |
There is a use case for a negative sequence number. For example, we use it in
WebAuth.buildChallengeTx(code).Note
This was introduced during migration. This check does not exist in the current version.