Skip to content

Commit

Permalink
fix(account-update.ts): add check for mayUseToken field in AccountUpd…
Browse files Browse the repository at this point in the history
…ate.check method to ensure parentsOwnToken and inheritFromParent are not both true

This change adds an additional check in the AccountUpdate.check method to validate that the mayUseToken field has valid values. The check ensures that parentsOwnToken and inheritFromParent flags are not both set to true, as that would be an invalid state. This fix helps maintain data integrity and catches potential issues early.

test(account-update.unit-test.ts): add test case for AccountUpdate.check method to verify it throws an error when both parentsOwnToken and inheritFromParent are true

A new test case has been added to verify that the AccountUpdate.check method correctly throws an error when both parentsOwnToken and inheritFromParent flags are set to true in the mayUseToken field. This test helps ensure the fix in the AccountUpdate.check method is working as expected and prevents invalid states.
  • Loading branch information
MartinMinkov committed Jul 10, 2024
1 parent 5a27a22 commit 6101789
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/lib/mina/account-update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,10 @@ class AccountUpdate implements Types.AccountUpdate {
static empty() {
return AccountUpdate.dummy();
}
static check = Types.AccountUpdate.check;
static check = (au: AccountUpdate) => {
Types.AccountUpdate.check(au);
Types.MayUseToken.check(au.body.mayUseToken);
};
static fromFields(fields: Field[], [other, aux]: any[]): AccountUpdate {
let accountUpdate = Types.AccountUpdate.fromFields(fields, aux);
return Object.assign(
Expand Down
13 changes: 13 additions & 0 deletions src/lib/mina/account-update.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,19 @@ function createAccountUpdateWithMayUseToken(
);
}

// throws an error when both flags are true in AccountUpdate.check method
{
let accountUpdate = createAccountUpdateWithMayUseToken({
parentsOwnToken: Bool(true),
inheritFromParent: Bool(true),
});
expect(() => {
AccountUpdate.check(accountUpdate);
}).toThrowError(
'MayUseToken: parentsOwnToken and inheritFromParent cannot both be true'
);
}

// correctly identifies when neither flag is set
{
let accountUpdate = createAccountUpdateWithMayUseToken({
Expand Down

0 comments on commit 6101789

Please sign in to comment.