Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Mint and Burn #1010

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d69edd0
test fail to burn
Primata Jan 20, 2025
e104ada
failing core-resources account
Primata Jan 21, 2025
a66c6e0
change addresses
Primata Jan 21, 2025
05b4639
0x1 signer
Primata Jan 21, 2025
8866ba5
main.mv
Primata Jan 21, 2025
f02c7d0
remove line
Primata Jan 21, 2025
d43c898
maptos private key
Primata Jan 21, 2025
a5f9b80
add sender
Primata Jan 21, 2025
a974f00
sign with core resources still failing
Primata Jan 21, 2025
d8590a5
pending correct genesis keypair
Primata Jan 22, 2025
3e35930
correct signer
Primata Jan 22, 2025
5602d23
failing to burn
Primata Jan 22, 2025
8be819d
unable to burn
Primata Jan 22, 2025
899badd
low-level error return
Primata Jan 24, 2025
e11b313
fix: working test
Primata Jan 25, 2025
075b8b2
fix: dynamic path
Primata Jan 26, 2025
5c97e29
Remove layer-zero submodule
Primata Jan 26, 2025
024d1db
Added v2-periphery as a submodule
Primata Jan 27, 2025
487e9ca
fix: imports
Primata Jan 27, 2025
09bf226
fix: pin aptos-core rev with dup fn removed
andygolay Jan 27, 2025
ab4ea7c
Merge branch 'main' into test-lock-mint-client
andygolay Jan 28, 2025
c3f2d95
fix: remove duplicate bcs entries in lockfile
andygolay Jan 28, 2025
ea549e0
set AptosFramework rev to movement
0xmovses Jan 29, 2025
afb5739
add dead check
Primata Jan 29, 2025
7667d06
fix: add dead check
Primata Jan 29, 2025
6ac2554
permissioned mint_to test
Primata Feb 3, 2025
b721590
fix: versioning
Primata Feb 7, 2025
2160814
fix version
Primata Feb 7, 2025
d20de32
Merge branch 'main' into test-lock-mint-client
Primata Feb 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
269 changes: 135 additions & 134 deletions Cargo.lock

Large diffs are not rendered by default.

64 changes: 32 additions & 32 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -141,40 +141,40 @@ borsh = { version = "0.10" } # todo: internalize jmt and bump

### We use a forked version so that we can override dependency versions. This is required
### to be avoid dependency conflicts with other Sovereign Labs crates.
aptos-api = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-api-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-bitvec = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-block-executor = { git = "https://github.com/movementlabsxyz/aptos-core.git", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-cached-packages = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-config = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-consensus-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-crypto = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e", features = [
aptos-api = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-api-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-bitvec = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-block-executor = { git = "https://github.com/movementlabsxyz/aptos-core.git", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-cached-packages = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-config = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-consensus-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-crypto = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de", features = [
"cloneable-private-keys",
] }
aptos-db = { git = "https://github.com/movementlabsxyz/aptos-core.git", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-executor = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-executor-test-helpers = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-executor-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-faucet-core = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-framework = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-language-e2e-tests = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-mempool = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-proptest-helpers = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-sdk = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-state-view = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-storage-interface = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-temppath = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-vm = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-vm-genesis = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-vm-logging = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-vm-validator = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-logger = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-vm-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-indexer = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-indexer-grpc-fullnode = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-indexer-grpc-table-info = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-protos = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "8b8eb8fd0a3fa78086522bda7886ecd86fc6d24e" }
aptos-db = { git = "https://github.com/movementlabsxyz/aptos-core.git", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-executor = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-executor-test-helpers = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-executor-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-faucet-core = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-framework = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-language-e2e-tests = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-mempool = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-proptest-helpers = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-sdk = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-state-view = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-storage-interface = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-temppath = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-vm = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-vm-genesis = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-vm-logging = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-vm-validator = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-logger = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-vm-types = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-indexer = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-indexer-grpc-fullnode = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-indexer-grpc-table-info = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }
aptos-protos = { git = "https://github.com/movementlabsxyz/aptos-core", rev = "ed40cf7a599caf329111a74a0373e031e16db9de" }

# Indexer
processor = { git = "https://github.com/movementlabsxyz/aptos-indexer-processors", rev = "7658338eb9224abd9698c1e02dbc6ca526c268ce" }
Expand Down
5 changes: 5 additions & 0 deletions networks/movement/movement-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ path = "src/bin/e2e/whitelist.rs"
name = "movement-tests-e2e-ggp-gas-fee"
path = "src/bin/e2e/ggp_gas_fee.rs"

[[bin]]
name = "movement-tests-e2e-lock-mint"
path = "src/bin/e2e/lock_mint.rs"


[dependencies]
aptos-vm-genesis = { workspace = true}
aptos-sdk = { workspace = true }
aptos-types = { workspace = true }
anyhow = { workspace = true }
Expand Down
299 changes: 299 additions & 0 deletions networks/movement/movement-client/src/bin/e2e/lock_mint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,299 @@
#![allow(unused_imports)]
use anyhow::{Chain, Context};
use movement_client::crypto::ValidCryptoMaterialStringExt;

use aptos_sdk::types::{
account_address::AccountAddress,
chain_id::ChainId,
transaction::{EntryFunction, Script, TransactionArgument},
AccountKey, LocalAccount,
};
use aptos_sdk::{
crypto::ed25519::ed25519_keys::Ed25519PublicKey,
crypto::multi_ed25519::MultiEd25519PublicKey,
move_types::{
identifier::Identifier,
language_storage::{ModuleId, StructTag, TypeTag},
},
rest_client::Account,
};
use aptos_sdk::{
rest_client::{
aptos_api_types::{
Address, EntryFunctionId, IdentifierWrapper, MoveModule, MoveModuleId, MoveStructTag,
MoveType, ViewRequest,
},
Response,
},
transaction_builder::TransactionBuilder,
};
use aptos_types::{
account_config::aptos_test_root_address, test_helpers::transaction_test_helpers,
transaction::TransactionPayload,
};
use movement_client::{
coin_client::CoinClient,
rest_client::{Client, FaucetClient},
};
use once_cell::sync::Lazy;
use rayon::vec;
use std::process::Command;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use std::{env, fs};
use tracing;
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
});

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()
});

#[tokio::main]
async fn main() -> 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 dead_address = AccountAddress::from_str(
"000000000000000000000000000000000000000000000000000000000000dead",
)?;
let associate_address = AccountAddress::from_str(
"0x000000000000000000000000000000000000000000000000000000000a550c18",
)?;

let chain_id = rest_client
.get_index()
.await
.context("failed to get chain ID")?
.inner()
.chain_id;

let mut core_resources_account = LocalAccount::from_private_key(
SUZUKA_CONFIG
.execution_config
.maptos_config
.chain
.maptos_private_key
.to_encoded_string()?
.as_str(),
0,
)?;
println!(
"resource account keypairs: {:?}, {:?}",
core_resources_account.private_key(),
core_resources_account.public_key()
);
println!("Core Resources Account address: {}", core_resources_account.address());

println!("Created core resources account");

// core_resources_account is already funded with u64 max value
// Create dead account
let create_dead_transaction =
transaction_test_helpers::get_test_signed_transaction_with_chain_id(
associate_address,
core_resources_account.sequence_number(),
&core_resources_account.private_key(),
core_resources_account.public_key().clone(),
Some(TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::from_hex_literal("0x1")?,
Identifier::new("aptos_account")?,
),
Identifier::new("create_account")?,
vec![],
vec![bcs::to_bytes(&dead_address)?],
))),
SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() + 60,
100,
None,
ChainId::new(chain_id),
);

rest_client
.submit_and_wait(&create_dead_transaction)
.await
.context("Failed to create dead account")?;

core_resources_account.increment_sequence_number();

faucet_client.fund(core_resources_account.address(), 1_000_000).await?;
core_resources_account.increment_sequence_number();
faucet_client.fund(dead_address, 1).await?;
core_resources_account.increment_sequence_number();

// Retrieve and log balances
let dead_balance = coin_client
.get_account_balance(&dead_address)
.await
.context("Failed to retrieve dead account balance")?;
let core_balance = coin_client
.get_account_balance(&core_resources_account.address())
.await
.context("Failed to retrieve core resources account balance")?;

println!("Core account balance: {}, Dead account balance: {}", core_balance, dead_balance);

Command::new("movement")
.args(["move", "compile", "--package-dir", "protocol-units/bridge/move-modules"])
.status()
.expect("Failed to execute `movement compile` command");

let enable_bridge_code = fs::read("protocol-units/bridge/move-modules/build/bridge-modules/bytecode_scripts/enable_bridge_feature.mv")?;
let enable_bridge_script_payload =
TransactionPayload::Script(Script::new(enable_bridge_code, vec![], vec![]));

let enable_bridge_script_transaction =
transaction_test_helpers::get_test_signed_transaction_with_chain_id(
associate_address,
core_resources_account.sequence_number(),
&core_resources_account.private_key(),
core_resources_account.public_key().clone(),
Some(enable_bridge_script_payload),
SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() + 60,
100,
None,
ChainId::new(chain_id),
);

rest_client
.submit_and_wait(&enable_bridge_script_transaction)
.await
.context("Failed to enable bridge script transaction")?;

core_resources_account.increment_sequence_number();

let store_mint_burn_caps_code = fs::read("protocol-units/bridge/move-modules/build/bridge-modules/bytecode_scripts/store_mint_burn_caps.mv")?;
let store_mint_burn_caps_script_payload =
TransactionPayload::Script(Script::new(store_mint_burn_caps_code, vec![], vec![]));

let store_mint_burn_caps_script_transaction =
transaction_test_helpers::get_test_signed_transaction_with_chain_id(
associate_address,
core_resources_account.sequence_number(),
&core_resources_account.private_key(),
core_resources_account.public_key().clone(),
Some(store_mint_burn_caps_script_payload),
SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() + 60,
100,
None,
ChainId::new(chain_id),
);

rest_client
.submit_and_wait(&store_mint_burn_caps_script_transaction)
.await
.context("Failed to store_mint_burn_caps script transaction")?;
core_resources_account.increment_sequence_number();

println!("Bridge feature enabled and mint burn caps stored");

let burn_dead_code = fs::read(
"protocol-units/bridge/move-modules/build/bridge-modules/bytecode_scripts/burn_from.mv",
)?;
let burn_dead_args =
vec![TransactionArgument::Address(dead_address), TransactionArgument::U64(1)];
let burn_dead_script_payload =
TransactionPayload::Script(Script::new(burn_dead_code, vec![], burn_dead_args));
let burn_dead_script_transaction =
transaction_test_helpers::get_test_signed_transaction_with_chain_id(
associate_address,
core_resources_account.sequence_number(),
&core_resources_account.private_key(),
core_resources_account.public_key().clone(),
Some(burn_dead_script_payload),
SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() + 60,
100,
None,
ChainId::new(chain_id),
);

rest_client
.submit_and_wait(&burn_dead_script_transaction)
.await
.context("Failed to execute burn dead balance script transaction")?;

core_resources_account.increment_sequence_number();

let desired_core_balance = 1;

let amount_to_burn = core_balance - desired_core_balance;

let burn_core_code = fs::read(
"protocol-units/bridge/move-modules/build/bridge-modules/bytecode_scripts/burn_from.mv",
)?;
let burn_core_args =
vec![TransactionArgument::Address(core_resources_account.address()), TransactionArgument::U64(amount_to_burn)];
let burn_core_script_payload =
TransactionPayload::Script(Script::new(burn_core_code, vec![], burn_core_args));
let burn_core_script_transaction =
transaction_test_helpers::get_test_signed_transaction_with_chain_id(
associate_address,
core_resources_account.sequence_number(),
&core_resources_account.private_key(),
core_resources_account.public_key().clone(),
Some(burn_core_script_payload),
SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs() + 60,
100,
None,
ChainId::new(chain_id),
);

rest_client
.submit_and_wait(&burn_core_script_transaction)
.await
.context("Failed to execute burn dead balance script transaction")?;

core_resources_account.increment_sequence_number();

println!("Script burn transactions successfully executed.");

assert!(
coin_client
.get_account_balance(&core_resources_account.address())
.await
.context("Failed to retrieve core resources account new balance")?
== desired_core_balance
);
// Transfer L1 move desired amount to L1 bridge address
// not needed to cover as its a simple bridge, what matters is transferring the correct amount without initiating a bridge attempt
// Manual check of if Relayer address balance on L2 equals to L1 bridge address

Ok(())
}
Loading
Loading