Skip to content

Commit

Permalink
patch donor voice tests, had an incorrect assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Sep 27, 2024
1 parent d009df2 commit 00fcf1b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module ol_framework::test_boundary {
use diem_framework::transaction_fee;
use diem_framework::account;
use ol_framework::burn;
use ol_framework::epoch_helper;
use ol_framework::mock;
use ol_framework::proof_of_fee;
use ol_framework::secret_bid;
Expand All @@ -23,7 +24,7 @@ module ol_framework::test_boundary {
use ol_framework::block;
use ol_framework::ol_account;

// use diem_std::debug::print;
use diem_std::debug::print;

const Alice: address = @0x1000a;
const Bob: address = @0x1000b;
Expand Down Expand Up @@ -288,50 +289,53 @@ module ol_framework::test_boundary {
#[test(root = @ol_framework)]
fun epoch_increase_thermostat(root: &signer) {
let vals = common_test_setup(root);

let this_epoch = epoch_helper::get_current_epoch();
let entry_fee_bid = 0100;
// mock bids
vector::for_each(vals, |a| {
let sig = account::create_signer_for_test(a);
secret_bid::mock_revealed_bid(root, &sig, 0100, 30); // 10% for 30 epochs
secret_bid::mock_revealed_bid(root, &sig, entry_fee_bid, this_epoch); // 10% for 30 epochs
});

// mock bid history to increase thermostat by 5%
proof_of_fee::test_mock_reward(
root,
1000, // nominal reward
0100, // clearing bid
0100, // median win bid
vector[ 0100, 0100, 0100, 0100, 0100, 0100 ] // median history bellow 50%
100_000, // nominal reward
entry_fee_bid, // clearing bid
entry_fee_bid, // median win bid
vector[ entry_fee_bid, entry_fee_bid, entry_fee_bid, entry_fee_bid, entry_fee_bid, entry_fee_bid, ] // median history bellow 50%
);

// trigger epoch
mock::trigger_epoch(root);

print(&transaction_fee::system_fees_collected());
// check subsidy increased by 5%
// fees collected = entry fee + reward * 105%
// entry fee = 100 * 10 = 1_000
// reward = 1050 * 10 = 10_500
// entry fee = 100_000 * 0.1 * 10 = 100_000
// reward = 100_000 * 1.05 * 10 = 1_050_000
// fees collected = 11_500
assert!(transaction_fee::system_fees_collected() == 11_500, 7357001);
assert!(transaction_fee::system_fees_collected() == 1150000, 7357001);
}

#[test(root = @ol_framework)]
fun epoch_decrease_thermostat(root: &signer) {
let vals = common_test_setup(root);

let entry_fee_bid = 0970;
// mock bids
let this_epoch = epoch_helper::get_current_epoch();
vector::for_each(vals, |a| {
let sig = account::create_signer_for_test(a);
secret_bid::mock_revealed_bid(root, &sig, 0970, 30); // 97% for 30 epochs
secret_bid::mock_revealed_bid(root, &sig, entry_fee_bid, this_epoch);
});

// mock bid history to decrease thermostat by 5%
proof_of_fee::test_mock_reward(
root,
100_000, // nominal reward
0970, // clearing bid
0970, // median win bid
vector[ 0970, 0970, 0970, 0970, 0970, 0970 ] // median history above 95%
entry_fee_bid, // clearing bid
entry_fee_bid, // median win bid
vector[ entry_fee_bid, entry_fee_bid, entry_fee_bid, entry_fee_bid, 0970, entry_fee_bid ] // median history above 95%
);

// trigger epoch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module ol_framework::test_donor_voice {
use ol_framework::donor_voice_governance;
use ol_framework::community_wallet_init;
use ol_framework::community_wallet;
use ol_framework::burn;
use ol_framework::slow_wallet;
use diem_framework::multisig_account;
use std::guid;
Expand All @@ -22,7 +21,7 @@ module ol_framework::test_donor_voice {
use diem_std::debug::print;

#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b)]
fun dd_init(root: &signer, alice: &signer, bob: &signer) {
fun dv_init(root: &signer, alice: &signer, bob: &signer) {
let vals = mock::genesis_n_vals(root, 2);

let (resource_sig, _cap) = ol_account::test_ol_create_resource_account(alice, b"0x1");
Expand All @@ -48,7 +47,7 @@ module ol_framework::test_donor_voice {
}

#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b)]
fun dd_propose_payment(root: &signer, alice: &signer, bob: &signer) {
fun dv_propose_payment(root: &signer, alice: &signer, bob: &signer) {
// Scenario: Alice creates a resource_account which will be a donor directed account. She will not be one of the authorities of the account.
// only bob, carol, and dave with be authorities

Expand Down Expand Up @@ -78,7 +77,7 @@ module ol_framework::test_donor_voice {
}

#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b, carol = @0x1000c, dave = @0x1000d)]
fun dd_schedule_happy(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer) {
fun dv_schedule_happy(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer) {
// Scenario: Alice creates a resource_account which will be a donor directed account. She will not be one of the authorities of the account.
// only bob, carol, and dave with be authorities

Expand Down Expand Up @@ -124,7 +123,7 @@ module ol_framework::test_donor_voice {
}

#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b, carol = @0x1000c, dave = @0x1000d, eve = @0x1000e)]
fun dd_propose_and_veto(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer, eve: &signer) {
fun dv_propose_and_veto(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer, eve: &signer) {
// Scenario: Eve wants to veto a transaction on a donor directed account.
// Alice creates a donor directed account where Alice, Bob and Carol, are admins.
// Dave and Eve make a donation and so are able to have some voting on that account. The veto can only happen after Alice Bob and Carol are able to schedule a tx.
Expand Down Expand Up @@ -213,7 +212,7 @@ module ol_framework::test_donor_voice {
// should not be able sign a tx twice
#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b, carol = @0x1000c, dave = @0x1000d)]
#[expected_failure(abort_code = 65550, location = 0x1::multi_action)]
fun dd_reject_duplicate_proposal(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer) {
fun dv_reject_duplicate_proposal(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer) {
// Scenario: Alice creates a resource_account which will be a donor directed account. She will not be one of the authorities of the account.
// only bob, carol, and dave with be authorities

Expand Down Expand Up @@ -252,7 +251,7 @@ module ol_framework::test_donor_voice {


#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b, carol = @0x1000c, dave = @0x1000d)]
fun dd_process_unit(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer) {
fun dv_process_unit(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer) {
// Scenario: Alice creates a resource_account which will be a donor directed account. She will not be one of the authorities of the account.
// only bob, carol, and dave with be authorities

Expand Down Expand Up @@ -328,7 +327,7 @@ module ol_framework::test_donor_voice {
}

#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b, carol = @0x1000c, marlon_rando = @0x123456)]
fun dd_process_epoch_boundary(root: &signer, alice: &signer, bob: &signer, carol: &signer, marlon_rando: &signer) {
fun dv_process_epoch_boundary(root: &signer, alice: &signer, bob: &signer, carol: &signer, marlon_rando: &signer) {
// Scenario: Alice creates a resource_account which will be a donor directed account. She will not be one of the authorities of the account.
// only bob, carol, and dave with be authorities

Expand Down Expand Up @@ -397,7 +396,7 @@ module ol_framework::test_donor_voice {
}

#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b, carol = @0x1000c, dave = @0x1000d, marlon_rando = @0x123456)]
fun dd_process_multi_same_epoch(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer, marlon_rando: &signer) {
fun dv_process_multi_same_epoch(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer, marlon_rando: &signer) {
// Scenario: Alice creates a resource_account which will be a donor directed account. She will not be one of the authorities of the account.
// only bob, carol, and dave with be authorities

Expand Down Expand Up @@ -544,7 +543,7 @@ module ol_framework::test_donor_voice {


#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b, carol = @0x1000c, marlon_rando = @0x123456)]
fun dd_process_multi_different_epochs(root: &signer, alice: &signer, bob: &signer, carol: &signer, marlon_rando: &signer) {
fun dv_process_multi_different_epochs(root: &signer, alice: &signer, bob: &signer, carol: &signer, marlon_rando: &signer) {
// Scenario: Alice creates a resource_account which will be a donor directed account. She will not be one of the authorities of the account.
// only bob, carol, and dave with be authorities

Expand Down Expand Up @@ -669,7 +668,7 @@ module ol_framework::test_donor_voice {


#[test(root = @ol_framework, _alice = @0x1000a, dave = @0x1000d, eve = @0x1000e, donor_voice = @0x1000f)]
fun dd_liquidate_to_donor(root: &signer, _alice: &signer, dave: &signer, eve: &signer, donor_voice: &signer) {
fun dv_liquidate_to_donor(root: &signer, _alice: &signer, dave: &signer, eve: &signer, donor_voice: &signer) {
// Scenario:
// Alice creates a donor directed account where Alice, Bob and Carol, are admins.
// Dave and Eve make a donation and so are able to have some voting on that account.
Expand All @@ -680,8 +679,6 @@ module ol_framework::test_donor_voice {
// start at epoch 1, since turnout tally needs epoch info, and 0 may cause
// issues
mock::trigger_epoch(root);
// a burn happend in the epoch above, so let's compare it to end of epoch
let (lifetime_burn_pre, _) = burn::get_lifetime_tracker();

let donor_voice_address = signer::address_of(donor_voice);
// the account needs basic donor directed structs
Expand Down Expand Up @@ -745,13 +742,10 @@ module ol_framework::test_donor_voice {
// eve shoul have received funds back
assert!(eve_balance > eve_balance_pre, 7357010);

// nothing should have been burned, it was a refund
let (lifetime_burn_now, _) = burn::get_lifetime_tracker();
assert!(lifetime_burn_now == lifetime_burn_pre, 7357011);
}

#[test(root = @ol_framework, alice = @0x1000a, dave = @0x1000d, eve = @0x1000e)]
fun dd_liquidate_to_match_index(root: &signer, alice: &signer, dave: &signer, eve: &signer) {
fun dv_liquidate_to_match_index(root: &signer, alice: &signer, dave: &signer, eve: &signer) {
// Scenario:
// Alice creates a donor directed account where Alice, Bob and Carol, are admins.
// Dave and Eve make a donation and so are able to have some voting on that account.
Expand All @@ -761,8 +755,7 @@ module ol_framework::test_donor_voice {
mock::ol_initialize_coin_and_fund_vals(root, 100000, true);
// start at epoch 1, since turnout tally needs epoch info, and 0 may cause issues
mock::trigger_epoch(root);
// a burn happend in the epoch above, so let's compare it to end of epoch
let (lifetime_burn_pre, _) = burn::get_lifetime_tracker();


let (resource_sig, _cap) = ol_account::test_ol_create_resource_account(alice, b"0x1");
let donor_voice_address = signer::address_of(&resource_sig);
Expand Down Expand Up @@ -832,10 +825,6 @@ module ol_framework::test_donor_voice {
// program says it goes to the matching index.
assert!(eve_balance == eve_balance_pre, 7357010);

let (lifetime_burn_now, _lifetime_match) = burn::get_lifetime_tracker();

// nothing should have been burned, it was a refund
assert!(lifetime_burn_now == lifetime_burn_pre, 7357011);
}

#[test(root = @ol_framework, community = @0x10011, alice = @0x1000a, bob = @0x1000b, carol = @0x1000c)]
Expand Down

0 comments on commit 00fcf1b

Please sign in to comment.