Skip to content

Commit 8995181

Browse files
authored
Merge pull request #29 from DataHighway-DHX/luke/fix-build-to-latest-substrate-master
test: Relates to #3. Fix unit and integration tests so they actually run (including with CI) and use latest Substrate master branch
2 parents 0c6fa79 + a34ebfc commit 8995181

File tree

30 files changed

+353
-184
lines changed

30 files changed

+353
-184
lines changed

.github/workflows/rust.yml

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ jobs:
2525

2626
- name: Initialize WASM build environment
2727
run: |
28-
rustup update nightly
2928
rustup update stable
30-
rustup target add wasm32-unknown-unknown --toolchain nightly
29+
rustup toolchain install nightly-2020-02-17
30+
rustup default nightly-2020-02-17
31+
rustup target add wasm32-unknown-unknown --toolchain nightly-2020-02-17
3132
3233
- name: Run cargo check
33-
uses: actions-rs/cargo@v1
34-
with:
35-
command: check
34+
run: cargo +nightly-2020-02-17 check
3635

3736
test:
3837
name: Test Suite
@@ -56,14 +55,44 @@ jobs:
5655

5756
- name: Initialize WASM build environment
5857
run: |
59-
rustup update nightly
6058
rustup update stable
61-
rustup target add wasm32-unknown-unknown --toolchain nightly
59+
rustup toolchain install nightly-2020-02-17
60+
rustup default nightly-2020-02-17
61+
rustup target add wasm32-unknown-unknown --toolchain nightly-2020-02-17
6262
63-
- name: Run cargo test
64-
uses: actions-rs/cargo@v1
65-
with:
66-
command: test
63+
# Runs integration tests in the runtime/tests folder
64+
- name: Run Integration Tests across all runtime modules
65+
run: |
66+
cargo +nightly-2020-02-17 test -p node-runtime
67+
68+
# Runs unit tests in each runtime module of the pallet folder
69+
- name: Run Unit Tests in each runtime module
70+
run: |
71+
cargo +nightly-2020-02-17 test -p roaming-operators &&
72+
cargo +nightly-2020-02-17 test -p roaming-networks &&
73+
cargo +nightly-2020-02-17 test -p roaming-organizations &&
74+
cargo +nightly-2020-02-17 test -p roaming-network-servers &&
75+
cargo +nightly-2020-02-17 test -p roaming-devices &&
76+
cargo +nightly-2020-02-17 test -p roaming-routing-profiles &&
77+
cargo +nightly-2020-02-17 test -p roaming-service-profiles &&
78+
cargo +nightly-2020-02-17 test -p roaming-accounting-policies &&
79+
cargo +nightly-2020-02-17 test -p roaming-agreement-policies &&
80+
cargo +nightly-2020-02-17 test -p roaming-network-profiles &&
81+
cargo +nightly-2020-02-17 test -p roaming-device-profiles &&
82+
cargo +nightly-2020-02-17 test -p roaming-sessions &&
83+
cargo +nightly-2020-02-17 test -p roaming-billing-policies &&
84+
cargo +nightly-2020-02-17 test -p roaming-charging-policies &&
85+
cargo +nightly-2020-02-17 test -p roaming-packet-bundles &&
86+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-configuration-token-mining &&
87+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-configuration-hardware-mining &&
88+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-rates-token-mining &&
89+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-rates-hardware-mining &&
90+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-sampling-token-mining &&
91+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-sampling-hardware-mining &&
92+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-eligibility-token-mining &&
93+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-eligibility-hardware-mining &&
94+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-claims-token-mining &&
95+
cargo +nightly-2020-02-17 test -p mining-speed-boosts-claims-hardware-mining
6796
6897
lints:
6998
name: Lints
@@ -88,19 +117,26 @@ jobs:
88117
override: true
89118
components: rustfmt, clippy
90119

