Skip to content

Commit

Permalink
feat: with sequencer number ooo test.
Browse files Browse the repository at this point in the history
  • Loading branch information
l-monninger committed Mar 5, 2025
1 parent 2cd95ff commit 48f96db
Show file tree
Hide file tree
Showing 344 changed files with 59,120 additions and 79 deletions.
4 changes: 4 additions & 0 deletions networks/movement/movement-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ path = "src/bin/e2e/transfer.rs"
name = "movement-tests-e2e-key-rotation"
path = "src/bin/e2e/key_rotation.rs"

[[bin]]
name = "movement-tests-sequence-number-ooo"
path = "src/bin/e2e/sequence_number_ooo.rs"


[dependencies]
aptos-language-e2e-tests = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions networks/movement/movement-client/src/bin/e2e/gas_dos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub async fn test_sending_failed_transaction() -> Result<(), anyhow::Error> {
assert!(initial_balance > failed_balance);

// TEST 2: Sending a transaction with a high sequence number
let too_high_sequence_number = alice.sequence_number() + 32 + 2;
let too_high_sequence_number = alice.sequence_number() + 1000 + 2;
println!("Alice's sequence number: {}", alice.sequence_number());
println!("Too high sequence number: {}", too_high_sequence_number);
let last_balance = failed_balance;
Expand All @@ -180,7 +180,7 @@ pub async fn test_sending_failed_transaction() -> Result<(), anyhow::Error> {
&alice,
bob.address(),
100,
too_high_sequence_number, // too new tolerance is 32
too_high_sequence_number, // too new tolerance is 1000 or more:
)
.await?;

Expand Down
187 changes: 187 additions & 0 deletions networks/movement/movement-client/src/bin/e2e/sequence_number_ooo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
use anyhow::Context;
use bcs::to_bytes;
use movement_client::{
coin_client::CoinClient,
move_types::{
identifier::Identifier,
language_storage::{ModuleId, TypeTag},
},
rest_client::{Client, FaucetClient},
transaction_builder::TransactionBuilder,
types::transaction::{EntryFunction, SignedTransaction, TransactionPayload},
types::{account_address::AccountAddress, chain_id::ChainId, LocalAccount},
};
use once_cell::sync::Lazy;
use std::str::FromStr;
use std::time::SystemTime;
use std::time::UNIX_EPOCH;
use url::Url;

static SUZUKA_CONFIG: Lazy<movement_config::Config> = Lazy::new(|| {
let dot_movement = dot_movement::DotMovement::try_from_env().unwrap();
let config = dot_movement.try_get_config_from_json::<movement_config::Config>().unwrap();
config
});

// :!:>section_1c
static NODE_URL: Lazy<Url> = Lazy::new(|| {
let node_connection_address = SUZUKA_CONFIG
.execution_config
.maptos_config
.client
.maptos_rest_connection_hostname
.clone();
let node_connection_port = SUZUKA_CONFIG
.execution_config
.maptos_config
.client
.maptos_rest_connection_port
.clone();

let node_connection_url =
format!("http://{}:{}", node_connection_address, node_connection_port);

Url::from_str(node_connection_url.as_str()).unwrap()
});

static FAUCET_URL: Lazy<Url> = Lazy::new(|| {
let faucet_listen_address = SUZUKA_CONFIG
.execution_config
.maptos_config
.client
.maptos_faucet_rest_connection_hostname
.clone();
let faucet_listen_port = SUZUKA_CONFIG
.execution_config
.maptos_config
.client
.maptos_faucet_rest_connection_port
.clone();

let faucet_listen_url = format!("http://{}:{}", faucet_listen_address, faucet_listen_port);

Url::from_str(faucet_listen_url.as_str()).unwrap()
});
// <:!:section_1c

pub async fn create_fake_signed_transaction(
chain_id: u8,
from_account: &LocalAccount,
to_account: AccountAddress,
amount: u64,
sequence_number: u64,
) -> Result<SignedTransaction, anyhow::Error> {
let coin_type = "0x1::aptos_coin::AptosCoin";
let timeout_secs = 600; // 10 minutes
let max_gas_amount = 5_000;
let gas_unit_price = 100;

let expiration_time =
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs() + timeout_secs;

let transaction_builder = TransactionBuilder::new(
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(AccountAddress::ONE, Identifier::new("coin").unwrap()),
Identifier::new("transfer")?,
vec![TypeTag::from_str(coin_type)?],
vec![to_bytes(&to_account)?, to_bytes(&amount)?],
)),
expiration_time,
ChainId::new(chain_id),
);

