Skip to content

Commit

Permalink
[types] remove several constants
Browse files Browse the repository at this point in the history
  • Loading branch information
davidiw authored and aptos-bot committed Apr 26, 2022
1 parent 856c899 commit 4431f4f
Show file tree
Hide file tree
Showing 9 changed files with 1 addition and 425 deletions.
172 changes: 1 addition & 171 deletions aptos-move/e2e-tests/src/common_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use aptos_transaction_builder::aptos_stdlib::{
encode_create_account_script_function, encode_rotate_authentication_key_script_function,
encode_transfer_script_function,
};
use aptos_types::{
account_config,
transaction::{RawTransaction, Script, SignedTransaction, TransactionArgument},
};
use aptos_types::transaction::{RawTransaction, Script, SignedTransaction};
use move_ir_compiler::Compiler;
use once_cell::sync::Lazy;

Expand All @@ -29,87 +26,6 @@ pub static EMPTY_SCRIPT: Lazy<Vec<u8>> = Lazy::new(|| {
compiler.into_script_blob(code).expect("Failed to compile")
});

pub static MULTI_AGENT_SWAP_SCRIPT: Lazy<Vec<u8>> = Lazy::new(|| {
let code = "
import 0x1.DiemAccount;
import 0x1.Signer;
import 0x1.XDX;
import 0x1.XUS;
// Alice and Bob agree on the value of amount_xus and amount_xdx off-chain.
main(alice: signer, bob: signer, amount_xus: u64, amount_xdx: u64) {
// First, Alice pays Bob in currency XUS.
let alice_withdrawal_cap: DiemAccount.WithdrawCapability;
let bob_withdrawal_cap: DiemAccount.WithdrawCapability;
let alice_addr: address;
let bob_addr: address;
label b0:
alice_withdrawal_cap = DiemAccount.extract_withdraw_capability(&alice);
bob_addr = Signer.address_of(&bob);
DiemAccount.pay_from<XUS.XUS>(
&alice_withdrawal_cap, move(bob_addr), move(amount_xus), h\"\", h\"\"
);
DiemAccount.restore_withdraw_capability(move(alice_withdrawal_cap));
// Then, Bob pays Alice in currency XDX.
bob_withdrawal_cap = DiemAccount.extract_withdraw_capability(&bob);
alice_addr = Signer.address_of(&alice);
DiemAccount.pay_from<XDX.XDX>(
&bob_withdrawal_cap, move(alice_addr), move(amount_xdx), h\"\", h\"\"
);
DiemAccount.restore_withdraw_capability(move(bob_withdrawal_cap));
return;
}
";

let compiler = Compiler {
deps: cached_framework_packages::modules().iter().collect(),
};
compiler.into_script_blob(code).expect("Failed to compile")
});

pub static MULTI_AGENT_MINT_SCRIPT: Lazy<Vec<u8>> = Lazy::new(|| {
let code = "
import 0x1.DiemAccount;
import 0x1.Signer;
import 0x1.XDX;
import 0x1.XUS;
main<CoinType>(
tc_account: signer,
dd_account: signer,
vasp_account: signer,
amount: u64,
tier_index: u64
) {
let dd_address: address;
let dd_withdrawal_cap: DiemAccount.WithdrawCapability;
let vasp_address: address;
label b0:
dd_address = Signer.address_of(&dd_account);
// First, TC mints to DD.
DiemAccount.tiered_mint<CoinType>(
&tc_account, move(dd_address), copy(amount), move(tier_index)
);
// Then, DD distributes funds to VASP.
dd_withdrawal_cap = DiemAccount.extract_withdraw_capability(&dd_account);
vasp_address = Signer.address_of(&vasp_account);
DiemAccount.pay_from<CoinType>(
&dd_withdrawal_cap, move(vasp_address), move(amount), h\"\", h\"\"
);
DiemAccount.restore_withdraw_capability(move(dd_withdrawal_cap));
return;
}
";

let compiler = Compiler {
deps: cached_framework_packages::modules().iter().collect(),
};
compiler.into_script_blob(code).expect("Failed to compile")
});

pub fn empty_txn(
sender: &Account,
seq_num: u64,
Expand Down Expand Up @@ -180,89 +96,3 @@ pub fn raw_rotate_key_txn(sender: &Account, new_key_hash: Vec<u8>, seq_num: u64)
.sequence_number(seq_num)
.raw()
}

/// Returns a transaction to swap currencies between two accounts.
pub fn multi_agent_swap_txn(
sender: &Account,
secondary_signer: &Account,
seq_num: u64,
xus_amount: u64,
xdx_amount: u64,
) -> SignedTransaction {
let args: Vec<TransactionArgument> = vec![
TransactionArgument::U64(xus_amount),
TransactionArgument::U64(xdx_amount),
];

// get a SignedTransaction
sender
.transaction()
.secondary_signers(vec![secondary_signer.clone()])
.script(Script::new(MULTI_AGENT_SWAP_SCRIPT.to_vec(), vec![], args))
.sequence_number(seq_num)
.sign_multi_agent()
}

