Skip to content

Commit c2bbb4f

Browse files
committed
Fix failing tests
1 parent 1303570 commit c2bbb4f

File tree

9 files changed

+74
-32
lines changed

9 files changed

+74
-32
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

integration-tests/src/tests/defaults.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub const CT_UNIT: u128 = 10_u128.pow(CT_DECIMALS as u32);
3636
pub type IntegrationInstantiator = pallet_funding::instantiator::Instantiator<
3737
PolimecRuntime,
3838
<PolimecRuntime as pallet_funding::Config>::AllPalletsWithoutSystem,
39-
cumulus_pallet_parachain_system::RelaychainDataProvider<PolimecRuntime>,
4039
<PolimecRuntime as pallet_funding::Config>::RuntimeEvent,
4140
>;
4241

pallets/funding/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ hex.workspace = true
5151
# Used in the instantiator.
5252
itertools.workspace = true
5353
sp-io.workspace = true
54+
cumulus-pallet-parachain-system.workspace = true
55+
cumulus-primitives-core.workspace = true
5456

5557
[dev-dependencies]
5658
pallet-timestamp.workspace = true

pallets/funding/src/benchmarking.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ use sp_runtime::traits::{Get, Member, TrailingZeroInput, Zero};
4848
const IPFS_CID: &str = "QmbvsJBhQtu9uAGVp7x4H77JkwAQxV7TA6xTfdeALuDiYB";
4949
const CT_DECIMALS: u8 = 17;
5050
const CT_UNIT: u128 = 10u128.pow(CT_DECIMALS as u32);
51-
type BenchInstantiator<T> =
52-
Instantiator<T, <T as Config>::AllPalletsWithoutSystem, System, <T as Config>::RuntimeEvent>;
51+
type BenchInstantiator<T> = Instantiator<T, <T as Config>::AllPalletsWithoutSystem, <T as Config>::RuntimeEvent>;
5352

5453
pub fn usdt_id() -> Location {
5554
AcceptedFundingAsset::USDT.id()

pallets/funding/src/instantiator/calculations.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ use sp_runtime::traits::TrailingZeroInput;
1212
use InvestorType::{self, *};
1313

1414
impl<
15-
T: Config,
15+
T: Config + cumulus_pallet_parachain_system::Config,
1616
AllPalletsWithoutSystem: OnFinalize<BlockNumberFor<T>> + OnIdle<BlockNumberFor<T>> + OnInitialize<BlockNumberFor<T>>,
17-
BNProvider: BlockNumberProvider<BlockNumber = frame_system::pallet_prelude::BlockNumberFor<T>>,
1817
RuntimeEvent: From<Event<T>> + TryInto<Event<T>> + Parameter + Member + IsType<<T as frame_system::Config>::RuntimeEvent>,
19-
> Instantiator<T, AllPalletsWithoutSystem, BNProvider, RuntimeEvent>
18+
> Instantiator<T, AllPalletsWithoutSystem, RuntimeEvent>
2019
{
2120
pub fn get_ed(&self) -> Balance {
2221
T::ExistentialDeposit::get()

pallets/funding/src/instantiator/chain_interactions.rs

+43-20
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ use polimec_common::assets::AcceptedFundingAsset;
66

77
// general chain interactions
88
impl<
9-
T: Config + pallet_balances::Config<Balance = Balance>,
9+
T: Config + pallet_balances::Config<Balance = Balance> + cumulus_pallet_parachain_system::Config,
1010
AllPalletsWithoutSystem: OnFinalize<BlockNumberFor<T>> + OnIdle<BlockNumberFor<T>> + OnInitialize<BlockNumberFor<T>>,
11-
BNProvider: BlockNumberProvider<BlockNumber = frame_system::pallet_prelude::BlockNumberFor<T>>,
1211
RuntimeEvent: From<Event<T>> + TryInto<Event<T>> + Parameter + Member + IsType<<T as frame_system::Config>::RuntimeEvent>,
13-
> Instantiator<T, AllPalletsWithoutSystem, BNProvider, RuntimeEvent>
12+
> Instantiator<T, AllPalletsWithoutSystem, RuntimeEvent>
1413
{
1514
pub fn new(ext: OptionalExternalities) -> Self {
1615
Self { ext, nonce: RefCell::new(0u64), _marker: PhantomData }
@@ -145,13 +144,13 @@ impl<
145144
}
146145

147146
pub fn current_block(&mut self) -> BlockNumberFor<T> {
148-
self.execute(|| BNProvider::current_block_number())
147+
self.execute(|| <T as Config>::BlockNumberProvider::current_block_number())
149148
}
150149

151150
pub fn advance_time(&mut self, amount: BlockNumberFor<T>) {
152151
self.execute(|| {
153152
for _block in 0u32..amount.saturated_into() {
154-
let mut current_block = BNProvider::current_block_number();
153+
let mut current_block = <T as Config>::BlockNumberProvider::current_block_number();
155154

156155
<AllPalletsWithoutSystem as OnFinalize<BlockNumberFor<T>>>::on_finalize(current_block);
157156
<frame_system::Pallet<T> as OnFinalize<BlockNumberFor<T>>>::on_finalize(current_block);
@@ -160,24 +159,26 @@ impl<
160159
<frame_system::Pallet<T> as OnIdle<BlockNumberFor<T>>>::on_idle(current_block, Weight::MAX);
161160

162161
current_block += One::one();
163-
println!("Advancing block to {}", current_block);
164-
// frame_system::Pallet::<T>::set_block_number(current_block);
165-
BNProvider::set_block_number(current_block);
162+
frame_system::Pallet::<T>::set_block_number(current_block);
166163

167-
let current_block = BNProvider::current_block_number();
168-
println!("Executing on_initialize for block {}", current_block);
169164
<frame_system::Pallet<T> as OnInitialize<BlockNumberFor<T>>>::on_initialize(current_block);
170165
<AllPalletsWithoutSystem as OnInitialize<BlockNumberFor<T>>>::on_initialize(current_block);
171166
}
172-
})
167+
});
168+
169+
let current_block = self.current_block();
170+
// in case we are relying on parachain system
171+
self.set_relay_chain_block_number(current_block + amount);
173172
}
174173

175174
pub fn jump_to_block(&mut self, block: BlockNumberFor<T>) {
176175
let current_block = self.current_block();
177-
println!("Jumping from block {} to block {}", current_block, block);
178176
if block > current_block {
179-
// self.execute(|| frame_system::Pallet::<T>::set_block_number(block - One::one()));
180-
self.execute(|| BNProvider::set_block_number(block - One::one()));
177+
self.execute(|| {
178+
frame_system::Pallet::<T>::set_block_number(block - One::one());
179+
});
180+
self.set_relay_chain_block_number(block - One::one());
181+
181182
self.advance_time(One::one());
182183
} else {
183184
// panic!("Cannot jump to a block in the present or past")
@@ -223,15 +224,38 @@ impl<
223224
});
224225
}
225226
}
227+
228+
/// NOTE: this is a workaround function to advance relaychain's block number, since
229+
/// `<T as Config>::BlockNumberProvider::set_block_number` is not working in tests
230+
///
231+
/// It is cloned version of the above trait function implementation in [`cumulus_pallet_parachain_system::RelaychainDataProvider`]
232+
///
233+
/// TODO: remove this function once the issue is fixed
234+
pub fn set_relay_chain_block_number(&mut self, to: BlockNumberFor<T>) {
235+
use cumulus_pallet_parachain_system::ValidationData;
236+
use cumulus_primitives_core::PersistedValidationData;
237+
238+
self.execute(|| {
239+
let mut validation_data = ValidationData::<T>::get().unwrap_or_else(||
240+
// PersistedValidationData does not impl default in non-std
241+
PersistedValidationData {
242+
parent_head: vec![].into(),
243+
relay_parent_number: Default::default(),
244+
max_pov_size: Default::default(),
245+
relay_parent_storage_root: Default::default(),
246+
});
247+
validation_data.relay_parent_number = to.saturated_into();
248+
ValidationData::<T>::put(validation_data)
249+
});
250+
}
226251
}
227252

228253
// assertions
229254
impl<
230-
T: Config + pallet_balances::Config<Balance = Balance>,
255+
T: Config + pallet_balances::Config<Balance = Balance> + cumulus_pallet_parachain_system::Config,
231256
AllPalletsWithoutSystem: OnFinalize<BlockNumberFor<T>> + OnIdle<BlockNumberFor<T>> + OnInitialize<BlockNumberFor<T>>,
232-
BNProvider: BlockNumberProvider<BlockNumber = frame_system::pallet_prelude::BlockNumberFor<T>>,
233257
RuntimeEvent: From<Event<T>> + TryInto<Event<T>> + Parameter + Member + IsType<<T as frame_system::Config>::RuntimeEvent>,
234-
> Instantiator<T, AllPalletsWithoutSystem, BNProvider, RuntimeEvent>
258+
> Instantiator<T, AllPalletsWithoutSystem, RuntimeEvent>
235259
{
236260
pub fn test_ct_created_for(&mut self, project_id: ProjectId) {
237261
self.execute(|| {
@@ -335,11 +359,10 @@ impl<
335359

336360
// project chain interactions
337361
impl<
338-
T: Config + pallet_balances::Config<Balance = Balance>,
362+
T: Config + pallet_balances::Config<Balance = Balance> + cumulus_pallet_parachain_system::Config,
339363
AllPalletsWithoutSystem: OnFinalize<BlockNumberFor<T>> + OnIdle<BlockNumberFor<T>> + OnInitialize<BlockNumberFor<T>>,
340-
BNProvider: BlockNumberProvider<BlockNumber = frame_system::pallet_prelude::BlockNumberFor<T>>,
341364
RuntimeEvent: From<Event<T>> + TryInto<Event<T>> + Parameter + Member + IsType<<T as frame_system::Config>::RuntimeEvent>,
342-
> Instantiator<T, AllPalletsWithoutSystem, BNProvider, RuntimeEvent>
365+
> Instantiator<T, AllPalletsWithoutSystem, RuntimeEvent>
343366
{
344367
pub fn get_issuer(&mut self, project_id: ProjectId) -> AccountIdOf<T> {
345368
self.execute(|| ProjectsDetails::<T>::get(project_id).unwrap().issuer_account)

pallets/funding/src/instantiator/types.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use super::*;
33
use crate::ParticipationMode;
44
use frame_support::{Deserialize, Serialize};
55
use polimec_common::assets::AcceptedFundingAsset;
6-
use sp_runtime::traits::BlockNumberProvider;
76

87
pub type RuntimeOriginOf<T> = <T as frame_system::Config>::RuntimeOrigin;
98
pub struct BoxToFunction(pub Box<dyn FnOnce()>);
@@ -20,14 +19,13 @@ pub type OptionalExternalities = Option<RefCell<sp_io::TestExternalities>>;
2019
pub type OptionalExternalities = Option<()>;
2120

2221
pub struct Instantiator<
23-
T: Config + pallet_balances::Config<Balance = Balance>,
22+
T: Config + pallet_balances::Config<Balance = Balance> + cumulus_pallet_parachain_system::Config,
2423
AllPalletsWithoutSystem: OnFinalize<BlockNumberFor<T>> + OnIdle<BlockNumberFor<T>> + OnInitialize<BlockNumberFor<T>>,
25-
BNProvider: BlockNumberProvider<BlockNumber = frame_system::pallet_prelude::BlockNumberFor<T>>,
2624
RuntimeEvent: From<Event<T>> + TryInto<Event<T>> + Parameter + Member + IsType<<T as frame_system::Config>::RuntimeEvent>,
2725
> {
2826
pub ext: OptionalExternalities,
2927
pub nonce: RefCell<u64>,
30-
pub _marker: PhantomData<(T, AllPalletsWithoutSystem, BNProvider, RuntimeEvent)>,
28+
pub _marker: PhantomData<(T, AllPalletsWithoutSystem, RuntimeEvent)>,
3129
}
3230

3331
impl<T: Config + pallet_balances::Config> Deposits<T> for Vec<AccountIdOf<T>> {

pallets/funding/src/mock.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use frame_support::{
2626
construct_runtime, derive_impl,
2727
pallet_prelude::Weight,
2828
parameter_types,
29-
traits::{AsEnsureOriginWithArg, ConstU16, ConstU32, ConstU64, OriginTrait, WithdrawReasons},
29+
traits::{AsEnsureOriginWithArg, ConstU16, ConstU32, ConstU64, EnqueueWithOrigin, OriginTrait, WithdrawReasons},
3030
PalletId,
3131
};
3232
use frame_system as system;
@@ -227,10 +227,27 @@ impl system::Config for TestRuntime {
227227
type Hashing = BlakeTwo256;
228228
type Lookup = IdentityLookup<Self::AccountId>;
229229
type MaxConsumers = frame_support::traits::ConstU32<16>;
230+
type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode<Self>;
230231
type PalletInfo = PalletInfo;
231232
type SS58Prefix = ConstU16<41>;
232233
}
233234

235+
// NOTE: this is not used in the mock runtime at all, but it is required to satisfy type bound of [`crate::instantiator::Instantiator`]
236+
// TODO: should be removed and `<T as crate::Config>::BlockNumberProvider::set_block_number` should be used instead
237+
impl cumulus_pallet_parachain_system::Config for TestRuntime {
238+
type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::AnyRelayNumber;
239+
type ConsensusHook = cumulus_pallet_parachain_system::ExpectParentIncluded;
240+
type DmpQueue = EnqueueWithOrigin<(), sp_core::ConstU8<0>>;
241+
type OnSystemEvent = ();
242+
type OutboundXcmpMessageSource = ();
243+
type ReservedDmpWeight = ();
244+
type ReservedXcmpWeight = ();
245+
type RuntimeEvent = RuntimeEvent;
246+
type SelfParaId = ();
247+
type WeightInfo = ();
248+
type XcmpMessageHandler = ();
249+
}
250+
234251
parameter_types! {
235252
pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
236253
}
@@ -437,6 +454,9 @@ construct_runtime!(
437454
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>, Config<T>},
438455
PolimecFunding: pallet_funding::{Pallet, Call, Storage, Event<T>, HoldReason} = 52,
439456
ProxyBonding: pallet_proxy_bonding,
457+
458+
// NOTE: this pallet is only necessary to satisfy type bound of [`crate::instantiator::Instantiator`]
459+
ParachainSystem: cumulus_pallet_parachain_system,
440460
}
441461
);
442462

pallets/funding/src/tests/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ mod runtime_api;
5252
mod settlement;
5353

5454
pub type MockInstantiator =
55-
Instantiator<TestRuntime, <TestRuntime as crate::Config>::AllPalletsWithoutSystem, System, RuntimeEvent>;
55+
Instantiator<TestRuntime, <TestRuntime as crate::Config>::AllPalletsWithoutSystem, RuntimeEvent>;
5656
pub const CT_DECIMALS: u8 = 15;
5757
pub const CT_UNIT: u128 = 10_u128.pow(CT_DECIMALS as u32);
5858
pub const USDT_UNIT: u128 = USD_UNIT;

0 commit comments

Comments
 (0)