Merge branch 'bug-volume' into 'master'
bug: Fix volume for periods with no trades See merge request riftenlabs/riftenlabs-indexer!32
This commit is contained in:
commit
821583b6e2
2 changed files with 36 additions and 4 deletions
|
|
@ -538,7 +538,7 @@ pub fn get_total_volume_sats(
|
|||
) -> anyhow::Result<i64> {
|
||||
let sql = "
|
||||
SELECT
|
||||
SUM(ABS(phe.sats_delta)) AS total_volume_sats
|
||||
COALESCE(SUM(ABS(phe.sats_delta)), 0) AS total_volume_sats
|
||||
FROM pool_history_entry phe
|
||||
JOIN pool p ON phe.pool = p.creation_utxo
|
||||
JOIN tx ON phe.txid = tx.txid
|
||||
|
|
@ -560,8 +560,8 @@ pub fn get_token_volume_sats(
|
|||
) -> anyhow::Result<(i64, i64)> {
|
||||
let sql = "
|
||||
SELECT
|
||||
SUM(ABS(phe.sats_delta)) AS token_volume_sats,
|
||||
SUM(ABS(phe.token_delta)) AS token_volume_tokens
|
||||
COALESCE(SUM(ABS(phe.sats_delta)), 0) AS token_volume_sats,
|
||||
COALESCE(SUM(ABS(phe.token_delta)), 0) AS token_volume_tokens
|
||||
FROM pool_history_entry phe
|
||||
JOIN pool p ON phe.pool = p.creation_utxo
|
||||
JOIN tx ON phe.txid = tx.txid
|
||||
|
|
@ -576,3 +576,35 @@ pub fn get_token_volume_sats(
|
|||
|
||||
Ok((sats_volume, token_volume))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::db::cauldron::prepare_tables;
|
||||
use crate::utiltest::mock_db_pool;
|
||||
use rusqlite::Connection;
|
||||
|
||||
fn setup_test_db(conn: &Connection) {
|
||||
prepare_tables(conn);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_volume_no_trades_in_period() {
|
||||
// tests an issue where volume function wouild fail if no trades exist in the time period
|
||||
let mock_db = mock_db_pool(setup_test_db);
|
||||
let conn = mock_db.cauldron_r.get().unwrap();
|
||||
|
||||
let start_timestamp = 1755508856u64;
|
||||
let end_timestamp = 1755595256u64;
|
||||
let token_id = "f6677f3d3805d70949b375d36e094ff0ec9ece2a2cb1fde6d8b0e90b368f1f63";
|
||||
|
||||
let result = get_token_volume_sats(&conn, start_timestamp, end_timestamp, token_id);
|
||||
let (sats_volume, token_volume) = result.unwrap();
|
||||
assert_eq!(sats_volume, 0);
|
||||
assert_eq!(token_volume, 0);
|
||||
|
||||
let result = get_total_volume_sats(&conn, start_timestamp, end_timestamp);
|
||||
let total_volume = result.unwrap();
|
||||
assert_eq!(total_volume, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ pub(crate) trait PoolVisitor {
|
|||
fn time_filters(
|
||||
filters: &PoolFilters,
|
||||
param_index: usize,
|
||||
) -> (String, Vec<rusqlite::types::ToSqlOutput>) {
|
||||
) -> (String, Vec<rusqlite::types::ToSqlOutput<'_>>) {
|
||||
let now = time_now() as u64;
|
||||
|
||||
let mut clauses: Vec<String> = vec!["1=1".to_string()];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue