Skip to content

Commit 93bbfe1

Browse files
committed
fix: rollback to funding using testnet
1 parent 82d10ce commit 93bbfe1

File tree

1 file changed

+53
-48
lines changed

1 file changed

+53
-48
lines changed

networks/movement/movement-client/src/bin/e2e/e2e_ggp_deprecation.rs

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
use anyhow::Context;
2+
use aptos_sdk::rest_client::{
3+
aptos_api_types::{Address, EntryFunctionId, IdentifierWrapper, MoveModuleId, ViewRequest},
4+
};
5+
use aptos_sdk::types::account_address::AccountAddress;
26
use movement_client::{
37
coin_client::CoinClient,
48
rest_client::Client,
59
types::LocalAccount,
610
};
7-
use aptos_sdk::rest_client::aptos_api_types::{ViewRequest, EntryFunctionId, MoveModuleId, Address, IdentifierWrapper};
8-
use movement_client::types::account_address::AccountAddress;
9-
use std::str::FromStr;
1011
use once_cell::sync::Lazy;
12+
use std::str::FromStr;
1113
use url::Url;
1214
use reqwest;
1315

@@ -17,7 +19,11 @@ static SUZUKA_CONFIG: Lazy<movement_config::Config> = Lazy::new(|| {
1719
config
1820
});
1921

