Skip to content
This repository was archived by the owner on Jul 4, 2022. It is now read-only.

Commit 636c2be

Browse files
committed
Pin ed25519-dalek to 1.0.0-pre.3 in support tests
Fix test build
1 parent f2b9b7c commit 636c2be

File tree

7 files changed

+49
-16
lines changed

7 files changed

+49
-16
lines changed

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frame/support/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,12 @@ pub enum Never {}
102102
///
103103
/// # Examples
104104
///
105-
/// ```
105+
/// ```no_compile
106106
/// # use frame_support::traits::Get;
107107
/// # use frame_support::parameter_types;
108108
/// // This function cannot be used in a const context.
109109
/// fn non_const_expression() -> u64 { 99 }
110110
///
111-
/// ```no_compile
112111
/// parameter_types! {
113112
/// pub const Argument: u64 = 42 + FIXED_VALUE;
114113
/// /// Visibility of the type is optional

frame/support/test/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ frame-support = { version = "2.0.0-alpha.5", default-features = false, path = ".
1717
sp-inherents = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/inherents" }
1818
sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/runtime" }
1919
sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/core" }
20-
trybuild = "1.0.17"
20+
trybuild = "1.0.24"
2121
pretty_assertions = "0.6.1"
22+
# pin ed25519-dalek to 1.0.0-pre.3
23+
# otherwise cargo will resolve 1.0.0-pre.4 which is breaking.
24+
ed25519-dalek = "=1.0.0-pre.3"
2225

2326
[features]
2427
default = ["std"]

frame/system/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ mod tests {
13801380
pub const MaximumBlockWeight: Weight = 1024;
13811381
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
13821382
pub const MaximumBlockLength: u32 = 1024;
1383-
pub const Version: RuntimeVersion = RuntimeVersion {
1383+
pub Version: RuntimeVersion = RuntimeVersion {
13841384
spec_name: sp_version::create_runtime_str!("test"),
13851385
impl_name: sp_version::create_runtime_str!("system-test"),
13861386
authoring_version: 1,

primitives/arithmetic/src/per_things.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,28 @@ macro_rules! implement_per_thing {
121121
///
122122
#[doc = $title]
123123
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
124-
#[derive(Encode, Decode, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug, CompactAs)]
124+
#[derive(Encode, Decode, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug)]
125125
pub struct $name($type);
126126

127+
/// Implementation makes any compact encoding of `PerThing::Inner` valid,
128+
/// when decoding it will saturate up to `PerThing::ACCURACY`.
129+
impl CompactAs for $name {
130+
type As = $type;
131+
fn encode_as(&self) -> &Self::As {
132+
&self.0
133+
}
134+
fn decode_from(x: Self::As) -> Self {
135+
// Saturates if `x` is more than `$max` internally.
136+
Self::from_parts(x)
137+
}
138+
}
139+
140+
impl From<codec::Compact<$name>> for $name {
141+
fn from(x: codec::Compact<$name>) -> $name {
142+
x.0
143+
}
144+
}
145+
127146
impl PerThing for $name {
128147
type Inner = $type;
129148
type Upper = $upper_type;
@@ -261,8 +280,8 @@ macro_rules! implement_per_thing {
261280
}
262281

263282
/// See [`PerThing::one`].
264-
pub fn one() -> Self {
265-
<Self as PerThing>::one()
283+
pub const fn one() -> Self {
284+
Self::from_parts($max)
266285
}
267286

268287
/// See [`PerThing::zero`].
@@ -714,6 +733,17 @@ macro_rules! implement_per_thing {
714733
);
715734
}
716735

736+
#[test]
737+
fn compact_decoding_saturate_when_beyond_accuracy() {
738+
use num_traits::Bounded;
739+
use codec::Compact;
740+
741+
let p = Compact::<$name>::decode(&mut &Compact(<$type>::max_value()).encode()[..])
742+
.unwrap();
743+
assert_eq!((p.0).0, $max);
744+
assert_eq!($name::from(p), $name::max_value());
745+
}
746+
717747
#[test]
718748
fn per_things_div_works() {
719749
// normal

primitives/phragmen/src/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,19 +496,19 @@ fn duplicate_target_is_ignored() {
496496
(30, 50, vec![1, 1, 2]),
497497
];
498498

499-
let ElectionResult { winners, assignments } = seq_phragmen::<_, Perbill>(
499+
let PhragmenResult { winners, assignments } = elect::<_, _, TestCurrencyToVote, Output>(
500500
2,
501501
2,
502502
candidates,
503503
voters,
504504
).unwrap();
505-
let winners = to_without_backing(winners);
505+
let (winners, _): (Vec<i32>, Vec<_>) = winners.into_iter().unzip();
506506

507507
assert_eq!(winners, vec![(2), (3)]);
508508
assert_eq!(
509509
assignments
510510
.into_iter()
511-
.map(|x| (x.who, x.distribution.into_iter().map(|(w, _)| w).collect::<Vec<_>>()))
511+
.map(|x| (x.0, x.1.into_iter().map(|(w, _)| w).collect::<Vec<_>>()))
512512
.collect::<Vec<_>>(),
513513
vec![
514514
(10, vec![2, 3]),
@@ -526,19 +526,19 @@ fn duplicate_target_is_ignored_when_winner() {
526526
(20, 100, vec![1, 2]),
527527
];
528528

529-
let ElectionResult { winners, assignments } = seq_phragmen::<_, Perbill>(
529+
let PhragmenResult { winners, assignments } = elect::<_, _, TestCurrencyToVote, Output>(
530530
2,
531531
2,
532532
candidates,
533533
voters,
534534
).unwrap();
535-
let winners = to_without_backing(winners);
535+
let (winners, _): (Vec<i32>, Vec<_>) = winners.into_iter().unzip();
536536

537537
assert_eq!(winners, vec![1, 2]);
538538
assert_eq!(
539539
assignments
540540
.into_iter()
541-
.map(|x| (x.who, x.distribution.into_iter().map(|(w, _)| w).collect::<Vec<_>>()))
541+
.map(|x| (x.0, x.1.into_iter().map(|(w, _)| w).collect::<Vec<_>>()))
542542
.collect::<Vec<_>>(),
543543
vec![
544544
(10, vec![1, 2]),

primitives/trie/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,12 +870,12 @@ mod tests {
870870
).unwrap();
871871

872872
let proof_db = proof.into_memory_db::<Blake2Hasher>();
873-
let first_storage_root = delta_trie_root::<Layout, _, _, _, _, _>(
873+
let first_storage_root = delta_trie_root::<Layout, _, _, _, _>(
874874
&mut proof_db.clone(),
875875
storage_root,
876876
valid_delta,
877877
).unwrap();
878-
let second_storage_root = delta_trie_root::<Layout, _, _, _, _, _>(
878+
let second_storage_root = delta_trie_root::<Layout, _, _, _, _>(
879879
&mut proof_db.clone(),
880880
storage_root,
881881
invalid_delta,

0 commit comments

Comments
 (0)