Skip to content

Commit

Permalink
multi currency support
Browse files Browse the repository at this point in the history
Closes: diem#3476
Approved by: sblackshear
  • Loading branch information
Tim Zakian authored and bors-libra committed Apr 20, 2020
1 parent ac4edd8 commit 10523d3
Show file tree
Hide file tree
Showing 146 changed files with 5,564 additions and 647 deletions.
7 changes: 4 additions & 3 deletions client/cli/src/client_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use transaction_builder::encode_register_validator_script;

const CLIENT_WALLET_MNEMONIC_FILE: &str = "client.mnemonic";
const GAS_UNIT_PRICE: u64 = 0;
const MAX_GAS_AMOUNT: u64 = 600_000;
const MAX_GAS_AMOUNT: u64 = 1_000_000;
const TX_EXPIRATION: i64 = 100;

/// Enum used for error formatting.
Expand Down Expand Up @@ -315,6 +315,7 @@ impl ClientProxy {
match self.faucet_account {
Some(_) => self.association_transaction_with_local_faucet_account(
transaction_builder::encode_mint_script(
lbr_type_tag(),
&receiver,
receiver_auth_key.prefix().to_vec(),
num_coins,
Expand Down Expand Up @@ -396,7 +397,7 @@ impl ClientProxy {
self.get_account_address_from_parameter(space_delim_strings[1])?;
match self.faucet_account {
Some(_) => self.association_transaction_with_local_faucet_account(
transaction_builder::encode_remove_validator_script(&account_address),
transaction_builder::encode_remove_validator_script(account_address),
is_blocking,
),
None => unimplemented!(),
Expand All @@ -418,7 +419,7 @@ impl ClientProxy {
self.get_account_address_from_parameter(space_delim_strings[1])?;
match self.faucet_account {
Some(_) => self.association_transaction_with_local_faucet_account(
transaction_builder::encode_add_validator_script(&account_address),
transaction_builder::encode_add_validator_script(account_address),
is_blocking,
),
None => unimplemented!(),
Expand Down
12 changes: 10 additions & 2 deletions client/libra-dev/src/account_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ pub unsafe extern "C" fn libra_LibraAccountResource_from(
#[cfg(test)]
mod tests {
use super::*;
use libra_types::account_config::{
from_currency_code_string, type_tag_for_currency_code, LBR_NAME,
};

/// Generate an AccountBlob and verify we can parse it
#[test]
Expand All @@ -98,7 +101,8 @@ mod tests {
false,
EventHandle::new(EventKey::new_from_address(&addr, 0), 777),
EventHandle::new(EventKey::new_from_address(&addr, 0), 888),
0,
false,
from_currency_code_string(LBR_NAME).unwrap(),
);
let br = BalanceResource::new(100);

Expand All @@ -108,7 +112,11 @@ mod tests {
lcs::to_bytes(&ar).expect("Account resource lcs serialization was not successful"),
);
map.insert(
BalanceResource::resource_path(),
// TODO: Need to update this to use BalanceResource::resource_path path once we can
// pass type arguments to it.
BalanceResource::access_path_for(type_tag_for_currency_code(
ar.balance_currency_code().to_owned(),
)),
lcs::to_bytes(&br).expect("Balance resource lcs serialization was not successful"),
);

Expand Down
9 changes: 7 additions & 2 deletions client/libra-dev/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn test_libra_LibraEvent_from() {
use libra_crypto::{ed25519::Ed25519PrivateKey, PrivateKey, Uniform};
use libra_types::{
account_address::AccountAddress,
account_config::SentPaymentEvent,
account_config::{from_currency_code_string, SentPaymentEvent, LBR_NAME},
contract_event::ContractEvent,
event::{EventHandle, EventKey},
language_storage::{StructTag, TypeTag::Struct},
Expand All @@ -201,7 +201,12 @@ fn test_libra_LibraEvent_from() {
});
let amount = 50_000_000;
let receiver_address = AccountAddress::random();
let event_data = SentPaymentEvent::new(amount, receiver_address, vec![]);
let event_data = SentPaymentEvent::new(
amount,
from_currency_code_string(LBR_NAME).unwrap(),
receiver_address,
vec![],
);
let event_data_bytes = lcs::to_bytes(&event_data).unwrap();

let event = ContractEvent::new(*event_key, sequence_number, type_tag, event_data_bytes);
Expand Down
15 changes: 8 additions & 7 deletions execution/executor-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl TransactionGenerator {
&self.genesis_key,
self.genesis_key.public_key(),
encode_create_account_script(
lbr_type_tag(),
&account.address,
account.auth_key_prefix(),
init_account_balance,
Expand Down Expand Up @@ -320,8 +321,8 @@ fn create_transaction(
sender,
sequence_number,
program,
400_000, /* max_gas_amount */
1, /* gas_unit_price */
1_000_000, /* max_gas_amount */
1, /* gas_unit_price */
expiration_time,
);

Expand All @@ -335,11 +336,11 @@ mod tests {
#[test]
fn test_benchmark() {
super::run_benchmark(
25, /* num_accounts */
1_000_000, /* init_account_balance */
5, /* block_size */
5, /* num_transfer_blocks */
None, /* db_dir */
25, /* num_accounts */
10_000_000, /* init_account_balance */
5, /* block_size */
5, /* num_transfer_blocks */
None, /* db_dir */
);
}
}
1 change: 1 addition & 0 deletions execution/executor/tests/db_bootstrapper_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ fn get_mint_transaction(
association_key.clone(),
association_key.public_key(),
Some(encode_create_account_script(
lbr_type_tag(),
&account,
account_auth_key.prefix().to_vec(),
amount,
Expand Down
19 changes: 11 additions & 8 deletions execution/executor/tests/storage_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,9 +579,10 @@ fn test_execution_with_storage() {
genesis_key.clone(),
genesis_key.public_key(),
Some(encode_create_account_script(
lbr_type_tag(),
&account1,
account1_auth_key.prefix().to_vec(),
2_000_000,
20_000_000,
)),
);

Expand All @@ -592,9 +593,10 @@ fn test_execution_with_storage() {
genesis_key.clone(),
genesis_key.public_key(),
Some(encode_create_account_script(
lbr_type_tag(),
&account2,
account2_auth_key.prefix().to_vec(),
1_200_000,
10_200_000,
)),
);

Expand All @@ -605,9 +607,10 @@ fn test_execution_with_storage() {
genesis_key.clone(),
genesis_key.public_key(),
Some(encode_create_account_script(
lbr_type_tag(),
&account3,
account3_auth_key.prefix().to_vec(),
1_000_000,
10_000_000,
)),
);

Expand Down Expand Up @@ -751,19 +754,19 @@ fn test_execution_with_storage() {
.reader
.get_account_state_with_proof(account1, current_version, current_version)
.unwrap();
verify_account_balance(&account1_state_with_proof, |x| x < 1_910_000).unwrap();
verify_account_balance(&account1_state_with_proof, |x| x < 19_910_000).unwrap();

let account2_state_with_proof = db
.reader
.get_account_state_with_proof(account2, current_version, current_version)
.unwrap();
verify_account_balance(&account2_state_with_proof, |x| x < 1_210_000).unwrap();
verify_account_balance(&account2_state_with_proof, |x| x < 10_060_000).unwrap();

let account3_state_with_proof = db
.reader
.get_account_state_with_proof(account3, current_version, current_version)
.unwrap();
verify_account_balance(&account3_state_with_proof, |x| x == 1_080_000).unwrap();
verify_account_balance(&account3_state_with_proof, |x| x == 10_080_000).unwrap();

let transaction_list_with_proof = db
.reader
Expand Down Expand Up @@ -858,13 +861,13 @@ fn test_execution_with_storage() {
.reader
.get_account_state_with_proof(account1, current_version, current_version)
.unwrap();
verify_account_balance(&account1_state_with_proof, |x| x < 1_770_000).unwrap();
verify_account_balance(&account1_state_with_proof, |x| x < 18_000_000).unwrap();

let account3_state_with_proof = db
.reader
.get_account_state_with_proof(account3, current_version, current_version)
.unwrap();
verify_account_balance(&account3_state_with_proof, |x| x == 1_220_000).unwrap();
verify_account_balance(&account3_state_with_proof, |x| x == 10_220_000).unwrap();

let transaction_list_with_proof = db
.reader
Expand Down
Loading

0 comments on commit 10523d3

Please sign in to comment.