Skip to content

Commit 1400ffa

Browse files
committed
better points API with its test
1 parent 5f1c00b commit 1400ffa

File tree

4 files changed

+44
-21
lines changed

4 files changed

+44
-21
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "dkn-compute-launcher"
33
edition = "2021"
4-
version = "0.1.13"
4+
version = "0.1.14"
55
license = "Apache-2.0"
66
readme = "README.md"
77
description = "Dria Compute Node Launcher"

src/commands/points.rs

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1+
use colored::Colorize;
12
use eyre::Context;
23

34
use crate::utils::{DriaEnv, LAUNCHER_USER_AGENT};
45

5-
const POINTS_API_BASE_URL: &str =
6-
"https://mainnet.dkn.dria.co/dashboard/supply/v0/leaderboard/steps";
6+
const POINTS_API_BASE_URL: &str = "https://mainnet.dkn.dria.co/points/v0/total/node/";
77

88
#[derive(Debug, serde::Deserialize)]
99
pub struct PointsRes {
1010
/// Indicates in which top percentile your points are.
11-
///
12-
/// TODO: fix this in new API
13-
/// TODO: sometimes returned as `null``
14-
pub percentile: Option<String>,
11+
pub percentile: usize,
1512
/// The total number of points you have accumulated.
1613
pub score: f64,
1714
}
@@ -24,9 +21,30 @@ pub async fn show_points() -> eyre::Result<()> {
2421
dria_env.ask_for_key_if_required()?;
2522
let (_, _, address) = dria_env.get_account()?;
2623

27-
// the address can have 0x or not, we enforce it ourselves here
24+
let points = get_points(&address)
25+
.await
26+
.wrap_err("could not get points")?;
27+
28+
if points.score == 0.0 {
29+
eprintln!(
30+
"You have not accumulated any {} yet.",
31+
"$DRIA points".purple()
32+
);
33+
} else {
34+
eprintln!(
35+
"You have accumulated {} {}, which puts you in the top {}%.",
36+
points.score,
37+
"$DRIA points".purple(),
38+
points.percentile
39+
);
40+
}
41+
42+
Ok(())
43+
}
44+
45+
async fn get_points(address: &str) -> eyre::Result<PointsRes> {
2846
let url = format!(
29-
"{}?address=0x{}",
47+
"{}/0x{}",
3048
POINTS_API_BASE_URL,
3149
address.trim_start_matches("0x")
3250
);
@@ -47,15 +65,18 @@ pub async fn show_points() -> eyre::Result<()> {
4765
.await
4866
.wrap_err("could not parse body")?;
4967

50-
if points.score == 0.0 {
51-
eprintln!("You have not accumulated any $DRIA points yet.");
52-
} else {
53-
eprintln!(
54-
"You have accumulated {} $DRIA points, which puts you in the top {}%.",
55-
points.score,
56-
points.percentile.unwrap_or_else(|| "100".to_string())
57-
);
58-
}
68+
Ok(points)
69+
}
5970

60-
Ok(())
71+
#[cfg(test)]
72+
mod tests {
73+
use super::*;
74+
75+
#[tokio::test]
76+
async fn test_get_points() {
77+
let address = "0x1234567890abcdef1234567890abcdef12345678";
78+
let points = get_points(address).await.unwrap();
79+
assert!(points.score >= 0.0);
80+
assert!(points.percentile <= 100);
81+
}
6182
}

src/utils/referrals.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,21 +197,23 @@ mod tests {
197197
use super::*;
198198

199199
#[tokio::test]
200+
#[ignore]
200201
async fn test_health() {
201202
let ok = ReferralsClient::default().healthcheck().await;
202203
assert!(ok);
203204
}
204205

205206
#[tokio::test]
207+
#[ignore]
206208
async fn test_get_referrals() {
207209
let _response = ReferralsClient::default()
208210
.get_referrals("3b64855e6f0cacca01089387c628e6540619ce07")
209211
.await
210212
.unwrap();
211-
// TODO: !!!
212213
}
213214

214215
#[tokio::test]
216+
#[ignore]
215217
async fn test_get_referred_by() {
216218
let _response = ReferralsClient::default()
217219
.get_referred_by("3b64855e6f0cacca01089387c628e6540619ce07")

0 commit comments

Comments
 (0)