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

fix: invariant logic for Wallet #109

Merged

Conversation

Maksandre
Copy link

Here is the code that will fail with the error: Error: Invariant failed: ABI and args should be provided together or not provided at all.

  const contract = await wallet.deployContract({
    bytecode: artifact.bytecode,
    shardId,
    salt: 1n,
    feeCredit: 0n,
  });

According to the message, it should work fine without both – abi and args. This is the fix

Copy link

changeset-bot bot commented Jul 30, 2024

⚠️ No Changeset found

Latest commit: 387babe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@ukorvl
Copy link
Member

ukorvl commented Aug 2, 2024

Actually, this works as intended.

    if (abi && args) {
      ... // abi and args are defined
      };
    } else {
      invariant(
        abi || args, // here we check if one of abi or args is defined, if true - throw an error
        "ABI and args should be provided together or not provided at all.",
      );
      ... // here they are both undefined
    }

@ukorvl ukorvl closed this Aug 2, 2024
@Maksandre
Copy link
Author

Maksandre commented Aug 2, 2024

Hey @ukorvl !

here we check if one of abi or args is defined, if true - throw an error

Actually no, If both abi and args are not defined this will also throws an error

Please check this code:

  const contract = await wallet.deployContract({
    bytecode: artifact.bytecode,
    shardId,
    salt: 1n,
    feeCredit: 0n,
  });

@ukorvl ukorvl reopened this Aug 2, 2024
@ukorvl
Copy link
Member

ukorvl commented Aug 2, 2024

@Maksandre yup, thanks.

But invariant will throw an Error if the condition is falsey.
Can you change the code accordingly please?
Now you throw an error if (!abi && !args) both are not provided. I suggest !(abi || args) condition.

@Maksandre
Copy link
Author

Ah, you're right, fixed it.

@ukorvl
Copy link
Member

ukorvl commented Aug 2, 2024

LGTM

@ukorvl ukorvl merged commit 609c494 into NilFoundation:master Aug 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants