Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ jobs:
with:
node-version: 14.x
- name: Check with Prettier
run: npx prettier --check --ignore-path .gitignore '**/*.(yml|js|ts|json)'
run: npx prettier --check --ignore-path .gitignore '**/*.(yml|js|ts|json)'

####### Building and Testing binaries #######

Expand Down Expand Up @@ -176,7 +176,7 @@ jobs:
npm install
cd ../tests
npm install
npm run test;
npm run test -- -j $(($(nproc) / 2));
- name: Save parachain binary
run: |
mkdir -p build
Expand Down
54 changes: 54 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Build & Launch Moonbeam Node (Linux)",
"preLaunchTask": "Build Moonbeam (debug symbols)",
"program": "${workspaceFolder}/target/release/moonbeam",
"args": [
"--execution=Native",
"--no-telemetry",
"--no-prometheus",
"--dev",
"--ethapi=txpool,debug,trace",
"--sealing=manual",
"-linfo",
"--port=${dbgconfig:port_p2p}",
"--rpc-port=${dbgconfig:port_rpc}",
"--ws-port=${dbgconfig:port_ws}",
"--tmp"
],
"cwd": "${workspaceFolder}",
"sourceLanguages": ["rust"],
"sourceMap": {
"/rustc/*": "${dbgconfig:rustc_path}"
}
},
{
"type": "lldb",
"request": "launch",
"name": "Launch Moonbeam Node (Linux)",
"program": "${workspaceFolder}/target/release/moonbeam",
"args": [
"--execution=Native",
"--no-telemetry",
"--no-prometheus",
"--dev",
"--ethapi=txpool,debug,trace",
"--sealing=manual",
"-linfo",
"--port=${dbgconfig:port_p2p}",
"--rpc-port=${dbgconfig:port_rpc}",
"--ws-port=${dbgconfig:port_ws}",
"--tmp"
],
"cwd": "${workspaceFolder}",
"sourceLanguages": ["rust"],
"sourceMap": {
"/rustc/*": "${dbgconfig:rustc_path}"
}
}
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,11 @@
},
"[yaml]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"lldb.dbgconfig": {
"rustc_path": "${env:HOME}/.rustup/toolchains/nightly-2021-01-13-x86_64-unknown-linux-gnu/lib/rustlib/src/rust",
"port_p2p": 19931,
"port_rpc": 19932,
"port_ws": 19933
}
}
23 changes: 23 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Moonbeam (debug symbols)",
"type": "shell",
"command": "RUSTFLAGS=-g cargo build --release",
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{
"label": "Run single test file in debug mode",
"type": "shell",
"command": "cd tests && DEBUG_MODE=true npm run test-single",
"presentation": {
"reveal": "always",
"panel": "new"
}
}
]
}
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ members = [

[profile.release]
panic = 'unwind'
opt-level = 0
60 changes: 58 additions & 2 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ and to print more information:
npm run test-with-logs
```

## Write Tests

### Add a new contract

- Add contract source code to `contracts/sources.ts`
- Run `npm run pre-build-contracts`=> This will generate the necessary abi and byte code
- Create your contract with
`const { contract, rawTx } = await createContract(context.web3, "TestContract");`

## Verbose mode

You can also add the node's logs to the output using the `MOONBEAM_LOG` env variable. Ex:
Expand All @@ -35,5 +44,52 @@ You can also add the node's logs to the output using the `MOONBEAM_LOG` env vari
MOONBEAM_LOG="warn,rpc=trace" npm run test
```

The Moonbeam node will be listening for RPC on port 19933, mostly to avoid
conflicts with already running Substrate nodes.
The test script will find available ports above 20000 in order to ensure that it doesn't conflict
with any other running services.

# Debugging a Moonbeam node

The repository contains a pre-configured debugger configuration for VSCode with the **CodeLLDB**
(`vadimcn.vscode-lldb`) extension.

Before debugging, you need to build the node with debug symbols with command
`RUSTFLAGS=-g cargo build --release` (available as a VSCode task). Then go in the **Debug** tab in
the left bar of VSCode and make sure **Launch Moonbeam Node (Linux)** is selected in the top
dropdown. **Build & Launch Moonbeam Node (Linux)** will trigger the build before launching the node.

To launch the debug session click on the green "play" arrow next to the dropdown. It will take some
time before the node starts, but the terminal containing the node output will appear when it is
really starting. The node is listening on ports 19931 (p2p), 19932 (rpc) and 19933 (ws).

You can explore the code and place a breakpoint on a line by left clicking on the left of the line
number. The execution will pause the next time this line is reached. The debug toolbar contains the
following buttons :

- Resume/Pause : Resume the execution if paused, pause the execution at the current location
(pretty random) if running.
- Step over : Resume the execution until next line, or go one level up if the end of the current
scope is reached.
- Step into : Resume the execution to go inside the immediatly next function call if any, otherwise
step to next line.
- Step out : Resume the execution until the end of the scope is reached.
- Restart : Kill the program and start a new debuging session.
- Stop : Kill the program and end debugin session.

Breakpoints stay between debugging sessions. When multiple function calls are made on the same line,
multiple step into, step out, step into, ... can be requiered to go inside one of the chained
calls.

When paused, content of variables is showed in the debuging tab of VSCode. Some basic types are
displayed correctly (primitive types, Vec, Arc) but more complex types such as HashMap/BTreeMap
are not "smartly" displayed (content of the struct is shown by mapping is hidden in the complexity
of the implementation).

## Running Typescript tests with a debug node

By setting the environement variable `DEBUG_MODE=true`, the Typescript tests will not spawn its
own node and instead will connect to an external node running on ports 19931/19932/19933, which
are the ports used by the debug node.

A VSCode test allow to quickly run the `test-single` test in debug mode. To run another test,
change the command in the `package.json`. Note that you should restart the node after running
one test file.
Loading