mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-31 01:41:03 +00:00
Squashed 'bridges/' changes from 23dda62482..407bf44a8a
407bf44a8a add missing license header (#1204) 9babb19810 Custom relay strategy (#1198) c287872a11 fix clippy things (#1200) 3a40e62789 Expose some const value and type (#1186) 32b61476d1 increase sleep before connectingMillau (#1195) aabe7041fa revert messages transactions mortality (#1194) 3651f4f909 Message transactions mortality (#1191) 364d6e155d Bump dependencies (#1180) f0389acc08 cargo +nightly fmt --all (#1192) b270b6a016 Unify error enums in substrate and ethereum clients with `thiserror` (#1094) 58c4946f74 Limit max call size of Rialto/Millau runtimes (#1187) fd56a8cd56 Add UI to the deployment (#1047) 16f01dc736 Westend -> Millau alerts are pending before notifications are sent (#1184) 5628c11ece replace collective flip with babe randomness in Rialto (#1188) 1094a63b00 ignore another (pretty bad) RUSTSEC (#1185) 379fe323ea fix/ignore cargo deny issues (#1183) 92af5e6e64 additional log in finality relay + rephrase "failed" (#1182) b996a3b681 Rialto parachain in test deployments (#1178) 28d9332b44 Resubmit transactions strategy for Polkadot/Kusama (#1175) d0172c6847 Playing with CI (#1179) fb6f42456d fix checks order when registering parachain (#1177) ee828c005a Register-parachain subcommand of substrate-relay (#1170) 8cd2b1a112 Token swap pallet benchmarks (#1174) bb811accb1 fix collision with westend bridge (#1172) 8d2fba70ed add token swaps to test deployments (#1169) b6d1bdfe2c publish rialto parachain collator image (#1171) 834ae4a10a Fix OutboundLaneData types (#1159) 5ee0ea1626 copypasted -> copied (#1168) c3bb835f18 fix spelling (#1167) f90d041dc9 Upgrade `jsonrpsee` to v0.3 (#1051) 598c9b6d0d add some basic tests for swap tokens (#1164) 05e88c61f5 publish images when tag of specific format(e.g. v2021-09-27 + v2021-09-27-1) is published (#1166) 7f3f94a6e0 Fix CI again (#1165) ff37de332f Move calculation relayer reward into `MessageDeliveryAndDispatchPayment` (#1153) 36fbba839b fix clippy warning (#1163) 16da44d018 explicit wasm build (#1158) c9c8226449 Match substrate's fmt (#1148) 2fdd7f3e5e Fix/ignore clippy warnings (#1157) 43dfcc2686 Adding LookupAddress (#1156) 951eaa5582 Add rialto-parachain runtime and node (#1142) 803d266d61 Rename MessageId -> BridgeMessageId (#1152) 5f234484fc Box large arguments of GRANDPA pallet (#1154) cf9abc1011 Fix spelling (#1150) ab83ba2e58 Relay subcommand that performs token RLT <> MLAU token swap (#1141) 832536caf0 Polkadot <> Kusama relayers (#1122) 6d0daa8975 Add `OnMessageAccepted` callback (#1134) 5d03a20b3e Integrate token swap pallet into Millau runtime (#1099) ea4cfa833e Adding MultiAddress type and ValidationCodeHash (#1139) c20325a784 Add tests for `Raw` and `BridgeSendMessage` enum `Call` variants (#1125) 6d802416e2 increase pause before pining Rialto nodes (#1137) b54fa56b62 calculate fee using full message payload (#1132) ca5d8178f5 Add parachain pallets to rialto runtime (#1053) 9eaae4142e fix transaction resubmitter limits for Millau -> Rialto transactions (#1135) 9d4e17783c add --mandatory-headers-only cli option to complex relay (#1129) 1c5e0ec1cb Add local CI info to README (#1131) a8e0929e14 chore: spellchecker fixes (#1130) 3b8e2118e3 set fee for importing mandatory headers to zero (#1127) 49bba9aa52 another bunch of words for spellchecker (#1128) 8a72eafef6 Increase pause before messages generation start (#1126) 1f0ba9a191 Move some associated types from relay_substrate_client::Chain to bp_runtime::Chain (#1087) 74bc1a5b54 Transactions resubmitter (#1083) 21ba001f26 log max balance drop when sending message (#1117) 638a7ddffa Code Cleaning (#1124) be6555c51b Fix buildah logout (#1120) 87539c4a98 Format code work (#1116) 526fe7fdd7 fix spelling (#1119) bd4ce7f241 Fix spelling (#1118) 3c1147858e added missing constants to Kusama/Polkadot primitives (#1114) 52093b22ab Fix delivery transaction estimation used by rational relayer (#1109) 77a2f2fbed Remove fund account checks from upgrade. (#1111) 824334802b Rename param and update comment (#1108) d7784bfe06 Fix spellcheck (#1110) 0b18f5906a Refactor substrate messages source and substrate messages target (#1105) b27240bbff fix compilation (#1107) 9697da4fe8 Emit mortal transactions from relay (#1073) b29396c077 Change vault vars type to env vars (#1084) 35e0bbdc0c Make clippy mandatory. (#1103) a517e8541f Remove unused deps (#1102) 873dae608a Remove unnessary deps (#1101) 13450b74ee Stored conversion rate updater (#1005) 74389829f3 [BREAKING] Migrate messages pallet to frame v2 (#1088) 424da938dd README fix (#1100) 865744c909 upgrade currency exchange pallet to frame v2 (#1097) b5038148b3 Add missing docs (#1095) 0791e911c1 Common crate for substrate-relay (#1082) 3834c9d880 Update high-level-overview.md (#1093) c93553face Increase the time window for messaging alerts. (#1092) 8b9cc3cecd migrate pallet-shift-session-manager to frame v2 (#1090) dc91813c22 migrate eth PoA pallet to frame v2 (#1091) f16bb098cc Migrate dispatch pallet to frame v2 (#1089) 19f4325348 Bridge/This Chain Ids should be exposed as constants on pallet level. (#1085) 6381122df7 Change ChainSpec::from_genesis for Rialto and Millau chains to reflect the chain names. (#1079) 0f1d33e973 Make CI happy again (#1086) 238e65d96f fix typo (#1080) fc008457b6 Token-swap-over-bridge pallet (#944) 3fb97fa5ef Fix full spellcheck (#1076) eae4ed7170 fixed wrong trace (#1075) 219a0fad04 merge two weight-related loops in messages pallet (#1071) fc85632fdb increase_message_fee depends on stored mesage size (#1066) 530f37a23b companion for https://github.com/paritytech/polkadot/pull/3507 (#1067) 53b8cba683 sc_basic_authorship=trace for millau nodes (#1074) 9874e05e98 Improve traces of message generator scripts (#1069) 7b5ee84fbb extract message_details impl into runtime common (#1070) 5a4aed5a8b refund weight for mot pruning messages (#1062) 90e3d1e111 Fix Westend -> Millau sync (#1064) 427d30ddfc When restarting client, also "restart" tokio runtime (#1065) d47c05eeef Change get pipeline sensitive variables from Vault instead of GitLab settings (#1063) d775a85415 use tokio reactor to execute jsonrpsee futures (#1061) 15c8cd61cb Use BABE to author blocks on Rialto (previously: Aura) (#1050) 5186293500 Allow reading suri && password override from file (#1059) b506298262 Update jsonrpsee reference (#1049) 1734d00517 enable weight fee adjustent in Rialto/Millau (#1044) 607265afae Pay dispatch fee at target chain cli option (#1043) ce79ef91be bump dependencies before start referencing polkadot repo (#1048) 924fa24f6d Cli option for greedy relayer + run no-losses relayer by default (#1042) e21eba7b59 Yrong README Fixup + M1 Fixes (#1045) 20d08204a2 Confirm delivery detects when more than expected messages are confirmed (#1039) 994b846b52 pre and post dispatch weights of OnDeliveryConfirmed callback (#1040) 1dd5297e84 give real value to Rialto and Millau tokens (#1038) 035bee8715 Use real conversion rate in greedy relayer strategy (#1035) 9cfaecd0f7 fixed metrics prefix (#1037) 1d8d224937 Use kebab-case for bridge arguments (#1036) f30a4c79a6 Shared reference to conversion rate metric value (#1034) c34d7a5cbb estimate transaction fee (#1015) 93404b18bb change alert period from 2m to 10m for Westend -> Millau (GRANDPA or public node itself is lagging sometimes) (#1032) git-subtree-dir: bridges git-subtree-split: 407bf44a8a5f4e60aceef2dc755cd9ff09929ac3
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
[package]
|
||||
name = "ethereum-contract-builtin"
|
||||
description = "Small crate that helps Solidity contract to verify finality proof."
|
||||
version = "0.1.0"
|
||||
authors = ["Parity Technologies <admin@parity.io>"]
|
||||
edition = "2018"
|
||||
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
|
||||
|
||||
[dependencies]
|
||||
codec = { package = "parity-scale-codec", version = "2.0.0" }
|
||||
ethereum-types = "0.11.0"
|
||||
finality-grandpa = "0.14.1"
|
||||
hex = "0.4"
|
||||
log = "0.4.14"
|
||||
|
||||
# Runtime/chain specific dependencies
|
||||
|
||||
rialto-runtime = { path = "../../bin/rialto/runtime" }
|
||||
|
||||
# Substrate Dependencies
|
||||
|
||||
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
|
||||
[dev-dependencies]
|
||||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "master" }
|
||||
@@ -1,374 +0,0 @@
|
||||
// Copyright 2019-2021 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Parity Bridges Common.
|
||||
|
||||
// Parity Bridges Common is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity Bridges Common is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity Bridges Common. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use codec::{Decode, Encode};
|
||||
use ethereum_types::U256;
|
||||
use finality_grandpa::voter_set::VoterSet;
|
||||
use rialto_runtime::{Block, BlockNumber, Hash, Header as RuntimeHeader};
|
||||
use sp_blockchain::Error as ClientError;
|
||||
use sp_finality_grandpa::{AuthorityList, ConsensusLog, GRANDPA_ENGINE_ID};
|
||||
|
||||
/// Builtin errors.
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// Failed to decode block number.
|
||||
BlockNumberDecode,
|
||||
/// Failed to decode Substrate header.
|
||||
HeaderDecode(codec::Error),
|
||||
/// Failed to decode best voters set.
|
||||
BestSetDecode(codec::Error),
|
||||
/// Best voters set is invalid.
|
||||
InvalidBestSet,
|
||||
/// Failed to decode finality proof.
|
||||
FinalityProofDecode(codec::Error),
|
||||
/// Failed to verify justification.
|
||||
JustificationVerify(Box<ClientError>),
|
||||
}
|
||||
|
||||
/// Substrate header.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct Header {
|
||||
/// Header hash.
|
||||
pub hash: Hash,
|
||||
/// Parent header hash.
|
||||
pub parent_hash: Hash,
|
||||
/// Header number.
|
||||
pub number: BlockNumber,
|
||||
/// GRANDPA validators change signal.
|
||||
pub signal: Option<ValidatorsSetSignal>,
|
||||
}
|
||||
|
||||
/// GRANDPA validators set change signal.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub struct ValidatorsSetSignal {
|
||||
/// Signal delay.
|
||||
pub delay: BlockNumber,
|
||||
/// New validators set.
|
||||
pub validators: Vec<u8>,
|
||||
}
|
||||
|
||||
/// Convert from U256 to BlockNumber. Fails if `U256` value isn't fitting within `BlockNumber`
|
||||
/// limits (the runtime referenced by this module uses u32 as `BlockNumber`).
|
||||
pub fn to_substrate_block_number(number: U256) -> Result<BlockNumber, Error> {
|
||||
let substrate_block_number = match number == number.low_u32().into() {
|
||||
true => Ok(number.low_u32()),
|
||||
false => Err(Error::BlockNumberDecode),
|
||||
};
|
||||
|
||||
log::trace!(
|
||||
target: "bridge-builtin",
|
||||
"Parsed Substrate block number from {}: {:?}",
|
||||
number,
|
||||
substrate_block_number,
|
||||
);
|
||||
|
||||
substrate_block_number
|
||||
}
|
||||
|
||||
/// Convert from BlockNumber to U256.
|
||||
pub fn from_substrate_block_number(number: BlockNumber) -> Result<U256, Error> {
|
||||
Ok(U256::from(number as u64))
|
||||
}
|
||||
|
||||
/// Parse Substrate header.
|
||||
pub fn parse_substrate_header(raw_header: &[u8]) -> Result<Header, Error> {
|
||||
let substrate_header = RuntimeHeader::decode(&mut &*raw_header)
|
||||
.map(|header| Header {
|
||||
hash: header.hash(),
|
||||
parent_hash: header.parent_hash,
|
||||
number: header.number,
|
||||
signal: sp_runtime::traits::Header::digest(&header)
|
||||
.log(|log| {
|
||||
log.as_consensus().and_then(|(engine_id, log)| {
|
||||
if engine_id == GRANDPA_ENGINE_ID {
|
||||
Some(log)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
})
|
||||
.and_then(|log| ConsensusLog::decode(&mut &*log).ok())
|
||||
.and_then(|log| match log {
|
||||
ConsensusLog::ScheduledChange(scheduled_change) => Some(ValidatorsSetSignal {
|
||||
delay: scheduled_change.delay,
|
||||
validators: scheduled_change.next_authorities.encode(),
|
||||
}),
|
||||
_ => None,
|
||||
}),
|
||||
})
|
||||
.map_err(Error::HeaderDecode);
|
||||
|
||||
log::debug!(
|
||||
target: "bridge-builtin",
|
||||
"Parsed Substrate header {}: {:?}",
|
||||
if substrate_header.is_ok() {
|
||||
format!("<{}-bytes-blob>", raw_header.len())
|
||||
} else {
|
||||
hex::encode(raw_header)
|
||||
},
|
||||
substrate_header,
|
||||
);
|
||||
|
||||
substrate_header
|
||||
}
|
||||
|
||||
/// Verify GRANDPA finality proof.
|
||||
pub fn verify_substrate_finality_proof(
|
||||
finality_target_number: BlockNumber,
|
||||
finality_target_hash: Hash,
|
||||
best_set_id: u64,
|
||||
raw_best_set: &[u8],
|
||||
raw_finality_proof: &[u8],
|
||||
) -> Result<(), Error> {
|
||||
let best_set = AuthorityList::decode(&mut &*raw_best_set)
|
||||
.map_err(Error::BestSetDecode)
|
||||
.and_then(|authorities| VoterSet::new(authorities.into_iter()).ok_or(Error::InvalidBestSet));
|
||||
|
||||
log::debug!(
|
||||
target: "bridge-builtin",
|
||||
"Parsed Substrate authorities set {}: {:?}",
|
||||
if best_set.is_ok() {
|
||||
format!("<{}-bytes-blob>", raw_best_set.len())
|
||||
} else {
|
||||
hex::encode(raw_best_set)
|
||||
},
|
||||
best_set,
|
||||
);
|
||||
|
||||
let best_set = best_set?;
|
||||
|
||||
let verify_result = sc_finality_grandpa::GrandpaJustification::<Block>::decode_and_verify_finalizes(
|
||||
raw_finality_proof,
|
||||
(finality_target_hash, finality_target_number),
|
||||
best_set_id,
|
||||
&best_set,
|
||||
)
|
||||
.map_err(Box::new)
|
||||
.map_err(Error::JustificationVerify)
|
||||
.map(|_| ());
|
||||
|
||||
log::debug!(
|
||||
target: "bridge-builtin",
|
||||
"Verified Substrate finality proof {}: {:?}",
|
||||
if verify_result.is_ok() {
|
||||
format!("<{}-bytes-blob>", raw_finality_proof.len())
|
||||
} else {
|
||||
hex::encode(raw_finality_proof)
|
||||
},
|
||||
verify_result,
|
||||
);
|
||||
|
||||
verify_result
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rialto_runtime::DigestItem;
|
||||
use sp_core::crypto::Public;
|
||||
use sp_finality_grandpa::{AuthorityId, ScheduledChange};
|
||||
use sp_runtime::generic::Digest;
|
||||
|
||||
#[test]
|
||||
fn to_substrate_block_number_succeeds() {
|
||||
assert_eq!(to_substrate_block_number(U256::zero()).unwrap(), 0);
|
||||
assert_eq!(
|
||||
to_substrate_block_number(U256::from(std::u32::MAX as u64)).unwrap(),
|
||||
0xFFFFFFFF
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_substrate_block_number_fails() {
|
||||
assert!(matches!(
|
||||
to_substrate_block_number(U256::from(std::u32::MAX as u64 + 1)),
|
||||
Err(Error::BlockNumberDecode)
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_substrate_block_number_succeeds() {
|
||||
assert_eq!(from_substrate_block_number(0).unwrap(), U256::zero());
|
||||
assert_eq!(
|
||||
from_substrate_block_number(std::u32::MAX).unwrap(),
|
||||
U256::from(std::u32::MAX)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substrate_header_without_signal_parsed() {
|
||||
let raw_header = RuntimeHeader {
|
||||
parent_hash: [0u8; 32].into(),
|
||||
number: 0,
|
||||
state_root: "b2fc47904df5e355c6ab476d89fbc0733aeddbe302f0b94ba4eea9283f7e89e7"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
extrinsics_root: "03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
digest: Default::default(),
|
||||
}
|
||||
.encode();
|
||||
assert_eq!(
|
||||
raw_header,
|
||||
hex::decode("000000000000000000000000000000000000000000000000000000000000000000b2fc47904df5e355c6ab476d89fbc0733aeddbe302f0b94ba4eea9283f7e89e703170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400").unwrap(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_substrate_header(&raw_header).unwrap(),
|
||||
Header {
|
||||
hash: "afbbeb92bf6ff14f60bdef0aa89f043dd403659ae82665238810ace0d761f6d0"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
parent_hash: Default::default(),
|
||||
number: 0,
|
||||
signal: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn substrate_header_with_signal_parsed() {
|
||||
let authorities = vec![
|
||||
(AuthorityId::from_slice(&[1; 32]), 101),
|
||||
(AuthorityId::from_slice(&[3; 32]), 103),
|
||||
];
|
||||
let mut digest = Digest::default();
|
||||
digest.push(DigestItem::Consensus(
|
||||
GRANDPA_ENGINE_ID,
|
||||
ConsensusLog::ScheduledChange(ScheduledChange {
|
||||
next_authorities: authorities.clone(),
|
||||
delay: 8,
|
||||
})
|
||||
.encode(),
|
||||
));
|
||||
|
||||
let raw_header = RuntimeHeader {
|
||||
parent_hash: "c0ac300d4005141ea690f3df593e049739c227316eb7f05052f3ee077388b68b"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
number: 8,
|
||||
state_root: "822d6b412033aa9ac8e1722918eec5f25633529225754b3d4149982f5cacd4aa"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
extrinsics_root: "e7b07c0ce2799416ce7877b9cefc7f596bea5e8813bb2a0abf760414073ca928"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
digest,
|
||||
}
|
||||
.encode();
|
||||
assert_eq!(
|
||||
raw_header,
|
||||
hex::decode("c0ac300d4005141ea690f3df593e049739c227316eb7f05052f3ee077388b68b20822d6b412033aa9ac8e1722918eec5f25633529225754b3d4149982f5cacd4aae7b07c0ce2799416ce7877b9cefc7f596bea5e8813bb2a0abf760414073ca928040446524e4b59010108010101010101010101010101010101010101010101010101010101010101010165000000000000000303030303030303030303030303030303030303030303030303030303030303670000000000000008000000").unwrap(),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
parse_substrate_header(&raw_header).unwrap(),
|
||||
Header {
|
||||
hash: "3dfebb280bd87a4640f89d7f2adecd62b88148747bff5b63af6e1634ee37a56e"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
parent_hash: "c0ac300d4005141ea690f3df593e049739c227316eb7f05052f3ee077388b68b"
|
||||
.parse()
|
||||
.unwrap(),
|
||||
number: 8,
|
||||
signal: Some(ValidatorsSetSignal {
|
||||
delay: 8,
|
||||
validators: authorities.encode(),
|
||||
}),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Number of the example block with justification.
|
||||
const EXAMPLE_JUSTIFIED_BLOCK_NUMBER: u32 = 8;
|
||||
/// Hash of the example block with justification.
|
||||
const EXAMPLE_JUSTIFIED_BLOCK_HASH: &str = "a2f45892db86b2ad133ce57d81b7e4375bb7035ce9883e6b68c358164f343775";
|
||||
/// Id of authorities set that have generated example justification. Could be computed by tracking
|
||||
/// every set change in canonized headers.
|
||||
const EXAMPLE_AUTHORITIES_SET_ID: u64 = 0;
|
||||
/// Encoded authorities set that has generated example justification. Could be fetched from `ScheduledChange`
|
||||
/// digest of the block that has scheduled this set OR by calling `GrandpaApi::grandpa_authorities()` at
|
||||
/// appropriate block.
|
||||
const EXAMPLE_AUTHORITIES_SET: &str = "1488dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0ee0100000000000000d17c2d7823ebf260fd138f2d7e27d114c0145d968b5ff5006125f2414fadae690100000000000000439660b36c6c03afafca027b910b4fecf99801834c62a5e6006f27d978de234f01000000000000005e639b43e0052c47447dac87d6fd2b6ec50bdd4d0f614e4299c665249bbd09d901000000000000001dfe3e22cc0d45c70779c1095f7489a8ef3cf52d62fbd8c2fa38c9f1723502b50100000000000000";
|
||||
/// Example justification. Could be fetched by calling 'chain_getBlock' RPC.
|
||||
const EXAMPLE_JUSTIFICATION: &str = "2600000000000000a2f45892db86b2ad133ce57d81b7e4375bb7035ce9883e6b68c358164f3437750800000010a2f45892db86b2ad133ce57d81b7e4375bb7035ce9883e6b68c358164f34377508000000d66b4ceb57ef8bcbc955071b597c8c5d2adcfdbb009c73f8438d342670fdeca9ac60686cbd58105b10f51d0a64a8e73b2e5829b2eab3248a008c472852130b00439660b36c6c03afafca027b910b4fecf99801834c62a5e6006f27d978de234fa2f45892db86b2ad133ce57d81b7e4375bb7035ce9883e6b68c358164f34377508000000f5730c14d3cd22b7661e2f5fcb3139dd5fef37f946314a441d01b40ce1200ef70d810525f23fd278b588cd67473c200bda83c338c407b479386aa83798e5970b5e639b43e0052c47447dac87d6fd2b6ec50bdd4d0f614e4299c665249bbd09d9a2f45892db86b2ad133ce57d81b7e4375bb7035ce9883e6b68c358164f34377508000000c78d6ec463f476461a695b4791d30e7626d16fdf72d7c252c2cad387495a97e8c2827ed4d5af853d6e05d31cb6fb7438c9481a7e9c6990d60a9bfaf6a6e1930988dc3417d5058ec4b4503e0c12ea1a0a89be200fe98922423d4334014fa6b0eea2f45892db86b2ad133ce57d81b7e4375bb7035ce9883e6b68c358164f3437750800000052b4fc52d430286b3e2d650aa6e01b6ff4fae8b968893a62be789209eb97ee6e23780d3f5af7042d85bb48f1b202890b22724dfebce138826f66a5e00324320fd17c2d7823ebf260fd138f2d7e27d114c0145d968b5ff5006125f2414fadae6900";
|
||||
|
||||
#[test]
|
||||
fn substrate_header_parse_fails() {
|
||||
assert!(matches!(parse_substrate_header(&[]), Err(_)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_substrate_finality_proof_succeeds() {
|
||||
verify_substrate_finality_proof(
|
||||
EXAMPLE_JUSTIFIED_BLOCK_NUMBER,
|
||||
EXAMPLE_JUSTIFIED_BLOCK_HASH.parse().unwrap(),
|
||||
EXAMPLE_AUTHORITIES_SET_ID,
|
||||
&hex::decode(EXAMPLE_AUTHORITIES_SET).unwrap(),
|
||||
&hex::decode(EXAMPLE_JUSTIFICATION).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_substrate_finality_proof_fails_when_wrong_block_is_finalized() {
|
||||
verify_substrate_finality_proof(
|
||||
4,
|
||||
Default::default(),
|
||||
EXAMPLE_AUTHORITIES_SET_ID,
|
||||
&hex::decode(EXAMPLE_AUTHORITIES_SET).unwrap(),
|
||||
&hex::decode(EXAMPLE_JUSTIFICATION).unwrap(),
|
||||
)
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_substrate_finality_proof_fails_when_wrong_set_is_provided() {
|
||||
verify_substrate_finality_proof(
|
||||
EXAMPLE_JUSTIFIED_BLOCK_NUMBER,
|
||||
EXAMPLE_JUSTIFIED_BLOCK_HASH.parse().unwrap(),
|
||||
EXAMPLE_AUTHORITIES_SET_ID,
|
||||
&hex::decode("deadbeef").unwrap(),
|
||||
&hex::decode(EXAMPLE_JUSTIFICATION).unwrap(),
|
||||
)
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_substrate_finality_proof_fails_when_wrong_set_id_is_provided() {
|
||||
verify_substrate_finality_proof(
|
||||
EXAMPLE_JUSTIFIED_BLOCK_NUMBER,
|
||||
EXAMPLE_JUSTIFIED_BLOCK_HASH.parse().unwrap(),
|
||||
42,
|
||||
&hex::decode(EXAMPLE_AUTHORITIES_SET).unwrap(),
|
||||
&hex::decode(EXAMPLE_JUSTIFICATION).unwrap(),
|
||||
)
|
||||
.unwrap_err();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verify_substrate_finality_proof_fails_when_wrong_proof_is_provided() {
|
||||
verify_substrate_finality_proof(
|
||||
EXAMPLE_JUSTIFIED_BLOCK_NUMBER,
|
||||
EXAMPLE_JUSTIFIED_BLOCK_HASH.parse().unwrap(),
|
||||
0,
|
||||
&hex::decode(EXAMPLE_AUTHORITIES_SET).unwrap(),
|
||||
&hex::decode("deadbeef").unwrap(),
|
||||
)
|
||||
.unwrap_err();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user