Improve HookStateScale validation (#38)

* Fix HookStateScale validation
* Fix new line in accountSet test
This commit is contained in:
zgrguric
2026-05-12 17:04:26 +02:00
committed by GitHub
parent b9fb8a1924
commit e838caaffc
2 changed files with 26 additions and 3 deletions

View File

@@ -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<string, unknown>): 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}`,
)
}
}

View File

@@ -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',
)
})
})