Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
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
Introduce separate setters for the fees.
  • Loading branch information
pepyakin committed Feb 26, 2020
commit bdeca7be0b21a9faffe03929f906d4e3c3570164
58 changes: 34 additions & 24 deletions frame/transaction-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,16 @@ mod tests {
}

impl ExtBuilder {
pub fn fees(mut self, base: u64, byte: u64, weight: u64) -> Self {
self.base_fee = base;
self.byte_fee = byte;
self.weight_to_fee = weight;
pub fn base_fee(mut self, base_fee: u64) -> Self {
self.base_fee = base_fee;
self
}
pub fn byte_fee(mut self, byte_fee: u64) -> Self {
self.byte_fee = byte_fee;
self
}
pub fn weight_fee(mut self, weight_to_fee: u64) -> Self {
self.weight_to_fee = weight_to_fee;
self
}
pub fn balance_factor(mut self, factor: u64) -> Self {
Expand Down Expand Up @@ -419,9 +425,9 @@ mod tests {

#[test]
fn signed_extension_transaction_payment_work() {
ExtBuilder::default()
.balance_factor(10) // 100
.fees(5, 1, 1) // 5 fixed, 1 per byte, 1 per weight
ExtBuilder::default()
.balance_factor(10)
.base_fee(5)
.build()
.execute_with(||
{
Expand All @@ -444,9 +450,9 @@ mod tests {

#[test]
fn signed_extension_transaction_payment_is_bounded() {
ExtBuilder::default()
ExtBuilder::default()
.balance_factor(1000)
.fees(0, 0, 1)
.byte_fee(0)
.build()
.execute_with(||
{
Expand All @@ -467,7 +473,7 @@ mod tests {
#[test]
fn signed_extension_allows_free_transactions() {
ExtBuilder::default()
.fees(100, 1, 1)
.base_fee(100)
.balance_factor(0)
.build()
.execute_with(||
Expand Down Expand Up @@ -506,7 +512,7 @@ mod tests {
#[test]
fn signed_ext_length_fee_is_also_updated_per_congestion() {
ExtBuilder::default()
.fees(5, 1, 1)
.base_fee(5)
.balance_factor(10)
.build()
.execute_with(||
Expand Down Expand Up @@ -534,7 +540,8 @@ mod tests {
let ext = xt.encode();
let len = ext.len() as u32;
ExtBuilder::default()
.fees(5, 1, 2)
.base_fee(5)
.weight_fee(2)
.build()
.execute_with(||
{
Expand All @@ -561,10 +568,11 @@ mod tests {
#[test]
fn compute_fee_works_without_multiplier() {
ExtBuilder::default()
.fees(100, 10, 1)
.balance_factor(0)
.build()
.execute_with(||
.base_fee(100)
.byte_fee(10)
.balance_factor(0)
.build()
.execute_with(||
{
// Next fee multiplier is zero
assert_eq!(NextFeeMultiplier::get(), Fixed64::from_natural(0));
Expand Down Expand Up @@ -600,10 +608,11 @@ mod tests {
#[test]
fn compute_fee_works_with_multiplier() {
ExtBuilder::default()
.fees(100, 10, 1)
.balance_factor(0)
.build()
.execute_with(||
.base_fee(100)
.byte_fee(10)
.balance_factor(0)
.build()
.execute_with(||
{
// Add a next fee multiplier
NextFeeMultiplier::put(Fixed64::from_rational(1, 2)); // = 1/2 = .5
Expand Down Expand Up @@ -632,10 +641,11 @@ mod tests {
#[test]
fn compute_fee_does_not_overflow() {
ExtBuilder::default()
.fees(100, 10, 1)
.balance_factor(0)
.build()
.execute_with(||
.base_fee(100)
.byte_fee(10)
.balance_factor(0)
.build()
.execute_with(||
{
// Overflow is handled
let dispatch_info = DispatchInfo {
Expand Down