diff --git a/framework/libra-framework/sources/modified_source/genesis.move b/framework/libra-framework/sources/modified_source/genesis.move index 56bc75370..7beca319d 100644 --- a/framework/libra-framework/sources/modified_source/genesis.move +++ b/framework/libra-framework/sources/modified_source/genesis.move @@ -171,25 +171,12 @@ module diem_framework::genesis { // we are leaving vendor's coin in place. /// Genesis step 2: Initialize Diem coin. fun initialize_diem_coin(diem_framework: &signer) { - - // let (burn_cap, mint_cap) = diem_coin::initialize(diem_framework); - // Give stake module MintCapability so it can mint rewards. - // stake::store_diem_coin_mint_cap(diem_framework, mint_cap); - // coin::destroy_mint_cap(mint_cap); - // Give transaction_fee module BurnCapability so it can burn gas. - // transaction_fee::store_diem_coin_burn_cap(diem_framework, burn_cap); - // coin::destroy_burn_cap(burn_cap); - - // 0L: genesis ceremony is calling this + // NOTE 0L: genesis ceremony is calling this gas_coin::initialize(diem_framework); - // Give stake module MintCapability so it can mint rewards. - // stake::store_diem_coin_mint_cap(diem_framework, mint_cap); - // gas_coin::restore_mint_cap(diem_framework, mint_cap); - // coin::destroy_burn_cap(burn_cap); + transaction_fee::initialize_fee_collection_and_distribution(diem_framework, 0); } - // TODO: 0L: replace this with gas coin. using vendor's to preserve tests while WIP. /// Only called for testnets and e2e tests. fun initialize_core_resources_and_diem_coin( diem_framework: &signer, @@ -199,9 +186,6 @@ module diem_framework::genesis { let core_resources = account::create_account(@core_resources); account::rotate_authentication_key_internal(&core_resources, core_resources_auth_key); - // diem_coin::configure_accounts_for_test(diem_framework, &core_resources, mint_cap); - // coin::destroy_mint_cap(mint_cap); - // coin::destroy_burn_cap(burn_cap); // initialize gas let (burn_cap_two, mint_cap_two) = gas_coin::initialize_for_core(diem_framework); diff --git a/framework/libra-framework/sources/ol_sources/genesis_migration.move b/framework/libra-framework/sources/ol_sources/genesis_migration.move index e609a81dc..06fc3fa38 100644 --- a/framework/libra-framework/sources/ol_sources/genesis_migration.move +++ b/framework/libra-framework/sources/ol_sources/genesis_migration.move @@ -78,12 +78,15 @@ module ol_framework::genesis_migration { fun rounding_mint(root: &signer, target_supply: u64) { let existing_supply = gas_coin::supply(); - assert!(target_supply >= existing_supply, error::invalid_state(EMINTED_OVER_TARGET)); + // we should not ever have migrated more coins than expected + // this should abort the genesis process + assert!(existing_supply <= target_supply, + error::invalid_state(EMINTED_OVER_TARGET)); + if (target_supply > existing_supply) { let coin = coin::vm_mint(root, target_supply - existing_supply); transaction_fee::vm_pay_fee(root, @ol_framework, coin); - - } + }; } /// for an uprade using an escrow percent. Only to be called at genesis diff --git a/framework/libra-framework/sources/ol_sources/libra_coin.move b/framework/libra-framework/sources/ol_sources/libra_coin.move index c0b8600e4..683acb57f 100644 --- a/framework/libra-framework/sources/ol_sources/libra_coin.move +++ b/framework/libra-framework/sources/ol_sources/libra_coin.move @@ -120,6 +120,7 @@ module ol_framework::gas_coin { use std::signer; use std::vector; use std::option::{Self, Option}; + // use diem_std::debug::print; use diem_framework::coin::{Self, MintCapability, BurnCapability}; use diem_framework::system_addresses; @@ -129,15 +130,23 @@ module ol_framework::gas_coin { friend diem_framework::genesis; friend ol_framework::genesis_migration; + const MAX_U64: u128 = 18446744073709551615; + /// Account does not have mint capability const ENO_CAPABILITIES: u64 = 1; /// Mint capability has already been delegated to this specified address const EALREADY_DELEGATED: u64 = 2; /// Cannot find delegation of mint capability to this account const EDELEGATION_NOT_FOUND: u64 = 3; + /// Supply somehow above MAX_U64 + const ESUPPLY_OVERFLOW: u64 = 4; struct LibraCoin has key {} + struct FinalMint has key { + value: u64, + } + struct MintCapStore has key { mint_cap: MintCapability, } @@ -170,12 +179,12 @@ module ol_framework::gas_coin { coin::destroy_freeze_cap(freeze_cap); coin::destroy_burn_cap(burn_cap); - // (burn_cap, mint_cap) } /// FOR TESTS ONLY /// Can only called during genesis to initialize the Diem coin. - public(friend) fun initialize_for_core(diem_framework: &signer): (BurnCapability, MintCapability) { + public(friend) fun initialize_for_core(diem_framework: &signer): + (BurnCapability, MintCapability) acquires FinalMint { system_addresses::assert_diem_framework(diem_framework); let (burn_cap, freeze_cap, mint_cap) = coin::initialize_with_parallelizable_supply( @@ -192,6 +201,9 @@ module ol_framework::gas_coin { coin::destroy_freeze_cap(freeze_cap); + genesis_set_final_supply(diem_framework, 100); // TODO: set this number + // in testnets + (burn_cap, mint_cap) } @@ -207,6 +219,42 @@ module ol_framework::gas_coin { coin::destroy_mint_cap(mint_cap); } + // at genesis we need to init the final supply + // done at genesis_migration + fun genesis_set_final_supply(diem_framework: &signer, + final_supply: u64) acquires FinalMint { + system_addresses::assert_ol(diem_framework); + + if (!exists(@ol_framework)) { + move_to(diem_framework, FinalMint { + value: final_supply + }); + } else { + let state = borrow_global_mut(@ol_framework); + state.value = final_supply + } + } + #[test_only] + public fun test_set_final_supply(diem_framework: &signer, + final_supply: u64) acquires FinalMint { + system_addresses::assert_ol(diem_framework); + + if (!exists(@ol_framework)) { + move_to(diem_framework, FinalMint { + value: final_supply + }); + } else { + let state = borrow_global_mut(@ol_framework); + state.value = final_supply + } + } + + #[view] + /// get the original final supply from genesis + public fun get_final_supply(): u64 acquires FinalMint{ + borrow_global(@ol_framework).value + } + #[view] /// get the gas coin supply. Helper which wraps coin::supply and extracts option type @@ -214,7 +262,18 @@ module ol_framework::gas_coin { public fun supply(): u64 { let supply_opt = coin::supply(); if (option::is_some(&supply_opt)) { - return (*option::borrow(&supply_opt) as u64) + let value = *option::borrow(&supply_opt); + assert!(value <= MAX_U64, ESUPPLY_OVERFLOW); + return (value as u64) + }; + 0 + } + #[view] + /// debugging view + public fun supply_128(): u128 { + let supply_opt = coin::supply(); + if (option::is_some(&supply_opt)) { + return *option::borrow(&supply_opt) }; 0 } @@ -226,6 +285,14 @@ module ol_framework::gas_coin { move_to(diem_framework, MintCapStore { mint_cap }); } + #[test_only] + public fun extract_mint_cap(diem_framework: &signer): + MintCapability acquires MintCapStore { + system_addresses::assert_diem_framework(diem_framework); + let MintCapStore { mint_cap } = move_from(@diem_framework); + mint_cap + } + /// FOR TESTS ONLY /// The `core addresses` sudo account is used to execute system transactions for testing /// Can only be called during genesis for tests to grant mint capability to diem framework and core resources @@ -241,7 +308,8 @@ module ol_framework::gas_coin { coin::register(core_resources); let coins = coin::mint( - 18446744073709551615, + 1000000 * 1000000, // core resources can have 1M coins, MAX_U64 was + // causing arthmetic errors calling supply() on downcast &mint_cap, ); coin::deposit(signer::address_of(core_resources), coins); @@ -271,6 +339,7 @@ module ol_framework::gas_coin { dst_addr: address, amount: u64, ) acquires MintCapStore { + let _s = supply(); // check we didn't overflow supply let account_addr = signer::address_of(root); @@ -282,6 +351,9 @@ module ol_framework::gas_coin { let mint_cap = &borrow_global(account_addr).mint_cap; let coins_minted = coin::mint(amount, mint_cap); coin::deposit(dst_addr, coins_minted); + + // TODO: update the final supply for tests + // genesis_set_final_supply(root, supply()); } #[test_only] diff --git a/framework/libra-framework/sources/ol_sources/mock.move b/framework/libra-framework/sources/ol_sources/mock.move index 6f1b3b311..d6c91905b 100644 --- a/framework/libra-framework/sources/ol_sources/mock.move +++ b/framework/libra-framework/sources/ol_sources/mock.move @@ -24,11 +24,13 @@ module ol_framework::mock { use ol_framework::musical_chairs; use ol_framework::globals; use diem_framework::block; - // use diem_framework::chain_status; - use diem_std::debug::print; + + // use diem_std::debug::print; const ENO_GENESIS_END_MARKER: u64 = 1; - const EDID_NOT_ADVANCE_EPOCH: u64 = 1; + const EDID_NOT_ADVANCE_EPOCH: u64 = 2; + /// coin supply does not match expected + const ESUPPLY_MISMATCH: u64 = 3; #[test_only] public fun reset_val_perf_one(vm: &signer, addr: address) { @@ -150,6 +152,9 @@ module ol_framework::mock { genesis::setup(); genesis::test_end_genesis(root); + let mint_cap = init_coin_impl(root); + gas_coin::restore_mint_cap(root, mint_cap); + assert!(!chain_status::is_genesis(), 0); } @@ -159,15 +164,20 @@ module ol_framework::mock { let mint_cap = init_coin_impl(root); - coin::destroy_mint_cap(mint_cap); + gas_coin::restore_mint_cap(root, mint_cap); } #[test_only] - public fun ol_initialize_coin_and_fund_vals(root: &signer, amount: u64, drip: bool) { + public fun ol_initialize_coin_and_fund_vals(root: &signer, amount: u64, + drip: bool) { system_addresses::assert_ol(root); - let mint_cap = init_coin_impl(root); + let mint_cap = if (coin::is_coin_initialized()) { + gas_coin::extract_mint_cap(root) + } else { + init_coin_impl(root) + }; let vals = stake::get_current_validators(); let i = 0; @@ -195,14 +205,14 @@ module ol_framework::mock { let (burn_cap, mint_cap) = gas_coin::initialize_for_test_without_aggregator_factory(root); coin::destroy_burn_cap(burn_cap); - transaction_fee::initialize_fee_collection_and_distribution(root, 0); let initial_fees = 1000000 * 100; // coin scaling * 100 coins let tx_fees = coin::test_mint(initial_fees, &mint_cap); transaction_fee::vm_pay_fee(root, @ol_framework, tx_fees); let supply_pre = gas_coin::supply(); - assert!(supply_pre == initial_fees, 666); + assert!(supply_pre == initial_fees, ESUPPLY_MISMATCH); + gas_coin::test_set_final_supply(root, initial_fees); mint_cap } @@ -290,7 +300,7 @@ module ol_framework::mock { public fun meta_epoch(root: signer) { ol_test_genesis(&root); musical_chairs::initialize(&root, 10); - ol_initialize_coin(&root); + // ol_initialize_coin(&root); let epoch = reconfiguration::current_epoch(); trigger_epoch(&root); let new_epoch = reconfiguration::current_epoch(); @@ -302,7 +312,6 @@ module ol_framework::mock { // genesis(); let set = genesis_n_vals(&root, 4); - print(&set); assert!(vector::length(&set) == 4, 7357001); let addr = vector::borrow(&set, 0); @@ -353,5 +362,4 @@ module ol_framework::mock { assert!(entry_fee == 999, 73570003); assert!(median_bid == 3, 73570004); } - } diff --git a/framework/libra-framework/sources/ol_sources/ol_account.move b/framework/libra-framework/sources/ol_sources/ol_account.move index 6b67918b5..7703e9451 100644 --- a/framework/libra-framework/sources/ol_sources/ol_account.move +++ b/framework/libra-framework/sources/ol_sources/ol_account.move @@ -3,13 +3,12 @@ module ol_framework::ol_account { use diem_framework::coin::{Self, Coin}; use diem_framework::event::{EventHandle, emit_event}; use diem_framework::system_addresses; - // use diem_framework::chain_status; use std::error; use std::signer; use std::option::{Self, Option}; use diem_std::from_bcs; - use ol_framework::gas_coin::LibraCoin as GasCoin; + use ol_framework::gas_coin::{Self, LibraCoin as GasCoin}; use ol_framework::slow_wallet; use ol_framework::receipts; use ol_framework::cumulative_deposits; @@ -43,6 +42,15 @@ module ol_framework::ol_account { const ECANT_MATCH_ADDRESS_IN_LOOKUP: u64 = 7; + struct BurnTracker has key { + prev_supply: u64, + prev_balance: u64, + burn_at_last_calc: u64, + cumu_burn: u64, + // percent: u64, + // percent_increase: u64, + } + /// Configuration for whether an account can receive direct transfers of coins that they have not registered. /// @@ -80,6 +88,7 @@ module ol_framework::ol_account { let new_signer = account::create_account(auth_key); coin::register(&new_signer); receipts::user_init(&new_signer); + init_burn_tracker(&new_signer); } // #[test_only] @@ -114,6 +123,7 @@ module ol_framework::ol_account { ); coin::register(&new_signer); + init_burn_tracker(&new_signer); new_signer } @@ -122,7 +132,8 @@ module ol_framework::ol_account { #[test_only] /// Batch version of GAS transfer. - public entry fun batch_transfer(source: &signer, recipients: vector
, amounts: vector) { + public entry fun batch_transfer(source: &signer, recipients: + vector
, amounts: vector) acquires BurnTracker { let recipients_len = vector::length(&recipients); assert!( recipients_len == vector::length(&amounts), @@ -140,30 +151,52 @@ module ol_framework::ol_account { /// Convenient function to transfer GAS to a recipient account that might not exist. /// This would create the recipient account first, which also registers it to receive GAS, before transferring. - public entry fun transfer(sender: &signer, to: address, amount: u64) { - transfer_checks(signer::address_of(sender), to, amount); - coin::transfer(sender, to, amount); + public entry fun transfer(sender: &signer, to: address, amount: u64) + acquires BurnTracker { + let payer = signer::address_of(sender); + transfer_checks(payer, to, amount); + // both update burn tracker + let c = withdraw(sender, amount); + deposit_coins(to, c); + slow_wallet::maybe_track_slow_transfer(payer, to, amount); } // transfer with capability, and do appropriate checks on both sides, and track the slow wallet - public fun transfer_with_capability(cap: &WithdrawCapability, recipient: address, amount: u64) { + public fun transfer_with_capability(cap: &WithdrawCapability, recipient: + address, amount: u64) acquires BurnTracker { let payer = account::get_withdraw_cap_address(cap); transfer_checks(payer, recipient, amount); - let c = coin::withdraw_with_capability(cap, amount); - coin::deposit(recipient, c); + // NOTE: these shoud update BurnTracker + let c = withdraw_with_capability(cap, amount); + deposit_coins(recipient, c); slow_wallet::maybe_track_slow_transfer(payer, recipient, amount); } /// Withdraw a coin while tracking the unlocked withdraw - public fun withdraw_with_capability(cap: &WithdrawCapability, amount: u64): Coin { + public fun withdraw_with_capability(cap: &WithdrawCapability, amount: u64): + Coin acquires BurnTracker { let payer = account::get_withdraw_cap_address(cap); let limit = slow_wallet::unlocked_amount(payer); assert!(amount < limit, error::invalid_state(EINSUFFICIENT_BALANCE)); slow_wallet::maybe_track_unlocked_withdraw(payer, amount); + // the outgoing coins should trigger an update on this account + maybe_update_burn_tracker_impl(payer); coin::withdraw_with_capability(cap, amount) } + /// Withdraw funds while respecting the transfer limits + public fun withdraw(sender: &signer, amount: u64): Coin acquires + BurnTracker { + let addr = signer::address_of(sender); + let limit = slow_wallet::unlocked_amount(addr); + assert!(amount < limit, error::invalid_state(EINSUFFICIENT_BALANCE)); + slow_wallet::maybe_track_unlocked_withdraw(addr, amount); + // the outgoing coins should trigger an update on this account + maybe_update_burn_tracker_impl(addr); + coin::withdraw(sender, amount) + } + // actual implementation to allow for capability fun transfer_checks(payer: address, recipient: address, amount: u64) { let limit = slow_wallet::unlocked_amount(payer); @@ -188,13 +221,7 @@ module ol_framework::ol_account { cumulative_deposits::maybe_update_deposit(payer, recipient, amount); } - /// Withdraw funds while respecting the transfer limits - public fun withdraw(sender: &signer, amount: u64): Coin { - let limit = slow_wallet::unlocked_amount(signer::address_of(sender)); - assert!(amount < limit, error::invalid_state(EINSUFFICIENT_BALANCE)); - slow_wallet::maybe_track_unlocked_withdraw(signer::address_of(sender), amount); - coin::withdraw(sender, amount) - } + /// vm can transfer between account to settle. /// THIS FUNCTION CAN BYPASS SLOW WALLET WITHDRAW RESTRICTIONS @@ -202,7 +229,8 @@ module ol_framework::ol_account { /// returns the actual amount transferred, and whether that amount was the /// whole amount expected to transfer. /// (amount_transferred, success) - public(friend) fun vm_transfer(vm: &signer, from: address, to: address, amount: u64): (u64, bool) { + public(friend) fun vm_transfer(vm: &signer, from: address, to: address, amount: u64): (u64, bool) acquires + BurnTracker { system_addresses::assert_ol(vm); let amount_transferred = 0; // should not halt @@ -212,10 +240,16 @@ module ol_framework::ol_account { if(amount > coin::balance(from)) return (0, false); let coin_option = coin::vm_withdraw(vm, from, amount); + if (option::is_some(&coin_option)) { let c = option::extract(&mut coin_option); amount_transferred = coin::value(&c); - coin::deposit(to, c); + coin::deposit(to, c); // TODO: this should use internal functions to + // deduplicate what follows + // update both accounts + maybe_update_burn_tracker_impl(from); + maybe_update_burn_tracker_impl(to); + }; option::destroy_none(coin_option); @@ -229,18 +263,23 @@ module ol_framework::ol_account { } #[test_only] - public fun test_vm_withdraw(vm: &signer, from: address, amount: u64): Option> { + public fun test_vm_withdraw(vm: &signer, from: address, amount: u64): + Option> acquires BurnTracker { system_addresses::assert_ol(vm); // should not halt if (!coin::is_account_registered(from)) return option::none(); if(amount > coin::balance(from)) return option::none(); + maybe_update_burn_tracker_impl(from); coin::vm_withdraw(vm, from, amount) + } /// vm can transfer between account to settle. /// THIS FUNCTION CAN BYPASS SLOW WALLET WITHDRAW RESTRICTIONS /// used to withdraw and track the withdrawal - public(friend) fun vm_withdraw_unlimited(vm: &signer, from: address, amount: u64): Option>{ + public(friend) fun vm_withdraw_unlimited(vm: &signer, from: address, amount: + u64): Option> acquires + BurnTracker { system_addresses::assert_ol(vm); // should not halt if(amount > coin::balance(from)) return option::none(); @@ -248,8 +287,19 @@ module ol_framework::ol_account { // since the VM can withdraw more than what is unlocked // it needs to adjust the unlocked amount, which may end up zero // if it goes over the limit - slow_wallet::maybe_track_unlocked_withdraw(from, amount); - coin::vm_withdraw(vm, from, amount) + let c_opt = coin::vm_withdraw(vm, from, amount); + + // we're not always sure what's in the option + if (option::is_some(&c_opt)) { + let coin = option::borrow(&c_opt); + let value = coin::value(coin); + if (value > 0) { + maybe_update_burn_tracker_impl(from); + slow_wallet::maybe_track_unlocked_withdraw(from, value); + } + }; + + return c_opt } @@ -266,6 +316,62 @@ module ol_framework::ol_account { slow_wallet::balance(addr) } + // on new account creation we need the burn tracker created + // note return quietly if it's already initialized, so we can use it + // in the creation and tx flow + public fun init_burn_tracker(sig: &signer) { + let addr = signer::address_of(sig); + if (exists(addr)) return; + + let (_, total_balance) = balance(addr); + + move_to(sig, BurnTracker { + prev_supply: gas_coin::supply(), + prev_balance: total_balance, + burn_at_last_calc: 0, + cumu_burn: 0, + }) + } + + + /// TODO: the user may update the tracker outside of transactions + public fun user_update_burn_tracker() {} + + // NOTE: this must be called before immediately after any coins are deposited or withrdrawn. + fun maybe_update_burn_tracker_impl(addr: address) acquires BurnTracker { + if (!exists(addr)) return;// return quietly as the VM may call this + + let state = borrow_global_mut(addr); + // 1. how much burn happened in between + // this must be true but we + // don't abort since the VM may be calling this + let current_supply = gas_coin::supply(); + let original_supply = gas_coin::get_final_supply(); + if (original_supply > current_supply) { + let burn_in_period = original_supply - current_supply; + + if (burn_in_period > 0 && burn_in_period > state.prev_balance && + state.prev_balance > 0 ) { + let attributed_burn = burn_in_period / state.prev_balance; + // attributed burn may be zero because of rounding effects + // in that case we should skip the updating altogether and + // only track when the attributable is > 1. Otherwise the + // whole chain of updates will be incorrect + if (attributed_burn > 0) { + state.cumu_burn = state.burn_at_last_calc + attributed_burn; + // now change last calc + state.burn_at_last_calc = attributed_burn; + // reset trackers for next tx + state.prev_supply = current_supply; + + let (_, total_balance) = balance(addr); + state.prev_balance = total_balance; + } + } + } + } + + // TODO: // #[test_only] // /// Batch version of transfer_coins. // public entry fun batch_transfer( @@ -276,28 +382,16 @@ module ol_framework::ol_account { // error::invalid_argument(EMISMATCHING_RECIPIENTS_AND_AMOUNTS_LENGTH), // ); - // let i = 0; - // while (i < recipients_len) { - // let to = *vector::borrow(&recipients, i); - // let amount = *vector::borrow(&amounts, i); - // transfer_coins(from, to, amount); - // i = i + 1; - // }; - // } - - // #[test_only] - // /// Convenient function to transfer a custom CoinType to a recipient account that might not exist. - // /// This would create the recipient account first and register it to receive the CoinType, before transferring. - // public entry fun transfer_coins(from: &signer, to: address, amount: u64) { - // deposit_coins(to, coin::withdraw(from, amount)); - // } /// A coin which is split or extracted can be sent to an account without a sender signing. /// TODO: cumulative tracker will not work here. - public fun deposit_coins(to: address, coins: Coin) { + public fun deposit_coins(to: address, coins: Coin) acquires + BurnTracker { assert!(coin::is_account_registered(to), error::invalid_state(EACCOUNT_NOT_REGISTERED_FOR_GAS)); slow_wallet::maybe_track_unlocked_deposit(to, coin::value(&coins)); coin::deposit(to, coins); + // the incoming coins should trigger an update in tracker + maybe_update_burn_tracker_impl(to); } // pass through function to guard the use of Coin @@ -363,11 +457,14 @@ module ol_framework::ol_account { struct FakeCoin {} #[test(root = @ol_framework, alice = @0xa11ce, core = @0x1)] - public fun test_transfer(root: &signer, alice: &signer, core: &signer) { + public fun test_transfer_ol(root: &signer, alice: &signer, core: &signer) + acquires BurnTracker { let bob = from_bcs::to_address(x"0000000000000000000000000000000000000000000000000000000000000b0b"); let carol = from_bcs::to_address(x"00000000000000000000000000000000000000000000000000000000000ca501"); - let (burn_cap, mint_cap) = ol_framework::gas_coin::initialize_for_test(core); + let (burn_cap, mint_cap) = + ol_framework::gas_coin::initialize_for_test(core); + gas_coin::test_set_final_supply(root, 1000); // dummy to prevent fail create_account(root, signer::address_of(alice)); create_account(root, bob); create_account(root, carol); @@ -384,12 +481,15 @@ module ol_framework::ol_account { } #[test(root = @ol_framework, alice = @0xa11ce, core = @0x1)] - public fun test_transfer_to_resource_account(root: &signer, alice: &signer, core: &signer) { + public fun test_transfer_to_resource_account_ol(root: &signer, alice: &signer, + core: &signer) acquires BurnTracker{ let (resource_account, _) = ol_create_resource_account(alice, vector[]); let resource_acc_addr = signer::address_of(&resource_account); - // assert!(!coin::is_account_registered(resource_acc_addr), 0); - let (burn_cap, mint_cap) = ol_framework::gas_coin::initialize_for_test(core); + let (burn_cap, mint_cap) = + ol_framework::gas_coin::initialize_for_test(core); + gas_coin::test_set_final_supply(root, 1000); // dummy to prevent fail + create_account(root, signer::address_of(alice)); coin::deposit(signer::address_of(alice), coin::mint(10000, &mint_cap)); transfer(alice, resource_acc_addr, 500); @@ -400,8 +500,12 @@ module ol_framework::ol_account { } #[test(root = @ol_framework, from = @0x123, core = @0x1, recipient_1 = @0x124, recipient_2 = @0x125)] - public fun test_batch_transfer(root: &signer, from: &signer, core: &signer, recipient_1: &signer, recipient_2: &signer) { - let (burn_cap, mint_cap) = diem_framework::gas_coin::initialize_for_test(core); + public fun test_batch_transfer(root: &signer, from: &signer, core: &signer, + recipient_1: &signer, recipient_2: &signer) acquires BurnTracker{ + let (burn_cap, mint_cap) = + diem_framework::gas_coin::initialize_for_test(core); + gas_coin::test_set_final_supply(root, 1000); // dummy to prevent fail + create_account(root, signer::address_of(from)); let recipient_1_addr = signer::address_of(recipient_1); let recipient_2_addr = signer::address_of(recipient_2); @@ -471,8 +575,14 @@ module ol_framework::ol_account { // } #[test(root = @ol_framework, user = @0x123)] - public fun test_set_allow_direct_coin_transfers(root: &signer, user: &signer) acquires DirectTransferConfig { + public fun test_set_allow_direct_coin_transfers(root: &signer, user: + &signer) acquires DirectTransferConfig { let addr = signer::address_of(user); + let (b, m) = gas_coin::initialize_for_test(root); + coin::destroy_burn_cap(b); + coin::destroy_mint_cap(m); + gas_coin::test_set_final_supply(root, 1000); // dummy to prevent fail + create_account(root, addr); set_allow_direct_coin_transfers(user, true); assert!(can_receive_direct_coin_transfers(addr), 0); @@ -481,51 +591,4 @@ module ol_framework::ol_account { set_allow_direct_coin_transfers(user, true); assert!(can_receive_direct_coin_transfers(addr), 2); } - - // #[test(root = @ol_framework, from = @0x1, to = @0x12)] - // public fun test_direct_coin_transfers_with_explicit_direct_coin_transfer_config( - // root: &signer, from: &signer, to: &signer) acquires DirectTransferConfig { - // let (burn_cap, freeze_cap, mint_cap) = coin::initialize( - // from, - // utf8(b"FC"), - // utf8(b"FC"), - // 10, - // true, - // ); - // create_account(root, signer::address_of(from)); - // create_account(root, signer::address_of(to)); - // set_allow_direct_coin_transfers(from, true); - // deposit_coins(signer::address_of(from), coin::mint(1000, &mint_cap)); - // // Recipient account did not explicit register for the coin. - // let to_addr = signer::address_of(to); - // transfer_coins(from, to_addr, 500); - // assert!(coin::balance(to_addr) == 500, 0); - - // coin::destroy_burn_cap(burn_cap); - // coin::destroy_mint_cap(mint_cap); - // coin::destroy_freeze_cap(freeze_cap); - // } - - // #[test(root = @ol_framework, from = @0x1, to = @0x12)] - // #[expected_failure(abort_code = 0x50003, location = Self)] - // public fun test_direct_coin_transfers_fail_if_recipient_opted_out( - // root: &signer, from: &signer, to: &signer) acquires DirectTransferConfig { - // let (burn_cap, freeze_cap, mint_cap) = coin::initialize( - // from, - // utf8(b"FC"), - // utf8(b"FC"), - // 10, - // true, - // ); - // create_account(root, signer::address_of(from)); - // create_account(root, signer::address_of(to)); - // set_allow_direct_coin_transfers(from, false); - // deposit_coins(signer::address_of(from), coin::mint(1000, &mint_cap)); - // // This should fail as the to account has explicitly opted out of receiving arbitrary coins. - // transfer_coins(from, signer::address_of(to), 500); - - // coin::destroy_burn_cap(burn_cap); - // coin::destroy_mint_cap(mint_cap); - // coin::destroy_freeze_cap(freeze_cap); - // } } diff --git a/framework/libra-framework/sources/ol_sources/tests/_meta_epoch.test.move b/framework/libra-framework/sources/ol_sources/tests/_meta_epoch.test.move index aaf6d0ca0..e3e9895be 100644 --- a/framework/libra-framework/sources/ol_sources/tests/_meta_epoch.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/_meta_epoch.test.move @@ -52,7 +52,7 @@ module ol_framework::test_meta { // #[test(root = @ol_framework)] // fun test_reconfigure_mock_trigger(root: signer) { // mock::ol_test_genesis(&root); - // mock::ol_initialize_coin(&root); + // // mock::ol_initialize_coin(&root); // let a = reconfiguration::get_current_epoch(); // mock::trigger_epoch(&root); diff --git a/framework/libra-framework/sources/ol_sources/tests/migration.test.move b/framework/libra-framework/sources/ol_sources/tests/migration.test.move index fc1b226da..94c246546 100644 --- a/framework/libra-framework/sources/ol_sources/tests/migration.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/migration.test.move @@ -3,7 +3,6 @@ module ol_framework::test_migration { use ol_framework::genesis_migration; use ol_framework::infra_escrow; use ol_framework::slow_wallet; - use diem_framework::genesis; use std::fixed_point32; use ol_framework::mock; use diem_framework::coin; @@ -11,21 +10,17 @@ module ol_framework::test_migration { use std::signer; use std::bcs; - // use diem_std::debug::print; - #[test(root = @ol_framework, user = @0xaaaaaa)] fun test_migration_balance_end_user(root: signer, user: signer) { let temp_auth_key = bcs::to_bytes(&signer::address_of(&user)); mock::genesis_n_vals(&root, 4); - genesis::test_initalize_coins(&root); genesis_migration::migrate_legacy_user( &root, &user, temp_auth_key, 20000, - // 5, ) } @@ -34,10 +29,7 @@ module ol_framework::test_migration { fun test_migration_balance_validators(root: signer, vm: signer, marlon_rando: signer) { let _vals = mock::genesis_n_vals(&root, 4); - // mock::ol_initialize_coin_and_fund_vals(&root, 1000000); - genesis::test_initalize_coins(&root); - // let alice = vector::borrow(&vals, 0); let addr = signer::address_of(&marlon_rando); let temp_auth_key = bcs::to_bytes(&addr); @@ -49,9 +41,6 @@ module ol_framework::test_migration { &marlon_rando, temp_auth_key, init_balance, - // true, // is_validator - // scale_integer * 1000000,// of 1m - // escrow_pct * 10000, // of 1m ); let user_balance = coin::balance(addr); diff --git a/framework/libra-framework/sources/ol_sources/tests/rewards.test.move b/framework/libra-framework/sources/ol_sources/tests/rewards.test.move index 5007123db..8c07e27a7 100644 --- a/framework/libra-framework/sources/ol_sources/tests/rewards.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/rewards.test.move @@ -1,38 +1,28 @@ #[test_only] module ol_framework::test_rewards { - // #[test_only] - // use std::vector; #[test_only] use ol_framework::rewards; - // #[test_only] - // use ol_framework::ol_account; #[test_only] use ol_framework::gas_coin::{Self, LibraCoin as GasCoin}; #[test_only] use diem_framework::coin; #[test_only] use ol_framework::mock; - - // #[test_only] - // use ol_framework::gas_coin::LibraCoin as GasCoin; #[test_only] use diem_framework::stake; - - // #[test_only] - // use diem_std::debug::print; - #[test(root = @ol_framework)] fun test_pay_reward_single(root: signer) { let alice = @0x1000a; mock::genesis_n_vals(&root, 1); + let mint_cap = gas_coin::extract_mint_cap(&root); + let uid_before = stake::get_reward_event_guid(alice); - let (burn_cap, mint_cap) = gas_coin::initialize_for_test_without_aggregator_factory(&root); let new_coin = coin::test_mint(10000, &mint_cap); - coin::destroy_burn_cap(burn_cap); + coin::destroy_mint_cap(mint_cap); rewards::test_helper_pay_reward(&root, alice, new_coin, 1); @@ -50,12 +40,11 @@ module ol_framework::test_rewards { let dave = @0x1000d; let vals = mock::genesis_n_vals(root, 4); + let mint_cap = gas_coin::extract_mint_cap(root); let uid_before = stake::get_reward_event_guid(dave); assert!(uid_before == 0, 7357000); - - let (burn_cap, mint_cap) = gas_coin::initialize_for_test_without_aggregator_factory(root); let new_coin = coin::test_mint(10000, &mint_cap); - coin::destroy_burn_cap(burn_cap); + coin::destroy_mint_cap(mint_cap); rewards::test_process_recipients(root, vals, 1000, &mut new_coin, 1); diff --git a/framework/libra-framework/sources/ol_sources/tests/slow_wallet.test.move b/framework/libra-framework/sources/ol_sources/tests/slow_wallet.test.move index 422ecbff5..b9526b2dc 100644 --- a/framework/libra-framework/sources/ol_sources/tests/slow_wallet.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/slow_wallet.test.move @@ -61,6 +61,9 @@ module ol_framework::test_slow_wallet { #[test(root = @ol_framework, alice = @0x123, bob = @0x456)] fun test_transfer_unlocked_happy(root: signer, alice: signer) { + mock::ol_test_genesis(&root); + let mint_cap = gas_coin::extract_mint_cap(&root); + slow_wallet::initialize(&root); @@ -73,9 +76,7 @@ module ol_framework::test_slow_wallet { assert!(slow_wallet::unlocked_amount(@0x123) == 0, 735701); // add some coins to alice - let (burn_cap, mint_cap) = gas_coin::initialize_for_test(&root); ol_account::deposit_coins(@0x123, coin::test_mint(10000, &mint_cap)); - coin::destroy_burn_cap(burn_cap); coin::destroy_mint_cap(mint_cap); // the transfer was of already unlocked coins, so they will post as unlocked on alice assert!(slow_wallet::unlocked_amount(@0x123) == 10000, 735703); @@ -92,6 +93,8 @@ module ol_framework::test_slow_wallet { #[test(root = @ol_framework, alice = @0x123, bob = @0x456)] #[expected_failure(abort_code = 196614, location = 0x1::ol_account)] fun test_transfer_sad(root: signer, alice: signer) { + mock::ol_test_genesis(&root); + let mint_cap = gas_coin::extract_mint_cap(&root); slow_wallet::initialize(&root); ol_account::create_account(&root, @0x123); slow_wallet::set_slow(&alice); @@ -99,9 +102,9 @@ module ol_framework::test_slow_wallet { assert!(slow_wallet::unlocked_amount(@0x123) == 0, 735701); // fund alice - let (burn_cap, mint_cap) = gas_coin::initialize_for_test(&root); + // let (burn_cap, mint_cap) = gas_coin::initialize_for_test(&root); ol_account::deposit_coins(@0x123, coin::test_mint(100, &mint_cap)); - coin::destroy_burn_cap(burn_cap); + // coin::destroy_burn_cap(burn_cap); coin::destroy_mint_cap(mint_cap); // alice will transfer and create bob's account @@ -120,7 +123,7 @@ module ol_framework::test_slow_wallet { // and a validator creation sets the users account to slow. fun slow_wallet_reconfigure (root: signer) { let set = mock::genesis_n_vals(&root, 4); - mock::ol_initialize_coin(&root); + // mock::ol_initialize_coin(&root); let a = vector::borrow(&set, 0); assert!(slow_wallet::unlocked_amount(*a) == 0, 735701); epoch_boundary::ol_reconfigure_for_test(&root, reconfiguration::get_current_epoch(), block::get_current_block_height()) diff --git a/framework/libra-framework/sources/ol_sources/tests/tower.test.move b/framework/libra-framework/sources/ol_sources/tests/tower.test.move index 1d20a4180..d6c340fe8 100644 --- a/framework/libra-framework/sources/ol_sources/tests/tower.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/tower.test.move @@ -21,7 +21,7 @@ module ol_framework::test_tower { #[test(root = @ol_framework)] fun epoch_changes_difficulty(root: signer) { mock::genesis_n_vals(&root, 4); - mock::ol_initialize_coin(&root); + // mock::ol_initialize_coin(&root); mock::tower_default(&root); // make all the validators initialize towers // because we need randomness for the toy rng @@ -41,7 +41,7 @@ module ol_framework::test_tower { #[test(root = @ol_framework, cousin_alice = @0x87515d94a244235a1433d7117bc0cb154c613c2f4b1e67ca8d98a542ee3f59f5)] fun init_tower_state(root: signer, cousin_alice: signer){ mock::ol_test_genesis(&root); - mock::ol_initialize_coin(&root); + // mock::ol_initialize_coin(&root); timestamp::fast_forward_seconds(1); ol_account::create_account(&root, signer::address_of(&cousin_alice)); @@ -59,7 +59,7 @@ module ol_framework::test_tower { #[test(root = @ol_framework)] fun toy_rng_state(root: signer) { mock::genesis_n_vals(&root, 4); - mock::ol_initialize_coin(&root); + // mock::ol_initialize_coin(&root); mock::tower_default(&root); // make all the validators initialize towers // because we need randomness for the toy rng @@ -74,7 +74,7 @@ module ol_framework::test_tower { fun toy_rng_minimal(root: signer) { // use diem_std::debug::print; mock::genesis_n_vals(&root, 1); - mock::ol_initialize_coin(&root); + // mock::ol_initialize_coin(&root); mock::tower_default(&root); // make all the validators initialize towers // because we need randomness for the toy rng @@ -89,7 +89,7 @@ module ol_framework::test_tower { fun miner_receives_reward(root: signer, cousin_alice: signer) { let a_addr = signer::address_of(&cousin_alice); let vals = mock::genesis_n_vals(&root, 5); - mock::ol_initialize_coin(&root); + // mock::ol_initialize_coin(&root); mock::pof_default(); ol_account::create_account(&root, a_addr); proof_of_fee::fill_seats_and_get_price(&root, 5, &vals, &vals); diff --git a/framework/libra-framework/sources/ol_sources/tests/validator_reward.test.move b/framework/libra-framework/sources/ol_sources/tests/validator_reward.test.move index c7db48c72..d26fbd074 100644 --- a/framework/libra-framework/sources/ol_sources/tests/validator_reward.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/validator_reward.test.move @@ -18,7 +18,7 @@ module ol_framework::test_reconfiguration { #[test(root = @ol_framework)] fun reconfig_reward_happy_case(root: signer) { let vals = mock::genesis_n_vals(&root, 5); - mock::ol_initialize_coin(&root); + // mock::ol_initialize_coin(&root); mock::pof_default(); assert!(vector::length(&vals) == 5, 7357001); let vals = stake::get_current_validators(); @@ -49,7 +49,7 @@ module ol_framework::test_reconfiguration { #[test(root = @ol_framework)] fun drop_non_performing(root: signer) { let _vals = mock::genesis_n_vals(&root, 5); - mock::ol_initialize_coin(&root); + // mock::ol_initialize_coin(&root); mock::pof_default(); assert!(coin::balance(@0x1000a) == 0, 7357000); @@ -97,7 +97,7 @@ module ol_framework::test_reconfiguration { #[test(root = @ol_framework)] fun reconfig_failover(root: signer) { let vals = mock::genesis_n_vals(&root, 5); - mock::ol_initialize_coin(&root); + // mock::ol_initialize_coin(&root); mock::pof_default(); diff --git a/framework/libra-framework/sources/ol_sources/tests/vote_lib/multi_action.test.move b/framework/libra-framework/sources/ol_sources/tests/vote_lib/multi_action.test.move index 463a8f5f9..9b124a504 100644 --- a/framework/libra-framework/sources/ol_sources/tests/vote_lib/multi_action.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/vote_lib/multi_action.test.move @@ -23,7 +23,7 @@ module ol_framework::test_multi_action { let vals = mock::genesis_n_vals(root, 2); - mock::ol_initialize_coin(root); + // mock::ol_initialize_coin(root); let (resource_sig, _cap) = ol_account::ol_create_resource_account(dave, b"0x1"); @@ -40,7 +40,7 @@ module ol_framework::test_multi_action { fun propose_action(root: &signer, dave: &signer, alice: &signer) { let vals = mock::genesis_n_vals(root, 2); - mock::ol_initialize_coin(root); + // mock::ol_initialize_coin(root); let (resource_sig, _cap) = ol_account::ol_create_resource_account(dave, b"0x1"); let new_resource_address = signer::address_of(&resource_sig); @@ -64,7 +64,7 @@ module ol_framework::test_multi_action { fun propose_action_prevent_duplicated(root: &signer, dave: &signer, alice: &signer, bob: &signer) { // Scenario: alice and bob are authorities. They try to send the same proposal let vals = mock::genesis_n_vals(root, 2); - mock::ol_initialize_coin(root); + // mock::ol_initialize_coin(root); let (resource_sig, _cap) = ol_account::ol_create_resource_account(dave, b"0x1"); let new_resource_address = signer::address_of(&resource_sig); diff --git a/framework/libra-framework/sources/ol_sources/tests/vote_lib/turnout_tally.test.move b/framework/libra-framework/sources/ol_sources/tests/vote_lib/turnout_tally.test.move index 342fae42a..7de5c0568 100644 --- a/framework/libra-framework/sources/ol_sources/tests/vote_lib/turnout_tally.test.move +++ b/framework/libra-framework/sources/ol_sources/tests/vote_lib/turnout_tally.test.move @@ -63,6 +63,7 @@ module ol_framework::test_turnout_tally { #[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b)] fun tally_vote_retract(root: &signer, alice: &signer, bob: &signer) { let _vals = mock::genesis_n_vals(root, 1); + // mock::ol_initialize_coin_and_fund_vals(root, 100, true); turnout_tally_demo::init(alice); // ZERO HERE MEANS IT NEVER EXPIRES let uid = turnout_tally_demo::propose_ballot_by_owner(alice, 100, 0); @@ -101,7 +102,7 @@ module ol_framework::test_turnout_tally { fun tally_vote_expired(root: &signer, alice: &signer, bob: &signer) { let _vals = mock::genesis_n_vals(root, 1); - mock::ol_initialize_coin(root); + // mock::ol_initialize_coin(root); // for this test let's start at epoch 1 mock::trigger_epoch(root); @@ -127,7 +128,7 @@ module ol_framework::test_turnout_tally { // The election will close before then once threshold is reached. let _vals = mock::genesis_n_vals(root, 1); - mock::ol_initialize_coin(root); + // mock::ol_initialize_coin(root); // for this test let's start at epoch 1 mock::trigger_epoch(root); @@ -162,7 +163,7 @@ module ol_framework::test_turnout_tally { #[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b)] fun tally_never_expires(root: &signer, alice: &signer, bob: &signer) { let _vals = mock::genesis_n_vals(root, 1); - mock::ol_initialize_coin(root); + // mock::ol_initialize_coin(root); turnout_tally_demo::init(alice); diff --git a/framework/releases/head.mrb b/framework/releases/head.mrb index fda2e129c..304d46ee3 100644 Binary files a/framework/releases/head.mrb and b/framework/releases/head.mrb differ diff --git a/smoke-tests/src/libra_smoke.rs b/smoke-tests/src/libra_smoke.rs index b5a522ae2..12edc5e58 100644 --- a/smoke-tests/src/libra_smoke.rs +++ b/smoke-tests/src/libra_smoke.rs @@ -73,9 +73,13 @@ impl LibraSmoke { // the genesis does NOT mint by default to genesis validators // 10,000 coins with 6 decimals precision let mut pub_info = swarm.diem_public_info(); - helpers::mint_libra(&mut pub_info, addr, 100_000_000_000).await?; + helpers::mint_libra(&mut pub_info, addr, 1000 * 1_000_000) + .await + .context("could not mint to account")?; - helpers::unlock_libra(&mut pub_info, addr, 100_000_000_000).await?; + helpers::unlock_libra(&mut pub_info, addr, 1000 * 1_000_000) + .await + .context("could not unlock coins")?; Ok(Self { swarm, diff --git a/tools/genesis/src/genesis_functions.rs b/tools/genesis/src/genesis_functions.rs index d5cb6e107..5a98bd316 100644 --- a/tools/genesis/src/genesis_functions.rs +++ b/tools/genesis/src/genesis_functions.rs @@ -311,6 +311,29 @@ pub fn rounding_mint(session: &mut SessionExt, supply_settings: &SupplySettings) ); } +// before any accounts are created we need to have a FinalMint in place +// It should also happen immediately after LibraCoin gets initialized +pub fn set_final_supply(session: &mut SessionExt, supply_settings: &SupplySettings) { + let serialized_values = serialize_values(&vec![ + MoveValue::Signer(CORE_CODE_ADDRESS), + MoveValue::U64(supply_settings.scale_supply() as u64), + ]); + + exec_function( + session, + "gas_coin", + "genesis_set_final_supply", + vec![], + serialized_values, + ); +} + +// pub fn mint_genesis_bootstrap_coin(session: &mut SessionExt, validators: &[Validator]) { +// validators.iter().for_each(|v| { +// let serialized_values = serialize_values(&vec![ +// MoveValue::Signer(AccountAddress::ZERO), // must be called by 0x0 +// MoveValue::Address(v.owner_address), +// ]); pub fn set_validator_baseline_reward(session: &mut SessionExt, nominal_reward: u64) { let serialized_values = serialize_values(&vec![ MoveValue::Signer(AccountAddress::ZERO), // must be called by 0x0 diff --git a/tools/genesis/src/vm.rs b/tools/genesis/src/vm.rs index 1f983fbc0..0792fe3d0 100644 --- a/tools/genesis/src/vm.rs +++ b/tools/genesis/src/vm.rs @@ -26,7 +26,7 @@ use diem_vm_genesis::{ use libra_types::{legacy_types::legacy_recovery::LegacyRecovery, ol_progress::OLProgress}; use crate::{ - genesis_functions::{rounding_mint, set_validator_baseline_reward}, + genesis_functions::{rounding_mint, set_final_supply, set_validator_baseline_reward}, supply::{populate_supply_stats_from_legacy, SupplySettings}, }; @@ -127,9 +127,13 @@ pub fn encode_genesis_change_set( initialize_features(&mut session); - // TODO: replace this + // TODO: consolidate with set_final_supply initialize_diem_coin(&mut session); + // final supply must be set after coin is initialized, but before any + // accounts are created + set_final_supply(&mut session, supply_settings); + initialize_on_chain_governance(&mut session, genesis_config); if let Some(r) = recovery { diff --git a/tools/genesis/tests/fixtures/genesis.blob b/tools/genesis/tests/fixtures/genesis.blob index 624d2a6b2..24e9815df 100644 Binary files a/tools/genesis/tests/fixtures/genesis.blob and b/tools/genesis/tests/fixtures/genesis.blob differ diff --git a/tools/query/tests/query.rs b/tools/query/tests/query.rs index ae5f669d7..95be6f9a8 100644 --- a/tools/query/tests/query.rs +++ b/tools/query/tests/query.rs @@ -15,8 +15,8 @@ async fn libra_query_test() { Ok(v) => { println!("v: {:?}", v); let b: LibraBalanceDisplay = serde_json::from_value(v).unwrap(); - assert!(b.unlocked == 100000.0); - assert!(b.total == 100000.0); + assert!(b.unlocked == 1000.0); + assert!(b.total == 1000.0); } Err(e) => { println!("e: {:?}", e); diff --git a/tools/query/tests/view.rs b/tools/query/tests/view.rs new file mode 100644 index 000000000..ee1600461 --- /dev/null +++ b/tools/query/tests/view.rs @@ -0,0 +1,28 @@ +use libra_query::query_type::QueryType; +use libra_smoke_tests::libra_smoke::LibraSmoke; + +/// Testing the query library +#[tokio::test(flavor = "multi_thread", worker_threads = 1)] +async fn libra_view_test() { + let mut s = LibraSmoke::new(None).await.expect("could not start swarm"); + + let c = s.client(); + + let q = QueryType::View { + function_id: "0x1::gas_coin::supply".to_string(), + type_args: None, + args: None, + }; + match q.query_to_json(Some(c.to_owned())).await { + Ok(v) => { + println!("v: {:?}", v); + // let b: LibraBalanceDisplay = serde_json::from_value(v).unwrap(); + // assert!(b.unlocked == 10.0); + // assert!(b.total == 10.0); + } + Err(e) => { + println!("e: {:?}", e); + panic!("nothing returned from query"); + } + } +} diff --git a/tools/tower/tests/tower_newbie.rs b/tools/tower/tests/tower_newbie.rs index 384b9fcb9..5ec3c9526 100644 --- a/tools/tower/tests/tower_newbie.rs +++ b/tools/tower/tests/tower_newbie.rs @@ -1,3 +1,4 @@ +use anyhow::Context; use libra_smoke_tests::libra_smoke::LibraSmoke; use libra_txs::submit_transaction::Sender; @@ -24,8 +25,9 @@ async fn tower_newbie() -> anyhow::Result<()> { // create an account for alice by transferring funds let mut s = Sender::from_app_cfg(&val_app_cfg, None).await?; let res = s - .transfer(alice.child_0_owner.account, 10_000.0, false) - .await? + .transfer(alice.child_0_owner.account, 100.0, false) + .await + .context("could not create account")? .unwrap(); assert!(res.info.status().is_success()); diff --git a/tools/txs/tests/sender_primitives.rs b/tools/txs/tests/sender_primitives.rs index 71f6cc6fa..249ce696b 100644 --- a/tools/txs/tests/sender_primitives.rs +++ b/tools/txs/tests/sender_primitives.rs @@ -26,7 +26,7 @@ async fn sender_back_and_forth() -> anyhow::Result<()> { // create an account for alice by transferring funds let mut s = Sender::from_app_cfg(&val_app_cfg, None).await?; let res = s - .transfer(alice.child_0_owner.account, 10_000.0, false) + .transfer(alice.child_0_owner.account, 100.0, false) .await? .unwrap(); assert!(res.info.status().is_success()); diff --git a/tools/txs/tests/transfer.rs b/tools/txs/tests/transfer.rs index 2c7999ac7..1130d269a 100644 --- a/tools/txs/tests/transfer.rs +++ b/tools/txs/tests/transfer.rs @@ -108,7 +108,7 @@ async fn smoke_transfer_estimate() { config_path: Some(d.path().to_owned().join("libra.yaml")), url: Some(s.api_endpoint.clone()), tx_profile: None, - tx_cost: Some(TxCost::default_baseline_cost()), + tx_cost: Some(TxCost::default_cheap_txs_cost()), estimate_only: true, };