-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from eigerco/feat/10/testing-environment
test: setup testing environment and reproducible build
- Loading branch information
Showing
11 changed files
with
311 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
|
||
if ! has nix_direnv_version || ! nix_direnv_version 3.0.4; then | ||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4=" | ||
fi | ||
|
||
watch_file rust-toolchain.toml | ||
use flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
exclude = [".direnv/*", "target/*"] | ||
|
||
[[rule]] | ||
include = ["**/*.toml"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Development environment for Polka Storage Node | ||
|
||
## Setup | ||
|
||
### Requirements | ||
- [nix](https://nixos.org/download/) with [flakes](https://nixos.wiki/wiki/flakes) enabled (`echo 'experimental-features = nix-command flakes' >> ~/.config/nix/nix.conf`) | ||
- reasoning: every developer has the same version of development tools (rust, protoc, zombienet), directed by [flake.nix](./flake.nix)`. | ||
- how it works? fasterthanli.me has [a whole series on it](https://fasterthanli.me/series/building-a-rust-service-with-nix/part-10). | ||
- optional: [vscode extension for Nix](https://marketplace.visualstudio.com/items?itemName=jnoortheen.nix-ide) | ||
- [direnv](https://direnv.net/) with a [shell hook](https://direnv.net/docs/hook.html) | ||
- *VS Code only* [direnv extension](https://marketplace.visualstudio.com/items?itemName=mkhl.direnv) (uses the same tooling as rust-toolchain.toml defined). | ||
- reasoning: when you enter a directory it uses everything defined in [.envrc](./.envrc), e.g. environment variables, `nix`, secrets. | ||
|
||
## How it works? | ||
Nix is a package manager, which sneakily downloads all of the dependencies and updates PATH when you launch it with `nix develop`. | ||
You end up having all of the required dependencies in a configured shell (so you don't have to install a specific cargo version, just, polkadot on your own). | ||
`nix develop` needs to be used in the workspace root, as it depends on [flake.nix](./flake.nix) file. | ||
`direnv` is a shell hook, which configures your shell based on the [.envrc](./.envrc) file. | ||
In our case it just launches `nix develop` shell for you and when you exit the folder, it disables it. | ||
|
||
|
||
## Usage | ||
|
||
1. Verify: | ||
``` | ||
$ polkadot --version | ||
polkadot 1.11.0-0bb6249 | ||
$ cargo --version | ||
cargo 1.77.0 (3fe68eabf 2024-02-29) | ||
$ zombienet version | ||
1.3.103 | ||
``` | ||
2. `just testnet` | ||
3. Click `charlie`'s direct link (should look like `https://polkadot.js.org/apps/?rpc=ws://<address here>#/explorer`). It will take you to the parachain interface where you can monitor block production. | ||
- testnet is defined via [zombienet configuration](https://paritytech.github.io/zombienet/guide.html) in [local-testnet.toml](./scripts//local-testnet.toml) | ||
|
||
## Maintenance | ||
|
||
- Updating nix flakes (`flake.lock` file has frozen state of package): `nix flake update`. | ||
- Running out of the disk space? `nix-collect-garbage`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
alias b := build | ||
alias r := release | ||
alias t := testnet | ||
|
||
lint: | ||
cargo clippy --locked --no-deps -- -D warnings | ||
taplo lint && taplo fmt --check | ||
|
||
build: lint | ||
cargo build | ||
|
||
release: lint | ||
cargo build --release | ||
|
||
testnet: release | ||
zombienet -p native spawn zombienet/local-testnet.toml |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
inputs = { | ||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; | ||
flake-utils.url = "github:numtide/flake-utils"; | ||
rust-overlay = { | ||
url = "github:oxalica/rust-overlay"; | ||
inputs = { | ||
nixpkgs.follows = "nixpkgs"; | ||
flake-utils.follows = "flake-utils"; | ||
}; | ||
}; | ||
zombienet = { | ||
url = "github:paritytech/zombienet"; | ||
inputs = { | ||
nixpkgs.follows = "nixpkgs"; | ||
}; | ||
}; | ||
}; | ||
outputs = { self, nixpkgs, flake-utils, rust-overlay, zombienet }: | ||
flake-utils.lib.eachDefaultSystem (system: | ||
let | ||
overlays = [ (import rust-overlay) zombienet.overlays.default ]; | ||
pkgs = import nixpkgs { | ||
inherit system overlays; | ||
}; | ||
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; | ||
buildInputs = with pkgs; [ | ||
clang | ||
pkg-config | ||
rustToolchain | ||
just | ||
taplo | ||
polkadot | ||
# Due to zombienet's flake.nix, needs to be prefixed with pkg.zombienet | ||
pkgs.zombienet.default | ||
] ++ lib.optionals stdenv.isDarwin [ | ||
darwin.apple_sdk.frameworks.Security | ||
darwin.apple_sdk.frameworks.CoreServices | ||
darwin.apple_sdk.frameworks.SystemConfiguration | ||
]; | ||
in | ||
with pkgs; | ||
{ | ||
devShells.default = mkShell { | ||
inherit buildInputs; | ||
|
||
LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib"; | ||
PROTOC = "${protobuf}/bin/protoc"; | ||
RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library/"; | ||
ROCKSDB_LIB_DIR = "${rocksdb}/lib"; | ||
}; | ||
} | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[toolchain] | ||
channel = "1.77.0" | ||
components = ["cargo", "clippy", "rust-analyzer", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"] | ||
profile = "minimal" | ||
targets = ["wasm32-unknown-unknown"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
[relaychain] | ||
chain = "rococo-local" | ||
default_command = "polkadot" | ||
|
||
[[relaychain.nodes]] | ||
name = "alice" | ||
validator = true | ||
|
||
[[relaychain.nodes]] | ||
name = "bob" | ||
validator = true | ||
|
||
[[parachains]] | ||
cumulus_based = true | ||
id = 2000 | ||
|
||
# run charlie as parachain collator | ||
[[parachains.collators]] | ||
command = "target/release/polka-storage-node" | ||
name = "charlie" | ||
validator = true |