Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dev setup #915

Merged
merged 7 commits into from
Aug 4, 2023
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 .envrc-example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8="
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

use flake
9 changes: 6 additions & 3 deletions scripts/pre-commit.sh → hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

// checks that the cumulus submodule is in sync with our substrate dependencies
# checks that the cumulus submodule is in sync with our substrate dependencies
check_duplicate_versions() {
local duplicates=`grep -Ei "source = \"git.*$1" cumulus/Cargo.lock parachain/Cargo.lock | sed 's/\.git//g' | sort -u`
local version_count=`echo "$duplicates" | awk -F':' '{for (i=2; i<NF; i++) printf $i " "; print $NF}' | sort -u | wc -l | xargs`
Expand All @@ -16,11 +16,14 @@ check_duplicate_versions() {
# check typos
chronic typos .

# lint and format for core contracts and typescript codes
(cd web && chronic pnpm lint && pnpm format)
# format contracts
(cd contracts && chronic forge fmt)

# lint and format for relayer codes
(cd relayer && chronic mage lint && chronic go fmt ./...)

# format rust
(cd parachain && chronic cargo +nightly fmt)

check_duplicate_versions substrate
check_duplicate_versions polkadot
4 changes: 2 additions & 2 deletions relayer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ The relayer relies on dynamically generated bindings for our Ethereum contracts.
Compile the contracts in the [contracts](../contracts) directory:

```bash
pnpm build
forge build
```

Generate the bindings in the [contracts](contracts/) directory:
Generate contract bindings:

```bash
go generate ./...
Expand Down
4 changes: 0 additions & 4 deletions relayer/contracts/generate.go

This file was deleted.

4 changes: 4 additions & 0 deletions relayer/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//go:generate bash -c "jq .abi ../contracts/out/BeefyClient.sol/BeefyClient.json | abigen --abi - --type BeefyClient --pkg contracts --out contracts/beefy_client.go"
//go:generate bash -c "jq .abi ../contracts/out/IGateway.sol/IGateway.json | abigen --abi - --type Gateway --pkg contracts --out contracts/gateway.go"

package main
4 changes: 4 additions & 0 deletions relayer/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func BuildMain() error {
if err != nil {
return err
}
err = sh.Run("go", "generate", "./...")
if err != nil {
return err
}
return sh.Run("go", "build", "-o", "build/snowbridge-relay", "main.go")
}

Expand Down
15 changes: 15 additions & 0 deletions scripts/generate_bindings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

set -e

echo "Build contracts"
(cd contracts && forge build)

echo "Generate contract bindings for javascript"
(cd web/packages/contract-types && pnpm typechain && pnpm build)

echo "Generate contract bindings for go"
(cd relayer && mage build)

echo "Generate contract and substrate bindings for rust"
(cd smoketest && ./make-bindings.sh)
4 changes: 2 additions & 2 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ echo "Setting up submodules"
git submodule update --init --recursive || true

echo "Setting up git hooks"
ln -sf pre-commit.sh .git/hooks/pre-commit
git config --local core.hooksPath hooks/

echo "Installing Rust nightly toolchain"
rustup install --profile minimal nightly-"$SNOWBRIDGE_RUST_NIGHTLY"
rustup component add --toolchain nightly-"$SNOWBRIDGE_RUST_NIGHTLY" rustfmt

echo "Installing sszgen"
go install github.com/ferranbt/fastssz/sszgen@latest
go install github.com/ferranbt/fastssz/sszgen@v0.1.3

echo "Installing web packages"
(cd web && pnpm install)
23 changes: 14 additions & 9 deletions smoketest/make-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ set -eu

mkdir -p src/contracts

# Generate Rust bindings for contracts
forge bind --module --overwrite \
--select 'IGateway|WETH9|GatewayUpgradeMock' \
--bindings-path src/contracts \
--root ../contracts

# Generate Rust bindings for BridgeHub
subxt_version=v0.27.1
cargo_dir=".cargo"
Expand All @@ -15,13 +21,12 @@ command -v subxt || cargo install subxt-cli \
--tag $subxt_version \
--root $cargo_dir

# Fetch metadata from BridgeHub and generate client
subxt codegen --url ws://localhost:11144 | rustfmt +nightly-"$SNOWBRIDGE_RUST_NIGHTLY" --edition 2021 --emit=stdout > src/parachains/bridgehub.rs
subxt codegen --url ws://localhost:12144 | rustfmt +nightly-"$SNOWBRIDGE_RUST_NIGHTLY" --edition 2021 --emit=stdout > src/parachains/assethub.rs
subxt codegen --url ws://localhost:9944 | rustfmt +nightly-"$SNOWBRIDGE_RUST_NIGHTLY" --edition 2021 --emit=stdout > src/parachains/relaychain.rs
if ! lsof -Pi :11144 -sTCP:LISTEN -t >/dev/null; then
echo "substrate nodes not running, please start with the e2e setup and rerun this script"
exit 1
fi

# Generate Rust bindings for contracts
forge bind --module --overwrite \
--select 'IGateway|WETH9|GatewayUpgradeMock' \
--bindings-path src/contracts \
--root ../contracts
# Fetch metadata from BridgeHub and generate client
subxt codegen --url ws://localhost:11144 | rustfmt +nightly-"$SNOWBRIDGE_RUST_NIGHTLY" --edition 2021 --emit=stdout >src/parachains/bridgehub.rs
subxt codegen --url ws://localhost:12144 | rustfmt +nightly-"$SNOWBRIDGE_RUST_NIGHTLY" --edition 2021 --emit=stdout >src/parachains/assethub.rs
subxt codegen --url ws://localhost:9944 | rustfmt +nightly-"$SNOWBRIDGE_RUST_NIGHTLY" --edition 2021 --emit=stdout >src/parachains/relaychain.rs