Update the Rust SDK test
@@ -16,7 +16,7 @@ $ tree .
Note that this is also a Rust package, hence the existence of a `Cargo.toml` (Rust manifest file) in the project root directory. The `Cargo.toml` in the root directory contains necessary Rust dependencies to enable you to write Rust-based tests using our [Rust SDK](https://github.com/FuelLabs/fuels-rs), (`fuels-rs`).
-These tests can be run using `forc test` which will look for Rust tests under the `tests/` directory (created automatically with `forc init`).
+These tests can be run using `forc test` which will look for Rust tests under the `tests/` directory (created automatically with `forc init` and prepopulated with boilerplate code).
For example, let's write tests against the following contract, written in Sway. This can be done in the pregenerated `src/main.sw` or in a new file in `src`. In the case of the latter, update the `entry` field in `Forc.toml` to point at the new contract.
@@ -29,27 +29,21 @@ Our `tests/harness.rs` file could look like:
<!--TODO add test here once examples are tested-->
```rust,ignore
-use fuel_tx::{ContractId, Salt};
-use fuels::prelude::*;
-use fuels::test_helpers;
+use fuels::{prelude::*, tx::ContractId};
use fuels_abigen_macro::abigen;
// Load abi from json
abigen!(MyContract, "out/debug/my-fuel-project-abi.json");
async fn get_contract_instance() -> (MyContract, ContractId) {
- // Deploy the compiled contract
- let salt = Salt::from([0u8; 32]);
- let compiled = Contract::load_sway_contract("./out/debug/my-fuel-project.bin", salt).unwrap();
-
// Launch a local network and deploy the contract
- let (provider, wallet) = test_helpers::setup_test_provider_and_wallet().await;
+ let wallet = launch_provider_and_get_single_wallet().await;
- let id = Contract::deploy(&compiled, &provider, &wallet, TxParameters::default())
+ let id = Contract::deploy("./out/debug/my-fuel-project.bin", &wallet, TxParameters::default())
.await
.unwrap();
- let instance = MyContract::new(id.to_string(), provider, wallet);
+ let instance = MyContract::new(id.to_string(), wallet);
(instance, id)
}
@@ -59,8 +53,6 @@ async fn can_get_contract_id() {
let (contract_instance, _id) = get_contract_instance().await;
// Now you have an instance of your contract you can use to test each function
- // Call `initialize_counter()` method in our deployed contract.
- // Note that, here, you get type-safety for free!
let result = contract_instance
.initialize_counter(42)
.call()
@@ -84,9 +76,9 @@ Then, in the root of our project, running `forc test` will run the test above, c
```console
$ forc test
-
+...
running 1 test
-test harness ... ok
+test can_get_contract_id ... ok
-test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.64s
+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.22s
```
