Skip to content

Commit

Permalink
Run neutron -> osmosis tests in test runner.
Browse files Browse the repository at this point in the history
  • Loading branch information
dowlandaiello committed Jul 18, 2024
1 parent a6e1e71 commit 2cc5164
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 44 deletions.
41 changes: 14 additions & 27 deletions local-interchaintest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,19 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
base_denom: String::from("uosmo"),
};

// Test case (neutron -> osmosis)
tests::test_transfer_osmosis()?;

// TODO:
// Test case (osmosis -> neutron)

TestRunner::new(&mut ctx, args)
.start()?
// Test case (neutron -> osmosis)
.run(TestBuilder::default()
.with_name("Transfer From Neutron to Osmosis")
.with_description("Transfers from Neutron to Osmosis should succeed")
.with_denom(untrn.clone(), 100000000000)
.with_test(Box::new(tests::test_transfer_osmosis) as TestFn)
.build()?
)?
// Test case (profitable arb):
//
// - Astroport: bruhtoken-amoguscoin @1.5 bruhtoken/amoguscoin
Expand All @@ -95,8 +101,6 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
amoguscoin.clone(),
Pool::Astroport(
AstroportPoolBuilder::default()
.with_asset_a(bruhtoken.clone())
.with_asset_b(amoguscoin.clone())
.with_balance_asset_a(15000000u128)
.with_balance_asset_b(10000000u128)
.build()?,
Expand All @@ -107,8 +111,6 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
amoguscoin.clone(),
Pool::Astroport(
AstroportPoolBuilder::default()
.with_asset_a(untrn.clone())
.with_asset_b(amoguscoin.clone())
.with_balance_asset_a(10000000u128)
.with_balance_asset_b(10000000u128)
.build()?,
Expand All @@ -119,13 +121,12 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
untrn.clone(),
Pool::Auction(
AuctionPoolBuilder::default()
.with_offer_asset(bruhtoken.clone())
.with_ask_asset(untrn.clone())
.with_balance_offer_asset(100000000u128)
.with_price(Decimal::percent(10))
.build()?,
),
)
.with_arbbot()
.with_test(Box::new(tests::test_profitable_arb) as TestFn)
.build()?,
)?
Expand All @@ -146,8 +147,6 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
amoguscoin.clone(),
Pool::Astroport(
AstroportPoolBuilder::default()
.with_asset_a(bruhtoken.clone())
.with_asset_b(amoguscoin.clone())
.with_balance_asset_a(15000000u128)
.with_balance_asset_b(10000000u128)
.build()?,
Expand All @@ -158,8 +157,6 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
amoguscoin.clone(),
Pool::Astroport(
AstroportPoolBuilder::default()
.with_asset_a(untrn.clone())
.with_asset_b(amoguscoin.clone())
.with_balance_asset_a(10000000u128)
.with_balance_asset_b(10000000u128)
.build()?,
Expand All @@ -170,13 +167,12 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
untrn.clone(),
Pool::Auction(
AuctionPoolBuilder::default()
.with_offer_asset(bruhtoken.clone())
.with_ask_asset(untrn.clone())
.with_balance_offer_asset(10000000u128)
.with_price(Decimal::percent(1000))
.build()?,
),
)
.with_arbbot()
.with_test(Box::new(tests::test_unprofitable_arb) as TestFn)
.build()?,
)?
Expand All @@ -197,8 +193,6 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
amoguscoin.clone(),
Pool::Astroport(
AstroportPoolBuilder::default()
.with_asset_a(bruhtoken.clone())
.with_asset_b(amoguscoin.clone())
.with_balance_asset_a(15000000u128)
.with_balance_asset_b(10000000u128)
.build()?,
Expand All @@ -209,8 +203,6 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
amoguscoin.clone(),
Pool::Astroport(
AstroportPoolBuilder::default()
.with_asset_a(untrn.clone())
.with_asset_b(amoguscoin.clone())
.with_balance_asset_a(10000000u128)
.with_balance_asset_b(10000000u128)
.build()?,
Expand All @@ -221,13 +213,12 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
untrn.clone(),
Pool::Auction(
AuctionPoolBuilder::default()
.with_offer_asset(bruhtoken.clone())
.with_ask_asset(untrn.clone())
.with_balance_offer_asset(10000000u128)
.with_price(Decimal::percent(100))
.build()?,
),
)
.with_arbbot()
.with_test(Box::new(tests::test_unprofitable_arb) as TestFn)
.build()?,
)?
Expand All @@ -248,8 +239,6 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
bruhtoken.clone(),
Pool::Auction(
AuctionPoolBuilder::default()
.with_offer_asset(bruhtoken.clone())
.with_ask_asset(untrn.clone())
.with_balance_offer_asset(10000000000u128)
.with_price(Decimal::percent(100))
.build()?,
Expand All @@ -260,8 +249,6 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
untrn.clone(),
Pool::Auction(
AuctionPoolBuilder::default()
.with_offer_asset(amoguscoin.clone())
.with_ask_asset(bruhtoken.clone())
.with_balance_offer_asset(10000000000u128)
.with_price(Decimal::percent(90))
.build()?,
Expand All @@ -272,13 +259,12 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
untrn.clone(),
Pool::Auction(
AuctionPoolBuilder::default()
.with_offer_asset(untrn.clone())
.with_ask_asset(amoguscoin.clone())
.with_balance_offer_asset(10000000000u128)
.with_price(Decimal::percent(100))
.build()?,
),
)
.with_arbbot()
.with_test(Box::new(tests::test_unprofitable_arb) as TestFn)
.build()?,
)?
Expand Down Expand Up @@ -336,6 +322,7 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
.build(),
),
)
.with_arbbot()
.with_test(Box::new(tests::test_osmo_arb) as TestFn)
.build()?,
)?
Expand Down
42 changes: 29 additions & 13 deletions local-interchaintest/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,23 @@ impl<'a> TestRunner<'a> {

test.setup(&mut self.denom_map, self.test_ctx)?;

with_arb_bot_output(Arc::new(Box::new(move |arbfile: Value| {
statuses.lock().expect("Failed to lock statuses").insert(
(test.name.clone(), test.description.clone()),
(*test.test)(arbfile),
);
if test.run_arbbot {
with_arb_bot_output(Arc::new(Box::new(move |arbfile: Option<Value>| {
statuses.lock().expect("Failed to lock statuses").insert(
(test.name.clone(), test.description.clone()),
(*test.test)(arbfile),
);

Ok(())
})))?;
Ok(())
})))?;

return Ok(self);
}

statuses.lock().expect("Failed to lock statuses").insert(
(test.name.clone(), test.description.clone()),
(*test.test)(None),
);

Ok(self)
}
Expand Down Expand Up @@ -295,7 +304,7 @@ impl<'a> TestRunner<'a> {
}

/// A test that receives arb bot executable output.
pub type TestFn = Box<dyn Fn(Value) -> TestResult + Send + Sync>;
pub type TestFn = Box<dyn Fn(Option<Value>) -> TestResult + Send + Sync>;
pub type OwnedTestFn = Arc<TestFn>;
pub type TestResult = Result<(), Box<dyn Error + Send + Sync>>;

Expand All @@ -321,6 +330,17 @@ pub struct Test {

/// The test that should be run with the arb bot output
test: OwnedTestFn,

/// Whether the arb bot output should be fed as input to the test
run_arbbot: bool,
}

impl TestBuilder {
pub fn with_arbbot(mut self) -> Self {
self.run_arbbot = Some(true);

self
}
}

impl Test {
Expand Down Expand Up @@ -509,8 +529,6 @@ pub enum Pool {
#[derive(Builder, Clone)]
#[builder(setter(into, strip_option, prefix = "with"))]
pub struct AstroportPool {
pub asset_a: Denom,
pub asset_b: Denom,
pub balance_asset_a: u128,
pub balance_asset_b: u128,
}
Expand Down Expand Up @@ -543,8 +561,6 @@ impl OsmosisPoolBuilder {
#[derive(Builder, Clone)]
#[builder(setter(into, strip_option, prefix = "with"))]
pub struct AuctionPool {
pub offer_asset: Denom,
pub ask_asset: Denom,
pub balance_offer_asset: u128,
pub price: Decimal,
}
Expand Down Expand Up @@ -590,7 +606,7 @@ pub fn with_arb_bot_output(test: OwnedTestFn) -> TestResult {
let arbfile: Value =
serde_json::from_reader(&f).expect("failed to deserialize arbs.json");

let res = test_handle(arbfile);
let res = test_handle(Some(arbfile));

proc_handle_watcher.kill().expect("failed to kill arb bot");
tx_res.send(res).expect("failed to send test results");
Expand Down
17 changes: 13 additions & 4 deletions local-interchaintest/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::{error::Error, process::Command};

const ERROR_MARGIN_PROFIT: u64 = 100000;

pub fn test_transfer_osmosis() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
pub fn test_transfer_osmosis(
_: Option<Value>,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
Command::new("python")
.current_dir("tests")
.arg("transfer_osmosis.py")
Expand All @@ -13,7 +15,10 @@ pub fn test_transfer_osmosis() -> Result<(), Box<dyn Error + Send + Sync + 'stat
Ok(())
}

pub fn test_profitable_arb(arbfile: Value) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
pub fn test_profitable_arb(
arbfile: Option<Value>,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let arbfile = arbfile.unwrap();
let arbs = arbfile.as_array().expect("no arbs in arbfile");

util::assert_err("!arbs.is_empty()", arbs.is_empty(), false)?;
Expand Down Expand Up @@ -55,7 +60,10 @@ pub fn test_profitable_arb(arbfile: Value) -> Result<(), Box<dyn Error + Send +
Ok(())
}

pub fn test_unprofitable_arb(arbfile: Value) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
pub fn test_unprofitable_arb(
arbfile: Option<Value>,
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let arbfile = arbfile.unwrap();
let arbs = arbfile.as_array().expect("no arbs in arbfile");

util::assert_err("!arbs.is_empty()", arbs.is_empty(), false)?;
Expand Down Expand Up @@ -88,7 +96,8 @@ pub fn test_unprofitable_arb(arbfile: Value) -> Result<(), Box<dyn Error + Send
Ok(())
}

pub fn test_osmo_arb(arbfile: Value) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
pub fn test_osmo_arb(arbfile: Option<Value>) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let arbfile = arbfile.unwrap();
let arbs = arbfile.as_array().expect("no arbs in arbfile");

util::assert_err("!arbs.is_empty()", arbs.is_empty(), false)?;
Expand Down

0 comments on commit 2cc5164

Please sign in to comment.