Skip to content

Commit 82d10ce

Browse files
committed
fix: fix unable to find account error before txn
1 parent 259c80b commit 82d10ce

File tree

1 file changed

+80
-19
lines changed

1 file changed

+80
-19
lines changed

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

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,40 +65,70 @@ async fn main() -> Result<(), anyhow::Error> {
6565

6666
// Try different approaches to match what the faucet expects
6767
let client = reqwest::Client::new();
68+
let pub_key_hex = hex::encode(sender.public_key().to_bytes());
6869

69-
// First try GET with query parameters (some faucets prefer this)
70+
// First try POST with pub_key (preferred)
71+
let mut funded = false;
7072
let response = client
71-
.get(&format!("{}/mint", faucet_url))
72-
.query(&[
73-
("address", sender.address().to_string()),
73+
.post(&format!("{}/mint", faucet_url))
74+
.form(&[
75+
("pub_key", pub_key_hex.clone()),
7476
("amount", "1000000".to_string()),
77+
("return_txns", "true".to_string()),
7578
])
7679
.send()
7780
.await
78-
.context("Failed to send faucet GET request")?;
79-
81+
.context("Failed to send faucet POST request with pub_key")?;
8082
let status = response.status();
81-
if !status.is_success() {
82-
// If GET fails, try POST with form data
83-
println!("GET request failed with status {}, trying POST with form data...", status);
84-
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
8589
let response = client
86-
.post(&format!("{}/mint", faucet_url))
87-
.form(&[
90+
.get(&format!("{}/mint", faucet_url))
91+
.query(&[
8892
("address", sender.address().to_string()),
8993
("amount", "1000000".to_string()),
94+
("return_txns", "true".to_string()),
9095
])
9196
.send()
9297
.await
93-
.context("Failed to send faucet POST request")?;
94-
98+
.context("Failed to send faucet GET request with address")?;
9599
let status = response.status();
96-
if !status.is_success() {
100+
if status.is_success() {
101+
funded = true;
102+
} else {
97103
let error_text = response.text().await.unwrap_or_default();
98104
return Err(anyhow::anyhow!("Faucet request failed with status {}: {}", status, error_text));
99105
}
100106
}
101107

108+
if funded {
109+
println!("Sender account funded request accepted by faucet");
110+
}
111+
112+
// Wait until the account exists on-chain (poll a few times)
113+
let mut created = false;
114+
for attempt in 1..=10 {
115+
match rest_client.get_account(sender.address()).await {
116+
Ok(account_info) => {
117+
println!("Account now exists on-chain with sequence {} (attempt {})", account_info.inner().sequence_number, attempt);
118+
created = true;
119+
break;
120+
}
121+
Err(_) => {
122+
println!("Waiting for account creation on-chain... attempt {}", attempt);
123+
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
124+
}
125+
}
126+
}
127+
128+
if !created {
129+
return Err(anyhow::anyhow!("Sender account not found on-chain after faucet funding"));
130+
}
131+
102132
println!("Sender account funded successfully via faucet");
103133

104134
// Create the beneficiary account (just create, no funding needed for this test)
@@ -241,10 +271,41 @@ async fn main() -> Result<(), anyhow::Error> {
241271
// Execute test transaction
242272
println!("Executing test transaction...");
243273

244-
let test_txn = coin_client
245-
.transfer(&mut sender, beneficiary.address(), 1_000, None)
246-
.await
247-
.context("Failed to submit test transaction")?;
274+
// Debug: Check account sequence number and other details
275+
println!("Sender account details:");
276+
println!(" Address: {}", sender.address());
277+
println!(" Sequence number: {}", sender.sequence_number());
278+
println!(" Public key: {:?}", sender.public_key());
279+
280+
// Try to get account info from the chain
281+
match rest_client.get_account(sender.address()).await {
282+
Ok(account_info) => {
283+
println!(" On-chain sequence number: {}", account_info.inner().sequence_number);
284+
println!(" On-chain authentication key: {:?}", account_info.inner().authentication_key);
285+
}
286+
Err(e) => {
287+
println!(" [WARN] Could not get on-chain account info: {}", e);
288+
}
289+
}
290+
291+
println!("Beneficiary address: {}", beneficiary.address());
292+
293+
// Try the transaction with better error handling
294+
let test_txn = match coin_client.transfer(&mut sender, beneficiary.address(), 1_000, None).await {
295+
Ok(txn) => {
296+
println!("Transaction submitted successfully with hash: {:?}", txn);
297+
txn
298+
}
299+
Err(e) => {
300+
println!("[ERROR] Transaction submission failed: {}", e);
301+
println!("[DEBUG] This might be due to:");
302+
println!(" - Account not properly funded");
303+
println!(" - Sequence number mismatch");
304+
println!(" - Network connectivity issues");
305+
println!(" - Gas price/limit issues");
306+
return Err(e.context("Failed to submit test transaction"));
307+
}
308+
};
248309

249310
rest_client
250311
.wait_for_transaction(&test_txn)

0 commit comments

Comments
 (0)