120+
# nightly-2020-02-17-x86_64-unknown-linux-gnu
91121
- name: Initialize WASM build environment
92122
run: |
93-
rustup update nightly
94123
rustup update stable
95-
rustup target add wasm32-unknown-unknown --toolchain nightly
124+
rustup toolchain install nightly-2020-02-17
125+
rustup default nightly-2020-02-17
126+
rustup target add wasm32-unknown-unknown --toolchain nightly-2020-02-17
96127
97128
- name: Run cargo fmt
98-
run: cargo +nightly fmt --all -- --check
129+
run: |
130+
rustup component add rustfmt --toolchain nightly-2020-02-17-x86_64-unknown-linux-gnu
131+
cargo +nightly-2020-02-17 fmt --all -- --check
99132
100133
- name: Run cargo clippy
101134
# uses: actions-rs/cargo@v1
102135
# with:
103136
# command: clippy
104137
# args: --release -- -D warnings
105138
# FIXME - temporary fix below. See https://github.com/rust-lang/rust-clippy/issues/5094#issuecomment-579116431
106-
run: cargo +nightly clippy-preview -Zunstable-options
139+
run: |
140+
rustup component add clippy --toolchain nightly-2020-02-17-x86_64-unknown-linux-gnu
141+
rustup component add clippy-preview --toolchain nightly-2020-02-17-x86_64-unknown-linux-gnu
142+
cargo +nightly-2020-02-17 clippy-preview -Zunstable-options

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ __WARNING__: This implementation is a proof-of-concept prototype and is not read
1414
* [Run multiple node PoA testnet using custom blockchain configuration](#chapter-f21efd)
1515
* [Linting](#chapter-c345d7)
1616
* [Continuous integration](#chapter-27d8c5)
17+
* [FAQ](#chapter-a0dda5)
1718

1819
Note: Generate a new chapter with `openssl rand -hex 3`
1920

@@ -319,6 +320,13 @@ cargo test -p mining-speed-boosts-claims-hardware-mining
319320
cargo test -p node-runtime
320321
```
321322

323+
#### Specific Integration Tests
324+
325+
Example
326+
```
327+
cargo test -p node-runtime --test cli_integration_tests_mining_tokens
328+
```
329+
322330
### Check
323331

324332
```
@@ -452,7 +460,7 @@ rustup component add rustfmt --toolchain nightly
452460
Check that you agree with all the formating changes that RustFmt will apply to identify anything that you do not agree with.
453461

454462
```bash
455-
cargo fmt --all -- --check
463+
cargo +nightly fmt --all -- --check
456464
```
457465

458466
### Apply Formating Changes
@@ -472,3 +480,29 @@ Install an [EditorConfig Plugin](https://editorconfig.org/) for your code editor
472480
## Continuous integration<a id="chapter-27d8c5"></a>
473481

474482
* Reference: https://help.github.com/en/actions/configuring-and-managing-workflows/configuring-a-workflow
483+
484+
## FAQ<a id="chapter-a0dda5"></a>
485+
486+
* Question: Why do we need to install Rust Stable and Rust Nightly?
487+
* Answer: In .github/workflows/rust.yml, we need to run the following,
488+
because Substrate builds two binaries: 1) Wasm binary of your Runtime;
489+
and 2) Native executable containing all your other Substrate components
490+
including your runtimes too. The Wasm build requires rust nightly and
491+
wasm32-unknown-unknown to be installed. Note that we do not use
492+
`rustup update nightly` since the latest Rust Nightly may break our build,
493+
so we must manually change this to the latest Rust Nightly version only
494+
when it is known to work.
495+
```bash
496+
rustup toolchain install nightly-2020-02-17
497+
rustup update stable
498+
rustup target add wasm32-unknown-unknown --toolchain nightly
499+
```
500+
501+
* Question: Why do we install a specific version of Rust Nightly in the CI?
502+
* Answer: Since the latest version of Rust Nightly may break our build,
503+
and because developers may forget to update to the latest version of Rust
504+
Nightly locally. So the solution is to install a specific version of
505+
Rust Nightly in .github/workflows/rust.yml (i.e.
506+
`rustup toolchain install nightly-2020-02-17`), since for example
507+
the latest Rust Nightly version nightly-2020-02-20 may cause our CI tests
508+
to fail (i.e. https://github.com/DataHighway-DHX/node/issues/32)

pallets/mining/mining-speed-boosts/claims/hardware-mining/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ mod tests {
464464
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
465465
}
466466
impl system::Trait for Test {
467+
type AccountData = balances::AccountData<u64>;
467468
type AccountId = u64;
468469
type AvailableBlockRatio = AvailableBlockRatio;
469470
type BlockHashCount = BlockHashCount;
@@ -479,17 +480,20 @@ mod tests {
479480
type MaximumBlockLength = MaximumBlockLength;
480481
type MaximumBlockWeight = MaximumBlockWeight;
481482
type ModuleToIndex = ();
483+
type OnNewAccount = ();
484+
type OnReapAccount = ();
482485
type Origin = Origin;
483486
type Version = ();
484487
}
488+
parameter_types! {
489+
pub const ExistentialDeposit: u64 = 1;
490+
}
485491
impl balances::Trait for Test {
492+
type AccountStore = System;
486493
type Balance = u64;
487-
type CreationFee = ();
488494
type DustRemoval = ();
489495
type Event = ();
490-
type ExistentialDeposit = ();
491-
type OnNewAccount = ();
492-
type TransferPayment = ();
496+
type ExistentialDeposit = ExistentialDeposit;
493497
}
494498
impl transaction_payment::Trait for Test {
495499
type Currency = Balances;
@@ -552,7 +556,7 @@ mod tests {
552556
type MiningSpeedBoostClaimsHardwareMiningClaimDateRedeemed = u64;
553557
type MiningSpeedBoostClaimsHardwareMiningIndex = u64;
554558
}
555-
// type System = system::Module<Test>;
559+
type System = system::Module<Test>;
556560
type Balances = balances::Module<Test>;
557561
type MiningSpeedBoostClaimsHardwareMiningTestModule = Module<Test>;
558562
type Randomness = randomness_collective_flip::Module<Test>;
@@ -563,7 +567,6 @@ mod tests {
563567
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
564568
balances::GenesisConfig::<Test> {
565569
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
566-
vesting: vec![],
567570
}
568571
.assimilate_storage(&mut t)
569572
.unwrap();

pallets/mining/mining-speed-boosts/claims/token-mining/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ mod tests {
563563
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
564564
}
565565
impl system::Trait for Test {
566+
type AccountData = balances::AccountData<u64>;
566567
type AccountId = u64;
567568
type AvailableBlockRatio = AvailableBlockRatio;
568569
type BlockHashCount = BlockHashCount;
@@ -578,17 +579,20 @@ mod tests {
578579
type MaximumBlockLength = MaximumBlockLength;
579580
type MaximumBlockWeight = MaximumBlockWeight;
580581
type ModuleToIndex = ();
582+
type OnNewAccount = ();
583+
type OnReapAccount = ();
581584
type Origin = Origin;
582585
type Version = ();
583586
}
587+
parameter_types! {
588+
pub const ExistentialDeposit: u64 = 1;
589+
}
584590
impl balances::Trait for Test {
591+
type AccountStore = System;
585592
type Balance = u64;
586-
type CreationFee = ();
587593
type DustRemoval = ();
588594
type Event = ();
589-
type ExistentialDeposit = ();
590-
type OnNewAccount = ();
591-
type TransferPayment = ();
595+
type ExistentialDeposit = ExistentialDeposit;
592596
}
593597
impl transaction_payment::Trait for Test {
594598
type Currency = Balances;
@@ -651,7 +655,7 @@ mod tests {
651655
type MiningSpeedBoostClaimsTokenMiningClaimDateRedeemed = u64;
652656
type MiningSpeedBoostClaimsTokenMiningIndex = u64;
653657
}
654-
// type System = system::Module<Test>;
658+
type System = system::Module<Test>;
655659
type Balances = balances::Module<Test>;
656660
type MiningSpeedBoostClaimsTokenMiningTestModule = Module<Test>;
657661
type Randomness = randomness_collective_flip::Module<Test>;
@@ -662,7 +666,6 @@ mod tests {
662666
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
663667
balances::GenesisConfig::<Test> {
664668
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
665-
vesting: vec![],
666669
}
667670
.assimilate_storage(&mut t)
668671
.unwrap();

pallets/mining/mining-speed-boosts/configuration/hardware-mining/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ mod tests {
428428
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
429429
}
430430
impl system::Trait for Test {
431+
type AccountData = balances::AccountData<u64>;
431432
type AccountId = u64;
432433
type AvailableBlockRatio = AvailableBlockRatio;
433434
type BlockHashCount = BlockHashCount;
@@ -443,17 +444,20 @@ mod tests {
443444
type MaximumBlockLength = MaximumBlockLength;
444445
type MaximumBlockWeight = MaximumBlockWeight;
445446
type ModuleToIndex = ();
447+
type OnNewAccount = ();
448+
type OnReapAccount = ();
446449
type Origin = Origin;
447450
type Version = ();
448451
}
452+
parameter_types! {
453+
pub const ExistentialDeposit: u64 = 1;
454+
}
449455
impl balances::Trait for Test {
456+
type AccountStore = System;
450457
type Balance = u64;
451-
type CreationFee = ();
452458
type DustRemoval = ();
453459
type Event = ();
454-
type ExistentialDeposit = ();
455-
type OnNewAccount = ();
456-
type TransferPayment = ();
460+
type ExistentialDeposit = ExistentialDeposit;
457461
}
458462
impl transaction_payment::Trait for Test {
459463
type Currency = Balances;
@@ -484,7 +488,7 @@ mod tests {
484488
type MiningSpeedBoostConfigurationHardwareMiningHardwareType = Vec<u8>;
485489
type MiningSpeedBoostConfigurationHardwareMiningIndex = u64;
486490
}
487-
// type System = system::Module<Test>;
491+
type System = system::Module<Test>;
488492
type Balances = balances::Module<Test>;
489493
type MiningSpeedBoostConfigurationHardwareMiningTestModule = Module<Test>;
490494
type Randomness = randomness_collective_flip::Module<Test>;
@@ -495,7 +499,6 @@ mod tests {
495499
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
496500
balances::GenesisConfig::<Test> {
497501
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
498-
vesting: vec![],
499502
}
500503
.assimilate_storage(&mut t)
501504
.unwrap();

pallets/mining/mining-speed-boosts/configuration/token-mining/src/lib.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ mod tests {
491491
pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75);
492492
}
493493
impl system::Trait for Test {
494+
type AccountData = balances::AccountData<u64>;
494495
type AccountId = u64;
495496
type AvailableBlockRatio = AvailableBlockRatio;
496497
type BlockHashCount = BlockHashCount;
@@ -506,17 +507,20 @@ mod tests {
506507
type MaximumBlockLength = MaximumBlockLength;
507508
type MaximumBlockWeight = MaximumBlockWeight;
508509
type ModuleToIndex = ();
510+
type OnNewAccount = ();
511+
type OnReapAccount = ();
509512
type Origin = Origin;
510513
type Version = ();
511514
}
515+
parameter_types! {
516+
pub const ExistentialDeposit: u64 = 1;
517+
}
512518
impl balances::Trait for Test {
519+
type AccountStore = System;
513520
type Balance = u64;
514-
type CreationFee = ();
515521
type DustRemoval = ();
516522
type Event = ();
517-
type ExistentialDeposit = ();
518-
type OnNewAccount = ();
519-
type TransferPayment = ();
523+
type ExistentialDeposit = ExistentialDeposit;
520524
}
521525
impl transaction_payment::Trait for Test {
522526
type Currency = Balances;
@@ -545,7 +549,7 @@ mod tests {
545549
// FIXME - how to use this enum from std? (including importing `use std::str::FromStr;`)
546550
type MiningSpeedBoostConfigurationTokenMiningTokenType = Vec<u8>;
547551
}
548-
// type System = system::Module<Test>;
552+
type System = system::Module<Test>;
549553
type Balances = balances::Module<Test>;
550554
type MiningSpeedBoostConfigurationTokenMiningTestModule = Module<Test>;
551555
type Randomness = randomness_collective_flip::Module<Test>;
@@ -556,7 +560,6 @@ mod tests {
556560
let mut t = system::GenesisConfig::default().build_storage::<Test>().unwrap();
557561
balances::GenesisConfig::<Test> {
558562
balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)],
559-
vesting: vec![],
560563
}
561564
.assimilate_storage(&mut t)
562565
.unwrap();

0 commit comments

Comments
 (0)