diff --git a/docs/developers/testing/rust/sc-test-setup.md b/docs/developers/testing/rust/sc-test-setup.md index babe3e1e4..ba8a5c76c 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) +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 +``` + +### 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`. + +### 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. + +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: + +```rust title=sc-config.toml +[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: + +```rust title=your_contract.rs +#![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".