Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 05b1c16

Browse files
bkchrgavofyork
authored andcommitted
Update to latest Substrate master (#472)
* Update to latest Substrate master * Fix * Fix compilation
1 parent 2213e91 commit 05b1c16

File tree

8 files changed

+432
-412
lines changed

8 files changed

+432
-412
lines changed

Cargo.lock

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

runtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,5 @@ std = [
114114
"babe/std",
115115
"babe-primitives/std",
116116
"substrate-session/std",
117+
"randomness-collective-flip/std",
117118
]

runtime/src/claims.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ use serde::{self, Serialize, Deserialize, Serializer, Deserializer};
2727
#[cfg(feature = "std")]
2828
use sr_primitives::traits::Zero;
2929
use sr_primitives::{
30-
weights::SimpleDispatchInfo,
31-
traits::ValidateUnsigned,
30+
weights::SimpleDispatchInfo, traits::ValidateUnsigned,
3231
transaction_validity::{
3332
TransactionLongevity, TransactionValidity, ValidTransaction, InvalidTransaction
3433
},
@@ -237,8 +236,7 @@ mod tests {
237236
use hex_literal::hex;
238237
use super::*;
239238

240-
use sr_io::with_externalities;
241-
use substrate_primitives::{H256, Blake2Hasher};
239+
use substrate_primitives::H256;
242240
use codec::Encode;
243241
// The testing primitives are very useful for avoiding having to work with signatures
244242
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are required.
@@ -348,7 +346,7 @@ mod tests {
348346

349347
// This function basically just builds a genesis storage key/value store according to
350348
// our desired mockup.
351-
fn new_test_ext() -> sr_io::TestExternalities<Blake2Hasher> {
349+
fn new_test_ext() -> sr_io::TestExternalities {
352350
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
353351
// We use default for brevity, but you can configure as desired if needed.
354352
balances::GenesisConfig::<Test>::default().assimilate_storage(&mut t).unwrap();
@@ -360,7 +358,7 @@ mod tests {
360358

361359
#[test]
362360
fn basic_setup_works() {
363-
with_externalities(&mut new_test_ext(), || {
361+
new_test_ext().execute_with(|| {
364362
assert_eq!(Claims::total(), 100);
365363
assert_eq!(Claims::claims(&alice_eth()), Some(100));
366364
assert_eq!(Claims::claims(&EthereumAddress::default()), None);
@@ -378,7 +376,7 @@ mod tests {
378376

379377
#[test]
380378
fn claiming_works() {
381-
with_externalities(&mut new_test_ext(), || {
379+
new_test_ext().execute_with(|| {
382380
assert_eq!(Balances::free_balance(&42), 0);
383381
assert_ok!(Claims::claim(Origin::NONE, 42, alice_sig(&42u64.encode())));
384382
assert_eq!(Balances::free_balance(&42), 100);
@@ -387,7 +385,7 @@ mod tests {
387385

388386
#[test]
389387
fn origin_signed_claiming_fail() {
390-
with_externalities(&mut new_test_ext(), || {
388+
new_test_ext().execute_with(|| {
391389
assert_eq!(Balances::free_balance(&42), 0);
392390
assert_err!(
393391
Claims::claim(Origin::signed(42), 42, alice_sig(&42u64.encode())),
@@ -398,7 +396,7 @@ mod tests {
398396

399397
#[test]
400398
fn double_claiming_doesnt_work() {
401-
with_externalities(&mut new_test_ext(), || {
399+
new_test_ext().execute_with(|| {
402400
assert_eq!(Balances::free_balance(&42), 0);
403401
assert_ok!(Claims::claim(Origin::NONE, 42, alice_sig(&42u64.encode())));
404402
assert_noop!(Claims::claim(Origin::NONE, 42, alice_sig(&42u64.encode())), "Ethereum address has no claim");
@@ -407,23 +405,23 @@ mod tests {
407405

408406
#[test]
409407
fn non_sender_sig_doesnt_work() {
410-
with_externalities(&mut new_test_ext(), || {
408+
new_test_ext().execute_with(|| {
411409
assert_eq!(Balances::free_balance(&42), 0);
412410
assert_noop!(Claims::claim(Origin::NONE, 42, alice_sig(&69u64.encode())), "Ethereum address has no claim");
413411
});
414412
}
415413

416414
#[test]
417415
fn non_claimant_doesnt_work() {
418-
with_externalities(&mut new_test_ext(), || {
416+
new_test_ext().execute_with(|| {
419417
assert_eq!(Balances::free_balance(&42), 0);
420418
assert_noop!(Claims::claim(Origin::NONE, 42, bob_sig(&69u64.encode())), "Ethereum address has no claim");
421419
});
422420
}
423421

424422
#[test]
425423
fn real_eth_sig_works() {
426-
with_externalities(&mut new_test_ext(), || {
424+
new_test_ext().execute_with(|| {
427425
// "Pay RUSTs to the TEST account:2a00000000000000"
428426
let sig = hex!["444023e89b67e67c0562ed0305d252a5dd12b2af5ac51d6d3cb69a0b486bc4b3191401802dc29d26d586221f7256cd3329fe82174bdf659baea149a40e1c495d1c"];
429427
let sig = EcdsaSignature(sig);
@@ -435,7 +433,7 @@ mod tests {
435433

436434
#[test]
437435
fn validate_unsigned_works() {
438-
with_externalities(&mut new_test_ext(), || {
436+
new_test_ext().execute_with(|| {
439437
assert_eq!(
440438
<Module<Test>>::validate_unsigned(&Call::claim(1, alice_sig(&1u64.encode()))),
441439
Ok(ValidTransaction {

runtime/src/crowdfund.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,8 @@ mod tests {
502502

503503
use std::{collections::HashMap, cell::RefCell};
504504
use srml_support::{impl_outer_origin, assert_ok, assert_noop, parameter_types};
505-
use sr_io::with_externalities;
506-
use substrate_primitives::{H256, Blake2Hasher};
507-
use primitives::parachain::Info as ParaInfo;
505+
use substrate_primitives::H256;
506+
use primitives::parachain::{Info as ParaInfo, Id as ParaId};
508507
// The testing primitives are very useful for avoiding having to work with signatures
509508
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
510509
use sr_primitives::{
@@ -639,6 +638,7 @@ mod tests {
639638
type Parachains = TestParachains;
640639
type LeasePeriod = LeasePeriod;
641640
type EndingPeriod = EndingPeriod;
641+
type Randomness = RandomnessCollectiveFlip;
642642
}
643643
parameter_types! {
644644
pub const SubmissionDeposit: u64 = 1;
@@ -658,10 +658,11 @@ mod tests {
658658
type Slots = slots::Module<Test>;
659659
type Treasury = treasury::Module<Test>;
660660
type Crowdfund = Module<Test>;
661+
type RandomnessCollectiveFlip = randomness_collective_flip::Module<Test>;
661662

662663
// This function basically just builds a genesis storage key/value store according to
663664
// our desired mockup.
664-
fn new_test_ext() -> sr_io::TestExternalities<Blake2Hasher> {
665+
fn new_test_ext() -> sr_io::TestExternalities {
665666
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
666667
balances::GenesisConfig::<Test>{
667668
balances: vec![(1, 1000), (2, 2000), (3, 3000), (4, 4000)],
@@ -688,7 +689,7 @@ mod tests {
688689

689690
#[test]
690691
fn basic_setup_works() {
691-
with_externalities(&mut new_test_ext(), || {
692+
new_test_ext().execute_with(|| {
692693
assert_eq!(System::block_number(), 1);
693694
assert_eq!(Crowdfund::fund_count(), 0);
694695
assert_eq!(Crowdfund::funds(0), None);
@@ -701,7 +702,7 @@ mod tests {
701702

702703
#[test]
703704
fn create_works() {
704-
with_externalities(&mut new_test_ext(), || {
705+
new_test_ext().execute_with(|| {
705706
// Now try to create a crowdfund campaign
706707
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
707708
assert_eq!(Crowdfund::fund_count(), 1);
@@ -732,7 +733,7 @@ mod tests {
732733

733734
#[test]
734735
fn create_handles_basic_errors() {
735-
with_externalities(&mut new_test_ext(), || {
736+
new_test_ext().execute_with(|| {
736737
// Cannot create a crowdfund with bad slots
737738
assert_noop!(Crowdfund::create(Origin::signed(1), 1000, 4, 1, 9), "last slot must be greater than first slot");
738739
assert_noop!(Crowdfund::create(Origin::signed(1), 1000, 1, 5, 9), "last slot cannot be more then 3 more than first slot");
@@ -744,7 +745,7 @@ mod tests {
744745

745746
#[test]
746747
fn contribute_works() {
747-
with_externalities(&mut new_test_ext(), || {
748+
new_test_ext().execute_with(|| {
748749
// Set up a crowdfund
749750
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
750751
assert_eq!(Balances::free_balance(1), 999);
@@ -774,7 +775,7 @@ mod tests {
774775

775776
#[test]
776777
fn contribute_handles_basic_errors() {
777-
with_externalities(&mut new_test_ext(), || {
778+
new_test_ext().execute_with(|| {
778779
// Cannot contribute to non-existing fund
779780
assert_noop!(Crowdfund::contribute(Origin::signed(1), 0, 49), "invalid fund index");
780781
// Cannot contribute below minimum contribution
@@ -797,7 +798,7 @@ mod tests {
797798

798799
#[test]
799800
fn fix_deploy_data_works() {
800-
with_externalities(&mut new_test_ext(), || {
801+
new_test_ext().execute_with(|| {
801802
// Set up a crowdfund
802803
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
803804
assert_eq!(Balances::free_balance(1), 999);
@@ -819,7 +820,7 @@ mod tests {
819820

820821
#[test]
821822
fn fix_deploy_data_handles_basic_errors() {
822-
with_externalities(&mut new_test_ext(), || {
823+
new_test_ext().execute_with(|| {
823824
// Set up a crowdfund
824825
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
825826
assert_eq!(Balances::free_balance(1), 999);
@@ -862,7 +863,7 @@ mod tests {
862863

863864
#[test]
864865
fn onboard_works() {
865-
with_externalities(&mut new_test_ext(), || {
866+
new_test_ext().execute_with(|| {
866867
// Set up a crowdfund
867868
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
868869
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
@@ -897,7 +898,7 @@ mod tests {
897898

898899
#[test]
899900
fn onboard_handles_basic_errors() {
900-
with_externalities(&mut new_test_ext(), || {
901+
new_test_ext().execute_with(|| {
901902
// Set up a crowdfund
902903
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
903904
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
@@ -934,7 +935,7 @@ mod tests {
934935

935936
#[test]
936937
fn begin_retirement_works() {
937-
with_externalities(&mut new_test_ext(), || {
938+
new_test_ext().execute_with(|| {
938939
// Set up a crowdfund
939940
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
940941
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
@@ -976,7 +977,7 @@ mod tests {
976977

977978
#[test]
978979
fn begin_retirement_handles_basic_errors() {
979-
with_externalities(&mut new_test_ext(), || {
980+
new_test_ext().execute_with(|| {
980981
// Set up a crowdfund
981982
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
982983
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
@@ -1020,7 +1021,7 @@ mod tests {
10201021

10211022
#[test]
10221023
fn withdraw_works() {
1023-
with_externalities(&mut new_test_ext(), || {
1024+
new_test_ext().execute_with(|| {
10241025
// Set up a crowdfund
10251026
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
10261027
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
@@ -1046,7 +1047,7 @@ mod tests {
10461047

10471048
#[test]
10481049
fn withdraw_handles_basic_errors() {
1049-
with_externalities(&mut new_test_ext(), || {
1050+
new_test_ext().execute_with(|| {
10501051
// Set up a crowdfund
10511052
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
10521053
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
@@ -1070,7 +1071,7 @@ mod tests {
10701071

10711072
#[test]
10721073
fn dissolve_works() {
1073-
with_externalities(&mut new_test_ext(), || {
1074+
new_test_ext().execute_with(|| {
10741075
// Set up a crowdfund
10751076
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
10761077
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
@@ -1105,7 +1106,7 @@ mod tests {
11051106

11061107
#[test]
11071108
fn dissolve_handles_basic_errors() {
1108-
with_externalities(&mut new_test_ext(), || {
1109+
new_test_ext().execute_with(|| {
11091110
// Set up a crowdfund
11101111
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
11111112
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
@@ -1137,7 +1138,7 @@ mod tests {
11371138

11381139
#[test]
11391140
fn fund_before_auction_works() {
1140-
with_externalities(&mut new_test_ext(), || {
1141+
new_test_ext().execute_with(|| {
11411142
// Create a crowdfund before an auction is created
11421143
assert_ok!(Crowdfund::create(Origin::signed(1), 1000, 1, 4, 9));
11431144
// Users can already contribute
@@ -1175,7 +1176,7 @@ mod tests {
11751176

11761177
#[test]
11771178
fn fund_across_multiple_auctions_works() {
1178-
with_externalities(&mut new_test_ext(), || {
1179+
new_test_ext().execute_with(|| {
11791180
// Create an auction
11801181
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
11811182
// Create two competing crowdfunds, with end dates across multiple auctions

runtime/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use version::NativeVersion;
5454
use substrate_primitives::OpaqueMetadata;
5555
use sr_staking_primitives::SessionIndex;
5656
use srml_support::{
57-
parameter_types, construct_runtime, traits::{SplitTwoWays, Currency}
57+
parameter_types, construct_runtime, traits::{SplitTwoWays, Currency, Randomness}
5858
};
5959
use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
6060
use im_online::sr25519::AuthorityId as ImOnlineId;
@@ -480,6 +480,7 @@ impl parachains::Trait for Runtime {
480480
type Origin = Origin;
481481
type Call = Call;
482482
type ParachainCurrency = Balances;
483+
type Randomness = RandomnessCollectiveFlip;
483484
type ActiveParachains = Registrar;
484485
type Registrar = Registrar;
485486
}
@@ -511,6 +512,7 @@ impl slots::Trait for Runtime {
511512
type Parachains = Registrar;
512513
type LeasePeriod = LeasePeriod;
513514
type EndingPeriod = EndingPeriod;
515+
type Randomness = RandomnessCollectiveFlip;
514516
}
515517

516518
parameter_types!{

0 commit comments

Comments
 (0)