diff --git a/packages/xahau/src/models/transactions/accountSet.ts b/packages/xahau/src/models/transactions/accountSet.ts index 6c16552394..7b9b942236 100644 --- a/packages/xahau/src/models/transactions/accountSet.ts +++ b/packages/xahau/src/models/transactions/accountSet.ts @@ -173,6 +173,7 @@ export interface AccountSet extends BaseTransaction { const MIN_TICK_SIZE = 3 const MAX_TICK_SIZE = 15 const MAX_HOOK_STATE_SCALE = 16 +const MIN_HOOK_STATE_SCALE = 1 /** * Verify the form and type of an AccountSet at runtime. @@ -233,12 +234,22 @@ export function validateAccountSet(tx: Record): void { } validateOptionalField(tx, 'HookStateScale', isNumber) + if ( typeof tx.HookStateScale === 'number' && tx.HookStateScale > MAX_HOOK_STATE_SCALE ) { throw new ValidationError( - `AccountSet: HookStateScale must be less than ${MAX_HOOK_STATE_SCALE}`, + `AccountSet: HookStateScale must be less than or equal to ${MAX_HOOK_STATE_SCALE}`, + ) + } + + if ( + typeof tx.HookStateScale === 'number' && + tx.HookStateScale < MIN_HOOK_STATE_SCALE + ) { + throw new ValidationError( + `AccountSet: HookStateScale must be greater than or equal to ${MIN_HOOK_STATE_SCALE}`, ) } } diff --git a/packages/xahau/test/models/accountSet.test.ts b/packages/xahau/test/models/accountSet.test.ts index 947615d41d..d12a35dbd6 100644 --- a/packages/xahau/test/models/accountSet.test.ts +++ b/packages/xahau/test/models/accountSet.test.ts @@ -182,12 +182,24 @@ describe('AccountSet', function () { assert.throws( () => validateAccountSet(account), ValidationError, - 'AccountSet: HookStateScale must be less than 16', + 'AccountSet: HookStateScale must be less than or equal to 16', ) assert.throws( () => validate(account), ValidationError, - 'AccountSet: HookStateScale must be less than 16', + 'AccountSet: HookStateScale must be less than or equal to 16', + ) + + account.HookStateScale = 0 + assert.throws( + () => validateAccountSet(account), + ValidationError, + 'AccountSet: HookStateScale must be greater than or equal to 1', + ) + assert.throws( + () => validate(account), + ValidationError, + 'AccountSet: HookStateScale must be greater than or equal to 1', ) }) })