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

refactor(tests): Spawn node for the tests #195

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c4ab458
pull/run gear node
gshep Nov 4, 2024
af10b25
add synchronization to erc20-relay tests helping to avoid gclient/gsd…
gshep Nov 4, 2024
4b26be3
run remaining relayer tests
gshep Nov 5, 2024
adb6497
refactor init_and_updating test
gshep Nov 6, 2024
092e30d
set env vars to disable redundant wasm-builder actions
gshep Nov 7, 2024
210d530
refactor
gshep Nov 7, 2024
a0d14d2
Merge remote-tracking branch 'origin/main'
gshep Nov 7, 2024
92c9f8e
debug cargo clippy
gshep Nov 7, 2024
fcec78b
remove env vars
gshep Nov 7, 2024
9fdd463
Merge remote-tracking branch 'origin/main'
gshep Nov 12, 2024
a96dc90
fix review remarks
gshep Nov 12, 2024
31d2f3b
Merge remote-tracking branch 'origin/main'
gshep Nov 25, 2024
985e329
use archived data instead of RPC
gshep Nov 25, 2024
ec89686
use different accounts for tests
gshep Nov 26, 2024
06ae5f8
Merge remote-tracking branch 'origin/main'
gshep Nov 26, 2024
b0cc0d6
run all tests
gshep Nov 26, 2024
e9cdc78
fix review remark
gshep Nov 26, 2024
33e6de9
Merge remote-tracking branch 'origin/main'
gshep Nov 28, 2024
3f45e79
Merge remote-tracking branch 'origin/main'
gshep Dec 2, 2024
a43471a
fix review remark
gshep Dec 2, 2024
5f72272
fix review remark
gshep Dec 2, 2024
eb293bd
fix review remark: introduce tools/deploy-checkpoints
gshep Dec 2, 2024
9b7ac37
cargo clippy
gshep Dec 2, 2024
9839a26
Merge remote-tracking branch 'origin/main'
gshep Dec 2, 2024
960eadd
set std feature
gshep Dec 2, 2024
c17b6b3
set wasm-binary feature
gshep Dec 3, 2024
c595ec3
inspect build
gshep Dec 3, 2024
2d4ccfe
fix command
gshep Dec 3, 2024
ed1cd56
prebuild vft-manager first
gshep Dec 3, 2024
1f96b06
workaround awkward bug of building crates dependency graph by cargo
gshep Dec 3, 2024
e345530
fix review remark
gshep Dec 3, 2024
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
20 changes: 15 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ concurrency:

env:
CARGO_TERM_COLOR: always
__GEAR_WASM_BUILDER_NO_FEATURES_TRACKING: 1

