diff --git a/diem-move/diem-framework/core/tests/TransactionFeeTests.move b/diem-move/diem-framework/core/tests/TransactionFeeTests.move new file mode 100644 index 0000000000000..5c543b8413bc7 --- /dev/null +++ b/diem-move/diem-framework/core/tests/TransactionFeeTests.move @@ -0,0 +1,18 @@ +#[test_only] +module DiemFramework::TransactionFeeTests { + use DiemFramework::TransactionFee; + use DiemFramework::Genesis; + + #[test(tc = @TreasuryCompliance, dr = @DiemRoot)] + #[expected_failure(abort_code = 1)] + fun cannot_initialize_after_genesis(tc: signer, dr: signer) { + Genesis::setup(&dr, &tc); + TransactionFee::initialize(&tc); + } + + #[test(account = @0x100)] + #[expected_failure(abort_code = 258)] + fun cannot_initialize_as_non_tc(account: signer) { + TransactionFee::initialize(&account); + } +} diff --git a/diem-move/diem-framework/core/transactional-tests/transaction_fee/add_transaction_fee_currency.exp b/diem-move/diem-framework/core/transactional-tests/transaction_fee/add_transaction_fee_currency.exp new file mode 100644 index 0000000000000..748b96d8b92bb --- /dev/null +++ b/diem-move/diem-framework/core/transactional-tests/transaction_fee/add_transaction_fee_currency.exp @@ -0,0 +1,31 @@ +processed 10 tasks + +task 1 'block'. lines 3-7: +Events:{ + key: 11000000000000000000000000000000000000000a550c18 + seq_num: 0 + type: 0x1::DiemBlock::NewBlockEvent + data: "0000000000000000c5e34b925cf6875fec02d4b77adbd2d6000300000000000000" +} + + +task 3 'block'. lines 29-29: +Events:{ + key: 11000000000000000000000000000000000000000a550c18 + seq_num: 1 + type: 0x1::DiemBlock::NewBlockEvent + data: "0000000000000000c5e34b925cf6875fec02d4b77adbd2d6000400000000000000" +} + + +task 5 'run'. lines 39-47: +Error: Transaction discarded. VMStatus: status ABORTED of type Execution with sub status 5 + +task 6 'run'. lines 49-56: +Error: Transaction discarded. VMStatus: status ABORTED of type Execution with sub status 5 + +task 8 'run'. lines 67-74: +Error: Transaction discarded. VMStatus: status ABORTED of type Execution with sub status 6 + +task 9 'run'. lines 76-84: +Error: Transaction discarded. VMStatus: status ABORTED of type Execution with sub status 1 diff --git a/diem-move/diem-framework/core/transactional-tests/transaction_fee/add_transaction_fee_currency.move b/diem-move/diem-framework/core/transactional-tests/transaction_fee/add_transaction_fee_currency.move new file mode 100644 index 0000000000000..e346f4ff050c5 --- /dev/null +++ b/diem-move/diem-framework/core/transactional-tests/transaction_fee/add_transaction_fee_currency.move @@ -0,0 +1,84 @@ +//# init --validators Vivian --parent-vasps Bob + +//# block --proposer Vivian --time 3 + +// TODO: see if we can replace some of the admin scripts with script function calls. + +// BEGIN: registration of a currency + +//# publish +module DiemRoot::COIN { + use Std::FixedPoint32; + use DiemFramework::Diem; + + struct COIN has store { } + + public fun initialize(dr_account: &signer, tc_account: &signer) { + // Register the COIN currency. + Diem::register_SCS_currency( + dr_account, + tc_account, + FixedPoint32::create_from_rational(1, 2), // exchange rate to XDX + 1000000, // scaling_factor = 10^6 + 100, // fractional_part = 10^2 + b"COIN", + ) + } +} + +//# block --proposer Vivian --time 4 + +//# run --admin-script --signers DiemRoot TreasuryCompliance +script { +use DiemRoot::COIN; +fun main(dr: signer, tc: signer) { + COIN::initialize(&dr, &tc); +} +} + +//# run --admin-script --signers DiemRoot DiemRoot +script { +use DiemFramework::TransactionFee; +use DiemFramework::Diem; +use DiemRoot::COIN::COIN; +fun main() { + TransactionFee::pay_fee(Diem::zero()); +} +} + +//# run --admin-script --signers DiemRoot TreasuryCompliance +script { +use DiemFramework::TransactionFee; +use DiemRoot::COIN::COIN; +fun main(_dr: signer, tc: signer) { + TransactionFee::burn_fees(&tc); +} +} + +//# run --admin-script --signers DiemRoot TreasuryCompliance +script { +use DiemFramework::TransactionFee; +use DiemRoot::COIN::COIN; +fun main(_dr: signer, tc: signer) { + TransactionFee::add_txn_fee_currency(&tc); +} +} + +//# run --admin-script --signers DiemRoot TreasuryCompliance +script { +use DiemFramework::TransactionFee; +use DiemRoot::COIN::COIN; +fun main(_dr: signer, tc: signer) { + TransactionFee::add_txn_fee_currency(&tc); +} +} + +//# run --admin-script --signers DiemRoot TreasuryCompliance +script { +use DiemFramework::TransactionFee; +use DiemFramework::XDX::XDX; +fun main(dr: signer, tc: signer) { + TransactionFee::add_txn_fee_currency(&tc); + TransactionFee::burn_fees(&tc); +} +} diff --git a/diem-move/diem-framework/core/transactional-tests/transaction_fee/burn_collected_fees.exp b/diem-move/diem-framework/core/transactional-tests/transaction_fee/burn_collected_fees.exp new file mode 100644 index 0000000000000..8236f17f772d2 --- /dev/null +++ b/diem-move/diem-framework/core/transactional-tests/transaction_fee/burn_collected_fees.exp @@ -0,0 +1,29 @@ +processed 7 tasks + +task 3 'run'. lines 12-13: +Error: Failed to execute transaction. VMStatus: status OUT_OF_GAS of type Execution + +task 4 'view'. lines 15-15: +key 0x1::DiemAccount::Balance<0x1::XUS::XUS> { + coin: store 0x1::Diem::Diem<0x1::XUS::XUS> { + value: 9300 + } +} + +task 5 'run'. lines 17-20: +Events:{ + key: 07000000000000000000000000000000000000000a550c18 + seq_num: 0 + type: 0x1::Diem::PreburnEvent + data: "bc02000000000000035855530000000000000000000000000b1e55ed" +} +{ + key: 06000000000000000000000000000000000000000a550c18 + seq_num: 0 + type: 0x1::Diem::BurnEvent + data: "bc02000000000000035855530000000000000000000000000b1e55ed" +} + + +task 6 'run'. lines 21-22: +Error: Failed to execute transaction. VMStatus: status ABORTED of type Execution with sub status 1799 diff --git a/diem-move/diem-framework/core/transactional-tests/transaction_fee/burn_collected_fees.move b/diem-move/diem-framework/core/transactional-tests/transaction_fee/burn_collected_fees.move new file mode 100644 index 0000000000000..1dd6edaae45ff --- /dev/null +++ b/diem-move/diem-framework/core/transactional-tests/transaction_fee/burn_collected_fees.move @@ -0,0 +1,22 @@ +//# init --parent-vasps Bob + +// Give Bob some money to pay for transactions... +//# run --type-args 0x1::XUS::XUS --signers DesignatedDealer --args @Bob 10000 x"" x"" +//# -- 0x1::PaymentScripts::peer_to_peer_with_metadata + +//# publish +module DiemRoot::InfiniteLoop { + public(script) fun run() { while (true) {} } +} + +//# run --signers Bob --gas-budget 700 --gas-price 1 --gas-currency XUS +//# -- 0xA550C18::InfiniteLoop::run + +//# view --address Bob --resource 0x1::DiemAccount::Balance<0x1::XUS::XUS> + +//# run --signers TreasuryCompliance --type-args 0x1::XUS::XUS --show-events +//# -- 0x1::TreasuryComplianceScripts::burn_txn_fees + +// No txn fee balance left to burn so this should fail. +//# run --signers TreasuryCompliance --type-args 0x1::XUS::XUS --show-events +//# -- 0x1::TreasuryComplianceScripts::burn_txn_fees diff --git a/diem-move/diem-transactional-test-harness/src/diem_test_harness.rs b/diem-move/diem-transactional-test-harness/src/diem_test_harness.rs index a1e4816ef0d4b..e41d3c68a8a3f 100644 --- a/diem-move/diem-transactional-test-harness/src/diem_test_harness.rs +++ b/diem-move/diem-transactional-test-harness/src/diem_test_harness.rs @@ -461,15 +461,15 @@ impl<'a> DiemTestAdapter<'a> { let (status, output) = outputs.pop().unwrap(); match output.status() { - TransactionStatus::Keep(kept_vm_status) => match kept_vm_status { - KeptVMStatus::Executed => { - self.storage.add_write_set(output.write_set()); - Ok(output) - } - _ => { - bail!("Failed to execute transaction. VMStatus: {}", status) + TransactionStatus::Keep(kept_vm_status) => { + self.storage.add_write_set(output.write_set()); + match kept_vm_status { + KeptVMStatus::Executed => Ok(output), + _ => { + bail!("Failed to execute transaction. VMStatus: {}", status) + } } - }, + } TransactionStatus::Discard(_) => { bail!("Transaction discarded. VMStatus: {}", status) } diff --git a/language/move-compiler/functional-tests/tests/diem/transaction_fee/add_transaction_fee_currency.move b/language/move-compiler/functional-tests/tests/diem/transaction_fee/add_transaction_fee_currency.move deleted file mode 100644 index 8c01b8531f2a9..0000000000000 --- a/language/move-compiler/functional-tests/tests/diem/transaction_fee/add_transaction_fee_currency.move +++ /dev/null @@ -1,126 +0,0 @@ -//! account: vivian, 1000000, 0, validator -//! account: dd, 0, 0, address -//! account: bob, 0XUS, 0, vasp - -//! new-transaction -//! sender: diemroot -// Change option to CustomModule -script { -use DiemFramework::DiemTransactionPublishingOption; -fun main(config: signer) { - let config = &config; - DiemTransactionPublishingOption::set_open_module(config, false) -} -} -// check: "Keep(EXECUTED)" - -//! block-prologue -//! proposer: vivian -//! block-time: 3 - -// BEGIN: registration of a currency - -//! new-transaction -//! sender: diemroot -address 0x1 { -module COIN { - use Std::FixedPoint32; - use DiemFramework::Diem; - - struct COIN has store { } - - public fun initialize(dr_account: &signer, tc_account: &signer) { - // Register the COIN currency. - Diem::register_SCS_currency( - dr_account, - tc_account, - FixedPoint32::create_from_rational(1, 2), // exchange rate to XDX - 1000000, // scaling_factor = 10^6 - 100, // fractional_part = 10^2 - b"COIN", - ) - } -} -} -// check: "Keep(EXECUTED)" - -//! block-prologue -//! proposer: vivian -//! block-time: 4 - -//! new-transaction -//! sender: diemroot -//! execute-as: blessed -script { -use 0x1::COIN; -fun main(dr_account: signer, tc_account: signer) { - let dr_account = &dr_account; - let tc_account = &tc_account; - COIN::initialize(dr_account, tc_account); -} -} -// check: "Keep(EXECUTED)" - - -//! new-transaction -script { -use DiemFramework::TransactionFee; -use DiemFramework::Diem; -use 0x1::COIN::COIN; -fun main() { - TransactionFee::pay_fee(Diem::zero()); -} -} -// check: "Keep(ABORTED { code: 5," - -//! new-transaction -//! sender: blessed -script { -use DiemFramework::TransactionFee; -use 0x1::COIN::COIN; -fun main(tc: signer) { - let tc = &tc; - TransactionFee::burn_fees(tc); -} -} -// check: "Keep(ABORTED { code: 5," - -//! new-transaction -//! sender: blessed -script { -use DiemFramework::TransactionFee; -use 0x1::COIN::COIN; -fun main(tc_account: signer) { - let tc_account = &tc_account; - TransactionFee::add_txn_fee_currency(tc_account); -} -} -// check: "Keep(EXECUTED)" - -// END: registration of a currency - -// try adding a currency twice -//! new-transaction -//! sender: blessed -script { -use DiemFramework::TransactionFee; -use 0x1::COIN::COIN; -fun main(tc_account: signer) { - let tc_account = &tc_account; - TransactionFee::add_txn_fee_currency(tc_account); -} -} -// check: "Keep(ABORTED { code: 6," - -//! new-transaction -//! sender: blessed -script { -use DiemFramework::TransactionFee; -use DiemFramework::XDX::XDX; -fun main(tc: signer) { - let tc = &tc; - TransactionFee::add_txn_fee_currency(tc); - TransactionFee::burn_fees(tc); -} -} -// check: "Keep(ABORTED { code: 1," diff --git a/language/move-compiler/functional-tests/tests/diem/transaction_fee/burn_collected_fees.move b/language/move-compiler/functional-tests/tests/diem/transaction_fee/burn_collected_fees.move deleted file mode 100644 index 66c99c10370e1..0000000000000 --- a/language/move-compiler/functional-tests/tests/diem/transaction_fee/burn_collected_fees.move +++ /dev/null @@ -1,40 +0,0 @@ -//! account: bob, 10000XUS - -//! new-transaction -//! sender: bob -//! max-gas: 700 -//! gas-price: 1 -//! gas-currency: XUS -script { - fun main() { while (true) {} } -} -// check: "EXECUTION_FAILURE { status_code: OUT_OF_GAS," -// check: "gas_used: 700," -// check: "Keep(OUT_OF_GAS)" - -//! new-transaction -//! sender: blessed -//! type-args: 0x1::XUS::XUS -script { -use DiemFramework::TransactionFee; -fun burn_txn_fees(blessed_account: signer) { - TransactionFee::burn_fees(&blessed_account); -} -} -// check: PreburnEvent -// check: BurnEvent -// check: "Keep(EXECUTED)" - -// No txn fee balance left to burn - -//! new-transaction -//! sender: blessed -//! type-args: 0x1::XUS::XUS -script { -use DiemFramework::TransactionFee; -fun burn_txn_fees(blessed_account: signer) { - TransactionFee::burn_fees(&blessed_account); -} -} - -// check: "Keep(ABORTED { code: 1799," diff --git a/language/move-compiler/functional-tests/tests/diem/transaction_fee/initialization.move b/language/move-compiler/functional-tests/tests/diem/transaction_fee/initialization.move deleted file mode 100644 index 3320ce24e0313..0000000000000 --- a/language/move-compiler/functional-tests/tests/diem/transaction_fee/initialization.move +++ /dev/null @@ -1,9 +0,0 @@ -//! new-transaction -script { -use DiemFramework::TransactionFee; -fun main(account: signer) { - let account = &account; - TransactionFee::initialize(account); -} -} -// check: "Keep(ABORTED { code: 1,"