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

Loans: Integration tests #1600

Merged
merged 12 commits into from
Oct 27, 2023
Merged

Loans: Integration tests #1600

merged 12 commits into from
Oct 27, 2023

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Oct 26, 2023

Fixes #1458 #1375

Changes and Descriptions

  • Add main loan use cases (under generic/src/cases/loans.rs):
    • Entire flow with internal priced loans
    • Entire flow with external priced loans using oracles
    • Mutating a loan through a pool change guard.
    • Check all kind of mutations based on different restriction. This is blocked since there is no way to pass one week without burning the computer during 15-minute computing blocks.
  • Removed obsoleted loan integration tests and moved some env tests to their more related placed (most of the modified diff files come from this, sorry 🙏🏻).
  • Reorganize generic modules under integration tests to be more readable, now:
runtime/integration-tests/src/generic
├── cases               // Use cases go here
│  ├── example.rs
│  └── loans.rs
├── envs                // Environments go here
│  ├── fudge_env
│  │  └── handle.rs
│  ├── fudge_env.rs
│  └── runtime_env.rs
├── utils               // Generic utilities for any use case:
│  ├── currency.rs      // Easy support for interacting with currencies as ED or its decimals
│  ├── genesis.rs       // Generic support for initializing pallets
│  └── mod.rs
├── config.rs           // Where Runtime trait and other configs are defined.
├── env.rs              // Environment trait with basic defaults
├── impls.rs            // where runtimes implement the new traits
├── mod.rs
└── README.md
  • Fixes a bug in processing blocks BySeconds
  • Add Block::JumpBySeconds see comment

@lemunozm lemunozm added I4-tests Test needs fixing or improving. P5-soon Issue should be addressed soon. I6-refactoring Code needs refactoring. labels Oct 26, 2023
@lemunozm lemunozm requested a review from hieronx October 26, 2023 13:12
@lemunozm lemunozm self-assigned this Oct 26, 2023
@cdamian
Copy link
Contributor

cdamian commented Oct 26, 2023

I assume we want to get this in before the .43 update so we'll have to eventually get these changes in that branch.

@lemunozm
Copy link
Contributor Author

Yes, and later, my idea is to create another "branch" where I update this over 9.43 before I leave and alleviate you from issues here. But I'm not sure if I'll get time!

@lemunozm lemunozm force-pushed the loans/integration-tests branch from e3842cc to 573a2d7 Compare October 26, 2023 17:33
Comment on lines +160 to +172
fn pass_time_one_block<T: Runtime>() {
let mut env = RuntimeEnv::<T>::from_storage(Default::default());

let before = env.state(|| pallet_timestamp::Pallet::<T>::get());

// Not supported in fudge
env.pass(Blocks::JumpBySeconds(SECONDS_PER_YEAR));

let after = env.state(|| pallet_timestamp::Pallet::<T>::get());

assert_eq!((after - before).into_seconds(), SECONDS_PER_YEAR)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdamian I need your fudge wisdom on this.

What I'm doing with the JumpBySeconds in the RuntimeEnv is jumping to a block in the future where it has passed SECONDS_PER_YEAR. This works quite well to "emulate" a state in the future, only creating one block. It's not as accurate as passing all blocks equivalent to a year, but it's much much faster and unlocks these tests for CI.

Do you think we can modify fudge to add this behavior, jumping to a block in the future without computing the intermediate blocks?

cc @mustermeiszer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for missing this. I don't think that will be feasible given our evolve logic, but I'm still lacking knowledge on the topic. @mustermeiszer Might know more.

@lemunozm lemunozm force-pushed the loans/integration-tests branch from 573a2d7 to 83a5095 Compare October 26, 2023 18:09
@lemunozm
Copy link
Contributor Author

Thanks for the approval @cdamian!

@lemunozm lemunozm merged commit f46d327 into main Oct 27, 2023
10 checks passed
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoot, I am a bit too late. Luckily, I only had non-blocking nitpicks. Great work @luis! Thanks so much for the README, it really helps!


You can choose the environment for each of your use cases:
- `RuntimeEnv`: Simple environment that acts as a wrapper over the runtime
- `FudgeEnv`: Advanced environment that use a client and connect the runtime to a relay chain.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
- `FudgeEnv`: Advanced environment that use a client and connect the runtime to a relay chain.
- `FudgeEnv`: Advanced environment that uses a client and connects the runtime to a relay chain.

- `RuntimeEnv`: Simple environment that acts as a wrapper over the runtime
- `FudgeEnv`: Advanced environment that use a client and connect the runtime to a relay chain.

Both environment uses the same interface so jumping from one to the another should be something "smooth".
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

Suggested change
Both environment uses the same interface so jumping from one to the another should be something "smooth".
Both environment use the same interface, so jumping from one to the another should be somewhat "smooth".


Both environment uses the same interface so jumping from one to the another should be something "smooth".

## Where I start?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

Suggested change
## Where I start?
## Where do I start?

@@ -42,112 +47,323 @@ use crate::{
const POOL_ADMIN: Keyring = Keyring::Admin;
const INVESTOR: Keyring = Keyring::Alice;
const BORROWER: Keyring = Keyring::Bob;
const LOAN_ADMIN: Keyring = Keyring::Charlie;
const ANY: Keyring = Keyring::Dave;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: We should make it clear this refers to a substrate address

Suggested change
const ANY: Keyring = Keyring::Dave;
const ANYONE: Keyring = Keyring::Dave;

@lemunozm
Copy link
Contributor Author

Written down as doc-debt! 😆
Thanks for the corrections!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I4-tests Test needs fixing or improving. I6-refactoring Code needs refactoring. P5-soon Issue should be addressed soon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loans: add integration tests
3 participants