mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
move storage keys computation to primitivs (#1254)
This commit is contained in:
committed by
Bastian Köcher
parent
3aff81a707
commit
22b1e456ab
@@ -801,32 +801,6 @@ pub mod pallet {
|
||||
}
|
||||
}
|
||||
|
||||
/// Getting storage keys for messages and lanes states. These keys are normally used when building
|
||||
/// messages and lanes states proofs.
|
||||
pub mod storage_keys {
|
||||
use super::*;
|
||||
use sp_core::storage::StorageKey;
|
||||
|
||||
/// Storage key of the outbound message in the runtime storage.
|
||||
pub fn message_key(pallet_prefix: &str, lane: &LaneId, nonce: MessageNonce) -> StorageKey {
|
||||
bp_runtime::storage_map_final_key_blake2_128concat(
|
||||
pallet_prefix,
|
||||
"OutboundMessages",
|
||||
&MessageKey { lane_id: *lane, nonce }.encode(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Storage key of the outbound message lane state in the runtime storage.
|
||||
pub fn outbound_lane_data_key(pallet_prefix: &str, lane: &LaneId) -> StorageKey {
|
||||
bp_runtime::storage_map_final_key_blake2_128concat(pallet_prefix, "OutboundLanes", lane)
|
||||
}
|
||||
|
||||
/// Storage key of the inbound message lane state in the runtime storage.
|
||||
pub fn inbound_lane_data_key(pallet_prefix: &str, lane: &LaneId) -> StorageKey {
|
||||
bp_runtime::storage_map_final_key_blake2_128concat(pallet_prefix, "InboundLanes", lane)
|
||||
}
|
||||
}
|
||||
|
||||
/// AccountId of the shared relayer fund account.
|
||||
///
|
||||
/// This account is passed to `MessageDeliveryAndDispatchPayment` trait, and depending
|
||||
@@ -1159,9 +1133,8 @@ mod tests {
|
||||
REGULAR_PAYLOAD, TEST_LANE_ID, TEST_RELAYER_A, TEST_RELAYER_B,
|
||||
};
|
||||
use bp_messages::{UnrewardedRelayer, UnrewardedRelayersState};
|
||||
use frame_support::{assert_noop, assert_ok, weights::Weight};
|
||||
use frame_support::{assert_noop, assert_ok, storage::generator::StorageMap, weights::Weight};
|
||||
use frame_system::{EventRecord, Pallet as System, Phase};
|
||||
use hex_literal::hex;
|
||||
use sp_runtime::DispatchError;
|
||||
|
||||
fn get_ready_for_events() {
|
||||
@@ -1889,45 +1862,6 @@ mod tests {
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn storage_message_key_computed_properly() {
|
||||
// If this test fails, then something has been changed in module storage that is breaking
|
||||
// all previously crafted messages proofs.
|
||||
let storage_key = storage_keys::message_key("BridgeMessages", &*b"test", 42).0;
|
||||
assert_eq!(
|
||||
storage_key,
|
||||
hex!("dd16c784ebd3390a9bc0357c7511ed018a395e6242c6813b196ca31ed0547ea79446af0e09063bd4a7874aef8a997cec746573742a00000000000000").to_vec(),
|
||||
"Unexpected storage key: {}",
|
||||
hex::encode(&storage_key),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outbound_lane_data_key_computed_properly() {
|
||||
// If this test fails, then something has been changed in module storage that is breaking
|
||||
// all previously crafted outbound lane state proofs.
|
||||
let storage_key = storage_keys::outbound_lane_data_key("BridgeMessages", &*b"test").0;
|
||||
assert_eq!(
|
||||
storage_key,
|
||||
hex!("dd16c784ebd3390a9bc0357c7511ed0196c246acb9b55077390e3ca723a0ca1f44a8995dd50b6657a037a7839304535b74657374").to_vec(),
|
||||
"Unexpected storage key: {}",
|
||||
hex::encode(&storage_key),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inbound_lane_data_key_computed_properly() {
|
||||
// If this test fails, then something has been changed in module storage that is breaking
|
||||
// all previously crafted inbound lane state proofs.
|
||||
let storage_key = storage_keys::inbound_lane_data_key("BridgeMessages", &*b"test").0;
|
||||
assert_eq!(
|
||||
storage_key,
|
||||
hex!("dd16c784ebd3390a9bc0357c7511ed01e5f83cf83f2127eb47afdc35d6e43fab44a8995dd50b6657a037a7839304535b74657374").to_vec(),
|
||||
"Unexpected storage key: {}",
|
||||
hex::encode(&storage_key),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn actual_dispatch_weight_does_not_overlow() {
|
||||
run_test(|| {
|
||||
@@ -2359,4 +2293,25 @@ mod tests {
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn storage_keys_computed_properly() {
|
||||
assert_eq!(
|
||||
OutboundMessages::<TestRuntime>::storage_map_final_key(MessageKey {
|
||||
lane_id: TEST_LANE_ID,
|
||||
nonce: 42
|
||||
}),
|
||||
bp_messages::storage_keys::message_key("Messages", &TEST_LANE_ID, 42).0,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
OutboundLanes::<TestRuntime>::storage_map_final_key(TEST_LANE_ID),
|
||||
bp_messages::storage_keys::outbound_lane_data_key("Messages", &TEST_LANE_ID).0,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
InboundLanes::<TestRuntime>::storage_map_final_key(TEST_LANE_ID),
|
||||
bp_messages::storage_keys::inbound_lane_data_key("Messages", &TEST_LANE_ID).0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user