Skip to content

Commit e7bbc1d

Browse files
authored
Merge pull request #8 from randa-mu/fix/various
Add rust actions
2 parents 08fa82e + ffb44ec commit e7bbc1d

File tree

13 files changed

+143
-91
lines changed

13 files changed

+143
-91
lines changed

.github/actions/build-and-test.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: 'Rust Test Action'
2+
description: 'Runs format check, clippy, and tests for a Rust crate'
3+
inputs:
4+
working-directory:
5+
required: true
6+
description: 'Directory containing the Rust crate'
7+
target-folder:
8+
required: false
9+
default: './target'
10+
description: 'Target folder used for building'
11+
extra-cache-key:
12+
required: false
13+
default: 'rust'
14+
description: 'Additional key used for caching'
15+
additional-flags:
16+
required: false
17+
default: ''
18+
description: 'Additional flags for cargo commands'
19+
20+
runs:
21+
using: "composite"
22+
steps:
23+
# Pull cargo nextest binaries
24+
- uses: taiki-e/install-action@v2
25+
with:
26+
tool: nextest,cargo-hack
27+
28+
- name: Cache Cargo
29+
uses: Swatinem/rust-cache@v2
30+
with:
31+
prefix-key: ${{ runner.os }}-cargo
32+
key: ${{ inputs.extra-cache-key }}
33+
34+
- name: Check formatting
35+
working-directory: ${{ inputs.working-directory }}
36+
run: cargo fmt --check ${{ inputs.additional-flags }}
37+
shell: bash
38+
39+
- name: Check clippy
40+
working-directory: ${{ inputs.working-directory }}
41+
run: cargo hack clippy --each-feature --all-targets --target-dir ${{ inputs.target-folder }} -- -Dwarnings ${{ inputs.additional-flags }}
42+
shell: bash
43+
44+
- name: Run all tests
45+
working-directory: ${{ inputs.working-directory }}
46+
run: cargo nextest run --target-dir ${{ inputs.target-folder }} --no-tests warn
47+
shell: bash
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: rust-build-and-tests
2+
on:
3+
push:
4+
branches: [master]
5+
pull_request:
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: ci-${{ github.ref }}-onlyswaps
10+
cancel-in-progress: true
11+
12+
env:
13+
CARGO_TERM_COLOR: always
14+
15+
jobs:
16+
rust-build-and-tests:
17+
name: Build and test rust crates
18+
runs-on: ["randamu-self-hosted-default"]
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
with:
23+
submodules: 'recursive'
24+
token: ${{ secrets.PAT_TOKEN }}
25+
26+
# 1. Compile onlysubs-solidity
27+
- name: Cache npm onlysubs-solidity
28+
uses: actions/cache@v3
29+
with:
30+
path: onlysubs-solidity/node_modules
31+
key: ${{ runner.os }}-npm-onlysubs-solidity-${{ hashFiles('onlysubs-solidity/package-lock.json') }}
32+
restore-keys: |
33+
${{ runner.os }}-npm-onlysubs-solidity-
34+
35+
- name: onlysubs-solidity - Install dependencies
36+
working-directory: ./onlysubs-solidity
37+
run: npm ci
38+
39+
- name: Cache Solidity onlysubs-solidity
40+
uses: actions/cache@v3
41+
with:
42+
path: onlysubs-solidity/out
43+
key: ${{ runner.os }}-sol-onlysubs-solidity-${{ hashFiles('onlysubs-solidity/src/**/*.sol', 'onlysubs-solidity/lib/**/*.sol') }}
44+
restore-keys: |
45+
${{ runner.os }}-sol-onlysubs-solidity-
46+
47+
- name: onlysubs-solidity - Build Solidity contracts
48+
working-directory: ./onlysubs-solidity
49+
run: npm run build:forge
50+
51+
# 2. Build and test workspace packages
52+
- name: Lint & Test Rust Workspace
53+
uses: ./.github/actions/rust-test-action
54+
with:
55+
working-directory: .
56+
extra-cache-key: 'onlyswaps-solver'

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ First retrieve and build submodules with `./build-dependencies.sh` then run `car
1818

1919
## Running locally
2020
- Start two anvil blockchains (note: block time is necessary or chain state can get confused):
21-
`$ anvil --port 1337 --chain-id 1337 --block-time 3`
22-
`$ anvil --port 1338 --chain-id 1338 --block-time 3`
21+
```bash
22+
$ anvil --port 1337 --chain-id 1337 --block-time 3
23+
$ anvil --port 1338 --chain-id 1338 --block-time 3
24+
```
2325

2426
- Deploy the contracts from onlysubs-solidity by:
2527
- `cd` into [onlysubs-solidity](./onlysubs-solidity)
@@ -29,7 +31,7 @@ First retrieve and build submodules with `./build-dependencies.sh` then run `car
2931
BLS_PUBLIC_KEY_X0=17445541620214498517833872661220947475697073327136585274784354247720096233162
3032
BLS_PUBLIC_KEY_X1=18268991875563357240413244408004758684187086817233527689475815128036446189503
3133
BLS_PUBLIC_KEY_Y0=11401601170172090472795479479864222172123705188644469125048759621824127399516
32-
BLS_PUBLIC_KEY_Y1=8044854403167346152897273335539146380878155193886184396711544300199836788154```
34+
BLS_PUBLIC_KEY_Y1=8044854403167346152897273335539146380878155193886184396711544300199836788154
3335
```
3436
- `source .env`
3537
- `$ forge script script/DeployAllContracts.s.sol --broadcast --rpc-url http://127.0.0.1:1337 --private-key $PRIVATE_KEY`

