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

Substitute mock-accountant macro by a mock builder pallet #1652

Merged
merged 10 commits into from
Dec 15, 2023

Conversation

lemunozm
Copy link
Contributor

@lemunozm lemunozm commented Dec 12, 2023

Description

From the addition of this feature (foss3/runtime-pallet-library#1), the mock accountant macro can be removed, and a mock builder pallet can be used instead.

Changes and Descriptions

  • Replace mock_accountant macro with a mock builder pallet.
  • Replace Rate by Quantity (both represent the same type, but using Quantity for correctness).
    • Adapt consequently computed prices hardcoded values in tests
  • Remove unused mocks from cfg-test-utils

@lemunozm lemunozm added P2-nice-to-have Issue is worth doing. I11-cleaning No mandatory issue that leave the repo more readable/organized labels Dec 12, 2023
@lemunozm lemunozm self-assigned this Dec 12, 2023
@lemunozm
Copy link
Contributor Author

Requires foss3/runtime-pallet-library#15 to work

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Besides the change to the FixedPoint type it looks good.

pallets/investments/src/tests.rs Show resolved Hide resolved
Comment on lines +94 to +106
#[allow(non_snake_case)]
pub fn mock_InvestmentAccountant_deposit(
f: impl Fn(&T::AccountId, T::TrancheCurrency, T::Balance) -> DispatchResult + 'static,
) {
register_call!(move |(a, b, c)| f(a, b, c));
}

#[allow(non_snake_case)]
pub fn mock_InvestmentAccountant_withdraw(
f: impl Fn(&T::AccountId, T::TrancheCurrency, T::Balance) -> DispatchResult + 'static,
) {
register_call!(move |(a, b, c)| f(a, b, c));
}
Copy link
Contributor Author

@lemunozm lemunozm Dec 13, 2023

Choose a reason for hiding this comment

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

The application of foss3/runtime-pallet-library#16, @wischli

Basically the pallet implements deposit() and withdraw() methods from two different traits. So we need to add mock_<trait>_method() to one of these deposit()/withdraw() to differentiate from the others

In those cases, the T::AccountId used as generic for InvestmentAccountant was wrongly internally coded.

@@ -1289,11 +1289,11 @@ fn fulfillment_partially_works_low_price() {
{
assert_eq!(
free_balance_of(investment_account(INVESTMENT_0_0), AUSD_CURRENCY_ID),
207245508982035928145
207245508982035928140
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rounding issues due to modifying Rate (27 decimals) to Quantity (18 decimals).

@@ -2781,7 +2783,7 @@ fn collecting_fully_works() {
INVESTMENT_0_0
));
assert_eq!(
n_last_event(3),
n_last_event(4),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The expected event is behind another produced event of killing an account.

I think the rounding issues put the account under the existential deposit value, and the account is killed.

Comment on lines +59 to +60
#[cfg(test)]
crate::mock::configure_accountant_mock();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Completely astonished by the needed for this.

Without the above line, the test crashes because the mock closure methods are not defined. Nevertheless, configure_accountant_mock() is already called under TextExternatilitiesBuilder::build(), so I would expect to have already defined the mock methods.

It seems like for benchmarking, somehow, the thread used to build the externality is not the same as the one used to benchmark. And then, the internal thread_local used by the mock builder doesn't correspond to the one used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, for testing the 4 benchmarking, just one call to TextExternatilitiesBuilder::build() is done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting finding.

Copy link
Collaborator

@mustermeiszer mustermeiszer left a comment

Choose a reason for hiding this comment

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

Thanks for the clarification!

@lemunozm lemunozm enabled auto-merge (squash) December 15, 2023 11:28
@lemunozm lemunozm merged commit ba5466c into main Dec 15, 2023
9 checks passed
@lemunozm lemunozm deleted the remove-mock-accountant branch December 15, 2023 11:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I11-cleaning No mandatory issue that leave the repo more readable/organized P2-nice-to-have Issue is worth doing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants