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

Rust-based tests #124

Closed
adlerjohn opened this issue Jul 15, 2021 · 1 comment · Fixed by #131, #320 or #342
Closed

Rust-based tests #124

adlerjohn opened this issue Jul 15, 2021 · 1 comment · Fixed by #131, #320 or #342
Assignees
Labels

Comments

@adlerjohn
Copy link
Contributor

adlerjohn commented Jul 15, 2021

Problem

Currently, tests can be done in a rudimentary way by writing a script with hard-coded values, which calls ABI methods on contract. Tests can also be done by manually crafting input data into a script, which then calls ABI methods on a contract.

Both of these options are onerous to use for anything over than trivial tests. We'd like to support

  1. Crafting input data to a script with Rust, and
  2. Crafting transactions to send to a node, and
  3. Parsing return data, logs, and other receipts, and comparing them against golden values (e.g. assertions) with Rust.

This would allow arbitrary-complexity tests that can do things like make use of disk or network resources.

Proposal

Add a new commend to forc, forc test, which runs one or more tests. Parameters can be based off of cargo test.

The command should run the selected tests (written in Rust, in the project directory). fuel-tx can be used for crafting TransactionScript transactions simply.

A Rust SDK is needed that will:

  1. Deploy one or more contracts.
  2. Serialize/convert native Rust types into (binary) native Sway types, and use this serialized form as input data to a script.
  3. Select a particular ABI method.
  4. Craft and send a script transaction to a node. A standard script can be used that simply forwards input data to a script, and calls the given ABI method. More complex script crafting can be left for future work.
  5. Parse return data, logs, and other receipts.

Refer to https://github.com/FuelLabs/fuel-v2-contracts/blob/0cf8df2026a25ffef0719bf807586e736565aa2a/test/merkleTreeBinary.ts#L19 for a comprehensive example of the functionality tests should offer (except they should be written in Rust instead of TS/JS).

Additional repo that's a good reference for some features: https://github.com/gakonst/ethers-rs

@digorithm
Copy link
Member

Done and closed by the last PR related to the initial infrastructure for Rust-based tests: #433

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment