Skip to content

Commit

Permalink
fixed supply casting issue in smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Oct 26, 2023
1 parent 2c5e0ba commit 5e03b9a
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 18 deletions.
14 changes: 11 additions & 3 deletions framework/libra-framework/sources/ol_sources/libra_coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {}

Expand Down Expand Up @@ -258,12 +263,13 @@ module ol_framework::gas_coin {
let supply_opt = coin::supply<LibraCoin>();
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<LibraCoin>();
if (option::is_some(&supply_opt)) {
Expand Down Expand Up @@ -302,7 +308,8 @@ module ol_framework::gas_coin {
coin::register<LibraCoin>(core_resources);

let coins = coin::mint<LibraCoin>(
18446744073709551615,
1000000 * 1000000, // core resources can have 1M coins, MAX_U64 was
// causing arthmetic errors calling supply() on downcast
&mint_cap,
);
coin::deposit<LibraCoin>(signer::address_of(core_resources), coins);
Expand Down Expand Up @@ -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);

Expand Down
13 changes: 6 additions & 7 deletions framework/libra-framework/sources/ol_sources/mock.move
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -362,5 +362,4 @@ module ol_framework::mock {
assert!(entry_fee == 999, 73570003);
assert!(median_bid == 3, 73570004);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ module ol_framework::ol_account {
if (exists<BurnTracker>(addr)) return;

let (_, total_balance) = balance(addr);

move_to(sig, BurnTracker {
prev_supply: gas_coin::supply(),
prev_balance: total_balance,
Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.
8 changes: 6 additions & 2 deletions smoke-tests/src/libra_smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 76 in smoke-tests/src/libra_smoke.rs

View workflow job for this annotation

GitHub Actions / clippy

digits grouped inconsistently by underscores
.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)

Check failure on line 80 in smoke-tests/src/libra_smoke.rs

View workflow job for this annotation

GitHub Actions / clippy

digits grouped inconsistently by underscores
.await
.context("could not unlock coins")?;

Ok(Self {
swarm,
Expand Down
2 changes: 1 addition & 1 deletion tools/genesis/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down
4 changes: 2 additions & 2 deletions tools/query/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions tools/query/tests/view.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
4 changes: 3 additions & 1 deletion tools/tower/tests/tower_newbie.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Context;
use libra_smoke_tests::libra_smoke::LibraSmoke;

use libra_txs::submit_transaction::Sender;
Expand Down Expand Up @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion tools/txs/tests/sender_primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion tools/txs/tests/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down

0 comments on commit 5e03b9a

Please sign in to comment.