Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
80f98b1
split off system randomness functions into a new module
Sep 26, 2019
b6dbab6
bump spec and impl version
Sep 27, 2019
5c59f76
Move randomness to bottom of construct_runtime calls, move initializa…
Sep 27, 2019
81d082f
Update srml/randomness/Cargo.toml
expenses Sep 27, 2019
fb41b38
Update srml/randomness/src/lib.rs
expenses Sep 27, 2019
6fafe55
Update srml/randomness/src/lib.rs
expenses Sep 27, 2019
8755b97
Update srml/randomness/Cargo.toml
expenses Sep 27, 2019
12158e3
Improve system example
expenses Sep 27, 2019
2bbc03a
Merge branch 'master' into randomness-module
expenses Sep 27, 2019
71bf01c
Merge branch 'randomness-module' of https://github.com/expenses/subst…
expenses Sep 27, 2019
394ad49
Update Cargo.lock
expenses Sep 27, 2019
664fc3c
Fix randomness example
expenses Sep 27, 2019
e3761d2
Get rid of the stored index
expenses Sep 27, 2019
907a29a
Add tests
expenses Sep 27, 2019
d98c7db
Add a random test
expenses Sep 27, 2019
64e3c22
Merge branch 'master' into randomness-module
expenses Sep 29, 2019
908d00f
Improve docs
expenses Sep 29, 2019
15011d1
Merge branch 'randomness-module' of https://github.com/expenses/subst…
expenses Sep 29, 2019
fb96026
Fix executive test :^)
expenses Sep 29, 2019
bc15acc
Add a utility function to tests
expenses Sep 29, 2019
f7e4d4d
Update srml/randomness/Cargo.toml
expenses Oct 1, 2019
8c8f70b
Update srml/randomness/src/lib.rs
expenses Oct 1, 2019
b71e627
Update srml/randomness/src/lib.rs
expenses Oct 2, 2019
44a3cc1
Merge branch 'master' into randomness-module
expenses Oct 2, 2019
d491ac8
Change interpretation of block numbers
expenses Oct 2, 2019
23b29af
Merge branch 'master' into randomness-module
expenses Oct 6, 2019
bb84094
rename crate
expenses Oct 7, 2019
3a28382
Merge branch 'randomness-module' of https://github.com/expenses/subst…
expenses Oct 7, 2019
742b3db
refactor randomess module usage
expenses Oct 7, 2019
8388726
Merge branch 'master' of https://github.com/paritytech/substrate into…
expenses Oct 7, 2019
b5cd993
change random material len to a const
expenses Oct 8, 2019
0db8a8b
Update srml/randomness-collective-flip/src/lib.rs
expenses Oct 8, 2019
6a88d62
Update srml/randomness-collective-flip/src/lib.rs
expenses Oct 8, 2019
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
Prev Previous commit
Next Next commit
Add a utility function to tests
  • Loading branch information
expenses committed Sep 29, 2019
commit bc15acc865c2994bcd3d33f0ee5c11e4dd5bc76d
52 changes: 17 additions & 35 deletions srml/randomness/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,25 @@ mod tests {
}
}

fn setup_blocks(blocks: u64) {
let mut parent_hash = System::parent_hash();

for i in 2 .. (blocks + 2) {
System::initialize(&i, &parent_hash, &Default::default(), &Default::default());
Randomness::on_initialize(i);

let header = System::finalize();
parent_hash = header.hash();
System::set_block_number(*header.number());
}
}

#[test]
fn test_random_material_parital() {
with_externalities(&mut new_test_ext(), || {
let genesis_hash = System::parent_hash();
let mut parent_hash = genesis_hash;

for i in 2..40 {
System::initialize(&i, &parent_hash, &Default::default(), &Default::default());
Randomness::on_initialize(i);

let header = System::finalize();
parent_hash = header.hash();
}
setup_blocks(38);

let random_material = Randomness::random_material();

Expand All @@ -236,15 +242,8 @@ mod tests {
fn test_random_material_filled() {
with_externalities(&mut new_test_ext(), || {
let genesis_hash = System::parent_hash();
let mut parent_hash = genesis_hash;

for i in 2..83 {
System::initialize(&i, &parent_hash, &Default::default(), &Default::default());
Randomness::on_initialize(i);

let header = System::finalize();
parent_hash = header.hash();
}
setup_blocks(81);

let random_material = Randomness::random_material();

Expand All @@ -258,15 +257,8 @@ mod tests {
fn test_random_material_filled_twice() {
with_externalities(&mut new_test_ext(), || {
let genesis_hash = System::parent_hash();
let mut parent_hash = genesis_hash;

for i in 2..164 {
System::initialize(&i, &parent_hash, &Default::default(), &Default::default());
Randomness::on_initialize(i);

let header = System::finalize();
parent_hash = header.hash();
}
setup_blocks(162);

let random_material = Randomness::random_material();

Expand All @@ -279,17 +271,7 @@ mod tests {
#[test]
fn test_random() {
with_externalities(&mut new_test_ext(), || {
let mut parent_hash = System::parent_hash();

for i in 2..164 {
System::initialize(&i, &parent_hash, &Default::default(), &Default::default());
Randomness::on_initialize(i);

let header = System::finalize();
parent_hash = header.hash();
// Why is this needed?
System::set_block_number(*header.number());
}
setup_blocks(162);

assert_eq!(System::block_number(), 163);
assert_eq!(Randomness::random_seed(), Randomness::random_seed());
Expand Down