You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Doesn't work for chains that have complex multi-stage setup, like Polygon.
Test arguments are static and immutable in the chain-config (cannot dynamically change node args).
You must use Docker (what if you prefer to run the chain locally?)
Proposal
Instead of start a new client for each test (which is slow and expensive), use the same rpc-node and connector for all tests, and just do the necessary setup before each test to assure it runs in a predictable way, ex: create a new set of accounts for each test.
1 - Refactor the BlockchainConfig to be a trait instead a struct. Also remove all testing related stuff like node_command, node_image, etc.
2 - Create an agnostic trait for setup the tests
traitTestSupport{/// Arguments the user provides for initialize the test contexttypeArgs;// Represents the test context, may include faucet accounts, smart-contract addresses, etc.typeContext;/// Get parameters to construct a `Env` suitable for testing.////// - `env_name`: test unique identifier, is equals to: concat!(module_path!(), "::", stringify!(#test_name))/// - `config`: The parameters necessary for setup the testfntest_context(env_name:&str,config:Self::Args) -> BoxFuture<'_,Self::Context>;/// Do the necessary cleanup after the test runs, ex: stop docker containers, delete accounts, etc.////// - `env_name`: test unique identifier, is equals to: concat!(module_path!(), "::", stringify!(#test_name))fncleanup_test(env_name:&str) -> BoxFuture<'_,Result<(),Error>>;}
and then implement it in the chain config crate, example:
3 - Start the RPC nodes before running the unit tests.
4 - Use test_context for create a new set of accounts for each test
5 - Create a macro similar to what sqlx does here and test_context for the unit tests, ex:
use rosetta_config_astar::{
config as astar_config,AstarTestEnv,};#[rosetta_client::test(config = astar_config("dev"), ctx = AstarTestEnv)]asyncfntask_executor_astar_sc_call(env:AstarTestEnv) -> anyhow::Result<()>{// ... test body here}
the output of the macro above is:
#[tokio::test]asyncfntask_executor_astar_sc_call(env:AstarTestEnv::TestArgs) -> anyhow::Result<()>{asyncfninner(env:AstarTestEnv) -> anyhow::Result<()>{// ... test body here}let env_name = concat!(module_path!(),"::", stringify!(task_executor_astar_sc_call));// Create the test contextlet ctx = <AstarTestEnvas::rosetta_core::test::TestSupport>::test_context(env_name,astar_config("dev")).await;// Run the test in a new thread, so we can perform cleanup when it panicslet result = tokio::spawn(async{inner(ctx).await}).await;// cleanup
<AstarTestEnvas::rosetta_core::test::TestSupport>::cleanup_test(env_name).await;// Now is safe to panicifletErr(err) = result {// Resume the panic on the main task
panic::resume_unwind(err.into_panic());}}
The text was updated successfully, but these errors were encountered:
I would like to propose deprecate the rosetta-docker and replace it by a more generic testing framework.
Issues of the current approach:
Proposal
Instead of start a new client for each test (which is slow and expensive), use the same rpc-node and connector for all tests, and just do the necessary setup before each test to assure it runs in a predictable way, ex: create a new set of accounts for each test.
1 - Refactor the BlockchainConfig to be a trait instead a struct. Also remove all testing related stuff like node_command, node_image, etc.
2 - Create an agnostic trait for setup the tests
and then implement it in the chain config crate, example:
3 - Start the RPC nodes before running the unit tests.
4 - Use
test_context
for create a new set of accounts for each test5 - Create a macro similar to what sqlx does here and test_context for the unit tests, ex:
the output of the macro above is:
The text was updated successfully, but these errors were encountered: