Skip to content

Commit

Permalink
Add CONTRACTS_ROOT, DEX_CONTRACTS_ROOT env var support
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianBorst committed Nov 21, 2024
1 parent fd979f9 commit f487c3e
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 44 deletions.
126 changes: 82 additions & 44 deletions integration_tests/test_runner/src/bootstrapping.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ibc_utils::get_channel;
use crate::utils::{
get_chain_id, get_deposit, get_ibc_chain_id, ALTHEA_RELAYER_ADDRESS, COSMOS_NODE_GRPC,
HERMES_CONFIG, IBC_RELAYER_ADDRESS, IBC_STAKING_TOKEN, OPERATION_TIMEOUT,
get_chain_id, get_deposit, get_ibc_chain_id, parse_contracts_root, ALTHEA_RELAYER_ADDRESS,
COSMOS_NODE_GRPC, HERMES_CONFIG, IBC_RELAYER_ADDRESS, IBC_STAKING_TOKEN, OPERATION_TIMEOUT,
RELAYER_MNEMONIC_FILE,
};
use crate::utils::{
Expand Down Expand Up @@ -96,29 +96,40 @@ pub async fn deploy_erc20_contracts(contact: &Contact) {
// yet produced the next block after submitting each eth address
contact.wait_for_next_block(TOTAL_TIMEOUT).await.unwrap();

// these are the possible paths where we could find the contract deployer
// and the gravity contract itself, feel free to expand this if it makes your
// deployments more straightforward.

// the default unmoved locations for the Gravity repo
const A: [&str; 2] = ["/althea/solidity/contract-deployer.ts", "/althea/solidity/"];
// the default unmoved locations for Github Actions
const B: [&str; 2] = [
"/home/runner/work/althea-L1/althea-L1/solidity/contract-deployer.ts",
"/home/runner/work/althea-L1/althea-L1/solidity/",
];
let output = match return_existing(vec![A, B]) {
Some(path) => Command::new("npx")
.args([
"ts-node",
path[0],
&format!("--eth-node={}", ETH_NODE.as_str()),
&format!("--eth-privkey={:#x}", *MINER_PRIVATE_KEY),
&format!("--artifacts-root={}", path[1]),
])
.current_dir(path[1])
.output()
.expect("Failed to deploy contracts!"),

// the user specified contracts root
let contracts_root = parse_contracts_root();
let paths = if let Ok(root) = contracts_root {
Some(vec![
format!("{}/contract-deployer.ts", root),
format!("{}/", root),
])
} else {
return_existing(vec![A, B]).map(|path| vec![path[0].to_string(), path[1].to_string()])
};

let output = match paths {
Some(path) => {
info!("Deploying contracts from {:?}", path);
Command::new("npx")
.args([
"ts-node",
&path[0],
&format!("--eth-node={}", ETH_NODE.as_str()),
&format!("--eth-privkey={:#x}", *MINER_PRIVATE_KEY),
&format!("--artifacts-root={}", path[1]),
])
.current_dir(&path[1])
.output()
.expect("Failed to deploy contracts!")
}
None => {
panic!("Could not find json contract artifacts in any known location!")
}
Expand Down Expand Up @@ -147,20 +158,34 @@ pub async fn deploy_dex() {
"/home/runner/work/althea-L1/althea-L1/solidity-dex/misc/scripts/dex-deployer.ts",
"/home/runner/work/althea-L1/althea-L1/solidity-dex/artifacts/contracts/",
];
let output = match return_existing(vec![A, B]) {
Some(path) => Command::new("npx")
.args([
"ts-node",
path[0],
&format!("--eth-node={}", ETH_NODE.as_str()),
&format!("--eth-privkey={:#x}", *MINER_PRIVATE_KEY),
&format!("--artifacts-root={}", path[1]),
])
.current_dir(path[1])
.output()
.expect("Failed to deploy contracts!"),
// the user specified contracts root
let contracts_root = parse_dex_contracts_root();
let paths = if let Ok(root) = contracts_root {
Some(vec![
format!("{}/misc/scripts/dex-deployer.ts", root),
format!("{}/artifacts/contracts/", root),
])
} else {
return_existing(vec![A, B]).map(|path| vec![path[0].to_string(), path[1].to_string()])
};

let output = match paths {
Some(path) => {
info!("Deploying contracts from {:?}", path);
Command::new("npx")
.args([
"ts-node",
&path[0],
&format!("--eth-node={}", ETH_NODE.as_str()),
&format!("--eth-privkey={:#x}", *MINER_PRIVATE_KEY),
&format!("--artifacts-root={}", path[1]),
])
.current_dir(&path[1])
.output()
.expect("Failed to deploy contracts!")
}
None => {
panic!("Could not find dex artifacts in any known location!")
panic!("Could not find json contract artifacts in any known location!")
}
};
info!("stdout: {}", String::from_utf8_lossy(&output.stdout));
Expand All @@ -184,19 +209,32 @@ pub async fn deploy_multicall() {
"/home/runner/work/althea-L1/althea-L1/solidity-dex/misc/scripts/multicall-deployer.ts",
"/home/runner/work/althea-L1/althea-L1/solidity-dex/artifacts/contracts/periphery/",
];
let paths = vec![A, B];
let output = match return_existing(paths) {
Some(path) => Command::new("npx")
.args([
"ts-node",
path[0],
&format!("--eth-node={}", ETH_NODE.as_str()),
&format!("--eth-privkey={:#x}", *MINER_PRIVATE_KEY),
&format!("--artifacts-root={}", path[1]),
])
.current_dir(path[1])
.output()
.expect("Failed to deploy contracts!"),
// the user specified contracts root
let contracts_root = parse_dex_contracts_root();
let paths = if let Ok(root) = contracts_root {
Some(vec![
format!("{}/misc/scripts/multicall-deployer.ts", root),
format!("{}artifacts/contracts/periphery/", root),
])
} else {
return_existing(vec![A, B]).map(|path| vec![path[0].to_string(), path[1].to_string()])
};

let output = match paths {
Some(path) => {
info!("Deploying contracts from {:?}", path);
Command::new("npx")
.args([
"ts-node",
&path[0],
&format!("--eth-node={}", ETH_NODE.as_str()),
&format!("--eth-privkey={:#x}", *MINER_PRIVATE_KEY),
&format!("--artifacts-root={}", path[1]),
])
.current_dir(&path[1])
.output()
.expect("Failed to deploy contracts!")
}
None => {
panic!("Could not find json contract artifacts in any known location!")
}
Expand Down
8 changes: 8 additions & 0 deletions integration_tests/test_runner/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ pub fn should_deploy_contracts() -> bool {
}
}

pub fn parse_contracts_root() -> Result<String, env::VarError> {
env::var("CONTRACTS_ROOT")
}

pub fn parse_DEX_contracts_root() -> Result<String, env::VarError> {
env::var("DEX_CONTRACTS_ROOT")
}

/// Gets the standard non-token fee for the testnet. We deploy the test chain with STAKE
/// and FOOTOKEN balances by default, one footoken is sufficient for any Cosmos tx fee except
/// fees for send_to_eth messages which have to be of the same bridged denom so that the relayers
Expand Down

0 comments on commit f487c3e

Please sign in to comment.