Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register token with inbound fixture #106

Merged
merged 7 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

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

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub mod accounts {
pub const CHARLIE: &str = "Charlie";
pub const DAVE: &str = "Dave";
pub const EVE: &str = "Eve";
pub const FERDIE: &str = "Ferdei";
pub const FERDIE: &str = "Ferdie";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! :)

pub const ALICE_STASH: &str = "Alice//stash";
pub const BOB_STASH: &str = "Bob//stash";
pub const CHARLIE_STASH: &str = "Charlie//stash";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ asset-hub-rococo-runtime = { path = "../../../../../runtimes/assets/asset-hub-ro
snowbridge-core = { path = "../../../../../../../../parachain/primitives/core", default-features = false }
snowbridge-router-primitives = { path = "../../../../../../../../parachain/primitives/router", default-features = false }
snowbridge-pallet-system = { path = "../../../../../../../../parachain/pallets/system", default-features = false }
snowbridge-pallet-inbound-queue = { path = "../../../../../../../../parachain/pallets/inbound-queue", default-features = false }
snowbridge-pallet-outbound-queue = { path = "../../../../../../../../parachain/pallets/outbound-queue", default-features = false }
snowbridge-pallet-inbound-queue = { path = "../../../../../../../../parachain/pallets/inbound-queue", default-features = false }
snowbridge-pallet-inbound-queue-fixtures = { path = "../../../../../../../../parachain/pallets/inbound-queue/fixtures" }
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use crate::*;
use bridge_hub_rococo_runtime::EthereumBeaconClient;
use codec::{Decode, Encode};
use emulated_integration_tests_common::xcm_emulator::ConvertLocation;
use frame_support::pallet_prelude::TypeInfo;
use hex_literal::hex;
use parachains_common::rococo::snowbridge::EthereumNetwork;
use rococo_westend_system_emulated_network::BridgeHubRococoParaSender as BridgeHubRococoSender;
use snowbridge_core::outbound::OperatingMode;
use snowbridge_pallet_inbound_queue_fixtures::{
register_token::make_register_token_message, send_token::make_send_token_message,
};
use snowbridge_pallet_system;
use snowbridge_router_primitives::inbound::{
Command, Destination, GlobalConsensusEthereumConvertsFor, MessageV1, VersionedMessage,
Expand Down Expand Up @@ -187,21 +192,26 @@ fn register_weth_token_from_ethereum_to_asset_hub() {
// Fund AssetHub sovereign account so that it can pay execution fees.
BridgeHubRococo::fund_para_sovereign(AssetHubRococo::para_id().into(), INITIAL_FUND);

let message_id: H256 = [1; 32].into();

BridgeHubRococo::execute_with(|| {
type RuntimeEvent = <BridgeHubRococo as Chain>::RuntimeEvent;
type RuntimeOrigin = <BridgeHubRococo as Chain>::RuntimeOrigin;
type EthereumInboundQueue =
<BridgeHubRococo as BridgeHubRococoPallet>::EthereumInboundQueue;
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE },
});
let (xcm, fee) = EthereumInboundQueue::do_convert(message_id, message).unwrap();

assert_ok!(EthereumInboundQueue::burn_fees(AssetHubRococo::para_id().into(), fee));
let register_asset_message = make_register_token_message();

let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubRococo::para_id().into()).unwrap();
EthereumBeaconClient::store_execution_header(
register_asset_message.message.proof.block_hash,
register_asset_message.execution_header,
0,
H256::default(),
);

EthereumInboundQueue::submit(
RuntimeOrigin::signed(BridgeHubRococoSender::get()),
register_asset_message.message,
)
.unwrap();
Comment on lines +203 to +214
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm I'm not sure this change is a good one. What do you think is the benefit of changing this? I feel like the previous way is clearer to read and understand what is happening, imo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To not expose the internal implementation details to the tests.
More context in Snowfork/snowbridge#1115 (comment)


assert_expected_events!(
BridgeHubRococo,
Expand Down Expand Up @@ -346,36 +356,42 @@ fn send_token_from_ethereum_to_asset_hub() {
// Fund ethereum sovereign on AssetHub
AssetHubRococo::fund_accounts(vec![(AssetHubRococoReceiver::get(), INITIAL_FUND)]);

let message_id: H256 = [1; 32].into();

BridgeHubRococo::execute_with(|| {
type RuntimeEvent = <BridgeHubRococo as Chain>::RuntimeEvent;
type RuntimeOrigin = <BridgeHubRococo as Chain>::RuntimeOrigin;
type EthereumInboundQueue =
<BridgeHubRococo as BridgeHubRococoPallet>::EthereumInboundQueue;
// Construct RegisterToken message
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE },
});
// Convert the message to XCM
let (xcm, _) = EthereumInboundQueue::do_convert(message_id, message).unwrap();
// Send the XCM
let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubRococo::para_id().into()).unwrap();

let register_asset_message = make_register_token_message();

EthereumBeaconClient::store_execution_header(
register_asset_message.message.proof.block_hash,
register_asset_message.execution_header,
0,
H256::default(),
);

EthereumInboundQueue::submit(
RuntimeOrigin::signed(BridgeHubRococoSender::get()),
register_asset_message.message,
)
.unwrap();

// Construct SendToken message
let message = VersionedMessage::V1(MessageV1 {
chain_id: CHAIN_ID,
command: Command::SendToken {
token: WETH.into(),
destination: Destination::AccountId32 { id: AssetHubRococoReceiver::get().into() },
amount: 1_000_000_000,
fee: XCM_FEE,
},
});
// Convert the message to XCM
let (xcm, _) = EthereumInboundQueue::do_convert(message_id, message).unwrap();
// Send the XCM
let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubRococo::para_id().into()).unwrap();
let send_token_message = make_send_token_message();

EthereumBeaconClient::store_execution_header(
send_token_message.message.proof.block_hash,
send_token_message.execution_header,
0,
H256::default(),
);

EthereumInboundQueue::submit(
RuntimeOrigin::signed(BridgeHubRococoSender::get()),
send_token_message.message,
)
.unwrap();

// Check that the message was sent
assert_expected_events!(
Expand Down Expand Up @@ -436,7 +452,8 @@ fn send_weth_asset_from_asset_hub_to_ethereum() {
command: Command::RegisterToken { token: WETH.into(), fee: XCM_FEE },
});
// Converts the versioned message to XCM
let (xcm, _) = EthereumInboundQueue::do_convert(message_id_register_token, message).unwrap();
let (xcm, _) =
EthereumInboundQueue::do_convert(message_id_register_token, message).unwrap();
let _ = EthereumInboundQueue::send_xcm(xcm, AssetHubRococo::para_id().into()).unwrap();

// Check that the register token message was sent using xcm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,6 @@ impl pallet_utility::Config for Runtime {
}

// Ethereum Bridge

#[cfg(not(feature = "runtime-benchmarks"))]
parameter_types! {
pub storage EthereumGatewayAddress: H160 = H160::zero();
}

#[cfg(feature = "runtime-benchmarks")]
parameter_types! {
pub storage EthereumGatewayAddress: H160 = H160(hex_literal::hex!("EDa338E4dC46038493b885327842fD3E301CaB39"));
}
Expand Down
Loading