Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/xahau/src/models/transactions/accountSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}`,
)
}
}
16 changes: 14 additions & 2 deletions packages/xahau/test/models/accountSet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)
})
})
Loading