use arrays for fee estimates, fix test build

This commit is contained in:
Aaron Blankstein
2021-10-13 14:49:49 -05:00
parent 1dfd21a250
commit c511fd5332
10 changed files with 64 additions and 49 deletions

View File

@@ -50,6 +50,7 @@ jobs:
- tests::neon_integrations::filter_long_runtime_tx_integration_test
- tests::neon_integrations::mining_transactions_is_fair
steps:
- uses: actions/checkout@v2
- name: Download docker image
uses: actions/download-artifact@v2
with:
@@ -74,6 +75,7 @@ jobs:
- tests::neon_integrations::atlas_integration_test
- tests::neon_integrations::atlas_stress_integration_test
steps:
- uses: actions/checkout@v2
- name: Download docker image
uses: actions/download-artifact@v2
with:

View File

@@ -8,14 +8,14 @@
"write_length": 1020
},
"estimated_cost_scalar": 14,
"estimated_fee_rates": {
"high": 10,
"low": 1.2410714285714286,
"middle": 8.958333333333332
},
"estimated_fees": {
"high": 140,
"low": 17,
"middle": 125
}
"estimated_fee_rates": [
1.2410714285714286,
8.958333333333332,
10
],
"estimated_fees": [
17,
125,
140
]
}

View File

@@ -25,23 +25,15 @@
}
},
"estimated_fee_rates": {
"type": "object",
"additionalProperties": false,
"required": ["high", "low", "middle"],
"properties": {
"high": { "type": "number" },
"low": { "type": "number" },
"middle": { "type": "number" }
"type": "array",
"items": {
"type": "number"
}
},
"estimated_fees": {
"type": "object",
"additionalProperties": false,
"required": ["high", "low", "middle"],
"properties": {
"high": { "type": "integer" },
"low": { "type": "integer" },
"middle": { "type": "integer" }
"type": "array",
"items": {
"type": "integer"
}
}
}

View File

@@ -322,7 +322,6 @@ paths:
`fee_rate` x `cost_scalar_change_by_byte` x (`final_size` - `estimated_size`)
description:
operationId: post_fee_transaction
requestBody:
content:

View File

@@ -65,6 +65,12 @@ fn saturating_f64_math(res: f64) -> f64 {
}
}
impl FeeRateEstimate {
pub fn to_vec(self) -> Vec<f64> {
vec![self.low, self.middle, self.high]
}
}
impl Mul<f64> for FeeRateEstimate {
type Output = FeeRateEstimate;

View File

@@ -49,6 +49,10 @@ impl CostMetric for TestCostMetric {
fn from_len(&self, _tx_len: u64) -> u64 {
1
}
fn change_per_byte(&self) -> f64 {
0f64
}
}
#[test]

View File

@@ -47,6 +47,10 @@ impl CostMetric for TestCostMetric {
fn from_len(&self, _tx_len: u64) -> u64 {
1
}
fn change_per_byte(&self) -> f64 {
0f64
}
}
#[test]

View File

@@ -1043,14 +1043,18 @@ impl RPCFeeEstimate {
low: estimated_fees_f64.low as u64,
}
}
pub fn to_vec(self) -> Vec<u64> {
vec![self.low, self.middle, self.high]
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RPCFeeEstimateResponse {
pub estimated_cost: ExecutionCost,
pub estimated_cost_scalar: u64,
pub estimated_fees: RPCFeeEstimate,
pub estimated_fee_rates: FeeRateEstimate,
pub estimated_fees: Vec<u64>,
pub estimated_fee_rates: Vec<f64>,
pub cost_scalar_change_by_byte: f64,
}

View File

@@ -1631,7 +1631,8 @@ impl ConversationHttp {
}
};
let estimated_fees = RPCFeeEstimate::estimate_fees(scalar_cost, fee_rates.clone());
let estimated_fees =
RPCFeeEstimate::estimate_fees(scalar_cost, fee_rates.clone()).to_vec();
let response = HttpResponseType::TransactionFeeEstimation(
response_metadata,
@@ -1639,7 +1640,7 @@ impl ConversationHttp {
estimated_cost,
estimated_fees,
estimated_cost_scalar: scalar_cost,
estimated_fee_rates: fee_rates,
estimated_fee_rates: fee_rates.to_vec(),
cost_scalar_change_by_byte: metric.change_per_byte(),
},
);

View File

@@ -856,15 +856,16 @@ fn integration_test_get_info() {
// the estimated scalar should still be non-zero, because the length of the tx goes into this field.
assert!(res.get("estimated_cost_scalar").unwrap().as_u64().unwrap() > 0);
let estimated_fee_rates = res.get("estimated_fee_rates").expect("Should have an estimated_fee_rates field");
let estimated_fees = res.get("estimated_fees").expect("Should have an estimated_fees field");
assert!(estimated_fee_rates.get("high").is_some(), "Should have 'high' field");
assert!(estimated_fee_rates.get("low").is_some(), "Should have 'low' field");
assert!(estimated_fee_rates.get("middle").is_some(), "Should have 'middle' field");
assert!(estimated_fees.get("high").is_some(), "Should have 'high' field");
assert!(estimated_fees.get("low").is_some(), "Should have 'low' field");
assert!(estimated_fees.get("middle").is_some(), "Should have 'middle' field");
let estimated_fee_rates = res.get("estimated_fee_rates").expect("Should have an estimated_fee_rates field")
.as_array()
.expect("Fees should be array");
let estimated_fees = res.get("estimated_fees").expect("Should have an estimated_fees field")
.as_array()
.expect("Fees should be array");
assert!(estimated_fee_rates.len() == 3, "Fee rates should be length 3 array");
assert!(estimated_fees.len() == 3, "Fees should be length 3 array");
let tx_payload = TransactionPayload::from(TransactionContractCall {
address: contract_addr.clone(),
@@ -901,15 +902,15 @@ fn integration_test_get_info() {
let estimated_cost_scalar = res.get("estimated_cost_scalar").unwrap().as_u64().unwrap();
assert!(estimated_cost_scalar > 0);
let estimated_fee_rates = res.get("estimated_fee_rates").expect("Should have an estimated_fee_rates field");
let estimated_fees = res.get("estimated_fees").expect("Should have an estimated_fees field");
let estimated_fee_rates = res.get("estimated_fee_rates").expect("Should have an estimated_fee_rates field")
.as_array()
.expect("Fees should be array");
let estimated_fees = res.get("estimated_fees").expect("Should have an estimated_fees field")
.as_array()
.expect("Fees should be array");
assert!(estimated_fee_rates.get("high").is_some(), "Should have 'high' field");
assert!(estimated_fee_rates.get("low").is_some(), "Should have 'low' field");
assert!(estimated_fee_rates.get("middle").is_some(), "Should have 'middle' field");
assert!(estimated_fees.get("high").is_some(), "Should have 'high' field");
assert!(estimated_fees.get("low").is_some(), "Should have 'low' field");
assert!(estimated_fees.get("middle").is_some(), "Should have 'middle' field");
assert!(estimated_fee_rates.len() == 3, "Fee rates should be length 3 array");
assert!(estimated_fees.len() == 3, "Fees should be length 3 array");
let tx_payload = TransactionPayload::from(TransactionContractCall {
address: contract_addr.clone(),
@@ -946,13 +947,15 @@ fn integration_test_get_info() {
assert!(estimated_cost_scalar > 0);
assert!(new_estimated_cost_scalar > estimated_cost_scalar, "New scalar estimate should be higher because of the tx length increase");
let new_estimated_fees = res.get("estimated_fees").expect("Should have an estimated_fees field");
let new_estimated_fees = res.get("estimated_fees").expect("Should have an estimated_fees field")
.as_array()
.expect("Fees should be array");
assert!(new_estimated_fees.get("high").unwrap().as_u64().unwrap() >= estimated_fees.get("high").unwrap().as_u64().unwrap(),
assert!(new_estimated_fees[2].as_u64().unwrap() >= estimated_fees[2].as_u64().unwrap(),
"Supplying an estimated tx length should increase the estimated fees");
assert!(new_estimated_fees.get("low").unwrap().as_u64().unwrap() >= estimated_fees.get("low").unwrap().as_u64().unwrap(),
assert!(new_estimated_fees[0].as_u64().unwrap() >= estimated_fees[0].as_u64().unwrap(),
"Supplying an estimated tx length should increase the estimated fees");
assert!(new_estimated_fees.get("middle").unwrap().as_u64().unwrap() >= estimated_fees.get("middle").unwrap().as_u64().unwrap(),
assert!(new_estimated_fees[1].as_u64().unwrap() >= estimated_fees[1].as_u64().unwrap(),
"Supplying an estimated tx length should increase the estimated fees");
},
_ => {},