Skip to content

Commit

Permalink
Add TestSource for testing blueprints (#746)
Browse files Browse the repository at this point in the history
* Add TestFetcher

* Add TestFetcher

* fmt

* update metadata
  • Loading branch information
tbraun96 authored Aug 27, 2024
1 parent 8771f1e commit eadd577
Show file tree
Hide file tree
Showing 50 changed files with 357 additions and 309 deletions.
6 changes: 2 additions & 4 deletions node/src/chainspec/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@ use parity_scale_codec::alloc::collections::BTreeMap;
use sc_consensus_grandpa::AuthorityId as GrandpaId;
use sc_service::ChainType;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::H160;
use sp_core::{sr25519, Pair, Public};
use sp_core::{sr25519, Pair, Public, H160};
use sp_runtime::{
traits::{AccountIdConversion, IdentifyAccount, Verify},
BoundedVec,
};
use tangle_primitives::types::{BlockNumber, Signature};
use tangle_runtime::EVMConfig;
use tangle_runtime::{
AccountId, BabeConfig, Balance, BalancesConfig, ClaimsConfig, CouncilConfig, EVMChainIdConfig,
ImOnlineConfig, MaxVestingSchedules, Perbill, RuntimeGenesisConfig, SessionConfig,
EVMConfig, ImOnlineConfig, MaxVestingSchedules, Perbill, RuntimeGenesisConfig, SessionConfig,
StakerStatus, StakingConfig, SudoConfig, SystemConfig, TreasuryPalletId, VestingConfig, UNIT,
WASM_BINARY,
};
Expand Down
13 changes: 7 additions & 6 deletions node/src/chainspec/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,22 @@

#![allow(clippy::type_complexity)]

use crate::distributions::{
combine_distributions, get_unique_distribution_results,
mainnet::{self, DistributionResult},
use crate::{
distributions::{
combine_distributions, get_unique_distribution_results,
mainnet::{self, DistributionResult},
},
testnet_fixtures::{get_bootnodes, get_initial_authorities, get_testnet_root_key},
};
use crate::testnet_fixtures::{get_bootnodes, get_initial_authorities, get_testnet_root_key};
use hex_literal::hex;
use pallet_airdrop_claims::MultiAddress;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use sc_consensus_grandpa::AuthorityId as GrandpaId;
use sc_service::ChainType;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_core::{ed25519, sr25519, Pair, Public, H160, U256};
use sp_runtime::traits::AccountIdConversion;
use sp_runtime::{
traits::{IdentifyAccount, Verify},
traits::{AccountIdConversion, IdentifyAccount, Verify},
BoundedVec,
};
use std::{collections::BTreeMap, str::FromStr};
Expand Down
10 changes: 6 additions & 4 deletions node/src/distributions/mainnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ fn read_investor_accounts_to_multiaddress(path_str: &str) -> BTreeMap<MultiAddre
// EDG Genesis Airdrop : 1% (5% immediate release)(95% vested over two years, with one month cliff)
// EDG Snapshot Airdrop : 1% (5% immediate release)(95% vested over two years, with one month cliff)
// Leaderboard airdrop : 2% (5% immediate release)(95% vested over two years, with one month cliff)
// Polkadot validator airdrop : 1% (5% immediate release)(95% vested over two years, with one month cliff)
// ***
// Polkadot validator airdrop : 1% (5% immediate release)(95% vested over two years, with one month
// cliff) ***

pub fn get_edgeware_genesis_list() -> Vec<H160> {
read_contents_to_evm_accounts("node/src/distributions/data/edgeware_genesis_participants.json")
Expand Down Expand Up @@ -377,7 +377,8 @@ pub fn get_distribution_for(
let remaining_fraction = 1.0 - cliff_fraction;

// the entire value is claimable here
// the claims pallet will lock all the vesting balance so in effect only claimable-amount is usable
// the claims pallet will lock all the vesting balance so in effect only claimable-amount is
// usable
claims.push((address.clone(), value, statement_kind));
let amount_on_cliff = (vested_amount as f64 * cliff_fraction) as u128;
let amount_after_cliff = (vested_amount as f64 * remaining_fraction) as u128;
Expand Down Expand Up @@ -660,7 +661,8 @@ fn test_distribution_shares() {
.map(|(_, amount, _, _, _)| amount)
.sum();

//println!("Remaining total team amount {:?}", 30000000000000000000000000 - total_team_claims_amount - total_direct_team_amount - 5000 * UNIT);
//println!("Remaining total team amount {:?}", 30000000000000000000000000 -
// total_team_claims_amount - total_direct_team_amount - 5000 * UNIT);
assert_eq!(total_team_claims_amount, 29856849309999998760386560); // 29856849 TNT
assert_eq!(
Perbill::from_rational(total_team_claims_amount, TOTAL_SUPPLY),
Expand Down
6 changes: 2 additions & 4 deletions pallets/claims/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use super::*;
use crate::{Call, Config, Pallet as ClaimsPallet};
use frame_benchmarking::{account, benchmarks};
use frame_support::traits::UnfilteredDispatchable;
use frame_support::BoundedVec;
use frame_system::pallet_prelude::*;
use frame_system::RawOrigin;
use frame_support::{traits::UnfilteredDispatchable, BoundedVec};
use frame_system::{pallet_prelude::*, RawOrigin};
use secp_utils::*;
use sp_runtime::{traits::ValidateUnsigned, AccountId32, DispatchResult};

Expand Down
3 changes: 1 addition & 2 deletions pallets/claims/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ use frame_support::pallet_prelude::DispatchError;
use hex_literal::hex;
use parity_scale_codec::Encode;
use secp_utils::*;
use sp_core::ConstU32;
use sp_core::Pair;
use sp_core::{ConstU32, Pair};
use sp_runtime::{BoundedVec, TokenError::Frozen};

// The testing primitives are very useful for avoiding having to work with signatures
Expand Down
16 changes: 7 additions & 9 deletions pallets/multi-asset-delegation/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Tangle. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use crate::types::*;
use crate::Pallet as MultiAssetDelegation;
use crate::{types::*, Pallet as MultiAssetDelegation};
use frame_benchmarking::{account, benchmarks, whitelisted_caller};
use frame_support::ensure;
use frame_support::pallet_prelude::DispatchResult;
use frame_support::traits::Currency;
use frame_support::traits::Get;
use frame_support::traits::ReservableCurrency;
use frame_support::{
ensure,
pallet_prelude::DispatchResult,
traits::{Currency, Get, ReservableCurrency},
};
use frame_system::RawOrigin;
use sp_runtime::traits::Zero;
use sp_runtime::DispatchError;
use sp_runtime::{traits::Zero, DispatchError};

const SEED: u32 = 0;

Expand Down
16 changes: 8 additions & 8 deletions pallets/multi-asset-delegation/src/functions/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Tangle. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use crate::types::*;
use crate::Pallet;
use frame_support::ensure;
use frame_support::pallet_prelude::DispatchResult;
use frame_support::traits::Get;
use crate::{types::*, Pallet};
use frame_support::{ensure, pallet_prelude::DispatchResult, traits::Get};
use sp_runtime::traits::Zero;
use sp_std::vec::Vec;

Expand Down Expand Up @@ -193,7 +190,8 @@ impl<T: Config> Pallet<T> {
///
/// # Errors
///
/// Returns an error if the delegator has no unstake requests or if none of the unstake requests are ready.
/// Returns an error if the delegator has no unstake requests or if none of the unstake requests
/// are ready.
pub fn process_execute_delegator_unstake(who: T::AccountId) -> DispatchResult {
Delegators::<T>::try_mutate(&who, |maybe_metadata| {
let metadata = maybe_metadata.as_mut().ok_or(Error::<T>::NotDelegator)?;
Expand Down Expand Up @@ -238,7 +236,8 @@ impl<T: Config> Pallet<T> {
///
/// # Errors
///
/// Returns an error if the delegator has no matching unstake request or if there is no active delegation.
/// Returns an error if the delegator has no matching unstake request or if there is no active
/// delegation.
pub fn process_cancel_delegator_unstake(
who: T::AccountId,
operator: T::AccountId,
Expand Down Expand Up @@ -266,7 +265,8 @@ impl<T: Config> Pallet<T> {
let operator_metadata =
maybe_operator_metadata.as_mut().ok_or(Error::<T>::NotAnOperator)?;

// Find the matching delegation and increase its amount, or insert a new delegation if not found
// Find the matching delegation and increase its amount, or insert a new
// delegation if not found
if let Some(delegation) = operator_metadata
.delegations
.iter_mut()
Expand Down
21 changes: 12 additions & 9 deletions pallets/multi-asset-delegation/src/functions/deposit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Tangle. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use crate::types::*;
use crate::Pallet;
use frame_support::ensure;
use frame_support::pallet_prelude::DispatchResult;
use crate::{types::*, Pallet};
use frame_support::{ensure, pallet_prelude::DispatchResult};

use frame_support::traits::fungibles::Mutate;

use frame_support::traits::Get;
use frame_support::{sp_runtime::traits::AccountIdConversion, traits::tokens::Preservation};
use frame_support::{
sp_runtime::traits::AccountIdConversion,
traits::{tokens::Preservation, Get},
};
use sp_runtime::traits::Zero;

impl<T: Config> Pallet<T> {
Expand All @@ -41,7 +41,8 @@ impl<T: Config> Pallet<T> {
///
/// # Errors
///
/// Returns an error if the user is already a delegator, if the stake amount is too low, or if the transfer fails.
/// Returns an error if the user is already a delegator, if the stake amount is too low, or if
/// the transfer fails.
pub fn process_deposit(
who: T::AccountId,
asset_id: T::AssetId,
Expand Down Expand Up @@ -77,7 +78,8 @@ impl<T: Config> Pallet<T> {
///
/// # Errors
///
/// Returns an error if the user is not a delegator, if there is insufficient balance, or if the asset is not supported.
/// Returns an error if the user is not a delegator, if there is insufficient balance, or if the
/// asset is not supported.
pub fn process_schedule_withdraw(
who: T::AccountId,
asset_id: T::AssetId,
Expand Down Expand Up @@ -119,7 +121,8 @@ impl<T: Config> Pallet<T> {
///
/// # Errors
///
/// Returns an error if the user is not a delegator, if there are no withdraw requests, or if the withdraw request is not ready.
/// Returns an error if the user is not a delegator, if there are no withdraw requests, or if
/// the withdraw request is not ready.
pub fn process_execute_withdraw(who: T::AccountId) -> DispatchResult {
Delegators::<T>::try_mutate(&who, |maybe_metadata| {
let metadata = maybe_metadata.as_mut().ok_or(Error::<T>::NotDelegator)?;
Expand Down
18 changes: 10 additions & 8 deletions pallets/multi-asset-delegation/src/functions/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

/// Functions for the pallet.
use super::*;
use crate::types::*;
use crate::Pallet;
use frame_support::ensure;
use frame_support::pallet_prelude::DispatchResult;
use frame_support::traits::Get;
use frame_support::traits::ReservableCurrency;
use crate::{types::*, Pallet};
use frame_support::{
ensure,
pallet_prelude::DispatchResult,
traits::{Get, ReservableCurrency},
};
use sp_runtime::DispatchError;
use tangle_primitives::ServiceManager;

Expand Down Expand Up @@ -117,7 +117,8 @@ impl<T: Config> Pallet<T> {
///
/// # Errors
///
/// Returns an error if the operator is not found, not in leaving state, or the leaving round has not been reached.
/// Returns an error if the operator is not found, not in leaving state, or the leaving round
/// has not been reached.
pub fn process_execute_leave_operators(who: &T::AccountId) -> Result<(), DispatchError> {
let operator = Operators::<T>::get(who).ok_or(Error::<T>::NotAnOperator)?;
let current_round = Self::current_round();
Expand Down Expand Up @@ -192,7 +193,8 @@ impl<T: Config> Pallet<T> {
///
/// # Errors
///
/// Returns an error if the operator is not found, has no scheduled stake reduction, or the request is not satisfied.
/// Returns an error if the operator is not found, has no scheduled stake reduction, or the
/// request is not satisfied.
pub fn process_execute_operator_unstake(who: &T::AccountId) -> Result<(), DispatchError> {
let mut operator = Operators::<T>::get(who).ok_or(Error::<T>::NotAnOperator)?;
let request = operator.request.as_ref().ok_or(Error::<T>::NoScheduledBondLess)?;
Expand Down
18 changes: 7 additions & 11 deletions pallets/multi-asset-delegation/src/functions/rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Tangle. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use crate::types::DelegatorBond;
use crate::types::*;
use crate::Pallet;
use frame_support::ensure;
use frame_support::pallet_prelude::DispatchResult;
use frame_support::traits::Currency;
use sp_runtime::traits::Zero;
use sp_runtime::DispatchError;
use sp_runtime::Saturating;
use sp_std::collections::btree_map::BTreeMap;
use sp_std::vec::Vec;
use crate::{
types::{DelegatorBond, *},
Pallet,
};
use frame_support::{ensure, pallet_prelude::DispatchResult, traits::Currency};
use sp_runtime::{traits::Zero, DispatchError, Saturating};
use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
use tangle_primitives::RoundIndex;

impl<T: Config> Pallet<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Tangle. If not, see <http://www.gnu.org/licenses/>.
use super::*;
use crate::types::*;
use crate::Pallet;
use crate::{types::*, Pallet};

use frame_support::pallet_prelude::DispatchResult;

Expand Down
52 changes: 32 additions & 20 deletions pallets/multi-asset-delegation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,43 @@

//! # Tangle Multi Asset Delegation Pallet
//!
//! This crate provides the delegation framework for the Tangle network, enabling the delegation of assets to operators for earning rewards.
//! This crate provides the delegation framework for the Tangle network, enabling the delegation of
//! assets to operators for earning rewards.
//!
//! ## Key Components
//!
//! - **Operators**: Operators are entities within the Tangle network that can receive delegated assets from delegators. They manage these assets, perform jobs and generate rewards for delegators.
//! - **Deposits**: Depositors must first reserve (deposit) their assets before they can delegate them to operators. This ensures that the assets are locked and available for delegation.
//! - **Delegation**: Delegation is the process where delegators assign their deposited assets to operators to earn rewards.
//! - **Operators**: Operators are entities within the Tangle network that can receive delegated
//! assets from delegators. They manage these assets, perform jobs and generate rewards for
//! delegators.
//! - **Deposits**: Depositors must first reserve (deposit) their assets before they can delegate
//! them to operators. This ensures that the assets are locked and available for delegation.
//! - **Delegation**: Delegation is the process where delegators assign their deposited assets to
//! operators to earn rewards.
//!
//! ## Workflow for Delegators
//!
//! 1. **Deposit**: Before a delegator can delegate assets to an operator, they must first deposit the desired amount of assets. This reserves the assets in the delegator's account.
//! 2. **Delegate**: After depositing assets, the delegator can delegate these assets to an operator. The operator then manages these assets, and the delegator can earn rewards from the operator's activities.
//! 3. **Unstake**: If a delegator wants to reduce their delegation, they can schedule a unstake request. This request will be executed after a specified delay, ensuring network stability.
//! 4. **withdraw Request**: To completely remove assets from delegation, a delegator must submit an withdraw request. Similar to unstake requests, withdraw requests also have a delay before they can be executed.
//! 1. **Deposit**: Before a delegator can delegate assets to an operator, they must first deposit
//! the desired amount of assets. This reserves the assets in the delegator's account.
//! 2. **Delegate**: After depositing assets, the delegator can delegate these assets to an
//! operator. The operator then manages these assets, and the delegator can earn rewards from the
//! operator's activities.
//! 3. **Unstake**: If a delegator wants to reduce their delegation, they can schedule a unstake
//! request. This request will be executed after a specified delay, ensuring network stability.
//! 4. **withdraw Request**: To completely remove assets from delegation, a delegator must submit an
//! withdraw request. Similar to unstake requests, withdraw requests also have a delay before
//! they can be executed.
//!
//! ## Workflow for Operators
//!
//! - **Join Operators**: An account can join as an operator by depositing a minimum stake amount. This stake is reserved and ensures that the operator has a stake in the network.
//! - **Leave Operators**: Operators can leave the network by scheduling a leave request. This request is subject to a delay, during which the operator's status changes to 'Leaving'.
//! - **Join Operators**: An account can join as an operator by depositing a minimum stake amount.
//! This stake is reserved and ensures that the operator has a stake in the network.
//! - **Leave Operators**: Operators can leave the network by scheduling a leave request. This
//! request is subject to a delay, during which the operator's status changes to 'Leaving'.
//! - **Stake More**: Operators can increase their stake to strengthen their stake in the network.
//! - **Stake Less**: Operators can schedule a stake reduction request, which is executed after a delay.
//! - **Go Offline/Online**: Operators can change their status to offline if they need to temporarily stop participating in the network, and can come back online when ready.
//!
//! - **Stake Less**: Operators can schedule a stake reduction request, which is executed after a
//! delay.
//! - **Go Offline/Online**: Operators can change their status to offline if they need to
//! temporarily stop participating in the network, and can come back online when ready.
#![cfg_attr(not(feature = "std"), no_std)]

pub use pallet::*;
Expand All @@ -62,19 +76,16 @@ pub use functions::*;
#[frame_support::pallet]
pub mod pallet {
use crate::types::*;
use frame_support::traits::fungibles;
use frame_support::{
dispatch::DispatchResult,
pallet_prelude::*,
traits::{Currency, LockableCurrency, ReservableCurrency},
traits::{fungibles, Currency, LockableCurrency, ReservableCurrency},
PalletId,
};
use frame_system::pallet_prelude::*;
use sp_runtime::traits::{AtLeast32BitUnsigned, MaybeSerializeDeserialize};
use sp_std::collections::btree_map::BTreeMap;
use sp_std::vec::Vec;
use tangle_primitives::traits::ServiceManager;
use tangle_primitives::RoundIndex;
use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
use tangle_primitives::{traits::ServiceManager, RoundIndex};

/// Configure the pallet by specifying the parameters and types on which it depends.
#[pallet::config]
Expand Down Expand Up @@ -201,7 +212,8 @@ pub mod pallet {

#[pallet::storage]
#[pallet::getter(fn reward_config)]
/// Storage for the reward configuration, which includes APY, cap for assets, and whitelisted blueprints.
/// Storage for the reward configuration, which includes APY, cap for assets, and whitelisted
/// blueprints.
pub type RewardConfigStorage<T: Config> =
StorageValue<_, RewardConfig<T::PoolId, BalanceOf<T>>, OptionQuery>;

Expand Down
Loading

0 comments on commit eadd577

Please sign in to comment.