Skip to content

Commit

Permalink
patch block and infra_escrow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Jan 21, 2025
1 parent 2fc6773 commit a4a56f4
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 19 deletions.
8 changes: 6 additions & 2 deletions framework/libra-framework/sources/block.move
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ module diem_framework::block {
let block_resource = borrow_global_mut<BlockResource>(@diem_framework);
let old_epoch_interval = block_resource.epoch_interval;

reconfiguration::set_epoch_interval(diem_framework, new_epoch_interval);

// NOTE this data is duplicated since block.move
// cannot be accessed by other system modules without creating
// circular dependencies.
// update locally
block_resource.epoch_interval = new_epoch_interval;
// and set in reconfigurations
reconfiguration::set_epoch_interval(diem_framework, new_epoch_interval);

event::emit_event<UpdateEpochIntervalEvent>(
Expand Down
20 changes: 14 additions & 6 deletions framework/libra-framework/sources/ol_sources/infra_escrow.move
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,20 @@ module ol_framework::infra_escrow{
}
}

#[test_only]
public(friend) fun test_fund_account_from_infra(framework: &signer, to: address, amount: u64) {
// belt and suspenders
system_addresses::assert_diem_framework(framework);
assert!(testnet::is_not_mainnet(), error::invalid_state(EWITHDRAW_NOT_ON_MAINNET));
// #[test_only]
// public(friend) fun test_fund_account_from_infra(framework: &signer, to: address, amount: u64) {
// // belt and suspenders
// system_addresses::assert_diem_framework(framework);
// assert!(testnet::is_not_mainnet(), error::invalid_state(EWITHDRAW_NOT_ON_MAINNET));

framework_fund_account(framework, to, amount);
// framework_fund_account(framework, to, amount);
// }

#[test_only]
// test helper to initialize escrow for unit tests which don't do a full genesis
public fun init_escrow_with_deposit(framework: &signer, depositor: &signer, amount: u64){
pledge_accounts::initialize(framework);
initialize(framework);
user_pledge_infra(depositor, amount);
}
}
64 changes: 53 additions & 11 deletions framework/libra-framework/sources/ol_sources/mock.move
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module ol_framework::mock {
use ol_framework::ol_account;
use ol_framework::epoch_helper;
use ol_framework::musical_chairs;
use ol_framework::infra_escrow;
use ol_framework::pledge_accounts;
use ol_framework::secret_bid;

Expand Down Expand Up @@ -187,7 +188,6 @@ module ol_framework::mock {
libra_coin::extract_mint_cap(root)
} else {
coin_init_minimal(root)

};

if (!account::exists_at(addr)) {
Expand Down Expand Up @@ -243,7 +243,6 @@ module ol_framework::mock {
transaction_fee::vm_pay_fee(root, @ol_framework, tx_fees_start);
}


#[test_only]
// For unit test, we need to try to initialize the minimal state for
// user transactions. In the case of a unit tests which does a genesis with validators, this will not attempt to re-initialize the state.
Expand All @@ -255,28 +254,71 @@ module ol_framework::mock {

transaction_fee::initialize_fee_collection_and_distribution(root, 0);

let genesis_mint = coin::test_mint(FINAL_SUPPLY_AT_GENESIS, &mint_cap);
// let initial_fees = 5_000_000 * 100; // coin scaling * 100 coins
let genesis_coins = coin::test_mint(FINAL_SUPPLY_AT_GENESIS, &mint_cap);
libra_coin::test_set_final_supply(root, FINAL_SUPPLY_AT_GENESIS);
assert!(libra_coin::supply() == FINAL_SUPPLY_AT_GENESIS, ESUPPLY_MISMATCH);
let supply_pre = libra_coin::supply();

assert!(supply_pre == FINAL_SUPPLY_AT_GENESIS, ESUPPLY_MISMATCH);

// transaction_fee::vm_pay_fee(root, @ol_framework, tx_fees);

// Forge Bruce
// We need to simulate a long running network
// where the Infra Pledge account accumulated.
// Here we use Wayne Enterprises as the sole sponsor of the
// test environment Infra Pedge
// test environment Infra Pledge
let bruce_address = @0xBA7;
ol_account::create_account(root, bruce_address);
// Bruce inherits a fortune, the remainder of genesis mint
ol_account::deposit_coins(bruce_address, genesis_mint);
let bruce_sig = account::create_signer_for_test(bruce_address);

// Bruce inherits a fortune, all the coins from genesis
ol_account::deposit_coins(bruce_address, genesis_coins);

// Bruce pledges 37B to infra escrow
let bruce = account::create_signer_for_test(bruce_address);
pledge_accounts::user_pledge(&bruce, @ol_framework, INFRA_ESCROW_START);
// Bruce mints a fortune
// let fortune_mint = coin::test_mint(fortune, &mint_cap);
// ol_account::deposit_coins(bruce_address, fortune_mint);

assert!(libra_coin::supply() == FINAL_SUPPLY_AT_GENESIS, ESUPPLY_MISMATCH);
// Bruce funds infra escrow
infra_escrow::init_escrow_with_deposit(root, &bruce_sig, INFRA_ESCROW_START);

assert!(supply_pre == libra_coin::supply(), ESUPPLY_MISMATCH);

mint_cap
}
// #[test_only]
// // For unit test, we need to try to initialize the minimal state for
// // user transactions. In the case of a unit tests which does a genesis with validators, this will not attempt to re-initialize the state.
// fun coin_init_minimal(root: &signer): coin::MintCapability<LibraCoin> {
// system_addresses::assert_ol(root);

// let (burn_cap, mint_cap) = libra_coin::initialize_for_test(root);
// coin::destroy_burn_cap(burn_cap);

// transaction_fee::initialize_fee_collection_and_distribution(root, 0);

// let genesis_mint = coin::test_mint(FINAL_SUPPLY_AT_GENESIS, &mint_cap);
// libra_coin::test_set_final_supply(root, FINAL_SUPPLY_AT_GENESIS);
// assert!(libra_coin::supply() == FINAL_SUPPLY_AT_GENESIS, ESUPPLY_MISMATCH);


// // We need to simulate a long running network
// // where the Infra Pledge account accumulated.
// // Here we use Wayne Enterprises as the sole sponsor of the
// // test environment Infra Pedge
// let bruce_address = @0xBA7;
// ol_account::create_account(root, bruce_address);
// // Bruce inherits a fortune, the remainder of genesis mint
// ol_account::deposit_coins(bruce_address, genesis_mint);

// // Bruce pledges 37B to infra escrow
// let bruce = account::create_signer_for_test(bruce_address);
// pledge_accounts::user_pledge(&bruce, @ol_framework, INFRA_ESCROW_START);

// assert!(libra_coin::supply() == FINAL_SUPPLY_AT_GENESIS, ESUPPLY_MISMATCH);

// mint_cap
// }

#[test_only]
public fun personas(): vector<address> {
Expand Down

0 comments on commit a4a56f4

Please sign in to comment.