Skip to content

Commit

Permalink
dev: 206 config file (eigerco#305)
Browse files Browse the repository at this point in the history
* initial config file
 
* parse config from file or from env

* update readme

* update --bin runs
  • Loading branch information
drspacemn committed Mar 16, 2023
1 parent c5023ab commit 6042d0c
Show file tree
Hide file tree
Showing 42 changed files with 433 additions and 339 deletions.
78 changes: 72 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 36 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
- [Beerusup](#beerusup)
- [Build](#build)
- [Test](#test)
- [Environment variables](#environment-variables)
- [Config](#config)
- [Config File](#config-file)
- [Environment Variables](#environment-variables)
- [Beerus CLI](#beerus-cli)
- [Debug Beerus CLI](#debug-beerus-cli)
- [Beerus CLI](#beerus-cli-1)
- [Beerus RPC](#beerus-rpc)
- [Debug Beerus RPC](#debug-beerus-rpc)
- [Beerus RPC](#beerus-rpc-1)
- [Roadmap](#roadmap)
- [Support](#support)
- [Project assistance](#project-assistance)
Expand Down Expand Up @@ -99,14 +101,7 @@ cargo build --release
cargo test
```

#### Environment variables

Beerus is configurable through environment variables.

```bash
cp examples/.env.example .env
source .env
```
#### Config

The project requires an Ethereum node and a Starknet node. For Ethereum nodes
you can use Alchemy (not Infura since it does not support getProof endpoint).
Expand All @@ -122,27 +117,47 @@ For StarkNet node for the moment you can use Infura but soon
will be implemented in Pathfinder nodes, and so will these nodes be working as
well.

| Name | Mainnet | Goerli |
| ------------- | ------------- | ------------- |
| ETHEREUM_NETWORK | `mainnet` | `goerli(default)` |
| ETHEREUM_EXECUTION_RPC_URL | <https://eth-mainnet.g.alchemy.com/v2/XXXXX> | <https://eth-goerli.g.alchemy.com/v2/XXXXX> |
| ETHEREUM_CONSENSUS_RPC_URL | <https://www.lightclientdata.org> | <http://testing.prater.beacon-api.nimbus.team> |
| STARKNET_RPC_URL | <https://starknet-mainnet.infura.io/v3/XXXXX> | <https://starknet-goerli.infura.io/v3/XXXXX>
| Env Var | TOML | Mainnet | Goerli |
| ------------- | ------------- | ------------- | ------------- |
| ETHEREUM_NETWORK | ethereum_network | `mainnet` | `goerli(default)` |
| ETHEREUM_EXECUTION_RPC_URL | ethereum_consensus_rpc | <https://eth-mainnet.g.alchemy.com/v2/XXXXX> | <https://eth-goerli.g.alchemy.com/v2/XXXXX> |
| ETHEREUM_CONSENSUS_RPC_URL | ethereum_execution_rpc | <https://www.lightclientdata.org> | <http://testing.prater.beacon-api.nimbus.team> |
| STARKNET_RPC_URL | starknet_rpc | <https://starknet-mainnet.infura.io/v3/XXXXX> | <https://starknet-goerli.infura.io/v3/XXXXX> |

##### Config File

Beerus is configurable via a config toml. If you have set the env var
`BEERUS_CONFIG` = `path/to/config` this will override all other environment
variables and take configuration from values defined herein.
Also the the cli can be directed via `berrus --config <path/to/config>`

[goerli.toml](./crates/beerus-core/tests/data/goerli.toml)

[mainnet.toml](./crates/beerus-core/tests/data/mainnet.toml)

##### Environment Variables

Beerus is configurable through environment variables.

```bash
cp examples/.env.example .env
source .env
```

#### [Beerus CLI](https://github.com/keep-starknet-strange/beerus/blob/main/docs/beerus-cli/cli.md)

##### Debug Beerus CLI
##### Beerus CLI

```bash
RUST_LOG=info cargo run --bin beerus-cli
cargo run --bin beerus starknet query-state-root
```

#### [Beerus RPC](https://github.com/keep-starknet-strange/beerus/blob/main/crates/beerus-rpc/rpc.md)

##### Debug Beerus RPC
##### Beerus RPC

```bash
RUST_LOG=info cargo run --bin beerus-rpc
cargo run --bin beerus-rpc
```

## Roadmap
Expand Down
11 changes: 4 additions & 7 deletions crates/beerus-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ use std::process::exit;
async fn main() {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();

// TODO: we need to print CLI usage
let cli = Cli::parse();
let config = match Config::new_from_env() {
Ok(config) => config,
Err(err) => {
error! {"{}", err};
exit(1);
}

let config = match &cli.config {
Some(path) => Config::from_file(path),
None => Config::from_env(),
};

info!("creating ethereum(helios) lightclient...");
Expand Down
15 changes: 2 additions & 13 deletions crates/beerus-cli/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[cfg(test)]

mod test {
use std::{path::PathBuf, str::FromStr};
use std::str::FromStr;

use beerus_cli::{
model::{
Expand Down Expand Up @@ -3738,19 +3738,8 @@ mod test {
}

fn config_and_mocks() -> (Config, MockEthereumLightClient, MockStarkNetLightClient) {
let config = Config {
ethereum_network: "mainnet".to_string(),
ethereum_consensus_rpc: "http://localhost:8545".to_string(),
ethereum_execution_rpc: "http://localhost:8545".to_string(),
starknet_rpc: "http://localhost:8545".to_string(),
data_dir: Some(PathBuf::from("/tmp")),
starknet_core_contract_address: Address::from_str(
"0x0000000000000000000000000000000000000000",
)
.unwrap(),
};
(
config,
Config::default(),
MockEthereumLightClient::new(),
MockStarkNetLightClient::new(),
)
Expand Down
2 changes: 2 additions & 0 deletions crates/beerus-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ hex = "0.4.3"
mockall = "0.11.3"
url = "2.3.1"
tokio = { version = "1.21.2", features = ["macros"] }
toml = "0.7.3"

[dev-dependencies]
httpmock = "0.6.7"
temp-env = "0.3.1"
serial_test = "1.0.0"

[dev-dependencies.cargo-husky]
version = "1.5.0"
Expand Down
Loading

0 comments on commit 6042d0c

Please sign in to comment.