Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Implement new truffle call command using @truffle/encoder and @truffle/decoder #5647

Merged
merged 61 commits into from May 9, 2023

Conversation

sukanyaparashar
Copy link
Contributor

@sukanyaparashar sukanyaparashar commented Oct 26, 2022

PR description

This PR adds the truffle call command leveraging Truffle's encoding and decoding functionality (including overload resolution). Prior work credit: @gnidan (#5330).

Testing instructions

To test this new feature, write a smart contract inside a truffle project with a function that returns some value or you can clone this Test Project with a simple storage contract.

  1. Run truffle develop inside a truffle project.

  2. In the REPL, run migrate to deploy the contract.

  3. In the REPL, run call <contract_name|contract_address> <function_name>.

    onlyfunction
  4. In the REPL, run call <contract_name|contract_address> <function_name> <arg>.

    functionwitharg
  5. In the REPL, run call <contract_name|contract_address> <function_name> that returns multiple values of different types.

    multiplevalues
  6. In the REPL, run call <contract_name|contract_address> <function_signature> <arg>. NOTE: ABI-style signatures doesn't allow spaces.

    functionsigwitharg
  7. In the REPL, run call <contract_name|contract_address> <function_name_that_reverts>.

    revertmessage
  8. In the REPL, run call <contract_name|contract_address> <function_name_that_panics>.

    panicmessage

NOTE: This can also be tested in a truffle project outside of truffle REPL with the following steps -

  1. Run a ganache instance in a separate terminal.

  2. Run truffle migrate.

  3. Run truffle call <contract_name|contract_address> <function_name>.

    onlyfunction
  4. Run truffle call <contract_name|contract_address> <function_name> <arg>.

    functionwitharg
  5. In the REPL, run truffle call <contract_name|contract_address> <function_name> that returns multiple values of different types.

    multiplevalues
  6. Run call <contract_name|contract_address> <function_signature> <arg>. NOTE: Function signature should be in "" and without spaces.

    functionsigwitharg
  7. Run truffle call <contract_name|contract_address> <function_name_that_reverts>.

    revertmessage
  8. Run truffle call <contract_name|contract_address> <function_name_that_panics>.

    panicmessage

Breaking changes and new features

  • I have added any needed breaking-change and new-feature labels for the appropriate packages.

packages/provider/index.js Outdated Show resolved Hide resolved
@sukanyaparashar sukanyaparashar force-pushed the implement-truffle-call branch 2 times, most recently from d7d0063 to 468d8e2 Compare November 24, 2022 19:20
@sukanyaparashar sukanyaparashar marked this pull request as ready for review November 29, 2022 03:15
@sukanyaparashar sukanyaparashar marked this pull request as draft December 16, 2022 02:48
@sukanyaparashar sukanyaparashar marked this pull request as ready for review December 16, 2022 19:55
@haltman-at haltman-at removed the request for review from fainashalts May 5, 2023 04:26
@haltman-at
Copy link
Contributor

Oops, I also need to just straight-up update the tests, it's failing CI because I didn't...

@haltman-at haltman-at marked this pull request as ready for review May 8, 2023 23:07
@haltman-at haltman-at dismissed their stale review May 8, 2023 23:08

I have revised things :)

@haltman-at
Copy link
Contributor

OK, I have substantially revised this and I think it should be OK now!

I had to leave out a few tests due to the framework making them difficult.

Also sorry for how slow the tests are. We can cut some if you like. Or if you know a better way to do it that would be quick to implement...

@haltman-at haltman-at self-requested a review May 9, 2023 01:40
@gnidan
Copy link
Contributor

gnidan commented May 9, 2023

Also sorry for how slow the tests are. We can cut some if you like.

Yeah, let's cut all the slow tests for now and open an issue about the lack of automated testing as a result.

Or maybe we keep 1-2 basic end-to-end tests just for minimal safety


const fromAddress =
options.from ?? config.networks[config.network]?.from ?? config.from;
if (!web3Utils.isAddress(fromAddress)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we skip the need to specify a from field?

At the very least this error should indicate which address is the problem, since this error now suggests that it might be the contract address that's wrong

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'm thinking... maybe we can just use 0x0 as the from address

Copy link
Contributor

@gnidan gnidan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good apart from the requirement for from. Let's use the zero-address for from instead of erroring.

@haltman-at
Copy link
Contributor

OK, made those changes!

@haltman-at haltman-at requested a review from gnidan May 9, 2023 20:46
Copy link
Contributor

@gnidan gnidan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@haltman-at haltman-at merged commit 4c17a8e into develop May 9, 2023
10 checks passed
@haltman-at haltman-at deleted the implement-truffle-call branch May 9, 2023 21:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
doc-change-required Issue indicates a change to documentation is required new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants