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

Fails when passing arguments to call back function used in "then" promise #2529

Closed
willemneal opened this issue Apr 27, 2020 · 1 comment
Closed
Labels
C-bug Category: This is a bug

Comments

@willemneal
Copy link
Contributor

willemneal commented Apr 27, 2020

Describe the bug

Using promise.then fails when arguments are being passed to the callback function.
The logs confirm that the args are encoded correctly.

export function reverseWordThree(): void {
  const word = new Word("sample")
  const contract = "words.examples"
  const method = "reverse"

  // setup args object for cross-contract call as key-value of contract method parameters
  // note: the method signature in the words contract is reverse(word: Word)
  let reverseArgs = new ReverseArgs(word)

  let promise = ContractPromise.create(
    contract,                             // contract account name
    method,                               // contract method name
    reverseArgs.encode(),                 // serialized contract method arguments encoded as Uint8Array
    10000000,                                    // gas attached to the call
    u128.Zero                             // attached deposit to be sent with the call
  )

  // Setting up args for the callback
  let responseArgs = new ReverseArgs(new Word("elpmas"));
  logging.log(responseArgs); // <-- this encodes it to print it.

  logging.log(context.contractName)

  let callbackPromise = promise.then(
    context.contractName,
    "_onReverseCalledTwo",
    responseArgs.encode(), //<- Passing empty byte array works for function that doesn't expect args
    2
  );

  callbackPromise.returnAsResult();
}

export function _onReverseCalledTwo(word: Word): bool {
  const drow = word;
  let results = ContractPromise.getResults();
  assert(results.length > 0, "should be contract promise result");
  let reverseResult = results[0];
  // logging.log(results[0]);
  // Verifying the remote contract call succeeded.
  if (reverseResult.status == 1) {
    // Decoding data from the bytes buffer into the local object.
    let word = decode<Word>(reverseResult.buffer);
    logging.log(word);
    return word.text == drow.text
  }

  return false
}

To Reproduce
See https://gitpod.io/#https://github.com/near/near-sdk-as/tree/cross_contract_bug

It should fail on start, but to rerun yarn test:vm, or in the vm directory, yarn ts-node test.ts

The test is vm/test.ts and the corresponding AS file is assembly/__tests__/sentences.ts

Expected behavior
Not fail when passing input args to then

Screenshots

Screen Shot 2020-04-27 at 11 25 01 AM

Version (please complete the following information):

  • nearcore commit/branch
  • rust version (if local)
  • docker (if using docker)
  • mainnet/testnet/betanet/devnet/local

Additional context
Add any other context about the problem here.

@willemneal willemneal added the C-bug Category: This is a bug label Apr 27, 2020
@willemneal
Copy link
Contributor Author

Fixed! Issue was AS specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug
Projects
None yet
Development

No branches or pull requests

1 participant