Skip to content

Commit

Permalink
feat: added extensive tracing for lock_bridge_transfer_assets
Browse files Browse the repository at this point in the history
  • Loading branch information
andygolay committed Aug 22, 2024
1 parent cc40817 commit 04c0e03
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 41 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

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

42 changes: 23 additions & 19 deletions protocol-units/bridge/chains/movement/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::utils::MovementAddress;
use anyhow::{Error, Result};
use aptos_sdk::{
move_types::language_storage::TypeTag,
rest_client::{Client, FaucetClient},
rest_client::{Client, FaucetClient, Transaction},
types::LocalAccount,
};
use aptos_types::account_address::AccountAddress;
Expand Down Expand Up @@ -99,7 +99,6 @@ impl MovementClient {
let mut address_bytes = [0u8; AccountAddress::LENGTH];
address_bytes[0..2].copy_from_slice(&[0xca, 0xfe]);
let counterparty_address = AccountAddress::new(address_bytes);

Ok(MovementClient {
counterparty_address,
initiator_address: Vec::new(), //dummy for now
Expand Down Expand Up @@ -195,7 +194,7 @@ impl MovementClient {
))
}

pub fn publish_for_test(&self) -> Result<()> {
pub fn publish_for_test(&mut self) -> Result<()> {
//println!("Current directory: {:?}", env::current_dir());
let mut process = Command::new("movement")
.args(&["init"])
Expand Down Expand Up @@ -246,7 +245,7 @@ impl MovementClient {
"--address",
address,
"--seed",
"12345",
"256789",
])
.stdout(Stdio::piped())
.stderr(Stdio::piped())
Expand Down Expand Up @@ -276,6 +275,10 @@ impl MovementClient {
format!("0x{}", resource_address)
};

// Set counterparty module address to resource address, for function calls:
self.counterparty_address = AccountAddress::from_hex_literal(&formatted_resource_address)?;


println!("Derived resource address: {}", formatted_resource_address);

let current_dir = env::current_dir().expect("Failed to get current directory");
Expand Down Expand Up @@ -330,7 +333,7 @@ impl MovementClient {
"--address-name",
"moveth",
"--seed",
"12345",
"256789",
"--package-dir",
"../move-modules"
])
Expand Down Expand Up @@ -379,24 +382,25 @@ impl BridgeContractCounterparty for MovementClient {
) -> BridgeContractCounterpartyResult<()> {
//@TODO properly return an error instead of unwrapping
let args = vec![
to_bcs_bytes(&initiator.0).unwrap(),
to_bcs_bytes(&bridge_transfer_id.0).unwrap(),
to_bcs_bytes(&hash_lock.0).unwrap(),
to_bcs_bytes(&time_lock.0).unwrap(),
to_bcs_bytes(&recipient.0).unwrap(),
to_bcs_bytes(&amount.0).unwrap(),
];
to_bcs_bytes(&initiator.0).map_err(|_| BridgeContractCounterpartyError::SerializationError)?,
to_bcs_bytes(&bridge_transfer_id.0).map_err(|_| BridgeContractCounterpartyError::SerializationError)?,
to_bcs_bytes(&hash_lock.0).map_err(|_| BridgeContractCounterpartyError::SerializationError)?,
to_bcs_bytes(&time_lock.0).map_err(|_| BridgeContractCounterpartyError::SerializationError)?,
to_bcs_bytes(&recipient.0).map_err(|_| BridgeContractCounterpartyError::SerializationError)?,
to_bcs_bytes(&amount.0).map_err(|_| BridgeContractCounterpartyError::SerializationError)?,
];
let payload = utils::make_aptos_payload(
self.counterparty_address,
COUNTERPARTY_MODULE_NAME,
"lock_bridge_transfer_assets",
self.counterparty_type_args(Call::Lock),
args,
"hello_world",
vec![],
vec![],
);
let _ = utils::send_aptos_transaction(&self.rest_client, self.signer.as_ref(), payload)
.await
.map_err(|_| BridgeContractCounterpartyError::LockTransferAssetsError);
Ok(())
let txn_result = utils::send_aptos_transaction(&self.rest_client, self.signer.as_ref(), payload)
.await
.map_err(|_| BridgeContractCounterpartyError::LockTransferAssetsError)?;
println!("{:?}", &txn_result);
Ok(())
}

