Skip to content

Commit

Permalink
Fix storage slots (#62)
Browse files Browse the repository at this point in the history
* add some tests

* update ping address

* send 10 requests

* wip

* cargo fmt

* fix tests
  • Loading branch information
seunlanlege authored Mar 8, 2024
1 parent 6fd9bfc commit d2f88d9
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 53 deletions.
114 changes: 97 additions & 17 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ ethers = { git = "https://github.com/polytope-labs/ethers-rs", rev = "f8ab49e1ca
ethers-contract-abigen = { git = "https://github.com/polytope-labs/ethers-rs", rev = "f8ab49e1ca2d68e8bf1113e705ade38e5f30b850" }

merkle-mountain-range = { package = "ckb-merkle-mountain-range", version = "0.5.2" }
reconnecting-jsonrpsee-ws-client = "0.2.0"
reconnecting-jsonrpsee-ws-client = { git = "https://github.com/polytope-labs/reconnecting-jsonrpsee-ws-client", rev = "7c0817478c2741cc0889e7c75c645aad9f3cbb55" }

# hyperbridge
beefy-verifier-primitives = { git = "https://github.com/polytope-labs/hyperbridge", rev = "dffb69a0aeae8588fe4971fe2a2a3a8f87d4420f" }
Expand Down
54 changes: 21 additions & 33 deletions evm/common/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,34 +249,20 @@ mod tests {
"https://clean-capable-dew.bsc-testnet.quiknode.pro/bed456956996abb801b7ab44fdb3f6f63cd1a4ec/".into(),
);

let ping_addr = H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F"));

let chains = vec![
(
StateMachine::Ethereum(Ethereum::ExecutionLayer),
H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")),
geth_url,
),
(
StateMachine::Ethereum(Ethereum::Arbitrum),
H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")),
arb_url,
),
(
StateMachine::Ethereum(Ethereum::Optimism),
H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")),
op_url,
),
(
StateMachine::Ethereum(Ethereum::Base),
H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")),
base_url,
),
(StateMachine::Bsc, H160(hex!("d4812d6A3b9fB46feA314260Cbb61D57EBc71D7F")), bsc_url),
(StateMachine::Ethereum(Ethereum::ExecutionLayer), geth_url),
(StateMachine::Ethereum(Ethereum::Arbitrum), arb_url),
(StateMachine::Ethereum(Ethereum::Optimism), op_url),
(StateMachine::Ethereum(Ethereum::Base), base_url),
(StateMachine::Bsc, bsc_url),
];

let stream = futures::stream::iter(chains.clone().into_iter().map(Ok::<_, anyhow::Error>));

stream
.try_for_each_concurrent(None, |(chain, ping, url)| {
.try_for_each_concurrent(None, |(chain, url)| {
let chains_clone = chains.clone();
async move {
let signer = sp_core::ecdsa::Pair::from_seed_slice(&hex!(
Expand All @@ -287,10 +273,11 @@ mod tests {
LocalWallet::from(SecretKey::from_slice(signer.seed().as_slice())?)
.with_chain_id(provider.get_chainid().await?.low_u64());
let client = Arc::new(provider.with_signer(signer));
let ping = PingModule::new(ping.clone(), client.clone());
let ping = PingModule::new(ping_addr.clone(), client.clone());

let host_addr = ping.host().await.context(format!("Error in {chain:?}"))?;
dbg!(&host_addr);
dbg!((&chain, &host_addr));

let host = EvmHost::new(host_addr, client.clone());
let erc_20 = Erc20::new(
host.dai().await.context(format!("Error in {chain:?}"))?,
Expand All @@ -301,29 +288,30 @@ mod tests {
call.gas(gas)
.send()
.await
.context(format!("Error in {chain:?}"))?
.context(format!("Failed to send approval for {host_addr} in {chain:?}"))?
.await
.context(format!("Error in {chain:?}"))?;
.context(format!("Failed to approve {host_addr} in {chain:?}"))?;

for (chain, ping_addr, _) in chains_clone.iter().filter(|(c, _, _)| chain != *c)
{
for (chain, _) in chains_clone.iter().filter(|(c, _)| chain != *c) {
for _ in 0..1 {
let call = ping.ping(PingMessage {
dest: chain.to_string().as_bytes().to_vec().into(),
module: ping_addr.clone().into(),
timeout: 10 * 60 * 60,
fee: U256::from(9_000_000_000_000_000_000u128),
count: U256::from(100),
count: U256::from(10),
});
let gas =
call.estimate_gas().await.context(format!("Error in {chain:?}"))?;
let gas = call
.estimate_gas()
.await
.context(format!("Failed to estimate gas in {chain:?}"))?;
let receipt = call
.gas(gas)
.send()
.await
.context(format!("Error in {chain:?}"))?
.context(format!("Failed to send ping tx to {chain:?}"))?
.await
.context(format!("Error in {chain:?}"))?;
.context(format!("Failed to execute ping message on {chain:?}"))?;

assert!(receipt.is_some());
}
Expand Down
4 changes: 2 additions & 2 deletions substrate/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use anyhow::Context;
use ismp::{consensus::ConsensusStateId, host::StateMachine};
use pallet_ismp::primitives::HashAlgorithm;
use primitives::{config::Chain, IsmpHost, IsmpProvider};
use reconnecting_jsonrpsee_ws_client::{Client, FixedInterval, PingConfig};
use reconnecting_jsonrpsee_ws_client::{Client, PingConfig, RetryPolicy};
use serde::{Deserialize, Serialize};
use sp_core::{bytes::from_hex, sr25519, Pair, H256};
use std::{sync::Arc, time::Duration};
Expand Down Expand Up @@ -102,7 +102,7 @@ where
let max_rpc_payload_size = config.max_rpc_payload_size.unwrap_or(15 * 1024 * 1024);
let raw_client = Client::builder()
// retry every second
.retry_policy(FixedInterval::from_millis(1000))
.retry_policy(RetryPolicy::fixed(Duration::from_millis(1000)))
.max_request_size(max_rpc_payload_size)
.max_response_size(max_rpc_payload_size)
.enable_ws_ping(
Expand Down

0 comments on commit d2f88d9

Please sign in to comment.