Skip to content
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
1 change: 1 addition & 0 deletions pallets/claims/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl pallet_balances::Config for Test {
type RuntimeFreezeReason = ();
type FreezeIdentifier = ();
type MaxFreezes = ();
type DoneSlashHandler = ();
}

parameter_types! {
Expand Down
8 changes: 7 additions & 1 deletion pallets/credits/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl pallet_balances::Config for Runtime {
type RuntimeFreezeReason = RuntimeHoldReason;
type FreezeIdentifier = [u8; 8];
type MaxFreezes = ConstU32<50>;
type DoneSlashHandler = ();
}

parameter_types! {
Expand Down Expand Up @@ -181,6 +182,7 @@ impl pallet_session::Config for Runtime {
type ValidatorId = AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Runtime>;
type WeightInfo = ();
type DisablingStrategy = pallet_session::disabling::UpToLimitDisablingStrategy;
}

pub struct OnChainSeqPhragmen;
Expand Down Expand Up @@ -224,7 +226,9 @@ impl pallet_staking::Config for Runtime {
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;
type NominationsQuota = pallet_staking::FixedNominationsQuota<MAX_QUOTA_NOMINATIONS>;
type WeightInfo = ();
type DisablingStrategy = pallet_staking::UpToLimitDisablingStrategy;
type OldCurrency = Balances;
type RuntimeHoldReason = RuntimeHoldReason;
type Filter = frame_support::traits::Everything;
}

parameter_types! {
Expand All @@ -250,6 +254,7 @@ impl pallet_assets::Config for Runtime {
type CallbackHandle = ();
type Extra = ();
type RemoveItemsLimit = ConstU32<5>;
type Holder = ();
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}
Expand Down Expand Up @@ -583,6 +588,7 @@ construct_runtime!(
}
);

#[allow(dead_code)]
pub struct ExtBuilder;

impl Default for ExtBuilder {
Expand Down
18 changes: 10 additions & 8 deletions pallets/multi-asset-delegation/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl<T: Config> OnRuntimeUpgrade for DelegatorMetadataMigration<T> {
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::DispatchError> {
// Count how many entries we have pre-migration
let count = Delegators::<T>::iter().count() as u32;
log::info!("DelegatorMetadataMigration pre_upgrade: Found {} delegator entries", count);
Expand All @@ -304,12 +304,14 @@ impl<T: Config> OnRuntimeUpgrade for DelegatorMetadataMigration<T> {
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), &'static str> {
fn post_upgrade(state: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
use sp_runtime::DispatchError;

// Decode the state from pre_upgrade
let mut state_cursor = &state[..];

let pre_count =
u32::decode(&mut state_cursor).map_err(|_| "Failed to decode pre-migration count")?;
u32::decode(&mut state_cursor).map_err(|_| DispatchError::Other("Failed to decode pre-migration count"))?;

// Get the current count
let post_count = Delegators::<T>::iter().count() as u32;
Expand All @@ -321,28 +323,28 @@ impl<T: Config> OnRuntimeUpgrade for DelegatorMetadataMigration<T> {
pre_count,
post_count
);
return Err("Entry count decreased after migration");
return Err(DispatchError::Other("Entry count decreased after migration"));
}

// Verify the sampled accounts still exist
let sample_count =
u32::decode(&mut state_cursor).map_err(|_| "Failed to decode sample count")?;
u32::decode(&mut state_cursor).map_err(|_| DispatchError::Other("Failed to decode sample count"))?;

for _ in 0..sample_count {
let account_id = <T as frame_system::Config>::AccountId::decode(&mut state_cursor)
.map_err(|_| "Failed to decode account ID")?;
.map_err(|_| DispatchError::Other("Failed to decode account ID"))?;

if !Delegators::<T>::contains_key(&account_id) {
log::error!(
"DelegatorMetadataMigration post_upgrade: Account {:?} missing after migration",
account_id
);
return Err("Account missing after migration");
return Err(DispatchError::Other("Account missing after migration"));
}

// Verify the new structure has the expected fields
let metadata =
Delegators::<T>::get(&account_id).ok_or("Failed to get metadata for account")?;
Delegators::<T>::get(&account_id).ok_or(DispatchError::Other("Failed to get metadata for account"))?;

// Check that delegations have is_nomination field
for delegation in metadata.delegations.iter() {
Expand Down
77 changes: 40 additions & 37 deletions pallets/multi-asset-delegation/src/tests/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
use super::*;
use crate::{CurrentRound, Error};
use frame_support::{assert_noop, assert_ok};
use sp_keyring::AccountKeyring::{Alice, Bob, Charlie};
use tangle_primitives::services::Asset;

const ALICE: u8 = 1;
const BOB: u8 = 2;
const CHARLIE: u8 = 3;

#[test]
fn delegate_should_work() {
new_test_ext().execute_with(|| {
// Arrange
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let asset = Asset::Custom(VDOT);
let amount = 100;

Expand Down Expand Up @@ -85,8 +88,8 @@ fn delegate_should_work() {
fn schedule_delegator_unstake_should_work() {
new_test_ext().execute_with(|| {
// Arrange
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let asset = Asset::Custom(VDOT);
let amount = 100;

Expand Down Expand Up @@ -150,8 +153,8 @@ fn schedule_delegator_unstake_should_work() {
fn execute_delegator_unstake_should_work() {
new_test_ext().execute_with(|| {
// Arrange
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let asset = Asset::Custom(VDOT);
let amount = 100;

Expand Down Expand Up @@ -206,8 +209,8 @@ fn execute_delegator_unstake_should_work() {
fn cancel_delegator_unstake_should_work() {
new_test_ext().execute_with(|| {
// Arrange
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let asset = Asset::Custom(VDOT);
let amount = 100;

Expand Down Expand Up @@ -281,8 +284,8 @@ fn cancel_delegator_unstake_should_work() {
fn cancel_delegator_unstake_should_update_already_existing() {
new_test_ext().execute_with(|| {
// Arrange
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let asset = Asset::Custom(VDOT);
let amount = 100;

Expand Down Expand Up @@ -360,8 +363,8 @@ fn cancel_delegator_unstake_should_update_already_existing() {
fn delegate_should_fail_if_not_enough_balance() {
new_test_ext().execute_with(|| {
// Arrange
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let asset = Asset::Custom(VDOT);
let amount = 10_000;

Expand Down Expand Up @@ -397,8 +400,8 @@ fn delegate_should_fail_if_not_enough_balance() {
fn schedule_delegator_unstake_should_fail_if_no_delegation() {
new_test_ext().execute_with(|| {
// Arrange
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let asset = Asset::Custom(VDOT);
let amount = 100;

Expand Down Expand Up @@ -434,8 +437,8 @@ fn schedule_delegator_unstake_should_fail_if_no_delegation() {
fn execute_delegator_unstake_should_fail_if_not_ready() {
new_test_ext().execute_with(|| {
// Arrange
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let asset = Asset::Custom(VDOT);
let amount = 100;

Expand Down Expand Up @@ -490,8 +493,8 @@ fn execute_delegator_unstake_should_fail_if_not_ready() {
fn delegate_should_not_create_multiple_on_repeat_delegation() {
new_test_ext().execute_with(|| {
// Arrange
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let asset = Asset::Custom(VDOT);
let amount = 100;
let additional_amount = 50;
Expand Down Expand Up @@ -563,7 +566,7 @@ fn delegate_should_not_create_multiple_on_repeat_delegation() {
#[test]
fn delegate_exceeds_max_delegations() {
new_test_ext().execute_with(|| {
let who: AccountId = Bob.into();
let who: AccountId = mock_pub_key(BOB);
let amount = 100;

// Setup max number of operators
Expand Down Expand Up @@ -605,7 +608,7 @@ fn delegate_exceeds_max_delegations() {
));
}

let operator: AccountId = Charlie.into();
let operator: AccountId = mock_pub_key(CHARLIE);
// Give operator enough balance to join
assert_ok!(Balances::force_set_balance(RuntimeOrigin::root(), operator.clone(), 100_000));
assert_ok!(MultiAssetDelegation::join_operators(
Expand All @@ -632,8 +635,8 @@ fn delegate_exceeds_max_delegations() {
#[test]
fn delegate_insufficient_deposit() {
new_test_ext().execute_with(|| {
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let deposit_amount = 100;
let delegate_amount = deposit_amount + 1;
let asset = Asset::Custom(USDC);
Expand Down Expand Up @@ -678,8 +681,8 @@ fn delegate_insufficient_deposit() {
#[test]
fn delegate_to_inactive_operator() {
new_test_ext().execute_with(|| {
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let amount = 100;

// Setup operator but make them inactive
Expand Down Expand Up @@ -720,8 +723,8 @@ fn delegate_to_inactive_operator() {
#[test]
fn delegate_repeated_same_asset() {
new_test_ext().execute_with(|| {
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let initial_amount = 100;
let additional_amount = 50;

Expand Down Expand Up @@ -780,8 +783,8 @@ fn delegate_repeated_same_asset() {
#[test]
fn delegate_multiple_assets_same_operator() {
new_test_ext().execute_with(|| {
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let amount = 100;

// Setup operator
Expand Down Expand Up @@ -836,8 +839,8 @@ fn delegate_multiple_assets_same_operator() {
#[test]
fn delegate_zero_amount() {
new_test_ext().execute_with(|| {
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);

// Setup operator
assert_ok!(MultiAssetDelegation::join_operators(
Expand All @@ -862,8 +865,8 @@ fn delegate_zero_amount() {
#[test]
fn delegate_with_no_deposit() {
new_test_ext().execute_with(|| {
let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let amount = 100;

// Setup operator
Expand Down Expand Up @@ -895,8 +898,8 @@ fn debug_tnt_delegation_verify_nomination_issue() {
new_test_ext().execute_with(|| {
// This test verifies TNT delegation works correctly without nomination verification

let who: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let who: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
let amount = 1000;
let delegate_amount = 500;

Expand Down Expand Up @@ -942,8 +945,8 @@ fn delegation_unstake_bug_with_nomination_pending() {
// Test case that reproduces the bug where delegation unstake calculation
// incorrectly includes nomination unstake requests
new_test_ext().execute_with(|| {
let delegator: AccountId = Bob.into();
let operator: AccountId = Alice.into();
let delegator: AccountId = mock_pub_key(BOB);
let operator: AccountId = mock_pub_key(ALICE);
// Use the same asset that nominations use: Asset::Custom(Zero::zero()) which is
// Asset::Custom(0)
let asset = Asset::Custom(0);
Expand Down
Loading