Usage
How to use Router Robot?
To leverage the capabilities of the Router Robot framework, you can use the router-robot CLI.
Installing the Latest Release
go install github.com/router-protocol/router-robot@latest
Generate Code
Generate a GoLang boilerplate code for cross-chain testing through Router Chain.
router-robot codegen --project-name <project name>
- Directory structure
Here, helloworldis your project-name.
Starting point of the project is robot_suite_test.go
Testing
You can write test cases with the help of Ginkgo framework.
Ginkgo is a popular BDD-style testing framework for the Go programming language. Here are some common CLI commands that you can use to run tests with Ginkgo:
ginkgo: This command runs all the tests in the current directory and its subdirectories. By default, Ginkgo looks for test files with the suffix_test.goand executes all the tests in those files.ginkgo -r: This command recursively runs all the tests in the current directory and its subdirectories.Please refer to Ginkgo docs for more commands.
Steps to setup cross-chain testing:
- Generate boilerplate code
go install github.com/router-protocol/router-robot@latest
- Add private keys in
networkconfig.json(This file is added in .gitignore) - Add artifacts for Router Chain and other third party chains.
- For Router Chain: Get the artifacts (.wasm files) generated during contract deployment on Router Chain.
- For EVM chain: Generate artifacts.
Copy these artifacts into
contract-wrapperfolder
- Write your test cases with Ginkgo testing framework and test.
Add test cases in
robot_test.goor create new files suffixed with_test.go. - Run
go buildcommand to build the project. Then use Ginkgo commands to run test cases. - To track any inbound or outbound request you can use:
TrackInboundRequest(),TrackOutboundRequest()methods provided via Robot instance.
Track a Transaction
Provide a transaction hash to track its status from source chain.
router-robot track --chainId <source chain id> --chainType <source chain type> --txhash <source transaction hash>
Here,
chainId: source chain ID
chainType: source chain type
txHash: source tx hash
Logging and debugging
For adding logs logrus library is configured inside router-robot itself.
You can use Logger via Robot instance, initialized in robot_suite_test.go
Logger.Info(”This is an information”)
Logger.Warn(”This is a warning”)
Logger.Fatal(”Fatal error occured”)
Example
Sample repository created with router-robot tool can be found here.