From 61017895a7f853ea55755c94e216e26547770d02 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Wed, 10 Jul 2024 15:43:15 -0700 Subject: [PATCH] fix(account-update.ts): add check for mayUseToken field in AccountUpdate.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. --- src/lib/mina/account-update.ts | 5 ++++- src/lib/mina/account-update.unit-test.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/lib/mina/account-update.ts b/src/lib/mina/account-update.ts index e3fd6946c2..df512221aa 100644 --- a/src/lib/mina/account-update.ts +++ b/src/lib/mina/account-update.ts @@ -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( diff --git a/src/lib/mina/account-update.unit-test.ts b/src/lib/mina/account-update.unit-test.ts index c8825b4c08..61b55f6e76 100644 --- a/src/lib/mina/account-update.unit-test.ts +++ b/src/lib/mina/account-update.unit-test.ts @@ -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({