Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken validators #2352

Closed
taoeffect opened this issue Sep 16, 2024 · 0 comments · Fixed by #2353
Closed

Broken validators #2352

taoeffect opened this issue Sep 16, 2024 · 0 comments · Fixed by #2353
Assignees
Labels
App:Frontend Kind:Bug Note:Contracts Issues involving modifications to contracts Priority:High

Comments

@taoeffect
Copy link
Member

taoeffect commented Sep 16, 2024

Problem

In 'gi.contracts/group/updateSettings', I mistakenly thought that these custom validation functions in objectMaybeOf worked:

    'gi.contracts/group/updateSettings': {
      // OPTIMIZE: Make this custom validation function
      // reusable accross other future validators
      validate: actionRequireActiveMember((data, { getters, meta, message: { innerSigningContractID } }) => {
        objectMaybeOf({
          groupName: stringMax(GROUP_NAME_MAX_CHAR, 'groupName'),
          groupPicture: x => typeof x === 'string',
          sharedValues: stringMax(GROUP_DESCRIPTION_MAX_CHAR, 'sharedValues'),
          mincomeAmount: x => typeof x === 'number' && x > 0,
          mincomeCurrency: stringMax(GROUP_CURRENCY_MAX_CHAR, 'mincomeCurrency'),
          distributionDate: x => typeof x === 'string',
          allowPublicChannels: x => typeof x === 'boolean'
        })(data)

But they do not.

The problem is that the custom validators do not throw an exception.

Similar problem in 'gi.contracts/group/groupProfileUpdate' too.

EDIT: similarly, there is another big problem that validators from outside of flowTyper.js, like isIsoString and isPeriodStamp are used with objectMaybeOf.

Solution

  • Replace x => typeof x === 'string' with the string validation function, and do the same for x => typeof x === 'boolean' (except use boolean function validator).
  • Then for mincomeAmount, use the new numberRange validator
  • In 'gi.contracts/group/groupProfileUpdate': incomeDetailsType and incomeAmount have a similar problem
  • Create a validatorFrom function inside of flowTyper.js that takes a function that returns a boolean and throws a validatorError if that function returns false, and then wrap functions like isPeriodStamp with it (when they're called as part of a validation with objectMaybeOf)
@taoeffect taoeffect added Kind:Bug App:Frontend Priority:High Note:Contracts Issues involving modifications to contracts labels Sep 16, 2024
@taoeffect taoeffect changed the title Broken validation in 'gi.contracts/group/updateSettings' Broken validators Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
App:Frontend Kind:Bug Note:Contracts Issues involving modifications to contracts Priority:High
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants