Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration tests: fudge support for the generic environment #1588

Merged
merged 29 commits into from
Oct 23, 2023
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b6eb261
Add handle and base env structure
lemunozm Oct 10, 2023
ad491e2
evolving and state support for fudge env
lemunozm Oct 10, 2023
6c5f848
Support Client APIs
lemunozm Oct 10, 2023
fa48bea
simplify test cases
lemunozm Oct 10, 2023
5f17c11
Add spetial fudge methos
lemunozm Oct 10, 2023
c45a04f
Add T to FudgeHandle
lemunozm Oct 10, 2023
12beb07
sumbmit extrinsic works
lemunozm Oct 11, 2023
170b4a2
use correct nonce
lemunozm Oct 11, 2023
b6c8075
minor Env trait simplification
lemunozm Oct 11, 2023
3032d09
minor example reorder
lemunozm Oct 11, 2023
084d148
fudge support for all runtimes
lemunozm Oct 11, 2023
c94c1ad
fix nonce and divide api between submit now and later
lemunozm Oct 13, 2023
2fb97d5
minor organization
lemunozm Oct 13, 2023
bf6269a
init tests for loans
lemunozm Oct 13, 2023
21577d0
fix ongoing loans test
lemunozm Oct 14, 2023
f998636
fix compilation
lemunozm Oct 16, 2023
848339d
Merge remote-tracking branch 'origin/main' into integration-tests/fud…
lemunozm Oct 16, 2023
4b159c5
minor renames
lemunozm Oct 16, 2023
5d056ab
restore expect
lemunozm Oct 16, 2023
ef4d158
loan testing in progress
lemunozm Oct 17, 2023
774c241
Merge remote-tracking branch 'origin/main' into integration-tests/fud…
lemunozm Oct 18, 2023
ab7138b
fixed issue with asset_registry
lemunozm Oct 18, 2023
5e79525
add CurrencyInfo genesis utility
lemunozm Oct 18, 2023
93a0dda
extend loan tests, fix block by seconds
lemunozm Oct 20, 2023
6b29b2b
Api from Runtime into an associated type for expliciteness
lemunozm Oct 20, 2023
83bd44c
minor changes
lemunozm Oct 20, 2023
ed92aab
fix and extend loan testing
lemunozm Oct 20, 2023
a496e35
fix and extend loan testing
lemunozm Oct 20, 2023
744f59f
remove unused pallet sudo addition
lemunozm Oct 20, 2023
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
Prev Previous commit
Next Next commit
minor Env trait simplification
  • Loading branch information
lemunozm committed Oct 12, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit b6c807579deccda883fb6c06d462b5708b2fb0bc
10 changes: 1 addition & 9 deletions runtime/integration-tests/src/generic/environment.rs
Original file line number Diff line number Diff line change
@@ -64,10 +64,7 @@ pub trait Env<T: Runtime> {
}

/// Submit an extrinsic mutating the state
fn submit(&mut self, who: Keyring, call: impl Into<T::RuntimeCall>) -> DispatchResult {
let extrinsic = self.create_extrinsic(who, call);
self.__priv_apply_extrinsic(extrinsic)
}
fn submit(&mut self, who: Keyring, call: impl Into<T::RuntimeCall>) -> DispatchResult;

/// Pass any number of blocks
fn pass(&mut self, blocks: Blocks<T>) {
@@ -152,9 +149,4 @@ pub trait Env<T: Runtime> {
}

fn __priv_build_block(&mut self, i: BlockNumber);

fn __priv_apply_extrinsic(
&mut self,
extrinsic: <T::Block as Block>::Extrinsic,
) -> DispatchResult;
}
34 changes: 18 additions & 16 deletions runtime/integration-tests/src/generic/envs/fudge_env.rs
Original file line number Diff line number Diff line change
@@ -5,9 +5,12 @@ use fudge::primitives::Chain;
use handle::{FudgeHandle, ParachainClient};
use sc_client_api::HeaderBackend;
use sp_api::{ApiRef, ProvideRuntimeApi};
use sp_runtime::{generic::BlockId, traits::Block, DispatchError, DispatchResult, Storage};
use sp_runtime::{generic::BlockId, DispatchError, DispatchResult, Storage};

use crate::generic::{environment::Env, runtime::Runtime};
use crate::{
generic::{environment::Env, runtime::Runtime},
utils::accounts::Keyring,
};

/// Trait that represent a runtime with Fudge support
pub trait FudgeSupport: Runtime {
@@ -29,6 +32,19 @@ impl<T: Runtime + FudgeSupport> Env<T> for FudgeEnv<T> {
Self { handle }
}

fn submit(&mut self, who: Keyring, call: impl Into<T::RuntimeCall>) -> DispatchResult {
let extrinsic = self.create_extrinsic(who, call);

self.handle
.parachain_mut()
.append_extrinsic(extrinsic)
.map(|_| ())
.map_err(|_| {
DispatchError::Other("Specific kind of DispatchError not supported by fudge now")
// More information, issue: https://github.com/centrifuge/fudge/issues/67
})
}

fn state_mut<R>(&mut self, f: impl FnOnce() -> R) -> R {
self.handle.parachain_mut().with_mut_state(f).unwrap()
cdamian marked this conversation as resolved.
Show resolved Hide resolved
}
@@ -40,20 +56,6 @@ impl<T: Runtime + FudgeSupport> Env<T> for FudgeEnv<T> {
fn __priv_build_block(&mut self, _i: BlockNumber) {
self.handle.evolve();
}

fn __priv_apply_extrinsic(
&mut self,
extrinsic: <T::Block as Block>::Extrinsic,
) -> DispatchResult {
self.handle
.parachain_mut()
.append_extrinsic(extrinsic)
.map(|_| ())
.map_err(|_| {
// More information, issue: https://github.com/centrifuge/fudge/issues/67
DispatchError::Other("Specific kind of DispatchError not supported by fudge now")
})
}
}

type ApiRefOf<'a, T> = ApiRef<
23 changes: 12 additions & 11 deletions runtime/integration-tests/src/generic/envs/runtime_env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cell::RefCell, marker::PhantomData, rc::Rc};

use cfg_primitives::{AuraId, BlockNumber, Header, Index};
use cfg_primitives::{AuraId, BlockNumber, Header};
use codec::Encode;
use cumulus_primitives_core::PersistedValidationData;
use cumulus_primitives_parachain_inherent::ParachainInherentData;
@@ -13,12 +13,15 @@ use frame_support::{
use sp_consensus_aura::{Slot, AURA_ENGINE_ID};
use sp_core::{sr25519::Public, H256};
use sp_runtime::{
traits::{Block, Extrinsic},
Digest, DigestItem, DispatchError, DispatchResult, Storage, TransactionOutcome,
traits::Extrinsic, Digest, DigestItem, DispatchError, DispatchResult, Storage,
TransactionOutcome,
};
use sp_timestamp::Timestamp;

use crate::generic::{environment::Env, runtime::Runtime};
use crate::{
generic::{environment::Env, runtime::Runtime},
utils::accounts::Keyring,
};

/// Evironment that interact directly with the runtime,
/// without the usage of a client.
@@ -46,6 +49,11 @@ impl<T: Runtime> Env<T> for RuntimeEnv<T> {
}
}

fn submit(&mut self, who: Keyring, call: impl Into<T::RuntimeCall>) -> DispatchResult {
let extrinsic = self.create_extrinsic(who, call);
self.state_mut(|| T::apply_extrinsic(extrinsic).unwrap())
}

fn state_mut<R>(&mut self, f: impl FnOnce() -> R) -> R {
self.ext.borrow_mut().execute_with(f)
}
@@ -66,13 +74,6 @@ impl<T: Runtime> Env<T> for RuntimeEnv<T> {
Self::prepare_block(i);
});
}

fn __priv_apply_extrinsic(
&mut self,
extrinsic: <T::Block as Block>::Extrinsic,
) -> DispatchResult {
self.state_mut(|| T::apply_extrinsic(extrinsic).unwrap())
}
}

impl<T: Runtime> RuntimeEnv<T> {
3 changes: 2 additions & 1 deletion runtime/integration-tests/src/generic/mod.rs
Original file line number Diff line number Diff line change
@@ -99,8 +99,9 @@ mod fudge_handles {
ParachainBuilder<development_runtime::Block, development_runtime::RuntimeApi>,
}

// TODO: Implement for T only once when fudge::companion
// Implement for T only once when fudge::companion
// supports generic in the struct signature.
// Issue: https://github.com/centrifuge/fudge/issues/21
impl FudgeHandle<development_runtime::Runtime> for DevelopmentFudge {
type ParachainApi = <development_runtime::RuntimeApi as ConstructRuntimeApi<
development_runtime::Block,