Skip to content

Commit

Permalink
Add smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Feb 21, 2024
1 parent fe7a814 commit 89c9e3f
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
2 changes: 2 additions & 0 deletions contracts/src/DeployScript.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {ChannelID, ParaID, OperatingMode} from "./Types.sol";
import {SafeNativeTransfer} from "./utils/SafeTransfer.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {UD60x18, ud60x18} from "prb/math/src/UD60x18.sol";
import {HelloWorld} from "../test/mocks/HelloWorld.sol";

contract DeployScript is Script {
using SafeNativeTransfer for address payable;
Expand Down Expand Up @@ -99,6 +100,7 @@ contract DeployScript is Script {
payable(assetHubAgent).safeNativeTransfer(initialDeposit);

new GatewayUpgradeMock();
new HelloWorld();

vm.stopBroadcast();
}
Expand Down
3 changes: 3 additions & 0 deletions contracts/src/FundAgent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ contract FundAgent is Script {

bytes32 bridgeHubAgentID = vm.envBytes32("BRIDGE_HUB_AGENT_ID");
bytes32 assetHubAgentID = vm.envBytes32("ASSET_HUB_AGENT_ID");
bytes32 penpalAgentID = vm.envBytes32("PENPAL_AGENT_ID");

address bridgeHubAgent = IGateway(gatewayAddress).agentOf(bridgeHubAgentID);
address assetHubAgent = IGateway(gatewayAddress).agentOf(assetHubAgentID);
address penpalAgent = IGateway(gatewayAddress).agentOf(penpalAgentID);

payable(bridgeHubAgent).safeNativeTransfer(initialDeposit);
payable(assetHubAgent).safeNativeTransfer(initialDeposit);
payable(penpalAgent).safeNativeTransfer(initialDeposit);

vm.stopBroadcast();
}
Expand Down
2 changes: 1 addition & 1 deletion smoketest/make-bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mkdir -p src/contracts

# Generate Rust bindings for contracts
forge bind --module --overwrite \
--select 'IGateway|WETH9|GatewayUpgradeMock' \
--select 'IGateway|WETH9|GatewayUpgradeMock|HelloWorld' \
--bindings-path src/contracts \
--root ../contracts

Expand Down
83 changes: 83 additions & 0 deletions smoketest/tests/transact_from_penpal_to_ethereum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use ethers::{
abi::{Abi, Token},
prelude::{Address, Middleware, Provider, Ws},
};
use futures::StreamExt;
use hex_literal::hex;
use snowbridge_smoketest::{
contracts::hello_world::{HelloWorld, SaidHelloFilter},
helper::*,
parachains::penpal::api as PenpalApi,
};
use std::{ops::Deref, sync::Arc};
use subxt::{
ext::sp_core::{sr25519::Pair, Pair as PairT},
tx::PairSigner,
};

const HELLO_WORLD_CONTRACT: [u8; 20] = hex!("EE9170ABFbf9421Ad6DD07F6BDec9D89F2B581E0");

#[tokio::test]
async fn transact_from_penpal_to_ethereum() {
let test_clients = initial_clients().await.expect("initialize clients");

let ethereum_client = *(test_clients.ethereum_client.clone());
let penpal_client = *(test_clients.penpal_client.clone());

let hello_world = HelloWorld::new(HELLO_WORLD_CONTRACT, ethereum_client.clone());
let contract_abi: Abi = hello_world.abi().clone();
let function = contract_abi.function("sayHello").unwrap();
let encoded_data =
function.encode_input(&[Token::String("Hello, Clara!".to_string())]).unwrap();

println!("data is {}", hex::encode(encoded_data.clone()));

let extrinsic_call = PenpalApi::transact_helper::calls::TransactionApi.transact_to_ethereum(
HELLO_WORLD_CONTRACT.into(),
encoded_data,
4_000_000_000,
80_000,
);

let owner: Pair = Pair::from_string("//Bob", None).expect("cannot create keypair");
let signer: PairSigner<PenpalConfig, _> = PairSigner::new(owner);

let _ = penpal_client
.tx()
.sign_and_submit_then_watch_default(&extrinsic_call, &signer)
.await
.expect("send through xcm call.");

wait_for_arbitrary_transact_event(&test_clients.ethereum_client, HELLO_WORLD_CONTRACT).await;
}

pub async fn wait_for_arbitrary_transact_event(
ethereum_client: &Box<Arc<Provider<Ws>>>,
contract_address: [u8; 20],
) {
let addr: Address = contract_address.into();
let contract = HelloWorld::new(addr, (*ethereum_client).deref().clone());

let wait_for_blocks = 300;
let mut stream = ethereum_client.subscribe_blocks().await.unwrap().take(wait_for_blocks);

let mut ethereum_event_found = false;
while let Some(block) = stream.next().await {
if let Ok(events) = contract
.event::<SaidHelloFilter>()
.at_block_hash(block.hash.unwrap())
.query()
.await
{
for _ in events {
println!("Event found at ethereum block {:?}", block.number.unwrap());
ethereum_event_found = true;
break
}
}
if ethereum_event_found {
break
}
}
assert!(ethereum_event_found);
}
4 changes: 3 additions & 1 deletion web/packages/test/scripts/set-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ assethub_ws_url="${ASSET_HUB_WS_URL:-ws://127.0.0.1:12144}"
assethub_seed="${ASSET_HUB_SEED:-//Alice}"
export ASSET_HUB_PARAID="${ASSET_HUB_PARAID:-1000}"
export ASSET_HUB_AGENT_ID="${ASSET_HUB_AGENT_ID:-0x81c5ab2571199e3188135178f3c2c8e2d268be1313d029b30f534fa579b69b79}"

export ASSET_HUB_CHANNEL_ID="0xc173fac324158e77fb5840738a1a541f633cbec8884c6a601c567d2b376a0539"

export PENPAL_AGENT_ID="5097ee1101e90c3aadb882858c59a22108668021ec81bce9f4930155e5c21e59"
export PENPAL_CHANNEL_ID="0xa69fbbae90bb6096d59b1930bbcfc8a3ef23959d226b1861deb7ad8fb06c6fa3"

export PRIMARY_GOVERNANCE_CHANNEL_ID="0x0000000000000000000000000000000000000000000000000000000000000001"
export SECONDARY_GOVERNANCE_CHANNEL_ID="0x0000000000000000000000000000000000000000000000000000000000000002"

Expand Down

0 comments on commit 89c9e3f

Please sign in to comment.