Skip to content

Commit 12c204c

Browse files
committed
refactor(e2e): use faucet to found account in checks/migrator/criteria/transacting
1 parent 58f4299 commit 12c204c

File tree

4 files changed

+62
-18
lines changed

4 files changed

+62
-18
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

checks/migrator/citeria/transacting/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ rust-version = { workspace = true }
1010

1111
[dependencies]
1212
mtma-migrator-test-types = { workspace = true }
13+
anyhow = { workspace = true }
1314
aptos-rest-client = { workspace = true }
1415
aptos-sdk = { workspace = true }
1516
bcs = { workspace = true }
17+
rand = { workspace = true }
1618
tokio = { workspace = true }
1719

1820
[lints]

checks/migrator/citeria/transacting/src/lib.rs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use anyhow::Context;
12
use aptos_sdk::move_types::{
23
identifier::Identifier, language_storage::ModuleId, language_storage::TypeTag,
34
};
@@ -26,7 +27,7 @@ impl MaptosTransferLifecycle {
2627
}
2728

2829
pub fn transfer(
29-
&self,
30+
from_account: &LocalAccount,
3031
to_account: AccountAddress,
3132
amount: u64,
3233
chain_id: ChainId,
@@ -41,12 +42,12 @@ impl MaptosTransferLifecycle {
4142
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() + 10,
4243
chain_id,
4344
)
44-
.sender(self.0.address())
45-
.sequence_number(self.0.sequence_number())
45+
.sender(from_account.address())
46+
.sequence_number(from_account.sequence_number())
4647
.max_gas_amount(5_000)
4748
.gas_unit_price(100);
4849

49-
self.0.sign_with_transaction_builder(transaction_builder)
50+
from_account.sign_with_transaction_builder(transaction_builder)
5051
}
5152
}
5253

@@ -61,33 +62,57 @@ impl Criterionish for MaptosTransferLifecycle {
6162
.await
6263
.map_err(|e| CriterionError::Internal(e.into()))?;
6364

64-
// TODO: fetch the correct chain-id
65-
let chain_id = ChainId::test();
65+
let movement_aptos_faucet_client = movement_aptos_migrator
66+
.wait_for_faucet_client_ready(tokio::time::Duration::from_secs(30))
67+
.await
68+
.map_err(|e| CriterionError::Internal(e.into()))?;
69+
70+
let alice = LocalAccount::generate(&mut rand::rngs::OsRng);
71+
let bob = LocalAccount::generate(&mut rand::rngs::OsRng);
6672

67-
let recipient1 = AccountAddress::random();
68-
let recipient2 = AccountAddress::random();
73+
movement_aptos_faucet_client
74+
.create_account(alice.address())
75+
.await
76+
.context("Failed to create Alice's account")
77+
.map_err(|e| CriterionError::Internal(e.into()))?;
78+
79+
movement_aptos_faucet_client
80+
.create_account(bob.address())
81+
.await
82+
.context("Failed to create Bob's account")
83+
.map_err(|e| CriterionError::Internal(e.into()))?;
84+
85+
let chain_id = movement_aptos_rest_client
86+
.get_index()
87+
.await
88+
.context("Failed to get chain ID")
89+
.map_err(|e| CriterionError::Internal(e.into()))?
90+
.inner()
91+
.chain_id;
92+
let chain_id = ChainId::new(chain_id);
6993

70-
// 1. transfer 1 MOVE to recipient1
71-
let tx1 = self.transfer(recipient1, 100_000_000, chain_id);
94+
// 1. transfer 1 MOVE to Alice
95+
let tx1 =
96+
MaptosTransferLifecycle::transfer(&self.0, alice.address(), 100_000_000, chain_id);
7297

7398
movement_aptos_rest_client.submit_and_wait(&tx1).await.map_err(|e| {
74-
CriterionError::Unsatisfied(format!("Transfer to recipient1 failed: {:?}", e).into())
99+
CriterionError::Unsatisfied(format!("Transfer to Aice failed: {:?}", e).into())
75100
})?;
76101

77-
// 2. transfer 0 MOVE to recipient1
78-
let tx2 = self.transfer(recipient1, 0, chain_id);
102+
// 2. transfer 0 MOVE to Alice
103+
let tx2 = MaptosTransferLifecycle::transfer(&alice, alice.address(), 0, chain_id);
79104

80105
movement_aptos_rest_client.submit_and_wait(&tx2).await.map_err(|e| {
81106
CriterionError::Unsatisfied(
82-
format!("Zero transfer to recipient1 failed: {:?}", e).into(),
107+
format!("Zero transfer from Alice to Alice failed: {:?}", e).into(),
83108
)
84109
})?;
85110

86-
// 3. transfers 0.1 MOVE to recipient2
87-
let tx3 = self.transfer(recipient2, 10_000_000, chain_id);
111+
// 3. transfers 0.1 MOVE to Bob
112+
let tx3 = MaptosTransferLifecycle::transfer(&alice, bob.address(), 10_000_000, chain_id);
88113

89114
movement_aptos_rest_client.submit_and_wait(&tx3).await.map_err(|e| {
90-
CriterionError::Unsatisfied(format!("Transfer to recipient2 failed: {:?}", e).into())
115+
CriterionError::Unsatisfied(format!("Transfer to Bob failed: {:?}", e).into())
91116
})?;
92117

93118
Ok(())

migration/util/migrator-types/src/migrator/movement_aptos_migrator.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use anyhow::Context;
22
use aptos_config::config::NodeConfig;
3-
use aptos_rest_client::Client as MovementAptosRestClient;
3+
use aptos_rest_client::{
4+
Client as MovementAptosRestClient, FaucetClient as MovementAptosFaucetClient,
5+
};
46
use kestrel::WaitCondition;
57
use movement_aptos_core::{runtime, MovementAptos};
68
use mtma_node_types::executor::MovementAptosNode;
@@ -72,6 +74,19 @@ impl MovementAptosMigrator {
7274
})?);
7375
Ok(rest_client)
7476
}
77+
/// Waits for the rest faucet client to be ready.
78+
pub async fn wait_for_faucet_client_ready(
79+
&self,
80+
condition: impl Into<WaitCondition>,
81+
) -> Result<MovementAptosFaucetClient, anyhow::Error> {
82+
// let rest_api_url = self.wait_for_rest_api_url(condition).await?;
83+
// let faucet_client =
84+
// MovementAptosFaucetClient::new(rest_api_url.parse().map_err(|e| {
85+
// anyhow::anyhow!("failed to parse Movement Aptos rest api url: {}", e)
86+
// })?);
87+
// Ok(faucet_client)
88+
todo!()
89+
}
7590
}
7691

7792
impl TryFrom<NodeConfig> for MovementAptosMigrator {

0 commit comments

Comments
 (0)