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

fix: discount calculation handle variable billing frequency #626

Merged
merged 4 commits into from
Mar 6, 2023

Conversation

renauter
Copy link
Contributor

@renauter renauter commented Mar 1, 2023

let amount_due_monthly = amount_due * 24 * 30;
// fist get the normalized amount for one hour so we can infer the amount due monthly (30 days ish)
let amount_due_hourly = U64F64::from_num(amount_due) * U64F64::from_num(seconds_elapsed)
/ U64F64::from_num(SECS_PER_HOUR);
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe check the billing frequency instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I get it
Problem is that the billing time can be different from billing frequency
See here:

seconds_elapsed = now.checked_sub(contract_lock.lock_updated).unwrap_or(0);

That why I made it more generic

@renauter renauter marked this pull request as ready for review March 2, 2023 13:47
@renauter renauter requested review from DylanVerstraete and removed request for robvanmieghem and LeeSmet March 2, 2023 13:48
Copy link
Contributor

@DylanVerstraete DylanVerstraete left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@brandonpille brandonpille left a comment

Choose a reason for hiding this comment

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

Looks great. One small comment.

);

// Bronze discount level
let result = cost::calculate_discount::<TestRuntime>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here and the ones below too. Each test should test one specific case. You can usually split those tests up into 3 pieces: prepare, execute, assert. If you don't have that you're probably testing too much in one test. The reason why this is so important is that it is very easy to navigate through/understand tests like that. Another solution here would be parameterized tests. Rust doesn't support that by default but you can use macros though: https://stackoverflow.com/questions/34662713/how-can-i-create-parameterized-tests-in-rust. Parameterized tests are good if you want to avoid dupplication of test code like in this example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx for the parameterized tests suggestion
More elegant now
See below

@renauter renauter requested a review from brandonpille March 3, 2023 15:14
@DylanVerstraete DylanVerstraete merged commit 81a1cc5 into development Mar 6, 2023
@DylanVerstraete DylanVerstraete deleted the development_fix_discount_calculation branch March 6, 2023 08:20
Copy link
Contributor

@brandonpille brandonpille left a comment

Choose a reason for hiding this comment

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

Looks great!

DylanVerstraete added a commit that referenced this pull request Apr 12, 2023
* feat: rework documentation (#571)

* doc: service consumer contract flow (#567)

* fix: farming policies map ids (#591)

* chore: reset runtime migrations

* feat: delete twin is not allowed (#586)

* fix: typos (#595)

* fix: locked balances (#590)

* feat: allow twin to connect to a relay (#570)

* chore: bump to version 2.3.0-rc1 (specVersion: 124)

* feat: add node power (#592)

* chore: update ADR docs

* chore: bump to version 2.3.0-rc2 (specVersion: 125)

* chore: rework logging pallet smart contract

* fix: allow numbers in relay addresses

* chore: bump to version 2.3.0-rc3 (specVersion: 125)

* fix: migration V15 for devnet #598

* chore: bump to version 2.3.0-rc4 (specVersion: 127)

* chore: restore V15 migration

* chore: update dev chain spec

* fix: soften serial number validation (#603)

* chore: set max length of serial number to 128 bytes

* chore: align tft bridge dependency

* chore: update default dev chainspec

* chore: revert default dev bridge validators chainspec

* Drop unused structopt dependency

This also removes some unused child dependencies

Signed-off-by: Lee Smet <lee.smet@hotmail.com>

* Set the substrate node default chart image to ghcr.io

* fix: rework balances migrations

* chore: refactor

* feat: also remove contract and lock if twin is deleted

* chore: add writes

* chore: resolve comment

* chore: fix ci

* chore: resolve pr comments

* chore: add log

* Update build_test.yaml to use the new runner (#617)

* chore: remove serial valdiation (#616)

* chore: bump to version 2.3.0-rc6 (specVersion: 129)

* chore: rework chart #620

* fix: discount calculation handle variable billing frequency (#626)

* fix: migrations for v2.3.0 (#627)

* chore: bump to version 2.3.0-rc7 (specVersion: 130)

* fix: soften node city/country validation

* chore: bump to version 2.3.0-rc8 (specVersion: 131)

* chore: update cargo lock

* chore: bump version to 2.3.0

---------

Signed-off-by: Lee Smet <lee.smet@hotmail.com>
Co-authored-by: Erwan Renaut <73958772+renauter@users.noreply.github.com>
Co-authored-by: omahs <73983677+omahs@users.noreply.github.com>
Co-authored-by: Lee Smet <lee.smet@hotmail.com>
Co-authored-by: Rob Van Mieghem <robvanmieghem@gmail.com>
Co-authored-by: Brandon <brandon@threefold.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants