Skip to content

Commit

Permalink
update e2e, bump WETH9 for e2e build
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmovses committed Jul 2, 2024
1 parent fbdb26b commit e0d8dd9
Show file tree
Hide file tree
Showing 418 changed files with 54,997 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
proc-compose.temp.log
methods/guest/Cargo.lock
protocol-units/bridge/move-modules/build/*
.idea/
target/
ledger_db/
Expand Down
15 changes: 15 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ members = [
"protocol-units/bridge/shared",
"protocol-units/bridge/cli",
"protocol-units/bridge/chains/ethereum",
"protocol-units/bridge/e2e",
]

[workspace.package]
Expand Down
2 changes: 2 additions & 0 deletions protocol-units/bridge/chains/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ impl EthClient<AlloyProvider> {
) -> Result<Self, anyhow::Error> {
let signer_private_key = config.signer_private_key;
let signer: LocalWallet = signer_private_key.parse()?;
println!("Signerrrr: {:?}", signer);
let initiator_address = config.initiator_address.parse()?;
println!("Initiator Address: {:?}", initiator_address);
let rpc_url = config.rpc_url.context("rpc_url not set")?;
let ws_url = config.ws_url.context("ws_url not set")?;
let rpc_provider = ProviderBuilder::new()
Expand Down
25 changes: 17 additions & 8 deletions protocol-units/bridge/cli/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub enum EthCommands {
initiator_address: String,
#[arg(short, long)]
recipient_address: String,
#[arg(short, long)]
#[arg(long)] // Don't use short as it clashes with help -h
hash_lock: String,
#[arg(short, long)]
time_lock: u64,
Expand Down Expand Up @@ -103,10 +103,16 @@ pub async fn run(command: &EthCommands) -> Result<()> {
}

fn load_config(path: &str) -> Result<Config> {
// Load the config from the provided path
let config_str = std::fs::read_to_string(path)?;
let config: Config = serde_json::from_str(&config_str)?;
Ok(config)
match std::fs::read_to_string(path) {
Ok(config_str) => {
let config: Config = serde_json::from_str(&config_str)?;
Ok(config)
}
Err(_) => {
println!("Config file not found, Using default config values");
Ok(Config::default())
}
}
}

async fn deploy(config: Config) -> Result<()> {
Expand All @@ -124,10 +130,13 @@ async fn initiate_transfer(
amount: u64,
) -> Result<()> {
let mut client = EthClient::build_with_config(config, recipient_address).await?;
let chain_id = 42; //dummy value for now
let initiator_address = EthAddress::parse_checksummed(initiator_address, Some(chain_id))?;
let recipient_address = EthAddress::parse_checksummed(recipient_address, Some(chain_id))?;
//let chain_id = 42; //dummy value for now
let initiator_address = EthAddress::parse_checksummed(initiator_address, None)?;
let recipient_address = EthAddress::parse_checksummed(recipient_address, None)?;
let hash_lock = HashLock::parse(hash_lock)?;
println!("initiator_address: {:?}", initiator_address);
println!("recipient_address: {:?}", recipient_address);
println!("hash_lock: {:?}", hash_lock);
client
.initiate_bridge_transfer(
InitiatorAddress(initiator_address),
Expand Down
1 change: 1 addition & 0 deletions protocol-units/bridge/cli/src/movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub enum MovementCommands {
},
}

#[allow(unused)]
pub async fn run(command: &MovementCommands) -> Result<()> {
match command {
MovementCommands::Deploy { config_path } => {
Expand Down
74 changes: 74 additions & 0 deletions protocol-units/bridge/contracts/src/WETH9.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright (C) 2015, 2016, 2017 Dapphub

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
pragma solidity ^0.8.22;

contract WETH9 {
string public name = "Wrapped Ether";
string public symbol = "WETH";
uint8 public decimals = 18;

event Approval(address indexed src, address indexed guy, uint wad);
event Transfer(address indexed src, address indexed dst, uint wad);
event Deposit(address indexed dst, uint wad);
event Withdrawal(address indexed src, uint wad);

mapping (address => uint) public balanceOf;
mapping (address => mapping (address => uint)) public allowance;

receive() external payable {
deposit();
}

function deposit() public payable {
balanceOf[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}

function withdraw(uint wad) public {
require(balanceOf[msg.sender] >= wad, "Insufficient balance");
balanceOf[msg.sender] -= wad;
payable(msg.sender).transfer(wad);
emit Withdrawal(msg.sender, wad);
}

function totalSupply() public view returns (uint) {
return address(this).balance;
}

function approve(address guy, uint wad) public returns (bool) {
allowance[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}

function transfer(address dst, uint wad) public returns (bool) {
return transferFrom(msg.sender, dst, wad);
}

function transferFrom(address src, address dst, uint wad)
public
returns (bool)
{
require(balanceOf[src] >= wad, "Insufficient balance");

if (src != msg.sender && allowance[src][msg.sender] != type(uint).max) {
require(allowance[src][msg.sender] >= wad, "Allowance exceeded");
allowance[src][msg.sender] -= wad;
}

balanceOf[src] -= wad;
balanceOf[dst] += wad;

emit Transfer(src, dst, wad);

return true;
}
}

28 changes: 28 additions & 0 deletions protocol-units/bridge/e2e/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "bridge-e2e-tests"
version.workspace = true
edition.workspace = true
license.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
publish.workspace = true
rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = { workspace = true }
clap = { workspace = true }
hex = { workspace = true }
tokio = { workspace = true }
serde_json = { workspace = true }
keccak-hash = { workspace = true }

alloy-primitives = { workspace = true }

bridge-shared = { workspace = true }
ethereum-bridge = { workspace = true }

[lints]
workspace = true
119 changes: 119 additions & 0 deletions protocol-units/bridge/e2e/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use anyhow::Result;
//use bridge_shared::types::BridgeTransferId;
//use std::process::Command;
use hex::encode;
use std::{env, process::Stdio};
use tokio::process::Command as TokioCommand;
use tokio::time::{sleep, Duration};

#[tokio::main]
async fn main() -> Result<()> {
let config_path = "path/to/config.json";
// 1st Anvil test address
let initiator_address = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
let recipient_address = "0x123"; // dummy val, this should be a movement address

let hash_lock = "forty-two".as_bytes();
let hash_lock_bytes = keccak_hash::keccak(hash_lock);
let hash_lock = encode(hash_lock_bytes);

let time_lock: u64 = 3600; // Example value
let amount: u64 = 1000; // Example value
let bridge_transfer_id = "bridge_transfer_id";
let pre_image = "pre_image";

let current_dir = env::current_dir()?;
println!("Current dir: {:?}", current_dir);

let build_output = TokioCommand::new("forge")
.args(&["build"])
.current_dir("protocol-units/bridge/contracts") //navigate to contracts dir
.output()
.await?;
if !build_output.status.success() {
eprint!("Failed to build contracts: {}", String::from_utf8_lossy(&build_output.stderr));
return Err(anyhow::anyhow!("Failed to build contracts"));
} else {
println!("forge build output:");
println!("{}", String::from_utf8_lossy(&build_output.stdout));
}

let _ = TokioCommand::new("anvil").stdout(Stdio::null()).stderr(Stdio::null()).spawn()?;
sleep(Duration::from_secs(5)).await;

// let deploy_status = TokioCommand::new("forge")
// .args(&["-c", "anvil", "-p", "anvil"])
// .status()
// .await?;
// assert!(deploy_status.success(), "Deployment failed");
//
sleep(Duration::from_secs(5)).await;

// Step 1: Deploy
println!("Deploying contract...");
let deploy_status = TokioCommand::new("cargo")
.args(&[
"run",
"--package",
"bridge-cli",
"--",
"eth",
"deploy",
"--config-path",
config_path,
])
.status()
.await?;
assert!(deploy_status.success(), "Deployment failed");

// Step 2: Initiate
println!("Initiating transfer...");
let initiate_status = TokioCommand::new("cargo")
.args(&[
"run",
"--package",
"bridge-cli",
"--",
"eth",
"initiate",
"--config-path",
config_path,
"--initiator-address",
initiator_address,
"--recipient-address",
recipient_address,
"--hash-lock",
hash_lock.as_str(),
"--time-lock",
&time_lock.to_string(),
"--amount",
&amount.to_string(),
])
.status()
.await?;
assert!(initiate_status.success(), "Initiation failed");

// Step 3: Complete
println!("Completing transfer...");
let complete_status = TokioCommand::new("cargo")
.args(&[
"run",
"--package",
"bridge-cli",
"--",
"eth",
"complete",
"--config-path",
config_path,
"--bridge-transfer-id",
bridge_transfer_id,
"--pre-image",
pre_image,
])
.status()
.await?;
assert!(complete_status.success(), "Completion failed");

println!("E2E flow completed successfully");
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
compiled_package_info:
package_name: bridge-modules
address_alias_instantiation:
Extensions: "0000000000000000000000000000000000000000000000000000000000000001"
aptos_framework: "0000000000000000000000000000000000000000000000000000000000000001"
aptos_fungible_asset: 000000000000000000000000000000000000000000000000000000000000000a
aptos_std: "0000000000000000000000000000000000000000000000000000000000000001"
aptos_token: "0000000000000000000000000000000000000000000000000000000000000003"
atomic_bridge: 000000000000000000000000000000000000000000000000000000000000feef
core_resources: 000000000000000000000000000000000000000000000000000000000a550c18
denylister: 000000000000000000000000000000000000000000000000000000000000cade
master_minter: 0000000000000000000000000000000000000000000000000000000000000bab
minter: 000000000000000000000000000000000000000000000000000000000000face
moveth: 000000000000000000000000000000000000000000000000000000000000beef
pauser: 000000000000000000000000000000000000000000000000000000000000dafe
std: "0000000000000000000000000000000000000000000000000000000000000001"
vm: "0000000000000000000000000000000000000000000000000000000000000000"
vm_reserved: "0000000000000000000000000000000000000000000000000000000000000000"
source_digest: 0F8104C161282EF43E3F9FBD5610B12B11FAC2F37178834FC036F8FC9BABFA3F
build_flags:
dev_mode: true
test_mode: true
generate_docs: false
generate_abis: false
generate_move_model: true
full_model_generation: false
install_dir: ~
force_recompilation: false
additional_named_addresses: {}
architecture: ~
fetch_deps_only: false
skip_fetch_latest_git_deps: false
compiler_config:
bytecode_version: ~
known_attributes:
- bytecode_instruction
- deprecated
- event
- expected_failure
- legacy_entry_fun
- native_interface
- randomness
- resource_group
- resource_group_member
- test
- test_only
- verify_only
- view
skip_attribute_checks: false
compiler_version: ~
language_version: ~
dependencies:
- AptosFramework
- AptosStdlib
- MoveStdlib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit e0d8dd9

Please sign in to comment.