/// Returns a multi-agent p2p transaction.
/// Returns a transaction to mint coins from TC to DD to VASP.
pub fn multi_agent_mint_txn(
tc_account: &Account,
dd_account: &Account,
vasp_account: &Account,
seq_num: u64,
amount: u64,
tier_index: u64,
) -> SignedTransaction {
let args: Vec<TransactionArgument> = vec![
TransactionArgument::U64(amount),
TransactionArgument::U64(tier_index),
];
// get a SignedTransaction
tc_account
.transaction()
.secondary_signers(vec![dd_account.clone(), vasp_account.clone()])
.script(Script::new(
MULTI_AGENT_MINT_SCRIPT.to_vec(),
vec![account_config::xus_tag()],
args,
))
.sequence_number(seq_num)
.sign_multi_agent()
}

/// Returns an unsigned raw transaction to swap currencies between two accounts.
pub fn raw_multi_agent_swap_txn(
sender: &Account,
secondary_signer: &Account,
seq_num: u64,
xus_amount: u64,
xdx_amount: u64,
) -> RawTransaction {
let args: Vec<TransactionArgument> = vec![
TransactionArgument::U64(xus_amount),
TransactionArgument::U64(xdx_amount),
];

sender
.transaction()
.secondary_signers(vec![secondary_signer.clone()])
.script(Script::new(MULTI_AGENT_SWAP_SCRIPT.to_vec(), vec![], args))
.sequence_number(seq_num)
.raw()
}

pub fn multi_agent_swap_script(xus_amount: u64, xdx_amount: u64) -> Script {
let args: Vec<TransactionArgument> = vec![
TransactionArgument::U64(xus_amount),
TransactionArgument::U64(xdx_amount),
];
Script::new(MULTI_AGENT_SWAP_SCRIPT.to_vec(), vec![], args)
}

pub fn multi_agent_mint_script(mint_amount: u64, tier_index: u64) -> Script {
let args: Vec<TransactionArgument> = vec![
TransactionArgument::U64(mint_amount),
TransactionArgument::U64(tier_index),
];
Script::new(MULTI_AGENT_MINT_SCRIPT.to_vec(), vec![], args)
}
56 changes: 0 additions & 56 deletions aptos-move/e2e-testsuite/src/tests/verify_txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,62 +54,6 @@ fn verify_signature() {
}
}

#[ignore]
#[test]
fn verify_multi_agent() {
let mut executor = FakeExecutor::from_genesis_file();
executor.set_golden_file(current_function_name!());
let sender = executor.create_raw_account_data(1_000_010, 10);
let secondary_signer = executor.create_raw_account_data(100_100, 100);

executor.add_account_data(&sender);
executor.add_account_data(&secondary_signer);

let signed_txn = transaction_test_helpers::get_test_unchecked_multi_agent_txn(
*sender.address(),
vec![*secondary_signer.address()],
10,
&sender.account().privkey,
sender.account().pubkey.clone(),
vec![&secondary_signer.account().privkey],
vec![secondary_signer.account().pubkey.clone()],
Some(multi_agent_swap_script(10, 10)),
);
assert_eq!(executor.verify_transaction(signed_txn).status(), None);
}

#[ignore]
#[test]
fn verify_multi_agent_multiple_secondary_signers() {
let mut executor = FakeExecutor::from_genesis_file();
executor.set_golden_file(current_function_name!());
let sender = executor.create_raw_account_data(1_000_010, 10);
let secondary_signer = executor.create_raw_account_data(100_100, 100);
let third_signer = executor.create_raw_account_data(100_100, 100);

executor.add_account_data(&sender);
executor.add_account_data(&secondary_signer);
executor.add_account_data(&third_signer);

let signed_txn = transaction_test_helpers::get_test_unchecked_multi_agent_txn(
*sender.address(),
vec![*secondary_signer.address(), *third_signer.address()],
10,
&sender.account().privkey,
sender.account().pubkey.clone(),
vec![
&secondary_signer.account().privkey,
&third_signer.account().privkey,
],
vec![
secondary_signer.account().pubkey.clone(),
third_signer.account().pubkey.clone(),
],
Some(multi_agent_mint_script(100, 0)),
);
assert_eq!(executor.verify_transaction(signed_txn).status(), None);
}

#[test]
fn verify_multi_agent_invalid_sender_signature() {
let mut executor = FakeExecutor::from_genesis_file();
Expand Down
2 changes: 0 additions & 2 deletions config/management/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ pub mod validator_config;
pub mod waypoint;

pub mod constants {
use aptos_types::account_config::XUS_NAME;
pub const COMMON_NS: &str = "common";
pub const LAYOUT: &str = "layout";
pub const VALIDATOR_CONFIG: &str = "validator_config";
pub const VALIDATOR_OPERATOR: &str = "validator_operator";

pub const GAS_UNIT_PRICE: u64 = 0;
pub const MAX_GAS_AMOUNT: u64 = 1_000_000;
pub const GAS_CURRENCY_CODE: &str = XUS_NAME;
pub const TXN_EXPIRATION_SECS: u64 = 3600;
}

Expand Down
73 changes: 0 additions & 73 deletions types/src/account_config/constants/coins.rs

This file was deleted.

6 changes: 0 additions & 6 deletions types/src/account_config/constants/designated_dealer.rs

This file was deleted.

Loading

0 comments on commit 4431f4f

Please sign in to comment.