Skip to content

Commit

Permalink
[BP: v7 <- #785] local-interchain: Rust Driver (#818)
Browse files Browse the repository at this point in the history
* local-interchain: Rust Driver (#785)

* cli: add app overrides for port and address

* init: rust client base

* request resp: use JSON

* minor: fmt

* bin builder

* feat: add query & binary actions + simple examples

* Add cw_std

* feat: tx, get_tx_hash, and query_tx_hash

* add: localic-std library

* condense main.rs to use new std lib

* use file_path for uploader instead

* lib misc: bank_send, errors, libs, bals

* CW: Store, Init, Query, Better ActionBuilder

* minor: test path cleanup

* ci: attempt basic local-ic + rust e2e

* ci: set manifest-path to sub-dir

* ci: fix manifest path

* cw: get_contract_address

* cw store: if err, return exact (may not be JSON)

* add execute_contract

* feat: Upload-Type for cosmwasm contracts

* better uploader error handling for debugging

* more test, get_files func,

* backup; more info queries

* move GetInfo into their own funcs

* query: get ibc config (denom, bin, etc)

* minor: more general test for node name

* recover-key, overwrite genesis, add-full-node

* format

* add relayer support

* upgrade old docker values

* tweaks, relayer Channel type

* CW: instantiate, execute, and query with mut CW object

* move CW & Bank -> a modules mod

* on Tx, poll for Tx hash resp. 5x before failure

* codebase lint

* ci: clippy lint workflow

* Move dump-contract-state to POST

* ci: fix lint

* add: `get_sdk_status_code`

* ci: change clippy working-directory

* `query_value`, Debug for CRBuilder

* remove old println, add err to fet_files

* migrate to a workspace

* mod tidy

* add back flags to start_chain

* abstract away required flags

* remove old panic, fmt

* move old rest server to be cli arg only

* Add setup documentation

(cherry picked from commit ea7ce03)

# Conflicts:
#	local-interchain/go.mod
#	local-interchain/go.sum

* fix go.mod & v8 namespace (-> v7)

---------

Co-authored-by: Reece Williams <[email protected]>
Co-authored-by: Reece Williams <[email protected]>
  • Loading branch information
3 people authored Oct 11, 2023
1 parent 54a27f8 commit 1e83cdf
Show file tree
Hide file tree
Showing 45 changed files with 4,117 additions and 66 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,24 @@ jobs:
version: latest
only-new-issues: true
args: --timeout=5m

clippy-lint:
defaults:
run:
working-directory: local-interchain/rust/localic-std
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install stable with clippy and rustfmt
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
- name: Install clippy
run: rustup component add clippy
- name: Update
run: cargo update
- name: Run clippy
run: make lint

54 changes: 53 additions & 1 deletion .github/workflows/local-interchain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
build:
runs-on: ubuntu-latest
name: build
defaults:
run:
working-directory: ./local-interchain
steps:
- name: Checkout interchaintest
uses: actions/checkout@v3
Expand All @@ -24,4 +27,53 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- run: cd local-interchain && go mod tidy && make install
- name: build local-interchain
run: go mod tidy && make install

- name: Upload localic artifact
uses: actions/upload-artifact@v3
with:
name: local-ic
path: ~/go/bin/local-ic

# TOOO: put the python workflow here. (https://github.com/strangelove-ventures/interchaintest/pull/775)

rust-e2e:
name: rust e2e
needs: build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./local-interchain
strategy:
fail-fast: false

steps:
- name: checkout chain
uses: actions/checkout@v3

- name: Install latest toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: wasm32-unknown-unknown
override: true

- name: Download Tarball Artifact
uses: actions/download-artifact@v3
with:
name: local-ic
path: /tmp

- name: Make local-ic executable
run: chmod +x /tmp/local-ic

- name: Start background ibc local-interchain
run: /tmp/local-ic start juno_ibc --api-port 8080 &

- name: Run Rust Script
run: cd rust && cargo run --package localic-bin --bin localic-bin

- name: Cleanup
run: killall local-ic && exit 0
1 change: 1 addition & 0 deletions local-interchain/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ configs/logs.json
configs/contracts.json

contracts/*.wasm
!contracts/cw_ibc_example.wasm


__pycache__/
9 changes: 6 additions & 3 deletions local-interchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

A simple way to config and run IBC local chain testing environments with any language of choice for interaction.

## Installing
## Repository CI

- [**Rust**](./rust/README.md)

## Installing Locally

**Install on Mac / Linux**
```bash
Expand Down Expand Up @@ -102,8 +106,7 @@ Here is a base chain template with every feature the configuration accepts. Acco
"gas_prices": "0%DENOM%",
"gas_adjustment": 2.0,
"number_vals": 1,
"number_node": 0,
"use_new_genesis_command": false,
"number_node": 0,
"ibc_paths": ["juno-ibc-1"],
"debugging": true,
"block_time": "500ms",
Expand Down
15 changes: 7 additions & 8 deletions local-interchain/chains/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"binary": "junod",
"bech32_prefix": "juno",
"docker_image": {
"repository": "ghcr.io/cosmoscontracts/juno-e2e",
"version": "v14.1.0"
},
"use_new_genesis_command": false,
"repository": "ghcr.io/cosmoscontracts/juno",
"version": "v17.0.0"
},
"gas_prices": "0%DENOM%",
"chain_type": "cosmos",
"coin_type": 118,
Expand All @@ -24,19 +23,19 @@
"genesis": {
"modify": [
{
"key": "app_state.gov.voting_params.voting_period",
"key": "app_state.gov.params.voting_period",
"value": "15s"
},
{
"key": "app_state.gov.deposit_params.max_deposit_period",
"key": "app_state.gov.params.max_deposit_period",
"value": "15s"
},
{
"key": "app_state.gov.deposit_params.min_deposit.0.denom",
"key": "app_state.gov.params.min_deposit.0.denom",
"value": "ujuno"
},
{
"key": "app_state.gov.deposit_params.min_deposit.0.amount",
"key": "app_state.gov.params.min_deposit.0.amount",
"value": "1"
}
],
Expand Down
4 changes: 2 additions & 2 deletions local-interchain/chains/base_ibc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"bech32_prefix": "juno",
"denom": "ujuno",
"docker_image": {
"repository": "ghcr.io/cosmoscontracts/juno-e2e",
"version": "v14.1.0"
"repository": "ghcr.io/cosmoscontracts/juno",
"version": "v17.0.0"
},
"block_time": "2s",
"encoding-options": ["juno"],
Expand Down
3 changes: 1 addition & 2 deletions local-interchain/chains/cosmoshub.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"bech32_prefix": "cosmos",
"docker_image": {
"version": "v10.0.1"
},
"use_new_genesis_command": false,
},
"gas_prices": "0%DENOM%",
"chain_type": "cosmos",
"coin_type": 118,
Expand Down
15 changes: 7 additions & 8 deletions local-interchain/chains/juno_ibc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"binary": "junod",
"bech32_prefix": "juno",
"docker_image": {
"repository": "ghcr.io/cosmoscontracts/juno-e2e",
"version": "v14.1.0"
"repository": "ghcr.io/cosmoscontracts/juno",
"version": "v17.0.0"
},
"use_new_genesis_command": false,
"gas_prices": "0%DENOM%",
"chain_type": "cosmos",
"coin_type": 118,
Expand All @@ -25,15 +24,15 @@
"genesis": {
"modify": [
{
"key": "app_state.gov.voting_params.voting_period",
"key": "app_state.gov.params.voting_period",
"value": "15s"
},
{
"key": "app_state.gov.deposit_params.max_deposit_period",
"key": "app_state.gov.params.max_deposit_period",
"value": "15s"
},
{
"key": "app_state.gov.deposit_params.min_deposit.0.denom",
"key": "app_state.gov.params.min_deposit.0.denom",
"value": "ujuno"
}
],
Expand All @@ -60,8 +59,8 @@
"bech32_prefix": "juno",
"denom": "ujuno",
"docker_image": {
"repository": "ghcr.io/cosmoscontracts/juno-e2e",
"version": "v14.1.0"
"repository": "ghcr.io/cosmoscontracts/juno",
"version": "v17.0.0"
},
"genesis": {
"accounts": [
Expand Down
3 changes: 1 addition & 2 deletions local-interchain/chains/stargaze.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
"bech32_prefix": "stars",
"docker_image": {
"version": "v10.0.1"
},
"use_new_genesis_command": false,
},
"gas_prices": "0%DENOM%",
"chain_type": "cosmos",
"coin_type": 118,
Expand Down
18 changes: 17 additions & 1 deletion local-interchain/cmd/local-ic/start_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import (
"github.com/strangelove-ventures/localinterchain/interchain"
)

const (
FlagAPIAddressOverride = "api-address"
FlagAPIPortOverride = "api-port"
)

var startCmd = &cobra.Command{
Use: "start <config.json>",
Aliases: []string{"s", "run"},
Expand All @@ -27,6 +32,17 @@ var startCmd = &cobra.Command{
configPath = filepath.Base(configPath)
}

interchain.StartChain(parentDir, configPath)
apiAddr, _ := cmd.Flags().GetString(FlagAPIAddressOverride)
apiPort, _ := cmd.Flags().GetUint16(FlagAPIPortOverride)

interchain.StartChain(parentDir, configPath, &interchain.AppConfig{
Address: apiAddr,
Port: apiPort,
})
},
}

func init() {
startCmd.Flags().String(FlagAPIAddressOverride, "127.0.0.1", "override the default API address")
startCmd.Flags().Uint16(FlagAPIPortOverride, 8080, "override the default API port")
}
6 changes: 0 additions & 6 deletions local-interchain/configs/server.json

This file was deleted.

Binary file added local-interchain/contracts/cw_ibc_example.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion local-interchain/docs/REST_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Since local-interchain exposes a REST API, you can interact with the chains usin

## Defaults

By default, the API is served at <http://127.0.0.1:8080/>. You can modify this before starting the chain via [the configs/server.json configuration file](../configs/server.json).
By default, the API is served at <http://127.0.0.1:8080/>. You can modify this before starting the binary with `--api-address` and `--api-port`.

## Environment Variables

Expand Down
3 changes: 2 additions & 1 deletion local-interchain/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ require (
github.com/spf13/cobra v1.7.0
github.com/strangelove-ventures/interchaintest/v7 v7.0.0-00010101000000-000000000000
github.com/tyler-smith/go-bip39 v1.1.0
go.uber.org/zap v1.25.0
go.uber.org/zap v1.26.0

)

require (
Expand Down
5 changes: 2 additions & 3 deletions local-interchain/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ github.com/aws/aws-sdk-go v1.44.203 h1:pcsP805b9acL3wUqa4JR2vg1k2wnItkDYNvfmcy6F
github.com/aws/aws-sdk-go v1.44.203/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand Down Expand Up @@ -1093,8 +1092,8 @@ go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9E
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.25.0 h1:4Hvk6GtkucQ790dqmj7l1eEnRdKm3k3ZUrUMS2d5+5c=
go.uber.org/zap v1.25.0/go.mod h1:JIAUzQIH94IC4fOJQm7gMmBJP5k7wQfdcnYdPoEXJYk=
go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo=
go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/crypto v0.0.0-20170613210332-850760c427c5/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
2 changes: 0 additions & 2 deletions local-interchain/interchain/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,12 @@ func LoadConfig(installDir, chainCfgFile string) (*types.Config, error) {
// configs Folder
configsDir := filepath.Join(installDir, "configs")
relayerFilePath := filepath.Join(configsDir, "relayer.json")
serverFilePath := filepath.Join(configsDir, "server.json")

config, err := loadConfig(config, cfgFilePath)
if err != nil {
return nil, err
}
config, _ = loadConfig(config, relayerFilePath)
config, _ = loadConfig(config, serverFilePath)

log.Println("Using directory:", installDir)
log.Println("Using chain config:", cfgFilePath)
Expand Down
Loading

0 comments on commit 1e83cdf

Please sign in to comment.