let raw_transaction = transaction_builder
.sender(from_account.address())
.sequence_number(sequence_number)
.max_gas_amount(max_gas_amount)
.gas_unit_price(gas_unit_price)
.expiration_timestamp_secs(expiration_time)
.chain_id(ChainId::new(chain_id))
.build();

let signed_transaction = from_account.sign_transaction(raw_transaction);

Ok(signed_transaction)
}

pub async fn test_sending_failed_transaction() -> Result<(), anyhow::Error> {
let rest_client = Client::new(NODE_URL.clone());
let faucet_client = FaucetClient::new(FAUCET_URL.clone(), NODE_URL.clone());
let coin_client = CoinClient::new(&rest_client);

let alice = LocalAccount::generate(&mut rand::rngs::OsRng);
let bob = LocalAccount::generate(&mut rand::rngs::OsRng);

println!("=== Addresses ===");
println!("Alice: {}", alice.address().to_hex_literal());
println!("Bob: {}", bob.address().to_hex_literal());

faucet_client
.fund(alice.address(), 100_000_000)
.await
.context("Failed to fund Alice's account")?;

faucet_client
.create_account(bob.address())
.await
.context("Failed to fund Bob's account")?;

let chain_id = rest_client
.get_index()
.await
.context("Failed to get chain ID")?
.inner()
.chain_id;
println!("\n=== Initial Balance ===");
let initial_balance = coin_client
.get_account_balance(&alice.address())
.await
.context("Failed to get Alice's account balance")?;
println!("Alice: {:?}", initial_balance);

// Send in ooo sequence numbers
// create transaction 1
let transaction_1 = create_fake_signed_transaction(
chain_id,
&alice,
bob.address(),
100,
alice.sequence_number(),
)
.await?;

// create transaction 2
let transaction_2 = create_fake_signed_transaction(
chain_id,
&alice,
bob.address(),
100,
alice.sequence_number() + 1,
)
.await?;

// submit 2 then 1
rest_client.submit(&transaction_2).await?;
rest_client.submit(&transaction_1).await?;

// wait for both the complete
rest_client.wait_for_signed_transaction(&transaction_1).await?;
rest_client.wait_for_signed_transaction(&transaction_2).await?;

// validate the effect of the transactions, the balance should be less than the initial balance
let balance = coin_client
.get_account_balance(&alice.address())
.await
.context("Failed to get Alice's account balance")?;
println!("\n=== After Tx#1 and Tx#2 ===");
println!("Alice: {:?}", balance);
assert!(initial_balance > balance);

Ok(())
}

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
test_sending_failed_transaction().await?;
Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3"

environment:

processes:

# Test whether the full node is resistant to Gas DOS
test-sequence-number-ooo:
command: |
cargo run --bin movement-tests-sequence-number-ooo
depends_on:
movement-full-node:
condition: process_healthy
movement-faucet:
condition: process_healthy
availability:
exit_on_end: true
53 changes: 53 additions & 0 deletions protocol-units/bridge/contracts/minter/build/Minter/BuildInfo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
compiled_package_info:
package_name: Minter
address_alias_instantiation:
Extensions: "0000000000000000000000000000000000000000000000000000000000000001"
aptos_framework: "0000000000000000000000000000000000000000000000000000000000000001"
aptos_fungible_asset: 000000000000000000000000000000000000000000000000000000000000000a
aptos_std: "0000000000000000000000000000000000000000000000000000000000000001"
aptos_token: "0000000000000000000000000000000000000000000000000000000000000003"
core_resources: 000000000000000000000000000000000000000000000000000000000a550c18
std: "0000000000000000000000000000000000000000000000000000000000000001"
vm: "0000000000000000000000000000000000000000000000000000000000000000"
vm_reserved: "0000000000000000000000000000000000000000000000000000000000000000"
source_digest: A8817968ED43F9948E78519424C10EFF89A5BAFA9A2E3927121B387159584519
build_flags:
dev_mode: false
test_mode: false
override_std: ~
generate_docs: false
generate_abis: false
generate_move_model: true
full_model_generation: false
install_dir: ~
force_recompilation: false
additional_named_addresses: {}
architecture: ~
fetch_deps_only: false
skip_fetch_latest_git_deps: false
compiler_config:
bytecode_version: ~
known_attributes:
- bytecode_instruction
- deprecated
- event
- expected_failure
- "fmt::skip"
- legacy_entry_fun
- "lint::allow_unsafe_randomness"
- native_interface
- randomness
- resource_group
- resource_group_member
- test
- test_only
- verify_only
- view
skip_attribute_checks: false
compiler_version: ~
language_version: ~
dependencies:
- AptosFramework
- AptosStdlib
- MoveStdlib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 48f96db

Please sign in to comment.