Skip to content

Commit

Permalink
add-endowment-in-bifrost-test-chainspec (#284)
Browse files Browse the repository at this point in the history
* add-endowment-in-bifrost-test-chainspec

* remove faucet_accounts

* remove unsupported tokens

Co-authored-by: Edwin Wang <lark930@gmail.com>
  • Loading branch information
herryho and ark930 committed Sep 11, 2021
1 parent c448a6a commit 9076bfe
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 23 deletions.
90 changes: 68 additions & 22 deletions node/service/src/chain_spec/bifrost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ use bifrost_runtime::{
constants::currency::DOLLARS, AccountId, AuraId, Balance, BalancesConfig, BancorConfig,
BlockNumber, CollatorSelectionConfig, CouncilConfig, DemocracyConfig, GenesisConfig,
IndicesConfig, ParachainInfoConfig, SessionConfig, SudoConfig, SystemConfig,
TechnicalCommitteeConfig, VestingConfig, WASM_BINARY,
TechnicalCommitteeConfig, TokensConfig, VestingConfig, WASM_BINARY,
};
use cumulus_primitives_core::ParaId;
use frame_benchmarking::{account, whitelisted_caller};
use hex_literal::hex;
use node_primitives::{CurrencyId, TokenSymbol};
use sc_service::ChainType;
Expand All @@ -45,12 +46,15 @@ const DEFAULT_PROTOCOL_ID: &str = "bifrost";
/// Specialized `ChainSpec` for the bifrost runtime.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig, RelayExtensions>;

const ENDOWMENT: u128 = 1_000_000 * DOLLARS;

pub fn bifrost_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
root_key: AccountId,
balances: Vec<(AccountId, Balance)>,
vestings: Vec<(AccountId, BlockNumber, BlockNumber, Balance)>,
id: ParaId,
tokens: Vec<(AccountId, CurrencyId, Balance)>,
) -> GenesisConfig {
GenesisConfig {
system: SystemConfig {
Expand Down Expand Up @@ -93,33 +97,44 @@ pub fn bifrost_genesis(
aura_ext: Default::default(),
parachain_system: Default::default(),
vesting: VestingConfig { vesting: vestings },
tokens: TokensConfig { balances: tokens },
bancor: BancorConfig {
bancor_pools: vec![
(CurrencyId::Token(TokenSymbol::DOT), 10_000 * DOLLARS),
(CurrencyId::Token(TokenSymbol::KSM), 1_000_000 * DOLLARS),
],
bancor_pools: vec![(CurrencyId::Token(TokenSymbol::KSM), 1_000_000 * DOLLARS)],
},
}
}

fn development_config_genesis(id: ParaId) -> GenesisConfig {
let endowed_accounts: Vec<AccountId> =
vec![get_account_id_from_seed::<sr25519::Public>("Alice")];
const ENDOWMENT: u128 = 1_000_000 * DOLLARS;
let endowed_accounts = vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
whitelisted_caller(), // Benchmarking whitelist_account
];
let balances = endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect();
let vestings = endowed_accounts
.iter()
.cloned()
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT / 4))
.collect();
let tokens = endowed_accounts
.iter()
.flat_map(|x| {
vec![
(x.clone(), CurrencyId::Stable(TokenSymbol::KUSD), ENDOWMENT * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT),
]
})
.collect();

bifrost_genesis(
vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_from_seed::<AuraId>("Alice"),
)],
get_account_id_from_seed::<sr25519::Public>("Alice"),
endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(),
endowed_accounts
.iter()
.cloned()
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT / 4))
.collect(),
balances,
vestings,
id,
tokens,
)
}

Expand All @@ -138,11 +153,44 @@ pub fn development_config(id: ParaId) -> Result<ChainSpec, String> {
}

fn local_config_genesis(id: ParaId) -> GenesisConfig {
let endowed_accounts: Vec<AccountId> = vec![
let endowed_accounts = vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
whitelisted_caller(), // Benchmarking whitelist_account
account("bechmarking_account_1", 0, 0), /* Benchmarking account_1, used for interacting
* with whitelistted_caller */
];
const ENDOWMENT: u128 = 1_000_000 * DOLLARS;
let balances = endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect();
let vestings = endowed_accounts
.iter()
.cloned()
.map(|x| (x.clone(), 0u32, 100u32, ENDOWMENT / 4))
.collect();
let tokens = endowed_accounts
.iter()
.flat_map(|x| {
vec![
(x.clone(), CurrencyId::Stable(TokenSymbol::KUSD), ENDOWMENT * 10_000),
(x.clone(), CurrencyId::Token(TokenSymbol::KSM), ENDOWMENT * 4_000_000),
(x.clone(), CurrencyId::Token(TokenSymbol::BNC), ENDOWMENT * 4_000_000),
(
x.clone(),
CurrencyId::VSBond(TokenSymbol::KSM, 3000, 13, 20),
ENDOWMENT * 4_000_000,
),
]
})
.collect();

bifrost_genesis(
vec![
Expand All @@ -153,13 +201,10 @@ fn local_config_genesis(id: ParaId) -> GenesisConfig {
(get_account_id_from_seed::<sr25519::Public>("Bob"), get_from_seed::<AuraId>("Bob")),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
endowed_accounts.iter().cloned().map(|x| (x, ENDOWMENT)).collect(),
endowed_accounts
.iter()
.cloned()
.map(|x| (x, 0u32, 100u32, ENDOWMENT / 4))
.collect(),
balances,
vestings,
id,
tokens,
)
}

Expand Down Expand Up @@ -272,6 +317,7 @@ fn bifrost_config_genesis(id: ParaId) -> GenesisConfig {
balances,
vesting_configs.into_iter().flat_map(|vc| vc.vesting).collect(),
id,
vec![],
)
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/bifrost/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ construct_runtime! {
Tips: pallet_tips::{Pallet, Call, Storage, Event<T>} = 63,

XTokens: orml_xtokens::{Pallet, Call, Event<T>} = 70,
Tokens: orml_tokens::{Pallet, Call, Storage, Event<T>} = 71,
Tokens: orml_tokens::{Pallet, Call, Storage, Event<T>, Config<T>} = 71,
Currencies: orml_currencies::{Pallet, Call, Event<T>} = 72,
UnknownTokens: orml_unknown_tokens::{Pallet, Storage, Event} = 73,
OrmlXcm: orml_xcm::{Pallet, Call, Event<T>} = 74,
Expand Down

0 comments on commit 9076bfe

Please sign in to comment.