Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions docs/developers/testing/rust/sc-test-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider rephrasing "If you haven't yet" to "If you haven't already" for smoother readability.

Suggested change
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.
If you haven't already, run the build command for your smart contract while in the contract directory `your-contract/`, that contains all the contract's directories.

Copilot uses AI. Check for mistakes.

```bash
sc-meta all build
```

### Creating test file
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

[nitpick] Heading capitalization is inconsistent; consider using title case (e.g., "### Create Test File") to match other section headings.

Suggested change
### Creating test file
### Creating Test File

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

[nitpick] The sc-config.toml snippet is TOML, so using toml instead of rust would improve syntax highlighting and clarity.

Suggested change
```rust title=sc-config.toml
```toml title=sc-config.toml

Copilot uses AI. Check for mistakes.
[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:


```
Copy link

Copilot AI Jun 30, 2025

Choose a reason for hiding this comment

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

[nitpick] This code block should specify a language (e.g., ```bash) for consistent formatting of CLI commands.

Suggested change
```
```bash

Copilot uses AI. Check for mistakes.
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".
Expand Down
Loading