src/api.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ pub(crate) struct ApiServer {
99
impl ApiServer {
1010
pub fn new(port: u16) -> Self {
1111
let app = Router::new().route("/health", get(healthcheck_handler));
12-
Self {
13-
port,
14-
app,
15-
}
12+
Self { port, app }
1613
}
1714

1815
pub async fn start(self) -> eyre::Result<()> {

src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use crate::executor::TradeExecutor;
2+
use crate::model::BlockEvent;
23
use crate::network::Network;
34
use crate::solver::Solver;
45
use alloy::providers::DynProvider;
6+
use futures::StreamExt;
57
use futures::future::try_join_all;
68
use futures::stream::select_all;
79
use std::collections::HashMap;
8-
use futures::StreamExt;
9-
use crate::model::BlockEvent;
1010

1111
pub struct App {}
1212
impl App {

src/config.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
use std::fs;
21
use clap::Parser;
32
use serde::Deserialize;
43
use shellexpand::tilde;
4+
use std::fs;
55

66
#[derive(Parser, Debug)]
77
pub(crate) struct CliArgs {
8-
#[arg(
9-
short = 'c',
10-
long = "config-path",
11-
env = "SOLVER_CONFIG_PATH",
12-
default_value = "~/.solver/config.json"
13-
)]
8+
#[arg(short = 'c', long = "config-path", env = "SOLVER_CONFIG_PATH", default_value = "~/.solver/config.json")]
149
pub config_path: String,
1510

1611
#[arg(short = 's', long = "private-key", env = "SOLVER_PRIVATE_KEY")]
@@ -36,12 +31,7 @@ pub(crate) struct NetworkConfig {
3631
pub(crate) fn load_config_file(cli: &CliArgs) -> ConfigFile {
3732
println!("loading config file {}", cli.config_path);
3833
match fs::read(tilde(&cli.config_path).into_owned()) {
39-
Ok(contents) => serde_json::from_slice(&contents)
40-
.expect(format!("failed to parse config file at {}", cli.config_path).as_str()),
41-
Err(err) => panic!(
42-
"failed to read config file at {}: {:?}",
43-
cli.config_path,
44-
err.to_string()
45-
),
34+
Ok(contents) => serde_json::from_slice(&contents).unwrap_or_else(|_| panic!("failed to parse config file at {}", cli.config_path)),
35+
Err(err) => panic!("failed to read config file at {}: {:?}", cli.config_path, err.to_string()),
4636
}
4737
}

src/eth.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use alloy::sol;
22

33
sol!(
4+
#[allow(clippy::too_many_arguments)]
45
#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
56
#[sol(rpc)]
67
ERC20FaucetToken,
78
"onlysubs-solidity/out/ERC20FaucetToken.sol/ERC20FaucetToken.json"
89
);
910

1011
sol!(
12+
#[allow(clippy::too_many_arguments)]
1113
#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
1214
#[sol(rpc)]
1315
Router,

src/executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a, P: Provider> TradeExecutor<'a, P> {
4141
match approve {
4242
Ok(_) => {}
4343
Err(e) => {
44-
println!("error approving trade: {}", e);
44+
println!("error approving trade: {e}");
4545
}
4646
}
4747

src/main.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
mod network;
21
mod api;
3-
mod eth;
4-
mod config;
52
mod app;
6-
mod solver;
7-
mod model;
3+
mod config;
4+
mod eth;
85
mod executor;
6+
mod model;
7+
mod network;
8+
mod solver;
99
mod util;
1010

11-
use clap::Parser;
12-
use eyre::eyre;
13-
use dotenv::dotenv;
1411
use crate::api::ApiServer;
1512
use crate::app::App;
16-
use crate::config::{load_config_file, CliArgs, ConfigFile};
13+
use crate::config::{CliArgs, ConfigFile, load_config_file};
1714
use crate::network::Network;
15+
use clap::Parser;
16+
use dotenv::dotenv;
17+
use eyre::eyre;
1818

1919
#[tokio::main]
2020
async fn main() -> eyre::Result<()> {
@@ -43,7 +43,7 @@ async fn main() -> eyre::Result<()> {
4343
Err(e) => Err(eyre!("http server stopped unexpectedly: {}", e))
4444
}
4545
}
46-
46+
4747
_ = sigterm.recv() => {
4848
println!("received SIGTERM, shutting down...");
4949
Ok(())

0 commit comments

Comments
 (0)