20-
static NODE_URL: Lazy<Url> = Lazy::new(|| {
22+
#[tokio::main]
23+
async fn main() -> Result<(), anyhow::Error> {
24+
println!("Starting e2e_ggp_deprecation test...");
25+
26+
// Connect to the node
2127
let node_connection_address = SUZUKA_CONFIG
2228
.execution_config
2329
.maptos_config
@@ -30,19 +36,11 @@ static NODE_URL: Lazy<Url> = Lazy::new(|| {
3036
.client
3137
.maptos_rest_connection_port
3238
.clone();
33-
3439
let node_connection_url = format!("http://{}:{}", node_connection_address, node_connection_port);
35-
Url::parse(node_connection_url.as_str()).unwrap()
36-
});
37-
38-
39-
40-
#[tokio::main]
41-
async fn main() -> Result<(), anyhow::Error> {
42-
println!("Starting e2e_ggp_deprecation test...");
4340

44-
println!("Connecting to node at: {}", NODE_URL.as_str());
45-
let rest_client = Client::new(NODE_URL.clone());
41+
println!("Connecting to node at: {}", node_connection_url);
42+
43+
let rest_client = Client::new(Url::from_str(&node_connection_url)?);
4644
let coin_client = CoinClient::new(&rest_client);
4745

4846
println!("Attempting to get chain info...");
@@ -54,73 +52,80 @@ async fn main() -> Result<(), anyhow::Error> {
5452
println!("Created test accounts");
5553
println!("Sender address: {}, Beneficiary address: {}", sender.address(), beneficiary.address());
5654

57-
// Fund the sender account using the faucet directly
58-
println!("Funding sender account via faucet...");
55+
// Fund the sender account using the testnet faucet
56+
println!("Funding sender account via testnet faucet...");
5957

6058
let faucet_url = if let Ok(override_url) = std::env::var("MOVEMENT_FAUCET_URL") {
6159
override_url
6260
} else {
63-
"https://faucet.movementnetwork.xyz".to_string()
61+
"https://faucet.testnet.movementinfra.xyz".to_string()
6462
};
6563

6664
// Try different approaches to match what the faucet expects
6765
let client = reqwest::Client::new();
68-
let pub_key_hex = hex::encode(sender.public_key().to_bytes());
6966

70-
// First try POST with pub_key (preferred)
71-
let mut funded = false;
67+
// First try GET with address (some faucets prefer this)
7268
let response = client
73-
.post(&format!("{}/mint", faucet_url))
74-
.form(&[
75-
("pub_key", pub_key_hex.clone()),
69+
.get(&format!("{}/mint", faucet_url))
70+
.query(&[
71+
("address", sender.address().to_string()),
7672
("amount", "1000000".to_string()),
7773
("return_txns", "true".to_string()),
7874
])
7975
.send()
8076
.await
81-
.context("Failed to send faucet POST request with pub_key")?;
77+
.context("Failed to send faucet GET request")?;
78+
8279
let status = response.status();
83-
if status.is_success() {
84-
funded = true;
85-
} else {
86-
let error_text = response.text().await.unwrap_or_default();
87-
println!("[WARN] Faucet POST(pub_key) failed {}: {}", status, error_text);
88-
// Try GET with address as fallback
80+
println!("Faucet GET response status: {}", status);
81+
82+
if !status.is_success() {
83+
// If GET fails, try POST with form data
84+
println!("GET request failed with status {}, trying POST with form data...", status);
8985
let response = client
90-
.get(&format!("{}/mint", faucet_url))
91-
.query(&[
86+
.post(&format!("{}/mint", faucet_url))
87+
.form(&[
9288
("address", sender.address().to_string()),
9389
("amount", "1000000".to_string()),
9490
("return_txns", "true".to_string()),
9591
])
9692
.send()
9793
.await
98-
.context("Failed to send faucet GET request with address")?;
94+
.context("Failed to send faucet POST request")?;
9995
let status = response.status();
100-
if status.is_success() {
101-
funded = true;
102-
} else {
96+
println!("Faucet POST response status: {}", status);
97+
if !status.is_success() {
10398
let error_text = response.text().await.unwrap_or_default();
10499
return Err(anyhow::anyhow!("Faucet request failed with status {}: {}", status, error_text));
105100
}
106101
}
107102

108-
if funded {
109-
println!("Sender account funded request accepted by faucet");
110-
}
103+
// Get the response body to see what the faucet actually returned
104+
let response_text = response.text().await.unwrap_or_default();
105+
println!("Faucet response body: {}", response_text);
111106

112-
// Wait until the account exists on-chain (poll a few times)
107+
println!("Sender account funded request accepted by faucet");
108+
109+
// Wait longer for account creation and add more debugging
110+
println!("Waiting for account to appear on-chain...");
113111
let mut created = false;
114-
for attempt in 1..=10 {
112+
for attempt in 1..=20 { // Increased from 10 to 20 attempts
113+
println!("Checking account existence... attempt {}/20", attempt);
115114
match rest_client.get_account(sender.address()).await {
116115
Ok(account_info) => {
117-
println!("Account now exists on-chain with sequence {} (attempt {})", account_info.inner().sequence_number, attempt);
116+
println!("✅ Account now exists on-chain!");
117+
println!(" Sequence number: {}", account_info.inner().sequence_number);
118+
println!(" Authentication key: {:?}", account_info.inner().authentication_key);
119+
println!(" Created in attempt {}", attempt);
118120
created = true;
119121
break;
120122
}
121-
Err(_) => {
122-
println!("Waiting for account creation on-chain... attempt {}", attempt);
123-
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
123+
Err(e) => {
124+
println!("❌ Account not found yet (attempt {}/20): {}", attempt, e);
125+
if attempt < 20 {
126+
println!("Waiting 1 second before next check...");
127+
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await; // Increased from 500ms to 1s
128+
}
124129
}
125130
}
126131
}
@@ -129,11 +134,11 @@ async fn main() -> Result<(), anyhow::Error> {
129134
return Err(anyhow::anyhow!("Sender account not found on-chain after faucet funding"));
130135
}
131136

132-
println!("Sender account funded successfully via faucet");
137+
println!("Sender account funded successfully via testnet faucet");
133138

134139
// Create the beneficiary account (just create, no funding needed for this test)
135140
println!("Creating beneficiary account...");
136-
// Created locally; on-chain creation occurs on first transfer
141+
// For now, just create the account locally - it will be created when first transaction is sent to it
137142

138143
// Test 1: Verify new fee collection mechanism
139144
println!("=== Test 1: Verifying new fee collection mechanism ===");

0 commit comments

Comments
 (0)