async fn complete_bridge_transfer(
Expand Down
43 changes: 31 additions & 12 deletions protocol-units/bridge/chains/movement/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use aptos_sdk::{
},
};
use derive_new::new;
use tracing::log::{info, debug};
use serde::{Deserialize, Serialize};
use std::str::FromStr;
use thiserror::Error;
Expand Down Expand Up @@ -99,22 +100,31 @@ pub async fn send_aptos_transaction(
signer: &LocalAccount,
payload: TransactionPayload,
) -> Result<AptosTransaction> {
info!("Starting send_aptos_transaction");
debug!("Payload: {:?}", payload);
debug!("Signer address: {:?}", signer.address());
let state = rest_client
.get_ledger_information()
.await
.context("Failed in getting chain id")?
.into_inner();
info!("Ledger information retrieved: chain_id = {}", state.chain_id);

let transaction_factory = TransactionFactory::new(ChainId::new(state.chain_id))
.with_gas_unit_price(100)
.with_max_gas_amount(GAS_UNIT_LIMIT);
debug!("Transaction factory created with chain_id = {}", state.chain_id);

let signed_tx = signer.sign_with_transaction_builder(transaction_factory.payload(payload));
debug!("Transaction signed: {:?}", signed_tx);

let response = rest_client
.submit_and_wait(&signed_tx)
.await
.map_err(|e| anyhow::anyhow!(e.to_string()))?
.map_err(|e| {
debug!("Transaction submission failed: {:?}", e);
anyhow::anyhow!(e.to_string())
})?
.into_inner();
Ok(response)
}
Expand Down Expand Up @@ -156,18 +166,27 @@ pub async fn simulate_aptos_transaction(

/// Make Aptos Transaction Payload
pub fn make_aptos_payload(
package_address: AccountAddress,
module_name: &'static str,
function_name: &'static str,
ty_args: Vec<TypeTag>,
args: Vec<Vec<u8>>,
package_address: AccountAddress,
module_name: &'static str,
function_name: &'static str,
ty_args: Vec<TypeTag>,
args: Vec<Vec<u8>>,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(package_address, ident_str!(module_name).to_owned()),
ident_str!(function_name).to_owned(),
ty_args,
args,
))
// Log the details of the payload being created
info!("Creating Aptos transaction payload:");
info!(" Package address: {:?}", package_address);
info!(" Module name: {}", module_name);
info!(" Function name: {}", function_name);
debug!(" Type arguments: {:?}", ty_args);
debug!(" Arguments: {:?}", args);

// Create and return the transaction payload
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(package_address, ident_str!(module_name).to_owned()),
ident_str!(function_name).to_owned(),
ty_args,
args,
))
}

/// Send View Request
Expand Down
2 changes: 2 additions & 0 deletions protocol-units/bridge/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ethereum-bridge = { workspace = true }
movement-bridge = { workspace = true }
futures = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

[dev-dependencies]
tokio = { workspace = true }
12 changes: 8 additions & 4 deletions protocol-units/bridge/integration-tests/tests/eth_movement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use std::{
str::FromStr,
time::Instant,
};
use tracing;
use tracing_subscriber;

use url::Url;

Expand Down Expand Up @@ -97,9 +99,13 @@ async fn test_movement_client_build_and_fund_accounts() -> Result<(), anyhow::Er
#[tokio::test]
//#[ignore]
async fn test_movement_client_happy_path() -> Result<(), anyhow::Error> {

let _ = tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.try_init();

let (mut harness, mut child) = TestHarness::new_with_movement().await;
{ let mut movement_client = harness.movement_client().expect("Failed to get MovementClient");
{ let mut movement_client = harness.movement_client_mut().expect("Failed to get MovementClient");

let rest_client = movement_client.rest_client();
let coin_client = CoinClient::new(&rest_client);
Expand All @@ -120,7 +126,7 @@ async fn test_movement_client_happy_path() -> Result<(), anyhow::Error> {
.movement_client_mut()
.expect("Failed to get MovmentClient")
.lock_bridge_transfer_assets(
BridgeTransferId(bridge_transfer_id),
BridgeTransferId(bridge_transfer_id),
HashLock(hash_lock),
TimeLock(100),
InitiatorAddress(initiator),
Expand All @@ -130,8 +136,6 @@ async fn test_movement_client_happy_path() -> Result<(), anyhow::Error> {
.await
.expect("Failed to complete bridge transfer");

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

harness
.movement_client_mut()
.expect("Failed to get MovmentClient")
Expand Down
12 changes: 6 additions & 6 deletions protocol-units/bridge/move-modules/Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ version = "1.0.0"
authors = []

[addresses]
resource_addr = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"
resource_addr = "0x389497d8fd32545f3bb2882d0b043c7e036a68700ab3add8b56dad0f06d6d7cb"
origin_addr = "0x84f978fa58adab3c1fbd99dc187074438455dbe3c0a217e00dbdd15342cd3122"
atomic_bridge = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"
moveth = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"
master_minter = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"
minter = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"
admin = "0xcabc48e6da9408ee34bec243bb027fc8772bbf1a9586115342ee4ba5d236e9c7"
atomic_bridge = "0x389497d8fd32545f3bb2882d0b043c7e036a68700ab3add8b56dad0f06d6d7cb"
moveth = "0x389497d8fd32545f3bb2882d0b043c7e036a68700ab3add8b56dad0f06d6d7cb"
master_minter = "0x389497d8fd32545f3bb2882d0b043c7e036a68700ab3add8b56dad0f06d6d7cb"
minter = "0x389497d8fd32545f3bb2882d0b043c7e036a68700ab3add8b56dad0f06d6d7cb"
admin = "0x389497d8fd32545f3bb2882d0b043c7e036a68700ab3add8b56dad0f06d6d7cb"
source_account = "0x84f978fa58adab3c1fbd99dc187074438455dbe3c0a217e00dbdd15342cd3122"
pauser = "0xdafe"
denylister = "0xcade"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ module atomic_bridge::atomic_bridge_counterparty {
move_to(resource, bridge_transfer_store);
move_to(resource, bridge_config);
}



public fun lock_bridge_transfer_assets(
caller: &signer,
Expand Down
2 changes: 2 additions & 0 deletions protocol-units/bridge/shared/src/bridge_contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ impl BridgeContractInitiatorError {
pub enum BridgeContractCounterpartyError {
#[error("Failed to lock bridge transfer assets")]
LockTransferAssetsError,
#[error("Failed to serialize or deserialize")]
SerializationError,
#[error("Failed to complete bridge transfer")]
CompleteTransferError,
#[error("Failed to abort bridge transfer")]
Expand Down

0 comments on commit 04c0e03

Please sign in to comment.