Skip to content

Commit

Permalink
Encode tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yrong committed Nov 4, 2024
1 parent 74d23af commit 6e32583
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
15 changes: 9 additions & 6 deletions bridges/snowbridge/pallets/outbound-queue-v2/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ impl Verifier for MockVerifier {
}

const GATEWAY_ADDRESS: [u8; 20] = hex!["eda338e4dc46038493b885327842fd3e301cab39"];
const WETH: [u8; 20] = hex!["C02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"];
const ASSET_HUB_AGENT: [u8; 32] =
hex!["81c5ab2571199e3188135178f3c2c8e2d268be1313d029b30f534fa579b69b79"];

parameter_types! {
pub const OwnParaId: ParaId = ParaId::new(1013);
Expand Down Expand Up @@ -186,13 +189,13 @@ where
pub fn mock_message(sibling_para_id: u32) -> Message {
Message {
origin: H256::from_low_u64_be(sibling_para_id as u64),
id: Default::default(),
fee: 0,
id: H256::from_low_u64_be(1),
fee: 1_000,
commands: BoundedVec::try_from(vec![Command::UnlockNativeToken {
agent_id: Default::default(),
token: Default::default(),
recipient: Default::default(),
amount: 0,
agent_id: H256(ASSET_HUB_AGENT),
token: H160(WETH),
recipient: H160(GATEWAY_ADDRESS),
amount: 1_000_000,
}])
.unwrap(),
}
Expand Down
23 changes: 22 additions & 1 deletion bridges/snowbridge/pallets/outbound-queue-v2/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use snowbridge_core::{
},
ChannelId, ParaId,
};
use sp_core::H256;
use sp_core::{hexdisplay::HexDisplay, H256};

#[test]
fn submit_messages_and_commit() {
Expand Down Expand Up @@ -247,3 +247,24 @@ fn encode_digest_item() {
);
});
}

#[test]
fn encode_mock_message() {
let message: Message = mock_message(1000);
let commands: Vec<CommandWrapper> = message
.commands
.into_iter()
.map(|command| CommandWrapper {
kind: command.index(),
gas: <Test as Config>::GasMeter::maximum_dispatch_gas_used_at_most(&command),
payload: command.abi_encode(),
})
.collect();

// Todo: print the abi-encoded message and try to decode with solidity test
let committed_message =
InboundMessage { origin: message.origin.0.to_vec(), nonce: 1, commands };
let message_abi_encoded = committed_message.abi_encode();
// print_hex(message_abi_encoded.as_slice());
println!("{}", HexDisplay::from(&message_abi_encoded));
}

0 comments on commit 6e32583

Please sign in to comment.