Skip to content

Commit

Permalink
refactor: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Apr 12, 2024
1 parent 37a5edb commit f3889ef
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 301 deletions.
49 changes: 2 additions & 47 deletions kit/src/behaviors/creator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,7 @@ use crate::{
pool::{Pool, PoolType},
};

// Idea: Let's make a behavior that has two states:
// State 1. This is for configuration and it should have everything be
// `Serialize`/`Deserialize` so that it can be read in from a config.
// State 2. This is the "built" version of the behavior that may now own client,
// messager, or contracts (etc.) and other things that had to be gotten from
// running the `startup` method.

// Example:
// Let's make a "pool_creator" type of behavior that will take some
// configuration for a pool and work to attempt to deploy that pool.
pub const MAX: eU256 = eU256::MAX;

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Creator<S: State> {
Expand Down Expand Up @@ -108,7 +99,7 @@ where
.await?
.await?;

let pool = Pool::<P>::new(
let _pool = Pool::<P>::new(
self.data.base_config.clone(),
self.data.params.clone(),
self.data.allocation_data.clone(),
Expand All @@ -121,39 +112,3 @@ where
Ok(None)
}
}

mod test {
use arbiter_engine::{agent::Agent, world::World};
use tracing::{level_filters::LevelFilter, Level};
use tracing_subscriber::FmtSubscriber;

use super::*;
use crate::behaviors::deployer::Deployer;

#[tokio::test(flavor = "multi_thread", worker_threads = 5)]
async fn creator_behavior_test() {
let subscriber = FmtSubscriber::builder()
.with_max_level(Level::DEBUG)
.pretty()
.finish();
tracing::subscriber::set_global_default(subscriber).unwrap();

let mut world = World::new("test");

// deployer
let agent = Agent::builder("deployer");
world.add_agent(agent.with_behavior(Deployer {}));

// Token Admin
let token_admin_config = default_admin_config();
let token_admin = Agent::builder("token_admin_agent");
world.add_agent(token_admin.with_behavior(token_admin_config));

// Pool Creator
let creator = Agent::builder("pool_creator_agent");
let pool_creator_config = default_creator_config();
world.add_agent(creator.with_behavior(pool_creator_config));

world.run().await.unwrap();
}
}
74 changes: 0 additions & 74 deletions kit/src/behaviors/deployer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,77 +72,3 @@ impl Behavior<()> for Deployer {
Ok(None)
}
}

#[cfg(test)]
mod tests {
use std::str::FromStr;

use arbiter_engine::{agent::Agent, world::World};
use ethers::types::Address;
use futures_util::StreamExt;
use tracing_subscriber::FmtSubscriber;

use crate::behaviors::deployer::{Deployer, DeploymentData};

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn deployer_behavior_test() {
let subscriber = FmtSubscriber::builder().finish();
tracing::subscriber::set_global_default(subscriber).unwrap();

let mut world = World::new("test");
let messager = world.messager.clone();

let agent = Agent::builder("token_admin_agent");
world.add_agent(agent.with_behavior(Deployer {}));

world.run().await.unwrap();
let mut stream = messager.stream().expect(
"Failed to get messager
stream",
);

if let Some(res) = stream.next().await {
let token_res_data = &res.data;
println!("{}", token_res_data);

let data: String = serde_json::from_str(token_res_data).expect(
"Failed to
deserialize message data",
);

let parsed_data: DeploymentData = serde_json::from_str(&data).expect(
"Failed to deserialize
token data",
);

println!("{:?}", parsed_data);

assert_eq!(
Address::from_str("0xb00efcb70090a21d46660adf95a16ec69623f694").unwrap(),
parsed_data.weth
);
assert_eq!(
Address::from_str("0x27781b40bd019ccb1dcb0c809135db71222e9353").unwrap(),
parsed_data.dfmm
);
assert_eq!(
Address::from_str("0x6e0035324097bfc66442e2d3f37ef378fb3750b2").unwrap(),
parsed_data.geometric_mean
);
assert_eq!(
Address::from_str("0x4be050270d209ef9f0c0435736c731767486279f").unwrap(),
parsed_data.log_normal
);
assert_eq!(
Address::from_str("0xaeb166f1355c6254d01a54317ef8d4d21bfcb4b0").unwrap(),
parsed_data.constant_sum
);
assert_eq!(
Address::from_str("0xa4bb88cbfc92d86ae00842dcfa5a1ac32b0714b3").unwrap(),
parsed_data.n_token_geometric_mean
);
} else {
panic!("No message received");
}
}
}
56 changes: 3 additions & 53 deletions kit/src/behaviors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ use arbiter_engine::{
use arbiter_macros::Behaviors;
use bindings::arbiter_token::ArbiterToken;

use self::{
creator::Creator,
deployer::Deployer,
pool::{
constant_sum::{ConstantSumAllocationData, ConstantSumParams, ConstantSumPool},
BaseConfig, PoolType,
},
token_admin::TokenAdmin,
};
use self::{creator::Creator, deployer::Deployer, pool::PoolType, token_admin::TokenAdmin};

use super::*;
pub use token_admin::{MintRequest, TokenAdminQuery};

// pub mod allocate;
pub mod creator;
Expand All @@ -29,47 +23,3 @@ pub enum Behaviors<P: PoolType> {
Deployer(Deployer),
TokenAdmin(TokenAdmin<token_admin::Config>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TokenData {
pub name: String,
pub symbol: String,
pub decimals: u8,
}

pub(crate) fn default_admin_config() -> TokenAdmin<token_admin::Config> {
let token1 = TokenData {
name: "US Dollar Coin".to_owned(),
symbol: "USDC".to_owned(),
decimals: 18,
};

let token2 = TokenData {
name: "ShibaInuObamaSonic Coin".to_owned(),
symbol: "SIOS".to_owned(),
decimals: 18,
};
let config = token_admin::Config {
token_data: vec![token1, token2],
};
TokenAdmin::<token_admin::Config> { data: config }
}

pub(crate) fn default_creator_config() -> Creator<creator::Config<ConstantSumPool>> {
Creator::<creator::Config<ConstantSumPool>> {
data: creator::Config {
params: ConstantSumParams { price: WAD },
token_list: vec!["Token X".to_string(), "Token Y".to_string()],
base_config: BaseConfig {
name: "Test Pool".to_string(),
symbol: "TP".to_string(),
swap_fee: 10000.into(),
controller_fee: 0.into(),
},
allocation_data: ConstantSumAllocationData {
reserve_x: WAD,
reserve_y: WAD,
},
},
}
}
Loading

0 comments on commit f3889ef

Please sign in to comment.