Skip to content

Commit

Permalink
[diem-transactional-tests] migrate transaction_fee tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vgao1996 authored and bors-libra committed Dec 17, 2021
1 parent bc3d0d8 commit 41ba47b
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 183 deletions.
18 changes: 18 additions & 0 deletions diem-move/diem-framework/core/tests/TransactionFeeTests.move
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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<COIN>(
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<COIN>());
}
}

//# run --admin-script --signers DiemRoot TreasuryCompliance
script {
use DiemFramework::TransactionFee;
use DiemRoot::COIN::COIN;
fun main(_dr: signer, tc: signer) {
TransactionFee::burn_fees<COIN>(&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<COIN>(&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<COIN>(&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<XDX>(&tc);
TransactionFee::burn_fees<XDX>(&tc);
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 41ba47b

Please sign in to comment.