This repo is a boilerplate meant to standardize file structure in a NEAR development environment as well as integration with near-workspaces.
With this template, developers can easily add multiple custom contracts to a single workspace, import external contracts (as .wasm files) into a workspace, and perform simulation tests on
a local Sandbox instance.
This section explains the file system layout of this template. For the purpose of standardization and faster onboarding to a project, this layout is only meant to be extended, not manipulated
-
- Your NEAR contracts will reside in this directory. Each contract must have it's own folder with a
Cargo.tomlandlib.rsfile to define it as it's own contract. After adding a contract, you must add the contract's root folder path to the[workspaces]section in theCargo.tomlin the root project folder. This allows the root project to recognize the contract folder as its own contract within the environment for building and testing
Because each contract within the
/contractsdirectory is isolated, they cannot import other contracts within the root contracts directory, and thus cannot perform cross-contract calls in their unit tests. To perform testing of cross contract calls read the simulation tests section. - Your NEAR contracts will reside in this directory. Each contract must have it's own folder with a
-
-
Simulation tests reside in the
/testsdirectory and are executed with the near-workspaces rust crate (see [https://doc.rust-lang.org/cargo/reference/workspaces.html]). Each file in the tests directory is its own simulation test. Helper functions are files that reside in the/tests/commondirectory. To create a helper function, import it into/test/common/mod.rsas a public module. Then the specified module can be used in the required simulation test file -
DOES NEAR WORKSPACES REQUIRE A MANUAL SANDBOX INSTALL??
-
-
- The
./scriptsdirectory should be used to house files whose goal is to execute NEAR commands. Ideally, we will have a framework that allows these scripts to be easily ran in a common language
- The
-
- This
/resdirectory is generated by the./buildcommand (see Bash Scripts section). This folder allows simple storage of the.wasmcontract builds as opposed to the./targetdirectory
- This
-
UPDATE AFTER LEARNING MORE DETAILS
-
The scripts reside in the root project directory, and are used to combine cargo, near, and general bash scripting to speed up development. (Note: These commands will only run on a linux environment, and you may need to run
sudo chmod +rx {FILE_NAME}to allow execution and read permissions.) -
./build- This function should be used to build contracts because it will recognize all contracts in your workspace, and copy the build output (.wasm files) to the
/resdirectory. This will make it easy to find your contract's .wasm builds as opposed to searching through the/targetfolders
- This function should be used to build contracts because it will recognize all contracts in your workspace, and copy the build output (.wasm files) to the
-
./sim- This function will first build any changes made to the contracts, and execute the simulation tests
-
./clean_sb- This function provides shorter command for cleaning the Sandbox cache
This section explains how to add contracts, simulation tests, and aliased cargo commands.
-
[dev-dependencies] -
These dependencies will only be utilized in the
testfolder. Contract dependencies reside in the respective contract's Cargo.toml. -
[workspaces]- see [https://doc.rust-lang.org/cargo/reference/workspaces.html]
- A workspace is a collection of one or more packages that share common dependency resolution (with a shared
Cargo.lock), output directory, and various settings such as profiles - To add a contract append the path to the contract's root folder (contains
Cargo.toml) to the array parameter in the[workspaces]section
-
[test]
-
[alias]- Some default aliased commands already set up to speed up testing. Feel free to extend to your liking