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 1 commit
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
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
};

outputs = { self, nixpkgs, flake-utils, foundry }:

let
supportedSystems = [ "aarch64-darwin" "x86_64-darwin" "x86_64-linux" ];
overlays = [ foundry.overlay ];
Expand Down
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 "Initialize foundry libraries and 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)
13 changes: 11 additions & 2 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

set -e

echo "Setup git hooks"
git config --local core.hooksPath hooks/

echo "Update submodules"
git submodule update --init --recursive || true

echo "Installing dev tools"
go install github.com/ferranbt/fastssz/[email protected]

echo "Install node packages"
(cd web && pnpm install)
go install github.com/ferranbt/fastssz/sszgen@latest
ln -sf pre-commit.sh .git/hooks/pre-commit

./scripts/generate_bindings.sh
yrong marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 9 additions & 4 deletions smoketest/make-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@ command -v subxt || cargo install subxt-cli \
--tag $subxt_version \
--root $cargo_dir

if lsof -Pi :11144 -sTCP:LISTEN -t >/dev/null ; then
echo "substrate nodes running, fetch metadata and generate api bindings"
# Fetch metadata from BridgeHub and generate client
subxt codegen --url ws://localhost:11144 | rustfmt --edition 2021 --emit=stdout > src/parachains/bridgehub.rs
subxt codegen --url ws://localhost:12144 | rustfmt --edition 2021 --emit=stdout > src/parachains/assethub.rs
subxt codegen --url ws://localhost:9944 | rustfmt --edition 2021 --emit=stdout > src/parachains/relaychain.rs
else
echo "substrate nodes not running, please start with the e2e setup and rerun this script"
fi
yrong marked this conversation as resolved.
Show resolved Hide resolved

# Fetch metadata from BridgeHub and generate client
subxt codegen --url ws://localhost:11144 | rustfmt --edition 2021 --emit=stdout > src/parachains/bridgehub.rs
subxt codegen --url ws://localhost:12144 | rustfmt --edition 2021 --emit=stdout > src/parachains/assethub.rs
subxt codegen --url ws://localhost:9944 | rustfmt --edition 2021 --emit=stdout > src/parachains/relaychain.rs

# Generate Rust bindings for contracts
forge bind --module --overwrite \
Expand Down
13 changes: 0 additions & 13 deletions web/init.sh

This file was deleted.