Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d598a1e
Price adjustements should be based on price
May 10, 2024
ae90650
AllowedRenewal -> PotentialRenewal
May 20, 2024
2855832
WIP: New price based `AdaptPrice` trait.
May 20, 2024
627acf7
Pub
May 21, 2024
31ea3a9
Also adjust sellout_price on renew.
May 21, 2024
63f5856
Adapt price implementation.
May 21, 2024
3630ccc
Some tests + handle going down to zero gracefully.
May 21, 2024
b615fbe
Fix tests.
May 21, 2024
fd03dc1
More linear tests.
May 21, 2024
6fdc11b
Add prdoc.
May 22, 2024
cb5485d
Put base price in the middle of the range.
May 23, 2024
9299010
new leadin curve.
May 23, 2024
28f13f4
price -> base_price
May 23, 2024
4b5a66d
Fmt
May 23, 2024
fad4aab
base_price -> min_price
May 24, 2024
4979fbb
Merge branch 'master' into rk-broker-new-price-adapter
May 27, 2024
5869882
New example adapter name + more parameters (cores)
May 27, 2024
baeab0e
Fix kitchensink
May 27, 2024
aa4defc
Some logging + test.
May 27, 2024
d5992b4
Fix prdoc
May 27, 2024
03db451
regular_price -> end_price
May 27, 2024
d67dfc4
Fixes.
May 27, 2024
edeaf69
Merge remote-tracking branch 'origin/master' into rk-broker-new-price…
May 27, 2024
890e6ca
Fix benchmarks
May 27, 2024
66bce5a
Update prdoc/pr_4521.prdoc
eskimor May 29, 2024
fbe5241
min_price -> end_price
May 29, 2024
fdf764e
Better docs for target_price.
May 29, 2024
86ec07c
Improved prdoc
May 29, 2024
1ca75af
Merge remote-tracking branch 'origin/rk-broker-new-price-adapter' int…
May 29, 2024
2a940a5
Make change major again.
May 29, 2024
52e0b80
One more test.
May 29, 2024
812f66c
Add migration for name change `PotentialRenewals`.
May 29, 2024
ae20d3c
Merge remote-tracking branch 'origin/master' into rk-broker-new-price…
May 29, 2024
7e2992c
Fix prdoc?
May 29, 2024
654d1e4
Merge branch 'master' of https://github.com/paritytech/polkadot-sdk i…
May 29, 2024
4cc238a
".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime…
May 29, 2024
d6857aa
Change bump to minor again to make CI happy.
May 29, 2024
c98a945
Merge remote-tracking branch 'origin/rk-broker-new-price-adapter' int…
May 29, 2024
d179b89
prdoc fix
May 29, 2024
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
Fix tests.
  • Loading branch information
eskimor committed May 21, 2024
commit b615fbe0f9b4aa5c2eafcc3512f96054795b5356
30 changes: 18 additions & 12 deletions substrate/frame/broker/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,22 +361,27 @@ fn migration_works() {

#[test]
fn renewal_works() {
TestExt::new().endow(1, 1000).execute_with(|| {
let b = 100_000;
TestExt::new().endow(1, b).execute_with(move || {
assert_ok!(Broker::do_start_sales(100, 1));
advance_to(2);
let region = Broker::do_purchase(1, u64::max_value()).unwrap();
assert_eq!(balance(1), 900);
// Price is lower, because already two blocks in:
let b = b - 100;
assert_eq!(balance(1), b);
assert_ok!(Broker::do_assign(region, None, 1001, Final));
// Should now be renewable.
advance_to(6);
assert_noop!(Broker::do_purchase(1, u64::max_value()), Error::<Test>::TooEarly);
let core = Broker::do_renew(1, region.core).unwrap();
assert_eq!(balance(1), 800);
let b = b - 100;
assert_eq!(balance(1), b);
advance_to(8);
assert_noop!(Broker::do_purchase(1, u64::max_value()), Error::<Test>::SoldOut);
advance_to(12);
assert_ok!(Broker::do_renew(1, core));
assert_eq!(balance(1), 690);
let b = b - 101;
assert_eq!(balance(1), b);
});
}

Expand Down Expand Up @@ -916,7 +921,8 @@ fn short_leases_are_cleaned() {

#[test]
fn leases_can_be_renewed() {
TestExt::new().endow(1, 1000).execute_with(|| {
let initial_balance = 100_000;
TestExt::new().endow(1, initial_balance).execute_with(|| {
// Timeslice period is 2.
//
// Sale 1 starts at block 7, Sale 2 starts at 13.
Expand All @@ -933,7 +939,7 @@ fn leases_can_be_renewed() {
assert_eq!(
PotentialRenewals::<Test>::get(PotentialRenewalId { core: 0, when: 10 }),
Some(PotentialRenewalRecord {
price: 100,
price: 5100,
completion: CompletionStatus::Complete(
vec![ScheduleItem { mask: CoreMask::complete(), assignment: Task(2001) }]
.try_into()
Expand All @@ -947,8 +953,8 @@ fn leases_can_be_renewed() {
// Advance to sale period 2, where we can renew.
advance_sale_period();
assert_ok!(Broker::do_renew(1, 0));
// We renew for the base price of the previous sale period.
assert_eq!(balance(1), 900);
// We renew for the price of the previous sale period.
assert_eq!(balance(1), initial_balance - 5100);

// We just renewed for this period.
advance_sale_period();
Expand Down Expand Up @@ -1274,7 +1280,7 @@ fn config_works() {
/// Ensure that a lease that ended before `start_sales` was called can be renewed.
#[test]
fn renewal_works_leases_ended_before_start_sales() {
TestExt::new().endow(1, 1000).execute_with(|| {
TestExt::new().endow(1, 100_000).execute_with(|| {
let config = Configuration::<Test>::get().unwrap();

// This lease is ended before `start_stales` was called.
Expand Down Expand Up @@ -1304,15 +1310,15 @@ fn renewal_works_leases_ended_before_start_sales() {
let new_core = Broker::do_renew(1, 0).unwrap();
// Renewing the active lease doesn't work.
assert_noop!(Broker::do_renew(1, 1), Error::<Test>::SoldOut);
assert_eq!(balance(1), 900);
assert_eq!(balance(1), 94900);

// This intializes the third sale and the period 2.
advance_sale_period();
let new_core = Broker::do_renew(1, new_core).unwrap();

// Renewing the active lease doesn't work.
assert_noop!(Broker::do_renew(1, 0), Error::<Test>::SoldOut);
assert_eq!(balance(1), 800);
assert_eq!(balance(1), 94800);

// All leases should have ended
assert!(Leases::<Test>::get().is_empty());
Expand All @@ -1324,7 +1330,7 @@ fn renewal_works_leases_ended_before_start_sales() {
assert_eq!(0, Broker::do_renew(1, new_core).unwrap());
// Renew the task 2.
assert_eq!(1, Broker::do_renew(1, 0).unwrap());
assert_eq!(balance(1), 600);
assert_eq!(balance(1), 94699);

// This intializes the fifth sale and the period 4.
advance_sale_period();
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/broker/src/tick_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ impl<T: Config> Pallet<T> {
let leadin_length = config.leadin_length;
let ideal_cores_sold = (config.ideal_bulk_proportion * cores_offered as u32) as u16;
let sellout_price = if cores_offered > 0 {
// No core sold -> price was too high.
// No core sold -> price was too high -> we have to adjust downwards.
Some(new_prices.price)
} else {
None
Expand Down