From f3b66ae31f95844ba3ef89faff9e880c7804dc5d Mon Sep 17 00:00:00 2001 From: Vini Barbosa Date: Fri, 20 Jun 2025 13:53:36 -0300 Subject: [PATCH 1/3] Add steps for rs test setup --- docs/developers/testing/rust/sc-test-setup.md | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/docs/developers/testing/rust/sc-test-setup.md b/docs/developers/testing/rust/sc-test-setup.md index babe3e1e4..0c4cdbe9a 100644 --- a/docs/developers/testing/rust/sc-test-setup.md +++ b/docs/developers/testing/rust/sc-test-setup.md @@ -9,6 +9,59 @@ title: Test setup [comment]: # (mx-context-auto) +### Preparing contracts for testing + +If you haven't yet, run the build command for your smart contract while in the contract directory `your-contract/`, that contains all the contract's directories. + +``` +sc-meta all build +``` + +**Create test file** +Navigate to the folder `tests/` inside the contract's main directory and create a new Rust file to write the code for testing `your-contract/tests/your_contract_test.rs`. + +**Generate Proxy** +Before creating the test, we need to set up the environment, starting with a Proxy. + +A smart contract's proxy is an object that mimics the contract. We will use the proxy to call the endpoints. + +The proxy contains entirely autogenerated code. However, before running the command to generate the proxy, we need to set up a configuration file. + +In the root of the contract, at the path `your-contract/`, create the configuration file `sc-config.toml`, where we will specify the path to generate the proxy. The file should contain the following code: + +``` +[settings] + +[[proxy]] +path = "src/your_contract_proxy.rs" +``` + +In the terminal, in the root of the contract, we will run the next command that will generate the proxy for your smart contract: + + +``` +sc-meta all proxy +``` + +Once the proxy is generated, the work is not over yet. The next thing to do is to import the module in your smart contract's code: + +``` +#![no_std] + +#[allow(unused_imports)] +use multiversx_sc::imports::*; + +pub mod your_contract_proxy; + +#[multiversx_sc::contract] +pub trait YourContract { + + //... +} +``` + +With each build of the contract executed by the developer, the proxy will be automatically updated with the changes made to the contract. + ### Registering contracts Since we don't have native execution in the Rust backend yet, the only way to run contracts is to register the contract implementation for the given contract code identifier. In simpler words, we tell the environment "whenever you encounter this contract code, run this code that I've written instead". From 0a00b67c6ef39e96532fa3825943af60c5937e50 Mon Sep 17 00:00:00 2001 From: Vini Barbosa Date: Fri, 20 Jun 2025 13:57:03 -0300 Subject: [PATCH 2/3] Fix add steps rs test setup --- docs/developers/testing/rust/sc-test-setup.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/developers/testing/rust/sc-test-setup.md b/docs/developers/testing/rust/sc-test-setup.md index 0c4cdbe9a..8cd0e7641 100644 --- a/docs/developers/testing/rust/sc-test-setup.md +++ b/docs/developers/testing/rust/sc-test-setup.md @@ -9,18 +9,18 @@ title: Test setup [comment]: # (mx-context-auto) -### Preparing contracts for testing - If you haven't yet, run the build command for your smart contract while in the contract directory `your-contract/`, that contains all the contract's directories. ``` sc-meta all build ``` -**Create test file** +### Creating test file + Navigate to the folder `tests/` inside the contract's main directory and create a new Rust file to write the code for testing `your-contract/tests/your_contract_test.rs`. -**Generate Proxy** +### Generating Proxy + Before creating the test, we need to set up the environment, starting with a Proxy. A smart contract's proxy is an object that mimics the contract. We will use the proxy to call the endpoints. From de3c6997c8d42972343ba0a2c2ee0a7917249ff1 Mon Sep 17 00:00:00 2001 From: Vini Barbosa Date: Fri, 20 Jun 2025 14:00:33 -0300 Subject: [PATCH 3/3] Add steps rs test setup | file and proxy --- docs/developers/testing/rust/sc-test-setup.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/developers/testing/rust/sc-test-setup.md b/docs/developers/testing/rust/sc-test-setup.md index 8cd0e7641..ba8a5c76c 100644 --- a/docs/developers/testing/rust/sc-test-setup.md +++ b/docs/developers/testing/rust/sc-test-setup.md @@ -11,7 +11,7 @@ title: Test setup If you haven't yet, run the build command for your smart contract while in the contract directory `your-contract/`, that contains all the contract's directories. -``` +```bash sc-meta all build ``` @@ -29,7 +29,7 @@ The proxy contains entirely autogenerated code. However, before running the comm In the root of the contract, at the path `your-contract/`, create the configuration file `sc-config.toml`, where we will specify the path to generate the proxy. The file should contain the following code: -``` +```rust title=sc-config.toml [settings] [[proxy]] @@ -45,7 +45,7 @@ sc-meta all proxy Once the proxy is generated, the work is not over yet. The next thing to do is to import the module in your smart contract's code: -``` +```rust title=your_contract.rs #![no_std] #[allow(unused_imports)]