Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
lease_period_index_start + 3, // Last slot
400, // Amount
));
// A bid for another para is counted separately.
assert_ok!(Auctions::bid(
Origin::signed(10),
ParaId::from(2),
1, // Auction Index
lease_period_index_start + 1, // First Slot
lease_period_index_start + 1, // Last slot
555, // Amount
));
assert_eq!(Balances::reserved_balance(&10), 400 + 555);
// Slot 2 for 800 from 20, overtaking 10's bid
assert_ok!(Auctions::bid(
Origin::signed(20),
ParaId::from(1),
1, // Auction Index
lease_period_index_start + 1, // First Slot
lease_period_index_start + 1, // Last slot
800, // Amount
));
// Slot 3 for 200 from 20
assert_ok!(Auctions::bid(
Origin::signed(20),
ParaId::from(1),
1, // Auction Index
lease_period_index_start + 2, // First Slot
lease_period_index_start + 2, // Last slot
200, // Amount
));
// Finish the auction
run_to_block(110);
// Should have won the lease periods
assert_eq!(
slots::Leases::<Test>::get(ParaId::from(1)),
// -- 1 --- 2 --- 3 ---------- 4 -------------- 5 -------------- 6 -------------- 7 -------
vec![None, None, None, Some((10, 100)), Some((20, 800)), Some((20, 200)), Some((10, 400))],
);
// Appropriate amount is reserved (largest of the values)
assert_eq!(Balances::reserved_balance(&10), 400);
// Appropriate amount is reserved (largest of the values)
assert_eq!(Balances::reserved_balance(&20), 800);
// Progress through the leases and note the correct amount of balance is reserved.
run_to_block(400);
assert_eq!(
slots::Leases::<Test>::get(ParaId::from(1)),
// --------- 4 -------------- 5 -------------- 6 -------------- 7 -------
vec![Some((10, 100)), Some((20, 800)), Some((20, 200)), Some((10, 400))],
);
// Nothing changed.
assert_eq!(Balances::reserved_balance(&10), 400);
assert_eq!(Balances::reserved_balance(&20), 800);
// Lease period 4 is done, but nothing is unreserved since user 1 has a debt on lease 7
run_to_block(500);
assert_eq!(
slots::Leases::<Test>::get(ParaId::from(1)),
// --------- 5 -------------- 6 -------------- 7 -------
vec![Some((20, 800)), Some((20, 200)), Some((10, 400))],
);
// Nothing changed.
assert_eq!(Balances::reserved_balance(&10), 400);
assert_eq!(Balances::reserved_balance(&20), 800);
// Lease period 5 is done, and 20 will unreserve down to 200.
run_to_block(600);
assert_eq!(
slots::Leases::<Test>::get(ParaId::from(1)),
// --------- 6 -------------- 7 -------
vec![Some((20, 200)), Some((10, 400))],
);
assert_eq!(Balances::reserved_balance(&10), 400);
assert_eq!(Balances::reserved_balance(&20), 200);
// Lease period 6 is done, and 20 will unreserve everything.
run_to_block(700);
assert_eq!(
slots::Leases::<Test>::get(ParaId::from(1)),
// --------- 7 -------
vec![Some((10, 400))],
);
assert_eq!(Balances::reserved_balance(&10), 400);
assert_eq!(Balances::reserved_balance(&20), 0);
// All leases are done. Everything is unreserved.
run_to_block(800);
assert_eq!(slots::Leases::<Test>::get(ParaId::from(1)), vec![]);
assert_eq!(Balances::reserved_balance(&10), 0);
assert_eq!(Balances::reserved_balance(&20), 0);
});
}