Skip to content

Commit 5b51ad9

Browse files
Fix e2e test: Use a small drip amount in CI (#343)
1 parent 9615c1b commit 5b51ad9

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

.github/workflows/e2e.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ jobs:
103103
export FAUCET_TOPUP_REQ_URL="https://github.com/ChainSafe/forest-explorer/discussions/134"
104104
export FAUCET_TX_URL_CALIBNET="https://beryx.io/fil/calibration/"
105105
export FAUCET_TX_URL_MAINNET="https://beryx.io/fil/mainnet/"
106+
# Set to ~0.000000001 tFIL for e2e tests
107+
export CALIBNET_DRIP_AMOUNT=1
106108
107109
corepack enable
108110
yarn --immutable

docs/env_variables.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Environment Variables
2+
3+
This document outlines the environment variables used in the Forest Explorer
4+
project. These variables configure various aspects of the application, such as
5+
URL endpoints and token drip amounts.
6+
7+
| Environment Variable | Description | Default Value |
8+
| ------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------ |
9+
| FAUCET_TOPUP_REQ_URL | URL for faucet top-up requests | https://github.com/ChainSafe/forest-explorer/discussions/134 |
10+
| FAUCET_TX_URL_CALIBNET | Base URL for Calibnet transactions | https://beryx.io/fil/calibration/ |
11+
| FAUCET_TX_URL_MAINNET | Base URL for Mainnet transactions | https://beryx.io/fil/mainnet/ |
12+
| MAINNET_DRIP_AMOUNT | Amount of tokens to drip on Mainnet in nanoFIL | 10000000 (0.01 FIL) |
13+
| CALIBNET_DRIP_AMOUNT | Amount of tokens to drip on Calibnet in nanoFIL | 5000000000 (5 tFIL) |
14+
| CALIBNET_USDFC_DRIP_AMOUNT | Amount of USDFC tokens to drip on Calibnet in nanoUSDFC | 5000000000 (5 tUSDFC) |
15+
| CALIBNET_USDFC_CONTRACT_ADDRESS | Contract address for Calibnet USDFC | 0xb3042734b608a1B16e9e86B374A3f3e389B4cDf0 |

src/faucet/constants.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,31 @@ use std::{str::FromStr as _, sync::LazyLock};
55
use strum::EnumString;
66

77
/// The amount of calibnet FIL to be dripped to the user.
8-
static CALIBNET_DRIP_AMOUNT: LazyLock<TokenAmount> = LazyLock::new(|| TokenAmount::from_whole(5));
8+
static CALIBNET_DRIP_AMOUNT: LazyLock<TokenAmount> = LazyLock::new(|| {
9+
TokenAmount::from_nano(
10+
option_env!("CALIBNET_DRIP_AMOUNT")
11+
.and_then(|s| s.parse::<u64>().ok())
12+
.unwrap_or(5_000_000_000),
13+
)
14+
});
915

1016
/// The amount of mainnet FIL to be dripped to the user. This corresponds to 0.01 FIL.
11-
static MAINNET_DRIP_AMOUNT: LazyLock<TokenAmount> =
12-
LazyLock::new(|| TokenAmount::from_nano(10_000_000));
17+
static MAINNET_DRIP_AMOUNT: LazyLock<TokenAmount> = LazyLock::new(|| {
18+
TokenAmount::from_nano(
19+
option_env!("MAINNET_DRIP_AMOUNT")
20+
.and_then(|s| s.parse::<u64>().ok())
21+
.unwrap_or(10_000_000),
22+
)
23+
});
1324

1425
/// The amount of calibnet `USDFC` to be dripped to the user.
15-
static CALIBNET_USDFC_DRIP_AMOUNT: LazyLock<TokenAmount> =
16-
LazyLock::new(|| TokenAmount::from_whole(5));
26+
static CALIBNET_USDFC_DRIP_AMOUNT: LazyLock<TokenAmount> = LazyLock::new(|| {
27+
TokenAmount::from_nano(
28+
option_env!("CALIBNET_USDFC_DRIP_AMOUNT")
29+
.and_then(|s| s.parse::<u64>().ok())
30+
.unwrap_or(5_000_000_000),
31+
)
32+
});
1733

1834
/// Multiplier to determine the maximum amount of tokens that can be dripped per wallet every [`FaucetInfo::reset_limiter_seconds`].
1935
const MAINNET_PER_WALLET_DRIP_MULTIPLIER: i64 = 1;
@@ -143,18 +159,19 @@ impl FaucetInfo {
143159
/// Returns the base URL for transactions on the given faucet. This is used to link to
144160
/// transaction details in the block explorer.
145161
pub fn transaction_base_url(&self) -> Option<url::Url> {
146-
match self {
162+
let url_str = match self {
147163
FaucetInfo::MainnetFIL => {
148-
option_env!("FAUCET_TX_URL_MAINNET").and_then(|url| url::Url::parse(url).ok())
164+
option_env!("FAUCET_TX_URL_MAINNET").unwrap_or("https://beryx.io/fil/mainnet/")
149165
}
150166
FaucetInfo::CalibnetFIL => {
151-
option_env!("FAUCET_TX_URL_CALIBNET").and_then(|url| url::Url::parse(url).ok())
167+
option_env!("FAUCET_TX_URL_CALIBNET").unwrap_or("https://beryx.io/fil/calibration/")
152168
}
153169
FaucetInfo::CalibnetUSDFC => {
154-
option_env!("FAUCET_TX_URL_CALIBNET").and_then(|url| url::Url::parse(url).ok())
155170
//None // USDFC does not have a transaction base URL for now - to investigate later.
171+
option_env!("FAUCET_TX_URL_CALIBNET").unwrap_or("https://beryx.io/fil/calibration/")
156172
}
157-
}
173+
};
174+
url::Url::parse(url_str).ok()
158175
}
159176

160177
/// Returns the type of token for the given faucet. This is used to determine how the token
@@ -224,7 +241,7 @@ mod tests {
224241
assert_eq!(mainnet_faucet.unit(), "FIL");
225242
assert_eq!(mainnet_faucet.network(), Network::Mainnet);
226243
assert_eq!(mainnet_faucet.secret_key_name(), "SECRET_MAINNET_WALLET");
227-
assert!(mainnet_faucet.transaction_base_url().is_none());
244+
assert!(mainnet_faucet.transaction_base_url().is_some());
228245
assert_eq!(mainnet_faucet.token_type(), TokenType::Native);
229246
assert_eq!(mainnet_faucet.chain_id(), 314);
230247
assert_eq!(mainnet_faucet.max_gas_limit(), 10_000_000);
@@ -251,7 +268,7 @@ mod tests {
251268
assert_eq!(calibnet_fil_faucet.unit(), "tFIL");
252269
assert_eq!(calibnet_fil_faucet.network(), Network::Testnet);
253270
assert_eq!(calibnet_fil_faucet.secret_key_name(), "SECRET_WALLET");
254-
assert!(calibnet_fil_faucet.transaction_base_url().is_none());
271+
assert!(calibnet_fil_faucet.transaction_base_url().is_some());
255272
assert_eq!(calibnet_fil_faucet.token_type(), TokenType::Native);
256273
assert_eq!(calibnet_fil_faucet.chain_id(), 314159);
257274
assert_eq!(calibnet_fil_faucet.max_gas_limit(), 30_000_000);
@@ -284,7 +301,7 @@ mod tests {
284301
calibnet_usdfc_faucet.secret_key_name(),
285302
"SECRET_CALIBNET_USDFC_WALLET"
286303
);
287-
assert!(calibnet_usdfc_faucet.transaction_base_url().is_none());
304+
assert!(calibnet_usdfc_faucet.transaction_base_url().is_some());
288305
assert_eq!(
289306
calibnet_usdfc_faucet.token_type(),
290307
TokenType::Erc20(

src/faucet/views/components/balance.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ pub fn FaucetBalance(faucet: RwSignal<FaucetController>) -> impl IntoView {
1414
}>
1515
{move || {
1616
if faucet.get().is_low_balance() {
17-
let topup_req_url = option_env!("FAUCET_TOPUP_REQ_URL");
17+
let topup_req_url = option_env!("FAUCET_TOPUP_REQ_URL")
18+
.unwrap_or("https://github.com/ChainSafe/forest-explorer/discussions/134");
1819
view! {
1920
<a class="btn-topup" target="_blank" rel="noopener noreferrer" href=topup_req_url>
2021
"Request Faucet Top-up"

0 commit comments

Comments
 (0)