Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
NunoAlexandre committed Oct 5, 2023
1 parent 430d462 commit 3c8c03e
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 33 deletions.
63 changes: 33 additions & 30 deletions pallets/restricted-tokens/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use frame_support::{
BalanceStatus, Currency, LockableCurrency, ReservableCurrency, WithdrawReasons,
},
};
use frame_support::traits::tokens::Provenance;
use orml_traits::GetByKey;

use crate::{
Expand Down Expand Up @@ -440,7 +441,7 @@ fn fungible_release() {
}

#[test]
fn fungible_transfer_held() {
fn fungible_transfer_on_hold() {
TestExternalitiesBuilder::default()
.build(Some(|| {}))
.execute_with(|| {
Expand All @@ -451,7 +452,7 @@ fn fungible_transfer_held() {


assert!(<pallet_restricted_tokens::Pallet::<Runtime> as fungible::MutateHold<AccountId>>::hold(&(), &2, DISTR_PER_ACCOUNT).is_ok());
assert!(<pallet_restricted_tokens::Pallet::<Runtime> as fungible::MutateHold<AccountId>>::transfer_held(&2, &9, DISTR_PER_ACCOUNT, false, false).is_ok());
assert!(<pallet_restricted_tokens::Pallet::<Runtime> as fungible::MutateHold<AccountId>>::transfer_on_hold(&(), &2, &9, DISTR_PER_ACCOUNT, Precision::Exact, Restriction::Free,Fortitude::Polite).is_ok());
assert_eq!(<pallet_restricted_tokens::Pallet::<Runtime> as fungible::Inspect<AccountId>>::reducible_balance(&9, Preservation::Protect, Fortitude::Polite), 2 * DISTR_PER_ACCOUNT - ExistentialDeposit::get());
assert_eq!(<pallet_restricted_tokens::Pallet::<Runtime> as fungible::Inspect<AccountId>>::reducible_balance(&2, Preservation::Protect, Fortitude::Polite), 0);
})
Expand All @@ -464,9 +465,9 @@ fn fungible_transfer() {
.execute_with(|| {
// Min holding period is not over
assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungible::Transfer<
<pallet_restricted_tokens::Pallet::<Runtime> as fungible::Mutate<
AccountId,
>>::transfer(&1, &100, DISTR_PER_ACCOUNT, false)
>>::transfer(&1, &100, DISTR_PER_ACCOUNT, Preservation::Expendable)
.is_err()
);
Timer::pass(MIN_HOLD_PERIOD);
Expand Down Expand Up @@ -549,13 +550,13 @@ fn fungibles_reducible_balance() {
assert_eq!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Inspect<
AccountId,
>>::reducible_balance(CurrencyId::Cfg, &1, false),
>>::reducible_balance(CurrencyId::Cfg, &1, Preservation::Expendable, Fortitude::Polite),
DISTR_PER_ACCOUNT - ExistentialDeposit::get()
);
assert_eq!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Inspect<
AccountId,
>>::reducible_balance(CurrencyId::AUSD, &1, false),
>>::reducible_balance(CurrencyId::AUSD, &1, Preservation::Expendable, Fortitude::Polite),
DISTR_PER_ACCOUNT / 2
);
})
Expand All @@ -569,13 +570,13 @@ fn fungibles_can_deposit() {
assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Inspect<
AccountId,
>>::can_deposit(CurrencyId::Cfg, &1, 10, false)
>>::can_deposit(CurrencyId::Cfg, &1, 10, Provenance::Extant)
== DepositConsequence::Success
);
assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Inspect<
AccountId,
>>::can_deposit(CurrencyId::AUSD, &1, 10, false)
>>::can_deposit(CurrencyId::AUSD, &1, 10, Provenance::Extant)
== DepositConsequence::Success
);
})
Expand Down Expand Up @@ -610,7 +611,7 @@ fn fungibles_balance_on_hold() {
assert_eq!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::InspectHold<
AccountId,
>>::balance_on_hold(CurrencyId::AUSD, &1,),
>>::balance_on_hold(CurrencyId::AUSD, &(), &1),
0
);
})
Expand All @@ -629,12 +630,12 @@ fn fungibles_can_hold() {
assert!(
!<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::InspectHold<
AccountId,
>>::can_hold(CurrencyId::AUSD, &1, 0)
>>::can_hold(CurrencyId::AUSD, &(), &1, 0)
);
assert!(
!<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::InspectHold<
AccountId,
>>::can_hold(CurrencyId::AUSD, &1, 0)
>>::can_hold(CurrencyId::AUSD, &(), &1, 0)
);
})
}
Expand All @@ -659,7 +660,7 @@ fn fungibles_burn_from() {
.build(Some(|| {}))
.execute_with(|| {
assert_noop!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Mutate<AccountId>>::burn_from(CurrencyId::RestrictedCoin, &1, DISTR_PER_ACCOUNT),
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Mutate<AccountId>>::burn_from(CurrencyId::RestrictedCoin, &1, DISTR_PER_ACCOUNT, Precision::Exact, Fortitude::Force),
Error::<Runtime>::PreConditionsNotMet,
);

Expand All @@ -675,21 +676,21 @@ fn fungibles_hold() {
assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::hold(CurrencyId::RestrictedCoin, &1, DISTR_PER_ACCOUNT)
>>::hold(CurrencyId::RestrictedCoin, &(), &1, DISTR_PER_ACCOUNT)
.is_ok()
);

assert_noop!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::hold(CurrencyId::AUSD, &1, 1),
>>::hold(CurrencyId::AUSD, &(), &1, 1),,
Error::<Runtime>::PreConditionsNotMet,
);

assert_noop!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::hold(CurrencyId::AUSD, &1, 1),
>>::hold(CurrencyId::AUSD, &(), &1, 1),,
Error::<Runtime>::PreConditionsNotMet,
);
})
Expand All @@ -703,25 +704,25 @@ fn fungibles_release() {
assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::hold(CurrencyId::RestrictedCoin, &1, DISTR_PER_ACCOUNT)
>>::hold(CurrencyId::RestrictedCoin, &(), &1, DISTR_PER_ACCOUNT)
.is_ok()
);
assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::release(CurrencyId::RestrictedCoin, &1, DISTR_PER_ACCOUNT, false)
>>::release(CurrencyId::RestrictedCoin, &(), &1, DISTR_PER_ACCOUNT, Precision::Exact)
.is_ok()
);
assert_noop!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::hold(CurrencyId::AUSD, &1, DISTR_PER_ACCOUNT),
>>::hold(CurrencyId::AUSD, &(), &1, DISTR_PER_ACCOUNT),
Error::<Runtime>::PreConditionsNotMet
);
assert_noop!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::hold(CurrencyId::AUSD, &1, DISTR_PER_ACCOUNT),
>>::hold(CurrencyId::AUSD, &(), &1, DISTR_PER_ACCOUNT),
Error::<Runtime>::PreConditionsNotMet
);
})
Expand All @@ -735,39 +736,41 @@ fn fungibles_transfer_held() {
assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::hold(CurrencyId::RestrictedCoin, &1, DISTR_PER_ACCOUNT)
>>::hold(CurrencyId::RestrictedCoin, &(), &1, DISTR_PER_ACCOUNT)
.is_ok()
);
assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::transfer_held(
>>::transfer_on_hold(
CurrencyId::RestrictedCoin,
&(),
&1,
&9,
DISTR_PER_ACCOUNT,
false,
true
Precision::Exact,
Restriction::OnHold,
Fortitude::Polite,
)
.is_ok()
);
assert_eq!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Inspect<
AccountId,
>>::reducible_balance(CurrencyId::RestrictedCoin, &1, false),
>>::reducible_balance(CurrencyId::RestrictedCoin, &1, Preservation::Expendable, Fortitude::Polite),
0
);
assert_eq!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Inspect<
AccountId,
>>::reducible_balance(CurrencyId::RestrictedCoin, &9, false),
>>::reducible_balance(CurrencyId::RestrictedCoin, &9, Preservation::Expendable, Fortitude::Polite),
DISTR_PER_ACCOUNT / 2
);

assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::MutateHold<
AccountId,
>>::hold(CurrencyId::RestrictedCoin, &2, DISTR_PER_ACCOUNT)
>>::hold(CurrencyId::RestrictedCoin, &(), &2, DISTR_PER_ACCOUNT)
.is_ok()
);
assert!(
Expand All @@ -786,13 +789,13 @@ fn fungibles_transfer_held() {
assert_eq!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Inspect<
AccountId,
>>::reducible_balance(CurrencyId::RestrictedCoin, &9, false),
>>::reducible_balance(CurrencyId::RestrictedCoin, &9, Preservation::Expendable, Fortitude::Polite),
DISTR_PER_ACCOUNT
);
assert_eq!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Inspect<
AccountId,
>>::reducible_balance(CurrencyId::RestrictedCoin, &2, false),
>>::reducible_balance(CurrencyId::RestrictedCoin, &2, Preservation::Expendable, Fortitude::Polite),
0
);
})
Expand Down Expand Up @@ -831,14 +834,14 @@ fn fungibles_transfer() {
);

assert!(
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Transfer<
<pallet_restricted_tokens::Pallet::<Runtime> as fungibles::Mutate<
AccountId,
>>::transfer(
CurrencyId::RestrictedCoin,
&100,
&101,
DISTR_PER_ACCOUNT,
false
Preservation::Expendable,
)
.is_ok()
);
Expand Down
4 changes: 4 additions & 0 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,7 @@ parameter_types! {
pub CouncilMotionDuration: BlockNumber = prod_or_fast!(5 * DAYS, 1 * MINUTES, "AIR_MOTION_DURATION");
pub const CouncilMaxProposals: u32 = 100;
pub const CouncilMaxMembers: u32 = 100;
pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block;
}

impl pallet_collective::Config<CouncilCollective> for Runtime {
Expand All @@ -661,6 +662,9 @@ impl pallet_collective::Config<CouncilCollective> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type WeightInfo = weights::pallet_collective::WeightInfo<Self>;
type SetMembersOrigin = EnsureRoot<AccountId>;
type MaxProposalWeight = MaxProposalWeight;

}

parameter_types! {
Expand Down
5 changes: 5 additions & 0 deletions runtime/altair/src/weights/pallet_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ impl<T: frame_system::Config> pallet_xcm::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4))
}

fn force_suspension() -> Weight {
todo!()
}

/// Storage: PolkadotXcm SupportedVersion (r:4 w:2)
/// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured)
fn migrate_supported_version() -> Weight {
Expand Down
1 change: 1 addition & 0 deletions runtime/centrifuge/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use cfg_primitives::{TwoThirdOfCouncil, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO};
use frame_support::{parameter_types, traits::FindAuthor, weights::Weight, ConsensusEngineId};
use pallet_evm::{EnsureAddressRoot, EnsureAddressTruncated};
use pallet_ethereum::PostLogContent;
use runtime_common::{
account_conversion::AccountConverter,
evm::{precompile::CentrifugePrecompiles, BaseFeeThreshold, WEIGHT_PER_GAS},
Expand Down
3 changes: 1 addition & 2 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ parameter_types! {
impl pallet_collective::Config<CouncilCollective> for Runtime {
type DefaultVote = pallet_collective::PrimeDefaultVote;
type MaxMembers = CouncilMaxMembers;
type MaxProposalWeight = ();
type MaxProposalWeight = MaxProposalWeight;
type MaxProposals = CouncilMaxProposals;
type MotionDuration = CouncilMotionDuration;
type Proposal = RuntimeCall;
Expand Down Expand Up @@ -2414,7 +2414,6 @@ impl_runtime_apis! {
estimated_transaction_len += access_list.encoded_size();
}


let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
let without_base_extrinsic_weight = true;

Expand Down
5 changes: 5 additions & 0 deletions runtime/centrifuge/src/weights/pallet_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ impl<T: frame_system::Config> pallet_xcm::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4))
}

fn force_suspension() -> Weight {
todo!()
}

/// Storage: PolkadotXcm SupportedVersion (r:4 w:2)
/// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured)
fn migrate_supported_version() -> Weight {
Expand Down
39 changes: 39 additions & 0 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@ parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 5 * DAYS;
pub const CouncilMaxProposals: u32 = 100;
pub const CouncilMaxMembers: u32 = 100;
pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block;
}

impl pallet_collective::Config<CouncilCollective> for Runtime {
Expand All @@ -675,6 +676,8 @@ impl pallet_collective::Config<CouncilCollective> for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
type WeightInfo = weights::pallet_collective::WeightInfo<Runtime>;
type SetMembersOrigin = EnsureRoot<AccountId>;
type MaxProposalWeight = MaxProposalWeight;
}

parameter_types! {
Expand Down Expand Up @@ -2400,6 +2403,42 @@ impl_runtime_apis! {

let is_transactional = false;
let validate = true;

// Estimated encoded transaction size must be based on the heaviest transaction
// type (EIP1559Transaction) to be compatible with all transaction types.
let mut estimated_transaction_len = data.len() +
// pallet ethereum index: 1
// transact call index: 1
// Transaction enum variant: 1
// chain_id 8 bytes
// nonce: 32
// max_priority_fee_per_gas: 32
// max_fee_per_gas: 32
// gas_limit: 32
// action: 21 (enum variant + call address)
// value: 32
// access_list: 1 (empty vec size)
// 65 bytes signature
258;

if access_list.is_some() {
estimated_transaction_len += access_list.encoded_size();
}

let gas_limit = gas_limit.min(u64::MAX.into()).low_u64();
let without_base_extrinsic_weight = true;

let (weight_limit, proof_size_base_cost) =
match <Runtime as pallet_evm::Config>::GasWeightMapping::gas_to_weight(
gas_limit,
without_base_extrinsic_weight
) {
weight_limit if weight_limit.proof_size() > 0 => {
(Some(weight_limit), Some(estimated_transaction_len as u64))
}
_ => (None, None),
};

<Runtime as pallet_evm::Config>::Runner::call(
from,
to,
Expand Down
5 changes: 5 additions & 0 deletions runtime/development/src/weights/pallet_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ impl<T: frame_system::Config> pallet_xcm::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(4))
}

fn force_suspension() -> Weight {
todo!()
}

/// Storage: PolkadotXcm SupportedVersion (r:4 w:2)
/// Proof Skipped: PolkadotXcm SupportedVersion (max_values: None, max_size: None, mode: Measured)
fn migrate_supported_version() -> Weight {
Expand Down
3 changes: 2 additions & 1 deletion runtime/development/src/xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ impl TakeRevenue for ToTreasury {
/// executed.
pub type Barrier = (
TakeWeightCredit,
xcm_primitives::AllowTopLevelPaidExecutionDescendOriginFirst<Everything>,
//todo(nuno): revisit this
// xcm_primitives::AllowTopLevelPaidExecutionDescendOriginFirst<Everything>,
AllowTopLevelPaidExecutionFrom<Everything>,
// Expected responses are OK.
AllowKnownQueryResponses<PolkadotXcm>,
Expand Down

0 comments on commit 3c8c03e

Please sign in to comment.