Skip to content

Commit

Permalink
[diem-transactional-tests] on-chain-config 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 17b462b commit c39a247
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 338 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
processed 7 tasks

task 3 'run'. lines 21-31:
Error: Transaction discarded. VMStatus: status ABORTED of type Execution with sub status 2

task 4 'block'. lines 34-36:
Events:
ContractEvent { key: EventKey(11000000000000000000000000000000000000000a550c18), index: 0, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemBlock"), name: Identifier("NewBlockEvent"), type_params: [] }), event_data: "0000000000000000c5e34b925cf6875fec02d4b77adbd2d6000200000000000000" }

task 6 'publish'. lines 46-49:
Error: Transaction discarded. VMStatus: status INVALID_MODULE_PUBLISHER of type Validation
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//# init --validators Vivian --parent-vasps Alice

// Changing the publishing option from Open to CustomScript
// Step 1: Make sure we can publish module Alice::Foo at the beginning
//# publish
module Alice::Foo {
public fun foo() {}
}


// Initially, any script is allowed.
//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::DiemTransactionPublishingOption;
fun main(dr: signer, _dr2: signer) {
assert!(DiemTransactionPublishingOption::is_script_allowed(&dr, &x""), 100);
}
}

// Turning off open scripts is a privileged operation.
//# run --admin-script --signers DiemRoot Vivian
script {
use DiemFramework::DiemTransactionPublishingOption;
fun main(_dr: signer, vv: signer) {
DiemTransactionPublishingOption::set_open_script(&vv);
}
}

// TODO: double check on `DiemTransactionPublishingOption::set_open_script`.
// - The name seems confusing.
// - Shall we send more transactions to test out its effects?


//# block --proposer Vivian --time 2

// Step 2: Change option to CustomModule
//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::DiemTransactionPublishingOption;

fun main(dr: signer, _dr2: signer) {
DiemTransactionPublishingOption::set_open_module(&dr, false)
}
}

//# publish
module Alice::Bar {
public fun bar() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
processed 8 tasks

task 1 'block'. lines 3-5:
Events:
ContractEvent { key: EventKey(11000000000000000000000000000000000000000a550c18), index: 0, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemBlock"), name: Identifier("NewBlockEvent"), type_params: [] }), event_data: "0000000000000000c5e34b925cf6875fec02d4b77adbd2d6000200000000000000" }

task 3 'run'. lines 14-18:
Error: Transaction discarded. VMStatus: status UNKNOWN_SCRIPT of type Validation

task 4 'block'. lines 20-23:
Events:
ContractEvent { key: EventKey(11000000000000000000000000000000000000000a550c18), index: 1, type: Struct(StructTag { address: 00000000000000000000000000000001, module: Identifier("DiemBlock"), name: Identifier("NewBlockEvent"), type_params: [] }), event_data: "0000000000000000c5e34b925cf6875fec02d4b77adbd2d6000300000000000000" }

task 6 'run'. lines 34-36:
Error: Failed to execute transaction. VMStatus: status ABORTED of type Execution with sub status 2055

task 7 'run'. lines 37-43:
Error: Transaction discarded. VMStatus: status ABORTED of type Execution with sub status 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//# init --validators Vivian --parent-vasps Alice

//# block --proposer Vivian --time 2

// Disable txes from all accounts except DiemRoot.
//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::DiemTransactionPublishingOption;
fun main(dr: signer, _dr2: signer) {
DiemTransactionPublishingOption::halt_all_transactions(&dr);
}
}
// Sending allowlisted script from normal account fails
//# run --signers Alice -- 0x1::AccountAdministrationScripts::rotate_authentication_key

// TODO: module publishing doesn't seem to be halted. Is this intentional?
// publish
// module Alice::M {}

//# block --proposer Vivian --time 3


// Re-enable. this also tests that sending from DiemRoot succeeds.
//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::DiemTransactionPublishingOption;
fun main(dr: signer, _dr2: signer) {
DiemTransactionPublishingOption::resume_transactions(&dr);
}
}

