Skip to content
This repository has been archived by the owner on Jan 27, 2025. It is now read-only.

Commit

Permalink
Audit validators and web-monitor (#602)
Browse files Browse the repository at this point in the history
* Web monitor: fixes cache initialization

* web monitor: Moves autopay amount format to the server side.
Removes previous amount from autopay table.
Display description for each payment type.

* Web monitor: adds audit view
Adds operator account info to the dash view
Adds 2 operator check health
Adds autopay info to the validator modal
Highlights owner's validator in the validators table

* Web monitor: adds user defined watch list

* Adds autopay watch list as a tab with more stats

* Web monitor: adds notes dictionary to watch list

* Adds autopay summary and some style fixes

* Apply account note to autopay instructions

* Fixes tables horizontal scroll for mobile view

* Fixes nav text align for mobile view

* Adds Audit smart contract WIP

* Fixes onboarding_reconfig test
  • Loading branch information
soaresa authored Jul 19, 2021
1 parent 02fd9ae commit 4eca03b
Show file tree
Hide file tree
Showing 102 changed files with 6,427 additions and 2,027 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! account: alice, 1000000, 0, validator
// Test audit function val_audit_passing having autopay disabled
//! new-transaction
//! sender: libraroot
//! execute-as: alice
script {
use 0x1::Audit;
use 0x1::ValidatorConfig;
use 0x1::AutoPay2;
use 0x1::MinerState;
use 0x1::GAS::GAS;
use 0x1::LibraAccount;

fun main(lr: &signer, alice_account: &signer) {
assert(ValidatorConfig::is_valid({{alice}}), 7357007001001);

// transfer enough coins to operator
AutoPay2::enable_autopay(alice_account);
let oper = ValidatorConfig::get_operator({{alice}});
LibraAccount::vm_make_payment_no_limit<GAS>(
{{alice}},
oper, // has a 0 in balance
50009,
x"",
x"",
lr
);
assert(LibraAccount::balance<GAS>(oper) == 50009, 7357007001002);
AutoPay2::disable_autopay(alice_account);

assert(!AutoPay2::is_enabled({{alice}}), 7357007001003);
assert(MinerState::is_init({{alice}}), 7357007001004);
assert(!Audit::val_audit_passing({{alice}}), 7357007001005);
}
}
// check: EXECUTED
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! account: alice, 1000000, 0, validator
// Test audit function val_audit_passing having not enough balance
//! new-transaction
//! sender: libraroot
//! execute-as: alice
script {
use 0x1::Audit;
// use 0x1::Signer;
use 0x1::ValidatorConfig;
use 0x1::AutoPay2;
use 0x1::MinerState;
use 0x1::GAS::GAS;
use 0x1::LibraAccount;

fun main(lr: &signer, alice_account: &signer) {
// enable autopay
AutoPay2::enable_autopay(alice_account);
assert(AutoPay2::is_enabled({{alice}}), 7357007002001);
assert(ValidatorConfig::is_valid({{alice}}), 7357007002002);
assert(MinerState::is_init({{alice}}), 7357007002003);

// check operator zero balance
let oper = ValidatorConfig::get_operator({{alice}});
assert(LibraAccount::balance<GAS>(oper) == 0, 7357007002004);
assert(!Audit::val_audit_passing({{alice}}), 7357007002005);

// transfer not enough balance to operator
let oper = ValidatorConfig::get_operator({{alice}});
LibraAccount::vm_make_payment_no_limit<GAS>(
{{alice}},
oper,
49999,
x"",
x"",
lr
);
assert(LibraAccount::balance<GAS>(oper) == 49999, 7357007002006);
assert(!Audit::val_audit_passing({{alice}}), 7357007002007);
}
}
// check: EXECUTED
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//! account: alice, 1000000, 0, validator
// Test audit function val_audit_passing satisfying all conditions
//! new-transaction
//! sender: libraroot
//! execute-as: alice
script {
use 0x1::Audit;
// use 0x1::Signer;
use 0x1::ValidatorConfig;
use 0x1::AutoPay2;
use 0x1::MinerState;
use 0x1::GAS::GAS;
use 0x1::LibraAccount;

fun main(lr: &signer, alice_account: &signer) {
assert(ValidatorConfig::is_valid({{alice}}), 7357007003001);

// transfer enough coins to operator
let oper = ValidatorConfig::get_operator({{alice}});
LibraAccount::vm_make_payment_no_limit<GAS>(
{{alice}},
oper, // has a 0 in balance
50009,
x"",
x"",
lr
);
assert(LibraAccount::balance<GAS>(oper) == 50009, 7357007003002);

// enable autopay
assert(!AutoPay2::is_enabled({{alice}}), 7357007003003);
AutoPay2::enable_autopay(alice_account);
assert(AutoPay2::is_enabled({{alice}}), 7357007003004);

assert(MinerState::is_init({{alice}}), 7357007003005);

// audit must pass
assert(Audit::val_audit_passing({{alice}}), 7357007003006);
}
}
// check: EXECUTED
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@

// This tests consensus Case 2.
// ALICE is a validator.
// DID validate successfully.
// DID NOT mine above the threshold for the epoch.

//! account: alice, 1, 0, validator
//! account: bob, 1, 0, validator
//! account: carol, 1, 0, validator
//! account: dave, 1, 0, validator
//! account: eve, 1, 0, validator
//! account: alice, 100000, 0, validator
//! account: bob, 100000, 0, validator
//! account: carol, 100000, 0, validator
//! account: dave, 100000, 0, validator
//! account: eve, 100000, 0, validator
//! block-prologue
//! proposer: alice
//! block-time: 1
//! NewBlockEvent
//! new-transaction
//! sender: libraroot
script {
use 0x1::LibraAccount;
use 0x1::GAS::GAS;
use 0x1::ValidatorConfig;

fun main(sender: &signer) {
// tranfer enough coins to operators
let oper_alice = ValidatorConfig::get_operator({{alice}});
let oper_bob = ValidatorConfig::get_operator({{bob}});
let oper_carol = ValidatorConfig::get_operator({{carol}});
let oper_dave = ValidatorConfig::get_operator({{dave}});
let oper_eve = ValidatorConfig::get_operator({{eve}});
LibraAccount::vm_make_payment_no_limit<GAS>({{alice}}, oper_alice, 50009, x"", x"", sender);
LibraAccount::vm_make_payment_no_limit<GAS>({{bob}}, oper_bob, 50009, x"", x"", sender);
LibraAccount::vm_make_payment_no_limit<GAS>({{carol}}, oper_carol, 50009, x"", x"", sender);
LibraAccount::vm_make_payment_no_limit<GAS>({{dave}}, oper_dave, 50009, x"", x"", sender);
LibraAccount::vm_make_payment_no_limit<GAS>({{eve}}, oper_eve, 50009, x"", x"", sender);
}
}
//check: EXECUTED

//! new-transaction
//! sender: bob
script {
Expand All @@ -35,7 +57,7 @@ script {

//// NO MINING ////

assert(LibraAccount::balance<GAS>({{bob}}) == 1, 7357000180106);
assert(LibraAccount::balance<GAS>({{bob}}) == 49991, 7357000180106);
assert(NodeWeight::proof_of_weight({{bob}}) == 0, 7357000180107);
assert(MinerState::test_helper_get_height({{bob}}) == 0, 7357000180108);
}
Expand Down Expand Up @@ -117,7 +139,7 @@ script {

//case 2 does not get rewards.
print(&LibraAccount::balance<GAS>({{bob}}));
assert(LibraAccount::balance<GAS>({{bob}}) == 1, 7357000180112);
assert(LibraAccount::balance<GAS>({{bob}}) == 49991, 7357000180112);

//case 2 does not increment weight.
assert(NodeWeight::proof_of_weight({{bob}}) == 0, 7357000180113);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,52 @@
// DID NOT validate successfully.
// DID mine above the threshold for the epoch.

//! account: alice, 1, 0, validator
//! account: bob, 1, 0, validator
//! account: carol, 1, 0, validator
//! account: dave, 1, 0, validator
//! account: eve, 1, 0, validator
//! account: frank, 1, 0, validator
//! account: alice, 100000, 0, validator
//! account: bob, 100000, 0, validator
//! account: carol, 100000, 0, validator
//! account: dave, 100000, 0, validator
//! account: eve, 100000, 0, validator
//! account: frank, 100000, 0, validator
//! block-prologue
//! proposer: carol
//! block-time: 1
//! NewBlockEvent
//! new-transaction
//! sender: libraroot
script {
use 0x1::LibraAccount;
use 0x1::GAS::GAS;
use 0x1::ValidatorConfig;

fun main(sender: &signer) {
// tranfer enough coins to operators
let oper_bob = ValidatorConfig::get_operator({{bob}});
let oper_eve = ValidatorConfig::get_operator({{eve}});
let oper_dave = ValidatorConfig::get_operator({{dave}});
let oper_alice = ValidatorConfig::get_operator({{alice}});
let oper_carol = ValidatorConfig::get_operator({{carol}});
let oper_frank = ValidatorConfig::get_operator({{frank}});
LibraAccount::vm_make_payment_no_limit<GAS>({{bob}}, oper_bob, 50009, x"", x"", sender);
LibraAccount::vm_make_payment_no_limit<GAS>({{eve}}, oper_eve, 50009, x"", x"", sender);
LibraAccount::vm_make_payment_no_limit<GAS>({{dave}}, oper_dave, 50009, x"", x"", sender);
LibraAccount::vm_make_payment_no_limit<GAS>({{alice}}, oper_alice, 50009, x"", x"", sender);
LibraAccount::vm_make_payment_no_limit<GAS>({{carol}}, oper_carol, 50009, x"", x"", sender);
LibraAccount::vm_make_payment_no_limit<GAS>({{frank}}, oper_frank, 50009, x"", x"", sender);
}
}
//check: EXECUTED

//! new-transaction
//! sender: alice
script {

use 0x1::MinerState;
use 0x1::Signer;
use 0x1::AutoPay2;

fun main(sender: &signer) {
AutoPay2::enable_autopay(sender);
MinerState::test_helper_mock_mining(sender, 5);
assert(MinerState::get_count_in_epoch(Signer::address_of(sender)) == 5, 73570001);
}
Expand All @@ -33,11 +58,12 @@ script {
//! new-transaction
//! sender: bob
script {

use 0x1::MinerState;
use 0x1::Signer;
use 0x1::AutoPay2;

fun main(sender: &signer) {
AutoPay2::enable_autopay(sender);
MinerState::test_helper_mock_mining(sender, 5);
assert(MinerState::get_count_in_epoch(Signer::address_of(sender)) == 5, 73570001);
}
Expand All @@ -47,11 +73,12 @@ script {
//! new-transaction
//! sender: carol
script {

use 0x1::MinerState;
use 0x1::Signer;
use 0x1::AutoPay2;

fun main(sender: &signer) {
AutoPay2::enable_autopay(sender);
MinerState::test_helper_mock_mining(sender, 5);
assert(MinerState::get_count_in_epoch(Signer::address_of(sender)) == 5, 73570001);
}
Expand All @@ -61,12 +88,12 @@ script {
//! new-transaction
//! sender: dave
script {

use 0x1::MinerState;
use 0x1::Signer;
//
use 0x1::AutoPay2;

fun main(sender: &signer) {
AutoPay2::enable_autopay(sender);
MinerState::test_helper_mock_mining(sender, 5);
assert(MinerState::get_count_in_epoch(Signer::address_of(sender)) == 5, 73570001);
}
Expand All @@ -76,11 +103,12 @@ script {
//! new-transaction
//! sender: eve
script {

use 0x1::MinerState;
use 0x1::Signer;
use 0x1::AutoPay2;

fun main(sender: &signer) {
AutoPay2::enable_autopay(sender);
MinerState::test_helper_mock_mining(sender, 5);
assert(MinerState::get_count_in_epoch(Signer::address_of(sender)) == 5, 73570001);
}
Expand All @@ -90,12 +118,12 @@ script {
//! new-transaction
//! sender: frank
script {

use 0x1::MinerState;
use 0x1::Signer;
//
use 0x1::AutoPay2;

fun main(sender: &signer) {
AutoPay2::enable_autopay(sender);
MinerState::test_helper_mock_mining(sender, 5);
assert(MinerState::get_count_in_epoch(Signer::address_of(sender)) == 5, 73570001);
}
Expand All @@ -105,7 +133,6 @@ script {
//! new-transaction
//! sender: libraroot
script {

use 0x1::LibraSystem;
use 0x1::MinerState;
use 0x1::GAS::GAS;
Expand All @@ -120,7 +147,7 @@ script {
assert(LibraSystem::validator_set_size() == 6, 7357000180101);
assert(LibraSystem::is_validator({{carol}}) == true, 7357000180102);
assert(MinerState::test_helper_get_height({{carol}}) == 0, 7357000180104);
assert(LibraAccount::balance<GAS>({{carol}}) == 1, 7357000180106);
assert(LibraAccount::balance<GAS>({{carol}}) == 49991, 7357000180106);
assert(MinerState::test_helper_get_height({{carol}}) == 0, 7357000180108);
}
}
Expand Down Expand Up @@ -185,7 +212,6 @@ script {
//! new-transaction
//! sender: libraroot
script {

use 0x1::LibraSystem;
use 0x1::NodeWeight;
use 0x1::GAS::GAS;
Expand All @@ -198,10 +224,9 @@ script {
// Check the validator set is at expected size
assert(LibraSystem::validator_set_size() == 5, 7357000180110);
assert(LibraSystem::is_validator({{carol}}) == false, 7357000180111);
assert(LibraAccount::balance<GAS>({{carol}}) == 1, 7357000180112);
assert(LibraAccount::balance<GAS>({{carol}}) == 49991, 7357000180112);
assert(NodeWeight::proof_of_weight({{carol}}) == 1, 7357000180113);
assert(LibraConfig::get_current_epoch()==2, 7357000180114);

}
}
//check: EXECUTED
Loading

0 comments on commit 4eca03b

Please sign in to comment.