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

Create conditions errors in code #142

Closed
manumonti opened this issue Dec 12, 2022 · 5 comments · Fixed by #143
Closed

Create conditions errors in code #142

manumonti opened this issue Dec 12, 2022 · 5 comments · Fixed by #143

Comments

@manumonti
Copy link
Member

I'm not sure if this is a documentation issue or a nucypher-ts bug.

If we check Conditions.RpcCondition docs, we see there are two ways of creating this condition. But both of them return errors if used as described in docs:

  1. Using RpcCondition:
const const rpc = new Conditions.RpcCondition({
  chain: 1,
  method: 'eth_getBalance',
  parameters: [
      ":userAddress",
      "latest"
    ],
  returnValueTest: {
    comparator: ">=",
    value: 10000000000000
  }
});
  1. Using Condition:
const rpcConfig = {
  contractAddress: '',
  standardContractType: '',
  chain: 1,
  method: 'eth_getBalance',
  parameters: [':userAddress', 'latest'],
  returnValueTest: {
    comparator: '>=',
    value: 10000000000000,
  },
};
const rpc = Conditions.Condition(rpcConfig);

If we use in the code the former one, we get an error:

"returnValueTest.value" must be a string

This error is fixed if we pass the Object key value as string instead of as number:

  returnValueTest: {
    comparator: ">=",
    value: "10000000000000"
  }

However, in the latter option, we can use both, string and number types, for the key value.

Should we homogenize this behavior by allowing only one type (string or number)?

Another issue is that the latter option returns error:

Error: Request failed with status code 500

It only works if we delete the two first keys of the config object:

const rpcConfig = {
  contractAddress: '', // DELETE THIS
  standardContractType: '', // DELETE THIS
  chain: 1,
  method: 'eth_getBalance',
  parameters: [':userAddress', 'latest'],
  returnValueTest: {
    comparator: '>=',
    value: 10000000000000,
  },
};

Also, we have the same problems in Conditions.TimelockCondition.

@manumonti manumonti mentioned this issue Dec 12, 2022
@theref
Copy link
Contributor

theref commented Dec 12, 2022

Nice, this is documentation error, thank you

Although I would've absolutely expected you to be able to pass the return value as an int - do you have the exact error? I'm wondering if it's nucypher-ts or nucypher

@manumonti
Copy link
Member Author

Nice, this is documentation error, thank you

Although I would've absolutely expected you to be able to pass the return value as an int - do you have the exact error? I'm wondering if it's nucypher-ts or nucypher

Yes, here it is:

conditions.js?eafd:99 Uncaught Error: "returnValueTest.value" must be a string
    at TimelockCondition.toObj (conditions.js?eafd:99:1)
    at eval (conditions.js?eafd:54:1)
    at Array.map (<anonymous>)
    at ConditionSet.toList (conditions.js?eafd:53:1)
    at ConditionSet.toJson (conditions.js?eafd:65:1)
    at ConditionSet.toWASMConditions (conditions.js?eafd:71:34)
    at Enrico.encryptMessage (enrico.js?7a1a:17:110)
    at encrypt (Encrypt.tsx?f69e:65:37)
    at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:3945:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:3994:1)

react-dom.development.js?61bb:4091 Uncaught Error: "returnValueTest.value" must be a string
    at TimelockCondition.toObj (conditions.js?eafd:99:1)
    at eval (conditions.js?eafd:54:1)
    at Array.map (<anonymous>)
    at ConditionSet.toList (conditions.js?eafd:53:1)
    at ConditionSet.toJson (conditions.js?eafd:65:1)
    at ConditionSet.toWASMConditions (conditions.js?eafd:71:34)
    at Enrico.encryptMessage (enrico.js?7a1a:17:110)
    at encrypt (Encrypt.tsx?f69e:65:37)
    at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:3945:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:3994:1)

@piotr-roslaniec
Copy link
Contributor

piotr-roslaniec commented Dec 12, 2022

Perhaps we should have a separate test suite in nucypher-ts, test/docs, where we keep code examples to be used in documentation. Then, we could copy&paste them with confidence instead of doing a QA on them every time we update the API.

@derekpierre
Copy link
Member

derekpierre commented Apr 14, 2023

@manumonti is this part of the docs work you did to ensure that the code used in docs is correct? If so, is this completed, and this issue can be closed? And the docs have been updated already?

@piotr-roslaniec
Copy link
Contributor

Closed by #147

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Completed
Development

Successfully merging a pull request may close this issue.

5 participants