// Sending from normal account succeeds again.
// Note: the transaction will still abort due to the bad key supplied. This is normal.
//# run --signers Alice --args x"" -- 0x1::AccountAdministrationScripts::rotate_authentication_key

// A normal account has insufficient privs to halt transactions.
//# run --admin-script --signers DiemRoot Vivian
script {
use DiemFramework::DiemTransactionPublishingOption;
fun main(dr: signer, vv: signer) {
DiemTransactionPublishingOption::halt_all_transactions(&vv);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
processed 11 tasks

task 4 'run'. lines 32-47:
Error: Failed to execute transaction. VMStatus: status ABORTED of type Execution with sub status 2

task 5 'run'. lines 48-61:
Error: Failed to execute transaction. VMStatus: status ABORTED of type Execution with sub status 7

task 10 'run'. lines 95-95:
Error: Transaction discarded. VMStatus: status GAS_UNIT_PRICE_BELOW_MIN_BOUND of type Validation
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//# init --parent-vasps Alice Bob

// Dummy module for testing...
//# publish
module DiemRoot::Nop {
public(script) fun nop() {}
}

// Give Alice some money to pay for transactions...
//# run --type-args 0x1::XUS::XUS --signers DesignatedDealer --args @Alice 100000 x"" x""
//# -- 0x1::PaymentScripts::peer_to_peer_with_metadata

// Give Bob some money to pay for transactions...
//# run --type-args 0x1::XUS::XUS --signers DesignatedDealer --args @Bob 100000 x"" x""
//# -- 0x1::PaymentScripts::peer_to_peer_with_metadata

// List of constants:
// sliding nonce
// global_memory_per_byte_cost
// global_memory_per_byte_write_cost
// min_transaction_gas_units
// large_transaction_cutoff
// intrinsic_gas_per_byte
// maximum_number_of_gas_units
// min_price_per_gas_unit
// max_price_per_gas_unit
// max_transaction_size_in_bytes
// gas_unit_scaling_factor
// default_account_size

// Wrong sender. Should fail.
//# run --args 0
//# 4
//# 9
//# 600
//# 600
//# 8
//# 4000000
//# 0
//# 10000
//# 4096
//# 1000
//# 800
//# --signers TreasuryCompliance
//# -- 0x1::SystemAdministrationScripts::set_gas_constants

// Min gas price greater than max gas price. Should fail.
//# run --args 0
//# 4
//# 9
//# 600
//# 600
//# 8
//# 4000000
//# 10
//# 9
//# 4096
//# 1000
//# 800
//# --signers DiemRoot
//# -- 0x1::SystemAdministrationScripts::set_gas_constants

//# run --signers Alice --gas-price 1 --gas-currency XUS -- 0xA550C18::Nop::nop

// Increase the min_transaction gas units and min_price_per_gas_unit
//# run --args 0
//# 4
//# 9
//# 6000
//# 600
//# 8
//# 4000000
//# 1
//# 10000
//# 4096
//# 1000
//# 800
//# --signers DiemRoot
//# -- 0x1::SystemAdministrationScripts::set_gas_constants

//# run --signers Bob --gas-price 1 --gas-currency XUS -- 0xA550C18::Nop::nop

//# run --admin-script --signers DiemRoot DiemRoot
script {
use DiemFramework::DiemAccount;
use DiemFramework::XUS::XUS;

fun main() {
// Alice processed before the bump in min transaction gas units so should have more money left
assert!(DiemAccount::balance<XUS>(@Bob) < DiemAccount::balance<XUS>(@Alice), 42);
}
}

// Can't process a transaction now with a gas price of zero since the lower bound was also changed.
//# run --signers Alice --gas-price 0 --gas-currency XUS -- 0xA550C18::Nop::nop
Loading

0 comments on commit c39a247

Please sign in to comment.