diff --git a/framework/libra-framework/sources/ol_sources/libra_coin.move b/framework/libra-framework/sources/ol_sources/libra_coin.move index 493b8bbac..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,12 +130,16 @@ 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 {} @@ -258,12 +263,13 @@ module ol_framework::gas_coin { let supply_opt = coin::supply(); if (option::is_some(&supply_opt)) { let value = *option::borrow(&supply_opt); - if (value == 0) return 0u64; + 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)) { @@ -302,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); @@ -332,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); diff --git a/framework/libra-framework/sources/ol_sources/mock.move b/framework/libra-framework/sources/ol_sources/mock.move index ef8957dc6..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) { @@ -203,14 +205,13 @@ 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 @@ -311,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); @@ -362,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 511671a00..7703e9451 100644 --- a/framework/libra-framework/sources/ol_sources/ol_account.move +++ b/framework/libra-framework/sources/ol_sources/ol_account.move @@ -324,6 +324,7 @@ module ol_framework::ol_account { if (exists(addr)) return; let (_, total_balance) = balance(addr); + move_to(sig, BurnTracker { prev_supply: gas_coin::supply(), prev_balance: total_balance, diff --git a/framework/releases/head.mrb b/framework/releases/head.mrb index 67f6abf62..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 9c20b87a2..5fd15491b 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.context("could not mint to account")?; + helpers::mint_libra(&mut pub_info, addr, 1000 * 1000_000) + .await + .context("could not mint to account")?; - helpers::unlock_libra(&mut pub_info, addr, 100_000_000_000).await.context("could not unlock coins")?; + helpers::unlock_libra(&mut pub_info, addr, 1000 * 1000_000) + .await + .context("could not unlock coins")?; Ok(Self { swarm, diff --git a/tools/genesis/src/vm.rs b/tools/genesis/src/vm.rs index fea1ede36..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, set_final_supply}, + genesis_functions::{rounding_mint, set_final_supply, set_validator_baseline_reward}, supply::{populate_supply_stats_from_legacy, SupplySettings}, }; 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..b7f1d9beb 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; @@ -25,7 +26,8 @@ async fn tower_newbie() -> anyhow::Result<()> { 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? + .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, };