Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
608 changes: 304 additions & 304 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,5 @@ std = [
"babe/std",
"babe-primitives/std",
"substrate-session/std",
"randomness-collective-flip/std",
]
24 changes: 11 additions & 13 deletions runtime/src/claims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ use serde::{self, Serialize, Deserialize, Serializer, Deserializer};
#[cfg(feature = "std")]
use sr_primitives::traits::Zero;
use sr_primitives::{
weights::SimpleDispatchInfo,
traits::ValidateUnsigned,
weights::SimpleDispatchInfo, traits::ValidateUnsigned,
transaction_validity::{
TransactionLongevity, TransactionValidity, ValidTransaction, InvalidTransaction
},
Expand Down Expand Up @@ -237,8 +236,7 @@ mod tests {
use hex_literal::hex;
use super::*;

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

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

#[test]
fn basic_setup_works() {
with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
assert_eq!(Claims::total(), 100);
assert_eq!(Claims::claims(&alice_eth()), Some(100));
assert_eq!(Claims::claims(&EthereumAddress::default()), None);
Expand All @@ -378,7 +376,7 @@ mod tests {

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

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

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

#[test]
fn non_sender_sig_doesnt_work() {
with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
assert_eq!(Balances::free_balance(&42), 0);
assert_noop!(Claims::claim(Origin::NONE, 42, alice_sig(&69u64.encode())), "Ethereum address has no claim");
});
}

#[test]
fn non_claimant_doesnt_work() {
with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
assert_eq!(Balances::free_balance(&42), 0);
assert_noop!(Claims::claim(Origin::NONE, 42, bob_sig(&69u64.encode())), "Ethereum address has no claim");
});
}

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

#[test]
fn validate_unsigned_works() {
with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
assert_eq!(
<Module<Test>>::validate_unsigned(&Call::claim(1, alice_sig(&1u64.encode()))),
Ok(ValidTransaction {
Expand Down
43 changes: 22 additions & 21 deletions runtime/src/crowdfund.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,8 @@ mod tests {

use std::{collections::HashMap, cell::RefCell};
use srml_support::{impl_outer_origin, assert_ok, assert_noop, parameter_types};
use sr_io::with_externalities;
use substrate_primitives::{H256, Blake2Hasher};
use primitives::parachain::Info as ParaInfo;
use substrate_primitives::H256;
use primitives::parachain::{Info as ParaInfo, Id as ParaId};
// The testing primitives are very useful for avoiding having to work with signatures
// or public keys. `u64` is used as the `AccountId` and no `Signature`s are requried.
use sr_primitives::{
Expand Down Expand Up @@ -639,6 +638,7 @@ mod tests {
type Parachains = TestParachains;
type LeasePeriod = LeasePeriod;
type EndingPeriod = EndingPeriod;
type Randomness = RandomnessCollectiveFlip;
}
parameter_types! {
pub const SubmissionDeposit: u64 = 1;
Expand All @@ -658,10 +658,11 @@ mod tests {
type Slots = slots::Module<Test>;
type Treasury = treasury::Module<Test>;
type Crowdfund = Module<Test>;
type RandomnessCollectiveFlip = randomness_collective_flip::Module<Test>;

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

#[test]
fn basic_setup_works() {
with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
assert_eq!(System::block_number(), 1);
assert_eq!(Crowdfund::fund_count(), 0);
assert_eq!(Crowdfund::funds(0), None);
Expand All @@ -701,7 +702,7 @@ mod tests {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#[test]
fn fund_across_multiple_auctions_works() {
with_externalities(&mut new_test_ext(), || {
new_test_ext().execute_with(|| {
// Create an auction
assert_ok!(Slots::new_auction(Origin::ROOT, 5, 1));
// Create two competing crowdfunds, with end dates across multiple auctions
Expand Down
4 changes: 3 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use version::NativeVersion;
use substrate_primitives::OpaqueMetadata;
use sr_staking_primitives::SessionIndex;
use srml_support::{
parameter_types, construct_runtime, traits::{SplitTwoWays, Currency}
parameter_types, construct_runtime, traits::{SplitTwoWays, Currency, Randomness}
};
use authority_discovery_primitives::{AuthorityId as EncodedAuthorityId, Signature as EncodedSignature};
use im_online::sr25519::AuthorityId as ImOnlineId;
Expand Down Expand Up @@ -480,6 +480,7 @@ impl parachains::Trait for Runtime {
type Origin = Origin;
type Call = Call;
type ParachainCurrency = Balances;
type Randomness = RandomnessCollectiveFlip;
type ActiveParachains = Registrar;
type Registrar = Registrar;
}
Expand Down Expand Up @@ -511,6 +512,7 @@ impl slots::Trait for Runtime {
type Parachains = Registrar;
type LeasePeriod = LeasePeriod;
type EndingPeriod = EndingPeriod;
type Randomness = RandomnessCollectiveFlip;
}

parameter_types!{
Expand Down
Loading