-
Notifications
You must be signed in to change notification settings - Fork 110
Test Mint and Burn #1010
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
Open
Primata
wants to merge
29
commits into
main
Choose a base branch
from
test-lock-mint-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test Mint and Burn #1010
Changes from 20 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
d69edd0
test fail to burn
Primata e104ada
failing core-resources account
Primata a66c6e0
change addresses
Primata 05b4639
0x1 signer
Primata 8866ba5
main.mv
Primata f02c7d0
remove line
Primata d43c898
maptos private key
Primata a5f9b80
add sender
Primata a974f00
sign with core resources still failing
Primata d8590a5
pending correct genesis keypair
Primata 3e35930
correct signer
Primata 5602d23
failing to burn
Primata 8be819d
unable to burn
Primata 899badd
low-level error return
Primata e11b313
fix: working test
Primata 075b8b2
fix: dynamic path
Primata 5c97e29
Remove layer-zero submodule
Primata 024d1db
Added v2-periphery as a submodule
Primata 487e9ca
fix: imports
Primata 09bf226
fix: pin aptos-core rev with dup fn removed
ganymedio ab4ea7c
Merge branch 'main' into test-lock-mint-client
ganymedio c3f2d95
fix: remove duplicate bcs entries in lockfile
ganymedio ea549e0
set AptosFramework rev to movement
0xmovses afb5739
add dead check
Primata 7667d06
fix: add dead check
Primata 6ac2554
permissioned mint_to test
Primata b721590
fix: versioning
Primata 2160814
fix version
Primata d20de32
Merge branch 'main' into test-lock-mint-client
Primata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
305 changes: 305 additions & 0 deletions
305
networks/movement/movement-client/src/bin/e2e/mint_burn.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,305 @@ | ||
| #![allow(unused_imports)] | ||
|
|
||
| use anyhow::{Chain, Context}; | ||
| use aptos_sdk::{ | ||
| crypto::{ed25519::ed25519_keys::Ed25519PublicKey, multi_ed25519::MultiEd25519PublicKey}, | ||
| move_types::{ | ||
| identifier::Identifier, | ||
| language_storage::{ModuleId, StructTag, TypeTag}, | ||
| }, | ||
| rest_client::{ | ||
| aptos_api_types::{ | ||
| Address, EntryFunctionId, IdentifierWrapper, MoveModule, MoveModuleId, MoveStructTag, | ||
| MoveType, ViewRequest, | ||
| }, | ||
| Account, Response, | ||
| }, | ||
| transaction_builder::TransactionBuilder, | ||
| types::{ | ||
| account_address::AccountAddress, | ||
| chain_id::ChainId, | ||
| transaction::{EntryFunction, Script, TransactionArgument}, | ||
| AccountKey, LocalAccount, | ||
| }, | ||
| }; | ||
| use aptos_types::{ | ||
| account_config::aptos_test_root_address, test_helpers::transaction_test_helpers, | ||
| transaction::TransactionPayload, | ||
| }; | ||
| use buildtime_helpers::cargo::cargo_workspace; | ||
| use movement_client::{ | ||
| coin_client::CoinClient, | ||
| crypto::ValidCryptoMaterialStringExt, | ||
| rest_client::{Client, FaucetClient}, | ||
| }; | ||
| use once_cell::sync::Lazy; | ||
| use rayon::vec; | ||
| use std::{ | ||
| env, fs, | ||
| path::PathBuf, | ||
| process::Command, | ||
| str::FromStr, | ||
| time::{SystemTime, UNIX_EPOCH}, | ||
| }; | ||
| 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, | ||
| )?; | ||
| tracing::info!( | ||
| "resource account keypairs: {:?}, {:?}", | ||
| core_resources_account.private_key(), | ||
| core_resources_account.public_key() | ||
| ); | ||
| tracing::info!("Core Resources Account address: {}", core_resources_account.address()); | ||
|
|
||
| tracing::info!("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")?; | ||
|
|
||
| tracing::info!( | ||
| "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 root: PathBuf = cargo_workspace()?; | ||
| let additional_path = | ||
| "protocol-units/bridge/move-modules/build/bridge-modules/bytecode_scripts/"; | ||
| let combined_path = root.join(additional_path); | ||
|
|
||
| let enable_bridge_code = fs::read(combined_path.join("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(combined_path.join("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(); | ||
|
|
||
| tracing::info!("Bridge feature enabled and mint burn caps stored"); | ||
|
|
||
| let burn_dead_code = fs::read(combined_path.join("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(); | ||
|
|
||
| tracing::info!("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 | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.