Skip to content

Commit

Permalink
Merge pull request #15 from madara-alliance/feat/refactor/tests
Browse files Browse the repository at this point in the history
Tests Refactoring
  • Loading branch information
Mohiiit authored Oct 28, 2024
2 parents 27f3679 + f90426c commit cf3de1a
Show file tree
Hide file tree
Showing 22 changed files with 620 additions and 229 deletions.
39 changes: 32 additions & 7 deletions .github/workflows/test-bridge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:

jobs:
test_bridge:
runs-on: macos-latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -25,15 +25,40 @@ jobs:
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Run anvil
- name: Setup build deps
run: |
sudo apt-get update
sudo apt-get install -y clang llvm libudev-dev protobuf-compiler
- uses: rui314/setup-mold@v1
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "2.8.2"
- uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Checkout Madara
uses: actions/checkout@v4
with:
repository: madara-alliance/madara
ref: "346700a1b3cf1dc857ee73c479720ef9c7abcc39"
path: madara

- name: Move Madara Devnet config
working-directory: madara
run: |
anvil </dev/null &>/dev/null &
mv configs/preset/devnet.yml ./src/tests/devnet.yml
- name: Run madara
- name: Build Madara
working-directory: madara
run: |
cargo build
mv target/debug/madara ../bin/madara
cd ..
- name: Run anvil
run: |
cd bin
echo "Running madara...."
./run_madara.sh
anvil &
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: taiki-e/install-action@nextest
Expand Down
83 changes: 83 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ starknet_api = { git = "https://github.com/bidzyyys/starknet-api.git", branch =
assert_matches = "1.5.0"
async-trait = "0.1.74"
clap = { version = "4.4.11", features = ["derive", "env"] }
color-eyre = "0.6.2"
dotenv = "0.15.0"
env_logger = "0.11.3"
log = "0.4.21"
Expand All @@ -61,4 +62,6 @@ bytes = "1.6.0"
flate2 = "1.0.30"
indexmap = "2.2.6"
inline_colorization = "0.1.6"
lazy_static = "1.4.0"
subxt-lightclient = { version = "0.35.3", optional = true, default-features = false }
tempfile = "3.10.1"
9 changes: 6 additions & 3 deletions src/contract_clients/core_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,21 @@ pub fn get_init_data_core_contract(
_verifier_address: Address,
) -> CoreContractInitData {
CoreContractInitData {
program_hash: U256::from_str_radix("1e324682835e60c4779a683b32713504aed894fd73842f7d05b18e7bd29cd70", 16).unwrap(), // zero program hash would be deemed invalid
program_hash: U256::from_str_radix("1e324682835e60c4779a683b32713504aed894fd73842f7d05b18e7bd29cd70", 16)
.unwrap(), // zero program hash would be deemed invalid
aggregate_program_hash: U256::zero(),
verifier_address: Address::from_str("0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512").unwrap(),
config_hash: convert_felt_to_u256(config_hash),
// TODO :
// Figure out the exact params for production env
initial_state: CoreContractState {
block_number: I256::from(11),
state_root: U256::from_str_radix("5f41b32fadc9d1bd9d2bf2eb8771e1c64b2ad1b6f3334bf6be0b38c408e4746", 16).unwrap(),
state_root: U256::from_str_radix("5f41b32fadc9d1bd9d2bf2eb8771e1c64b2ad1b6f3334bf6be0b38c408e4746", 16)
.unwrap(),
// TODO :
// Remove hardcoded values.
block_hash: U256::from_str_radix("6aeb708c2a47182fd921db56803102eabbd2940c75e0c306012fff144b02186", 16).unwrap(),
block_hash: U256::from_str_radix("6aeb708c2a47182fd921db56803102eabbd2940c75e0c306012fff144b02186", 16)
.unwrap(),
},
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/contract_clients/eth_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl StarknetLegacyEthBridge {
.unwrap();
let contract_address = get_contract_address_from_deploy_tx(account.provider(), &deploy_tx).await.unwrap();

log::debug!("🎡 contract address (eth bridge) : {:?}", contract_address);
log::info!("🎡 contract address (eth bridge) : {:?}", contract_address);

let add_implementation_txn = invoke_contract(
legacy_eth_bridge_proxy_address,
Expand Down Expand Up @@ -158,7 +158,7 @@ impl StarknetLegacyEthBridge {
calldata.extend(empty_bytes);
calldata.extend(padded_messaging_bytes);

log::debug!("🎡 add_implementation_eth_bridge : bytes : {:?}", Bytes::from(calldata.clone()));
log::info!("🎡 add_implementation_eth_bridge : bytes : {:?}", Bytes::from(calldata.clone()));

self.eth_bridge
.add_implementation(Bytes::from(calldata), self.implementation_address(), false)
Expand All @@ -185,7 +185,7 @@ impl StarknetLegacyEthBridge {
calldata.extend(empty_bytes);
calldata.extend(padded_messaging_bytes);

log::debug!("🎡 upgrade_to_eth_bridge : bytes : {:?}", Bytes::from(calldata.clone()));
log::info!("🎡 upgrade_to_eth_bridge : bytes : {:?}", Bytes::from(calldata.clone()));

self.eth_bridge
.upgrade_to(Bytes::from(calldata), self.implementation_address(), false)
Expand Down Expand Up @@ -228,12 +228,12 @@ impl StarknetLegacyEthBridge {
)
.await;

log::debug!("🎡 setup_l2_bridge : l2 bridge initialized //");
log::info!("🎡 setup_l2_bridge : l2 bridge initialized //");
wait_for_transaction(rpc_provider, tx.transaction_hash, "setup_l2_bridge : initialize").await.unwrap();

let tx = invoke_contract(l2_bridge_address, "set_l2_token", vec![erc20_address], account).await;

log::debug!("🎡 setup_l2_bridge : l2 token set //");
log::info!("🎡 setup_l2_bridge : l2 token set //");
wait_for_transaction(rpc_provider, tx.transaction_hash, "setup_l2_bridge : set_l2_token").await.unwrap();

let tx = invoke_contract(
Expand All @@ -244,7 +244,7 @@ impl StarknetLegacyEthBridge {
)
.await;

log::debug!("🎡 setup_l2_bridge : l1 bridge set //");
log::info!("🎡 setup_l2_bridge : l1 bridge set //");
wait_for_transaction(rpc_provider, tx.transaction_hash, "setup_l2_bridge : set_l1_bridge").await.unwrap();
}

Expand Down
18 changes: 9 additions & 9 deletions src/contract_clients/starknet_sovereign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl CoreContract for StarknetSovereignContract {
}

fn implementation_address(&self) -> Address {
log::debug!(
log::info!(
"🎡 self.core_contract_client.implementation_address() : {:?}",
self.core_contract_client.implementation_address()
);
Expand All @@ -52,7 +52,7 @@ impl CoreContract for StarknetSovereignContract {
async fn initialize_with(&self, init_data: CoreContractInitData) {
let data = ProxyInitializeData::<0> { sub_contract_addresses: [], eic_address: Default::default(), init_data };

log::debug!("ℹ️ initialize_with : data : {:?}", data);
log::info!("ℹ️ initialize_with : data : {:?}", data);

self.core_contract_client.initialize_with(data).await.expect("Failed to initialize");

Expand All @@ -78,7 +78,7 @@ impl CoreContract for StarknetSovereignContract {
get_init_data_core_contract(block_number, state_root, program_hash, config_hash, verifier_address);
let final_bytes = get_calldata_bytes(init_data.clone());

log::debug!("ℹ️ add_implementation : data : {:?} : {:?}", init_data, final_bytes.clone());
log::info!("ℹ️ add_implementation : data : {:?} : {:?}", init_data, final_bytes.clone());

// https://sepolia.etherscan.io/tx/0x9ac02beb912e5c6226828110380d727a6fd7e4748cbded2198cdf62ea78dab62
// let bytes_etherscan =
Expand All @@ -91,7 +91,7 @@ impl CoreContract for StarknetSovereignContract {
.await
.expect("Failed to call add implementation");

log::debug!("ℹ️ add_implementation : done");
log::info!("ℹ️ add_implementation : done");
}

/// Add implementation Starknet core contract with the specified data.
Expand All @@ -110,7 +110,7 @@ impl CoreContract for StarknetSovereignContract {
get_init_data_core_contract(block_number, state_root, program_hash, config_hash, verifier_address);
let final_bytes = get_calldata_bytes(init_data.clone());

log::debug!("ℹ️ upgrade_to : data : {:?} : {:?}", init_data, final_bytes.clone());
log::info!("ℹ️ upgrade_to : data : {:?} : {:?}", init_data, final_bytes.clone());

// https://sepolia.etherscan.io/tx/0x9ac02beb912e5c6226828110380d727a6fd7e4748cbded2198cdf62ea78dab62
// let bytes_etherscan =
Expand All @@ -123,13 +123,13 @@ impl CoreContract for StarknetSovereignContract {
.await
.expect("Failed to call upgrade to");

log::debug!("ℹ️ upgrade_to : done");
log::info!("ℹ️ upgrade_to : done");
}

/// For registering the operator for Starknet Core Contract
async fn register_operator_core_contract(&self, operator_address: Address) {
self.core_contract_client.register_operator(operator_address).await.expect("Failed to register operator");
log::debug!("ℹ️ register_operator : done");
log::info!("ℹ️ register_operator : done");
}

/// For nominating the governor for Starknet Core Contract
Expand All @@ -138,7 +138,7 @@ impl CoreContract for StarknetSovereignContract {
.starknet_nominate_new_governor(l1_governor_address)
.await
.expect("Failed to nominate governor");
log::debug!("ℹ️ register_operator : done");
log::info!("ℹ️ register_operator : done");
}

/// For nominating the governor for Starknet Core Contract Proxy
Expand All @@ -147,7 +147,7 @@ impl CoreContract for StarknetSovereignContract {
.proxy_nominate_new_governor(l1_governor_address)
.await
.expect("Failed to register operator");
log::debug!("ℹ️ proxy_nominate_new_governor : done");
log::info!("ℹ️ proxy_nominate_new_governor : done");
}

/// Initialize Starknet core contract with the specified program and config hashes. The rest of
Expand Down
Loading

0 comments on commit cf3de1a

Please sign in to comment.