This repository has been archived by the owner on Jan 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Integration tests #143
Merged
Merged
Integration tests #143
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
779b9df
update config
2017fe4
format code
6b81b9f
Update checkpoint.rs
cryptoAtwill 5e37680
use addr instead of id
7e7e6d8
Merge branch 'refactor_config' of protocol-github:consensus-shipyard/…
ac8f73a
initial commit
a49f747
Merge branch 'main' of protocol-github:consensus-shipyard/ipc-client …
ae25bd9
merge with main
874156a
remove default gateway addr
d678e53
initial commit (#142)
cryptoAtwill 049f64c
add integration testing
bda7491
Merge branch 'refactor_config' of protocol-github:consensus-shipyard/…
7384912
rename tests
b6997d9
merge with main
5e816f9
update readme
6677b70
move readme to /tests
adlrocha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Integration tests | ||
This directory includes a set of tools to perform end-to-end integration tests between the agent and the underlying subnet infrastructure.Before running the test cases, one needs to launch a `lotus` cluster and a `ipc-agent` daemon using the instructions shared in the project's [README](../README). | ||
Once the infrastructure has been setup, the integration tests can be run using: | ||
```shell | ||
cargo test --test <TESTCASE_NAME> | ||
|
||
# To run the subnet lifecycle test, perform: | ||
cargo test --test subnet_lifecycle | ||
``` | ||
|
||
> Note: This is a basic skeleton to showcase how we can run automated end-to-end tests over IPC. In the future, the goal is to automate the deployment of the IPC agent and the infrastructure so all tests can be run automatically. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2022-2023 Protocol Labs | ||
// SPDX-License-Identifier: MIT | ||
use fvm_shared::address::Address; | ||
use ipc_agent::cli::{ | ||
CommandLineHandler, CreateSubnet, CreateSubnetArgs, GlobalArguments, JoinSubnet, | ||
JoinSubnetArgs, KillSubnet, KillSubnetArgs, LeaveSubnet, LeaveSubnetArgs, | ||
}; | ||
use ipc_sdk::subnet_id::SubnetID; | ||
use std::str::FromStr; | ||
|
||
pub struct TestClient { | ||
json_rpc_url: Option<String>, | ||
} | ||
|
||
impl TestClient { | ||
pub fn new(json_rpc_url: Option<String>) -> Self { | ||
Self { json_rpc_url } | ||
} | ||
|
||
pub async fn create_subnet(&self, parent: &str) -> anyhow::Result<Address> { | ||
let global = GlobalArguments::default(); | ||
let args = CreateSubnetArgs { | ||
ipc_agent_url: self.json_rpc_url.clone(), | ||
from: None, | ||
parent: String::from(parent), | ||
name: "test".to_string(), | ||
min_validator_stake: 1, | ||
min_validators: 0, | ||
finality_threshold: 2, | ||
check_period: 10, | ||
}; | ||
|
||
let raw = CreateSubnet::create(&global, &args).await?; | ||
Ok(Address::from_str(&raw)?) | ||
} | ||
|
||
pub async fn join_subnet( | ||
&self, | ||
subnet_id: &SubnetID, | ||
validator_net_addr: String, | ||
) -> anyhow::Result<()> { | ||
JoinSubnet::handle( | ||
&GlobalArguments::default(), | ||
&JoinSubnetArgs { | ||
ipc_agent_url: self.json_rpc_url.clone(), | ||
from: None, | ||
subnet: subnet_id.to_string(), | ||
collateral: 10, | ||
validator_net_addr, | ||
}, | ||
) | ||
.await | ||
} | ||
|
||
pub async fn kill_subnet(&self, subnet_id: &SubnetID) -> anyhow::Result<()> { | ||
KillSubnet::handle( | ||
&GlobalArguments::default(), | ||
&KillSubnetArgs { | ||
ipc_agent_url: self.json_rpc_url.clone(), | ||
from: None, | ||
subnet: subnet_id.to_string(), | ||
}, | ||
) | ||
.await | ||
} | ||
|
||
pub async fn leave_subnet(&self, subnet_id: &SubnetID) -> anyhow::Result<()> { | ||
LeaveSubnet::handle( | ||
&GlobalArguments::default(), | ||
&LeaveSubnetArgs { | ||
ipc_agent_url: self.json_rpc_url.clone(), | ||
from: None, | ||
subnet: subnet_id.to_string(), | ||
}, | ||
) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2022-2023 Protocol Labs | ||
// SPDX-License-Identifier: MIT | ||
|
||
use crate::common::TestClient; | ||
use ipc_sdk::subnet_id::{SubnetID, ROOTNET_ID}; | ||
|
||
mod common; | ||
|
||
const IPC_AGENT_JSON_RPC_URL_ENV: &str = "IPC_AGENT_JSON_RPC_URL"; | ||
|
||
#[tokio::test] | ||
async fn subnet_lifecycle() { | ||
let client = TestClient::new(std::env::var(IPC_AGENT_JSON_RPC_URL_ENV).ok()); | ||
|
||
// step 1. create the subnet | ||
let address = client | ||
.create_subnet("/root") | ||
.await | ||
.expect("create subnet in root failed"); | ||
|
||
// obtain the created subnet id | ||
let subnet_id = SubnetID::new_from_parent(&ROOTNET_ID, address); | ||
log::info!("created subnet: {:} in root", subnet_id); | ||
|
||
// step 2. join the subnet | ||
client | ||
.join_subnet(&subnet_id, String::from("test_validator")) | ||
.await | ||
.expect("cannot join subnet"); | ||
log::info!("joined subnet: {:}", subnet_id); | ||
|
||
// step 3. try kill the subnet, fail because not all validators have left | ||
let r = client.kill_subnet(&subnet_id).await; | ||
assert!( | ||
r.is_err(), | ||
"should failed when killing subnet as not all validators have left" | ||
); | ||
log::info!( | ||
"expected cannot kill subnet: {:} when there are validators in subnet", | ||
subnet_id | ||
); | ||
|
||
// step 4. leave the subnet | ||
client | ||
.leave_subnet(&subnet_id) | ||
.await | ||
.expect("cannot leave subnet"); | ||
log::info!("left subnet: {:}", subnet_id); | ||
|
||
// step 5. kill the subnet works now as all validators have left | ||
client | ||
.kill_subnet(&subnet_id) | ||
.await | ||
.expect("cannot kill subnet"); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this is that it will prevent all integration tests from running, for example it will stop the
ipld/resolver/tests/smoke.rs
as well, which does not rely on a cluster to be set up.Looking at the ref-fvm CI workflow, they use
cargo test --exclude
to prevent multiple tests from running. This only works on the crate level I think, which is why the integration tests are in a separate create within the workspace.Other options would be to put these tests behind a feature flag and only switch them on when you want to run the end to end tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of them work for me, at this point I would suggest doing whatever is easier and less cumbersome for users while keeping the door open to eventually integrating it on CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They might work locally, but not on CI with
make test
. Compare the first passing commit to the last commit:The first runs the smoke test:
The second only runs the top section, not the bottom one.
IMO we should not let CI fall back on running the tests that it can run in the name of convenience of just not having to organise code better.
OTOH maybe it would be better to move the resolver into its own repository, since it doesn't rely on the IPC agent library at all, IIRC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a PR to move it; I don't think it's any less convenient: #153