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 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 11 additions & 1 deletion .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 Down Expand Up @@ -60,6 +61,8 @@ jobs:
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
--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
3 changes: 3 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,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
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));
Copy link
Member

Choose a reason for hiding this comment

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

Why salt and code ID are in one mutex?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are no other arguments to introduce a new one though. Actually the mutex should store something like struct Context with all required fields but it's too tempting to use tuples )


async fn spin_up_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(),
)
}

#[ignore]
#[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) = spin_up_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) = spin_up_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) = spin_up_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
4 changes: 4 additions & 0 deletions relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ utils-prometheus.workspace = true

[build-dependencies]
cgo_oligami.workspace = true

[dev-dependencies]
ruzstd.workspace = true
sp-core = { workspace = true, features = ["std"] }
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"}}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"deneb","data":{"attested_header":{"beacon":{"slot":"3016836","proposer_index":"406009","parent_root":"0x61dea92b520f340b12ff6910db21b36762d2ab848f43cd7e0edc2aaf9ca4d07f","state_root":"0x07e40f7e449385635bd0717402e638e2b08fe3a3a425b9f8823ab25c6b241435","body_root":"0xc6bf679b4949307054f774c06c631aacabc44e92454023433313b5bd0281488e"},"execution":{"parent_hash":"0xfe3855d68a64aceaeefba312d7f1a00c54aada91f05682486eff0404e4401265","fee_recipient":"0x3826539cbd8d68dcf119e80b994557b4278cec9f","state_root":"0x67f8767a756ea7a8efd979dbc7d26cbaddec3437a50a101bc19127f9ac1df149","receipts_root":"0x1204b5a7b56227778e70c09c4295eb8041a34e82a170c269d0e98488c33a1a16","logs_bloom":"0x04000c012000004000804000008801000008008020000110428808400000000201000040000000000000100060000004000000000008000000400020002400000000000100080040100c400808000001000101444004201044180120000400008005010012004080000000020008280000000040000010000014801000000448000014000004000010000001000248000000241000400000000001010100011002000004000030010800010000000080000600000007000a192000025000084044000002000001000001000000010000001000000009a0040000020001006200411400000000405020900040000000000810418040800c100000200000000000","prev_randao":"0x69c5cd3337aebedb7e622571005589ee6a2eba79ced812d95f00b43d90b7c917","block_number":"2778176","gas_limit":"30000000","gas_used":"8827286","timestamp":"1732104432","extra_data":"0x","base_fee_per_gas":"14","block_hash":"0x1665b78ca90106d34585749aa8f93fc8f8b4846a92b4401376d0e8fada985d30","transactions_root":"0x31b2bbac3f958cc21c83dc5e7e463ee604160e3932f92e60240036003e4c9bd4","withdrawals_root":"0x1e4247550e2dfb0a0b4574ae24bf3f056275cdd389810510b879738e34685f11","blob_gas_used":"131072","excess_blob_gas":"0"},"execution_branch":["0x0a961438e851ce5df2b1f20076eb2206b80761a82f2a504f94e7e3e979c26682","0x263a2f4199114d22b9f349fc810e9ff9988b079ad9e608bab5af8a2a7b84f069","0xdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71","0x002adfff27c9d39e280a1d0cac6e2f94b8bd4750db0f3c44f2e8f88f9ed2736d"]},"finalized_header":{"beacon":{"slot":"3016768","proposer_index":"1107558","parent_root":"0x0d704138f785c4d131487fbcd3147566404780d64eb7cd406b18dd616b3ea90a","state_root":"0x6f3e2d71e838bf76c80aab117cea41e44323698c60f889aa145eae5a73d45664","body_root":"0x5fc519f7e87400414baca6b01f239e8ae28b856b39a5455a7d6ad784c7aee979"},"execution":{"parent_hash":"0xad58e879af4ae2d3108d3a44fad1f80d355b08eb7f1bdb2f8d4d76027cea4541","fee_recipient":"0x0c10000000756bd1d14f9c837f022929a97bda45","state_root":"0xc91cedb0d240bd4a2a6d61e5aea251905dbdd792e3622937ef53438f64dfe233","receipts_root":"0x6d9a8f219b1a9cfa1a33b8a6c418dbc369fef12e3fbe4feb53012fe0bdb711e6","logs_bloom":"0x0000880020000040000000000008400000000080200001010000004000000000000001000000000000001080400000002002000000000000000008000020000000282001100800400804400800000041008001000001001044080300040040000100000000004000000001220040000000000080008000000000801000000008800000800005200020001000000000000100201001c02000800001800400000002880000000010000002001000000000000000001001000212208000000000000000000201000100000002000000000008100000000140440000000001084004401000000000000000120040000000000040000040000c000010000000000000","prev_randao":"0xadc5837a3b1823bf43b60ff1c4236815554cd15783a42d395fd9cc3c78caf9af","block_number":"2778114","gas_limit":"30000000","gas_used":"5613764","timestamp":"1732103616","extra_data":"0xd883010e07846765746888676f312e32322e35856c696e7578","base_fee_per_gas":"8","block_hash":"0x81f7474469bbb819c028aa1d2c68270eb942cc6205f339dcb8d48f1aa1604942","transactions_root":"0xc98fedf1e55851846d3419aa89ecd72921f4895351a55c48a14aa22f66878378","withdrawals_root":"0xa9d14d666133217d9cd8365a86d5a51d0215a9da5eaabb21c6c322fd5d1a7d01","blob_gas_used":"262144","excess_blob_gas":"0"},"execution_branch":["0xf20c1eb1ccfcabe6f36e62609c9e6af169387956c9d51d351788963b7f47028b","0xa0dcb324e8397cd3116c60f4510d6b9a30245b712a2466c6ff483f81b73e0433","0xdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71","0x993a3e2bd50922129441a62dff8a5b66870a96403d70b0434d59918b682a83c4"]},"finality_branch":["0x4270010000000000000000000000000000000000000000000000000000000000","0x96c9bdd4ae2f71dd6f8b9cb87bf98fdc3945cd45c759ad9a17ff6daff478c393","0x1c6652e50d4aee265dc3e358901d9321c6513f54bf3f03e28445744691ba987e","0x600f5ec075f4cc3cccfe1ab3a912a78f19719452524d3459345d4f4d963c94d8","0xeb2620c468a0e2822438dfa3b806f5025c817521d65e55c70447ba3bd82ab338","0xdfa72d40981aa5517b1886e19a9ee71803cbbb38b361c3aa023dd1754ad51f58"],"sync_aggregate":{"sync_committee_bits":"0xf7ff79ffffdfeffffedffffffff3df6fff5fdf7ffff7ffffffffefbffdffdfffeffffeff9fffddfffffffefffffffdfffffffffbfcfffffff77ff5effffff9f5","sync_committee_signature":"0xb8ccc0de5c7774354827c45b2617d5fc87aa36b6f69233659ee251fa2d6e84d34bc3ae3983392fa31c1fe206a38811bd132d3504af5b648c845f4b20bbabd9dd264ebc27bd597259c66c2d681815be3d65e36f952abf226c05dede06ff167736"},"signature_slot":"3016837"}}
Loading
Loading