Skip to content

Commit

Permalink
fix(minor-ampd): update MultiversX sdk to fix transaction not being v…
Browse files Browse the repository at this point in the history
…erified bug (axelarnetwork#645)
  • Loading branch information
raress96 authored Oct 7, 2024
1 parent 23cec5a commit dd25645
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 22 deletions.
55 changes: 46 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion ampd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ k256 = { workspace = true }
mockall = "0.11.3"
move-core-types = { git = "https://github.com/mystenlabs/sui", tag = "mainnet-v1.26.2" }
multisig = { workspace = true, features = ["library"] }
multiversx-sdk = "0.4.1"
multiversx-sdk = "0.6.1"
num-traits = { workspace = true }
openssl = { version = "0.10.35", features = ["vendored"] } # Needed to make arm compilation work by forcing vendoring
prost = "0.11.9"
Expand Down
6 changes: 3 additions & 3 deletions ampd/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use event_processor::EventHandler;
use event_sub::EventSub;
use evm::finalizer::{pick, Finalization};
use evm::json_rpc::EthereumClient;
use multiversx_sdk::blockchain::CommunicationProxy;
use multiversx_sdk::gateway::GatewayProxy;
use queue::queued_broadcaster::QueuedBroadcaster;
use router_api::ChainName;
use thiserror::Error;
Expand Down Expand Up @@ -338,7 +338,7 @@ where
handlers::mvx_verify_msg::Handler::new(
verifier.clone(),
cosmwasm_contract,
CommunicationProxy::new(proxy_url.to_string().trim_end_matches('/').into()),
GatewayProxy::new(proxy_url.to_string().trim_end_matches('/').into()),
self.block_height_monitor.latest_block_height(),
),
event_processor_config.clone(),
Expand All @@ -351,7 +351,7 @@ where
handlers::mvx_verify_verifier_set::Handler::new(
verifier.clone(),
cosmwasm_contract,
CommunicationProxy::new(proxy_url.to_string().trim_end_matches('/').into()),
GatewayProxy::new(proxy_url.to_string().trim_end_matches('/').into()),
self.block_height_monitor.latest_block_height(),
),
event_processor_config.clone(),
Expand Down
70 changes: 68 additions & 2 deletions ampd/src/mvx/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use async_trait::async_trait;
use futures::future::join_all;
use hex::ToHex;
use mockall::automock;
use multiversx_sdk::blockchain::CommunicationProxy;
use multiversx_sdk::data::transaction::TransactionOnNetwork;
use multiversx_sdk::gateway::GatewayProxy;

use crate::types::Hash;

Expand All @@ -25,7 +25,7 @@ pub trait MvxProxy {
}

#[async_trait]
impl MvxProxy for CommunicationProxy {
impl MvxProxy for GatewayProxy {
async fn transactions_info_with_results(
&self,
tx_hashes: HashSet<Hash>,
Expand Down Expand Up @@ -61,3 +61,69 @@ impl MvxProxy for CommunicationProxy {
tx.hash.is_some() && tx.logs.is_some() && tx.status == *STATUS_SUCCESS
}
}

#[cfg(test)]
mod tests {
use multiversx_sdk::data::address::Address;
use multiversx_sdk::data::transaction::{ApiLogs, TransactionOnNetwork};
use multiversx_sdk::gateway::GatewayProxy;

use super::MvxProxy;

#[test]
fn should_not_be_valid_transaction_no_hash() {
let tx = TransactionOnNetwork {
hash: None,
..TransactionOnNetwork::default()
};

assert!(!GatewayProxy::is_valid_transaction(&tx));
}

#[test]
fn should_not_be_valid_transaction_no_logs() {
let tx = TransactionOnNetwork {
hash: Some("txHash".into()),
logs: None,
..TransactionOnNetwork::default()
};

assert!(!GatewayProxy::is_valid_transaction(&tx));
}

#[test]
fn should_not_be_valid_transaction_invalid_status() {
let tx = TransactionOnNetwork {
hash: Some("txHash".into()),
logs: Some(ApiLogs {
address: Address::from_bech32_string(
"erd1qqqqqqqqqqqqqpgqhe8t5jewej70zupmh44jurgn29psua5l2jps3ntjj3",
)
.unwrap(),
events: vec![],
}),
status: "pending".into(),
..TransactionOnNetwork::default()
};

assert!(!GatewayProxy::is_valid_transaction(&tx));
}

#[test]
fn should_be_valid_transaction() {
let tx = TransactionOnNetwork {
hash: Some("txHash".into()),
logs: Some(ApiLogs {
address: Address::from_bech32_string(
"erd1qqqqqqqqqqqqqpgqhe8t5jewej70zupmh44jurgn29psua5l2jps3ntjj3",
)
.unwrap(),
events: vec![],
}),
status: "success".into(),
..TransactionOnNetwork::default()
};

assert!(GatewayProxy::is_valid_transaction(&tx));
}
}
14 changes: 7 additions & 7 deletions ampd/src/mvx/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod tests {
use multisig::key::KeyType;
use multisig::test::common::{build_verifier_set, ed25519_test_data};
use multiversx_sdk::data::address::Address;
use multiversx_sdk::data::transaction::{ApiLogs, Events, TransactionOnNetwork};
use multiversx_sdk::data::transaction::{ApiLogs, Events, LogData, TransactionOnNetwork};

use crate::handlers::mvx_verify_msg::Message;
use crate::handlers::mvx_verify_verifier_set::VerifierSetConfirmation;
Expand Down Expand Up @@ -430,7 +430,7 @@ mod tests {
address: gateway_address.clone(),
identifier: CONTRACT_CALL_IDENTIFIER.into(),
topics: Some(vec![STANDARD.encode(SIGNERS_ROTATED_EVENT)]), // wrong event name
data: None,
data: LogData::Empty,
};

// On MultiversX, topics and data are base64 encoded
Expand All @@ -444,7 +444,7 @@ mod tests {
STANDARD.encode(msg.destination_address.clone()),
STANDARD.encode(payload_hash),
]),
data: Some("".into()), // data is irrelevant here since it contains only the offchain payload
data: LogData::String("".into()), // data is irrelevant here since it contains only the offchain payload
};

let other_address = Address::from_bech32_string(
Expand Down Expand Up @@ -483,7 +483,7 @@ mod tests {
data: None,
hyperblock_nonce: Some(1),
hyperblock_hash: Some("".into()),
smart_contract_results: None,
smart_contract_results: vec![],
processing_type_on_destination: "".into(),
};

Expand Down Expand Up @@ -526,7 +526,7 @@ mod tests {
address: gateway_address.clone(),
identifier: ROTATE_SIGNERS_IDENTIFIER.into(),
topics: Some(vec![STANDARD.encode(CONTRACT_CALL_EVENT)]), // wrong event name
data: None,
data: LogData::Empty,
};

// On MultiversX, topics and data are base64 encoded
Expand All @@ -538,7 +538,7 @@ mod tests {
STANDARD.encode("0"), // epoch (irrelevant here)
STANDARD.encode(signers_hash), // signers hash
]),
data: Some(STANDARD.encode(data)),
data: LogData::String(STANDARD.encode(data)),
};

let other_address = Address::from_bech32_string(
Expand Down Expand Up @@ -577,7 +577,7 @@ mod tests {
data: None,
hyperblock_nonce: Some(1),
hyperblock_hash: Some("".into()),
smart_contract_results: None,
smart_contract_results: vec![],
processing_type_on_destination: "".into(),
};

Expand Down

0 comments on commit dd25645

Please sign in to comment.