jobs:
build:
Expand All @@ -35,7 +36,7 @@ jobs:
run: forge build
working-directory: ./ethereum
- name: Build
run: cargo build --release --all-targets
run: cargo build --package vft-manager --release --all-targets && cargo build --release --all-targets
lints:
runs-on: kuberunner
steps:
Expand All @@ -55,11 +56,13 @@ jobs:
run: forge build
working-directory: ./ethereum
- name: Run clippy
run: cargo clippy --release --all-targets -- -D warnings $(cat .lints | cut -f1 -d"#" | tr '\n' ' ')
run: cargo clippy --release --all-targets --package vft-manager -- -D warnings && cargo clippy --release --all-targets -- -D warnings $(cat .lints | cut -f1 -d"#" | tr '\n' ' ')
- name: Run rustfmt
run: cargo fmt -- --check
tests:
runs-on: kuberunner
env:
NODE_CONTAINER_NAME: gear_node${{ github.run_id }}_${{ github.run_number }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -76,18 +79,25 @@ jobs:
- name: Build ethereum smart-contracts
run: forge build
working-directory: ./ethereum
- name: Pull & run Gear node container
run: |
docker pull ghcr.io/gear-tech/node:v1.6.2
docker run --name $NODE_CONTAINER_NAME --detach --rm --publish 127.0.0.1:9944:9944 ghcr.io/gear-tech/node:v1.6.2 gear --dev --tmp --rpc-external
- name: Run tests
run: cargo test --release --workspace
run: cargo test --release --no-run --package vft-manager && cargo test --release --workspace
--exclude prover
--exclude plonky2_blake2b256
--exclude plonky2_ecdsa
--exclude plonky2_ed25519
--exclude plonky2_sha512
--exclude plonky2_u32
--exclude plonky2_u32 || { exit_code=$?; if [ x$exit_code != x0 ]; then docker stop $NODE_CONTAINER_NAME; fi; exit $exit_code; }
- name: Run solidity tests
run: |
cd ethereum
forge test
- name: Stop Gear node container (if any)
continue-on-error: true
run: docker stop $NODE_CONTAINER_NAME
check-zk-circuits-changed:
runs-on: kuberunner
outputs:
Expand Down Expand Up @@ -141,7 +151,7 @@ jobs:
run: forge build --force --no-cache
working-directory: ./ethereum
- name: Build workspace
run: cargo build --release --all-targets
run: cargo build --package vft-manager --release --all-targets && cargo build --release --all-targets
- name: Check that files match
run: |
stored=(
Expand Down
36 changes: 36 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"prover",
"relayer",
"circuits/*",
"ethereum_beacon_client",
"ethereum-common",
"gear-programs/bridging-payment",
"gear-programs/bridging-payment/app",
Expand All @@ -22,6 +23,7 @@ members = [
"gear-programs/wrapped-vara/app",
"gear-programs/wrapped-vara/client",
"utils-prometheus",
"tools/deploy-checkpoints",
"tools/deploy-to-gear",
"tools/genesis-config",
]
Expand All @@ -41,6 +43,7 @@ plonky2_ed25519 = { path = "./circuits/plonky2_ed25519" }
plonky2_ecdsa = { path = "./circuits/plonky2_ecdsa" }
plonky2_u32 = { path = "./circuits/plonky2_u32" }
ethereum-client = { path = "./ethereum/client" }
ethereum_beacon_client = { path = "ethereum_beacon_client" }
ethereum-common = { path = "ethereum-common", default-features = false }

bridging-payment = { path = "gear-programs/bridging-payment" }
Expand Down Expand Up @@ -129,6 +132,7 @@ ring = { git = "https://github.com/gear-tech/ring.git", branch = "gear-v0.17.8",
"alloc",
] }
rlp = { version = "0.5.2", default-features = false }
ruzstd = "0.5.0"
scale-info = { version = "2.10", default-features = false, features = [
"derive",
] }
Expand Down
15 changes: 15 additions & 0 deletions ethereum_beacon_client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "ethereum_beacon_client"
version.workspace = true
edition.workspace = true

[dependencies]
anyhow.workspace = true
ark-serialize = { workspace = true, features = ["std"] }
checkpoint_light_client-io = { workspace = true, features = ["std"] }
ethereum-common = { workspace = true, features = ["std"] }
futures.workspace = true
hex = { workspace = true, features = ["std"] }
reqwest.workspace = true
serde = { workspace = true, features = ["std"] }
serde_json.workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ impl BeaconClient {
Err(anyhow!("Block was not found"))
}

#[cfg(test)]
pub async fn get_bootstrap(
&self,
checkpoint: &str,
Expand Down
2 changes: 1 addition & 1 deletion gear-programs/bridging-payment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bridging-payment = { path = ".", features = ["wasm-binary"] }
bridging-payment-client = { path = "client" }
vft-manager = { workspace = true, features = ["wasm-binary"] }
vft-manager-client.workspace = true
extended-vft.workspace = true
extended-vft = { workspace = true, features = ["wasm-binary"] }
extended-vft-client.workspace = true

sails-rs = { workspace = true, features = ["gtest"] }
Expand Down
1 change: 1 addition & 0 deletions gear-programs/erc20-relay/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ futures.workspace = true
gclient.workspace = true
gstd.workspace = true
sails-rs = { workspace = true, features = ["gclient"] }
sp-core = { workspace = true, features = ["std"] }
tokio = { workspace = true, features = ["rt", "macros"] }
hex-literal.workspace = true
hex.workspace = true
Expand Down
59 changes: 45 additions & 14 deletions gear-programs/erc20-relay/app/tests/gclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,68 @@ mod vft {
}

use erc20_relay_client::traits::{Erc20Relay, Erc20RelayFactory};
use gclient::{Event, EventProcessor, GearApi, GearEvent};
use gclient::{Event, EventProcessor, GearApi, GearEvent, WSAddress};
use sails_rs::{calls::*, gclient::calls::*, prelude::*};
use sp_core::crypto::DEV_PHRASE;
use tokio::sync::Mutex;
use vft::vft_manager;

async fn spin_up_node() -> (GClientRemoting, GearApi, CodeId, GasUnit) {
static LOCK: Mutex<(u32, Option<CodeId>)> = Mutex::const_new((0, None));
mertwole marked this conversation as resolved.
Show resolved Hide resolved

async fn connect_to_node() -> (impl Remoting + Clone, GearApi, CodeId, GasUnit, [u8; 4]) {
let api = GearApi::dev().await.unwrap();
let gas_limit = api.block_gas_limit().unwrap();
let remoting = GClientRemoting::new(api.clone());
let (code_id, _) = api.upload_code(erc20_relay::WASM_BINARY).await.unwrap();
let (api, code_id, salt) = {
let mut lock = LOCK.lock().await;
let code_id = match lock.1 {
Some(code_id) => code_id,
None => {
let (code_id, _) = api.upload_code(erc20_relay::WASM_BINARY).await.unwrap();
lock.1 = Some(code_id);

code_id
}
};

let salt = lock.0;
lock.0 += 1;

let suri = format!("{DEV_PHRASE}//erc20-relay-{salt}:");
let api2 = GearApi::init_with(WSAddress::dev(), suri).await.unwrap();

let account_id: &[u8; 32] = api2.account_id().as_ref();
api.transfer_keep_alive((*account_id).into(), 100_000_000_000_000)
.await
.unwrap();

(api2, code_id, salt)
};

(remoting, api, code_id, gas_limit)
(
GClientRemoting::new(api.clone()),
api,
code_id,
gas_limit,
salt.to_le_bytes(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just generate random [u8; 32] for salt? As I see it will simplify code a lot

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid we will need the mutex anyway since the first transaction of transferring funds from Alice to the account should be sent beforehand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, maybe not a lot but you will not need to pass salt everywhere around

)
}

#[ignore]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is used for calculating minimal gas required to send MintTokens request so shouldn't be run every time. Moreover it will be removed in the PR with historical proxy implementation

#[tokio::test]
#[ignore = "Requires running node"]
async fn gas_for_reply() {
use erc20_relay_client::{traits::Erc20Relay as _, Erc20Relay, Erc20RelayFactory};

let route = <vft_manager::io::SubmitReceipt as ActionIo>::ROUTE;

let (remoting, api, code_id, gas_limit) = spin_up_node().await;
let (remoting, api, code_id, gas_limit, salt) = connect_to_node().await;
let account_id: ActorId = <[u8; 32]>::from(api.account_id().clone()).into();

let factory = Erc20RelayFactory::new(remoting.clone());

let program_id = factory
.gas_calculation(1_000, 5_500_000_000)
.with_gas_limit(gas_limit)
.send_recv(code_id, [])
.send_recv(code_id, salt)
.await
.unwrap();

Expand Down Expand Up @@ -89,11 +122,10 @@ async fn gas_for_reply() {
}

#[tokio::test]
#[ignore = "Requires running node"]
async fn set_vft_manager() {
use erc20_relay_client::Config;

let (remoting, _api, code_id, gas_limit) = spin_up_node().await;
let (remoting, _api, code_id, gas_limit, salt) = connect_to_node().await;

let factory = erc20_relay_client::Erc20RelayFactory::new(remoting.clone());

Expand All @@ -106,7 +138,7 @@ async fn set_vft_manager() {
},
)
.with_gas_limit(gas_limit)
.send_recv(code_id, [])
.send_recv(code_id, salt)
.await
.unwrap();

Expand Down Expand Up @@ -161,11 +193,10 @@ async fn set_vft_manager() {
}

#[tokio::test]
#[ignore = "Requires running node"]
async fn update_config() {
use erc20_relay_client::Config;

let (remoting, _api, code_id, gas_limit) = spin_up_node().await;
let (remoting, _api, code_id, gas_limit, salt) = connect_to_node().await;

let factory = erc20_relay_client::Erc20RelayFactory::new(remoting.clone());

Expand All @@ -181,7 +212,7 @@ async fn update_config() {
},
)
.with_gas_limit(gas_limit)
.send_recv(code_id, [])
.send_recv(code_id, salt)
.await
.unwrap();

Expand Down
2 changes: 1 addition & 1 deletion gear-programs/vft-manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sails-idl-gen.workspace = true
[dev-dependencies]
vft-manager = { path = ".", features = ["wasm-binary"] }
vft-manager-client = { path = "client" }
extended-vft = { workspace = true, features = ["wasm-binary"] }
extended-vft-client.workspace = true

alloy-consensus.workspace = true
Expand All @@ -26,7 +27,6 @@ gear-core.workspace = true
gtest.workspace = true
parity-scale-codec.workspace = true
scale-info.workspace = true
extended-vft.workspace = true
gclient.workspace = true

[features]
Expand Down
5 changes: 5 additions & 0 deletions relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ clap.workspace = true
derive_more.workspace = true
dotenv.workspace = true
erc20-relay-client.workspace = true
ethereum_beacon_client.workspace = true
ethereum-common.workspace = true
futures.workspace = true
gear-core.workspace = true
Expand All @@ -49,3 +50,7 @@ utils-prometheus.workspace = true

[build-dependencies]
cgo_oligami.workspace = true

[dev-dependencies]
ruzstd.workspace = true
sp-core = { workspace = true, features = ["std"] }
2 changes: 1 addition & 1 deletion relayer/src/ethereum_checkpoints/replay_back.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::ethereum_beacon_client::{self, BeaconClient};
use ethereum_beacon_client::{self, BeaconClient};

#[allow(clippy::too_many_arguments)]
pub async fn execute(
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/ethereum_checkpoints/sync_update.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::ethereum_beacon_client::{self, BeaconClient};
pub use checkpoint_light_client_io::sync_update::Error;
use ethereum_beacon_client::{self, BeaconClient};
use std::ops::ControlFlow::{self, *};

pub fn spawn_receiver(beacon_client: BeaconClient, sender: Sender<SyncCommitteeUpdate>) {
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"deneb","data":{"attested_header":{"beacon":{"slot":"3016814","proposer_index":"1380911","parent_root":"0xf3d5096150566bb2687601fe109ebb1b61e3f30123722763ea93e346a38e1c7b","state_root":"0x98c064397ad127b46cc49178a812c351226531e6ca5ad8fe38c3c6a26f2d3aea","body_root":"0x5cf4167844e5797ec90b4bc5e50575b3252435372587b2717fd5d69a26d593a9"},"execution":{"parent_hash":"0xc7862a6ce91525c77a7970ea1fd76cbf7d22ddb01e403a0898894692bd06885b","fee_recipient":"0x80058a30b84f339befb7abcb25b1412ff0f88ec3","state_root":"0xead225061308ae4e238a3fe5765a2162cf50cd289672666126171db6cad76427","receipts_root":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logs_bloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","prev_randao":"0x300670dd2990f2531c903f787d346ef2d384dddec9b409cd508857b9887b0bcb","block_number":"2778156","gas_limit":"30000000","gas_used":"0","timestamp":"1732104168","extra_data":"0x","base_fee_per_gas":"19","block_hash":"0x47a282309fafbf1d768b367a4c382a06d6cef325249a65732b33f5f90b092bfc","transactions_root":"0x7ffe241ea60187fdb0187bfa22de35d1f9bed7ab061d9401fd47e34a54fbede1","withdrawals_root":"0xf489101462d71d96c9a297adc78ee558f107ce072cf4a3c044402d7487d2a692","blob_gas_used":"0","excess_blob_gas":"0"},"execution_branch":["0x7f62fda28c83c818acccaea3982c597c69283878a61277f278255f3e92ea3c48","0xb46f0c01805fe212e15907981b757e6c496b0cb06664224655613dcec82505bb","0xdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71","0x03d29a307417d82b2beb9649f6e927a7dadc3e38e3afee73a0cc56dcf2ba822a"]},"finalized_header":{"beacon":{"slot":"3016736","proposer_index":"306051","parent_root":"0x0eb0e34db85cafad1969b15b7a6c80d6cc1aac81e052d2bed704cd9d06478c3c","state_root":"0xe5080f936036fd96ff9e304df7df22c39686f62ef0acefb45134496f58aa318d","body_root":"0xf382b98973092f0c3b639badc5f7479522c79ac1df4c52058e561dd8ce5e7e0f"},"execution":{"parent_hash":"0x508949056ec4fa4a413e62b0d584e785455fd7017b0ecfc9be4594d69f2ec718","fee_recipient":"0x4d496ccc28058b1d74b7a19541663e21154f9c84","state_root":"0xa736039d44316bd0d81576db08d13561ff1b280d159649d69faafc3aa8fb8c1d","receipts_root":"0xe25b0bf719439ad2d1d92732b3d0459c41612c4f12148adac0244932030338f1","logs_bloom":"0x400108012040004001004000a09821000009408030001110461040418148300388000020000100002040139040000010002004401018004000504020102c15000680200500804440500c48182001404100851304203420506403212006002b0880070100920042a0820200828008298000810048000800400014a0100002042c400000130107482430080029040240288001309208814000000241010580010002080001902010008c100000000001000002109080cb0002182440004e800802007000022010012000100cd0000120c1081010024085810000002240c10060084154040008500073009020484002002408e0414440800c00009022044500040a","prev_randao":"0x8e593f7dedabf10e73e3da0af0e8ee3df586bded82a0f4f4443b017ba5d7af11","block_number":"2778085","gas_limit":"30000000","gas_used":"14104325","timestamp":"1732103232","extra_data":"0x4e65746865726d696e64","base_fee_per_gas":"10","block_hash":"0x6f9b19ee70c3d2055b81b81bd049dec4e18593cf8f4c5029b2d8a4d709476580","transactions_root":"0xc1461e7c3a33e47628224ac61e89105fa1b5181ee2ed1e5601e90bab86c25b36","withdrawals_root":"0x898e77a54125d09cec9c51e4569c257cfe3744c6f50dcf8ea578cb7decfd680f","blob_gas_used":"262144","excess_blob_gas":"0"},"execution_branch":["0x14356e610075ceb2338fec02053239d81d33338d7573a2f672b26759c9efec1f","0x5de2676a591e5be9def585ced61015cdb4791eef9a11f716f18b82d8c15c9fec","0xdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71","0x2d7a0064938718309497dd91fbee4e398302d3e54efbe1539c99d802a03d2df2"]},"finality_branch":["0x4170010000000000000000000000000000000000000000000000000000000000","0x96c9bdd4ae2f71dd6f8b9cb87bf98fdc3945cd45c759ad9a17ff6daff478c393","0x1c6652e50d4aee265dc3e358901d9321c6513f54bf3f03e28445744691ba987e","0xd2df90aad668583112318ff455796dc221401bf48716d06e408e6eb1047cf00d","0x45c215c6dc16b001c44bc3f44ff94dbabd400d9acac865be0b0a6866c4fd8b20","0x09babb27f8bd76f101bab630e841a732b7417ee374de6f26be19f7e48f1e34dd"],"sync_aggregate":{"sync_committee_bits":"0xf7ff79ffffdfefffffdffffffff3db7fff5fdf7ffff7ffffffffefbffdffdfffe7fffeffdfffddfffffffffffffffcffffbffffbfefbfdfff7fff5fffffff9f5","sync_committee_signature":"0xb86b74157180feaba0c89863e0d55501aee7011cf8aa7baed99aa784e8edb494e5906e6b945d2f054652a157f8d19bb70da359cbfa58480e0aa30d3658fecd1811d786ddf292d6d54119f079861341e1fda1190dd137146675c18eae9e4599d8"},"signature_slot":"3016815"}}
Loading
Loading