Skip to content

Commit

Permalink
Added verification of generated events
Browse files Browse the repository at this point in the history
  • Loading branch information
mstrug-rdx committed Nov 21, 2023
1 parent b670715 commit fa342fd
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions radix-engine-tests/tests/stake_reconcilation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use radix_engine_common::prelude::*;
use transaction::prelude::*;
use scrypto_unit::*;
use radix_engine_store_interface::interface::*;
use scrypto_unit::*;
use transaction::prelude::*;

#[test]
fn test_stake_reconcilation() {
Expand All @@ -12,14 +12,14 @@ fn test_stake_reconcilation() {

let validator_address = test_runner.new_validator_with_pub_key(pub_key, account);
let manifest = ManifestBuilder::new()
.lock_fee(FAUCET, 100)
.create_proof_from_account_of_non_fungibles(
account,
VALIDATOR_OWNER_BADGE,
[NonFungibleLocalId::bytes(validator_address.as_node_id().0).unwrap()],
)
.register_validator(validator_address)
.build();
.lock_fee(FAUCET, 100)
.create_proof_from_account_of_non_fungibles(
account,
VALIDATOR_OWNER_BADGE,
[NonFungibleLocalId::bytes(validator_address.as_node_id().0).unwrap()],
)
.register_validator(validator_address)
.build();
let receipt = test_runner.execute_manifest(
manifest,
vec![NonFungibleGlobalId::from_public_key(&account_pk)],
Expand Down Expand Up @@ -55,14 +55,30 @@ fn test_stake_reconcilation() {
vec![NonFungibleGlobalId::from_public_key(&account_pk)],
);


// Assert
println!("{:-^120}", "Application Events");

// ordered list of expected events
let expected_events = vec![
"LockFeeEvent",
"WithdrawEvent",
"WithdrawEvent",
"MintFungibleResourceEvent",
"DepositEvent",
"StakeEvent",
"VaultCreationEvent",
"DepositEvent",
"DepositEvent",
"PayFeeEvent",
"DepositEvent",
"BurnFungibleResourceEvent",
];

let events = receipt.expect_commit(true).clone().application_events;
for event in &events {
for (idx, event) in events.iter().enumerate() {
let name = test_runner.event_name(&event.0);
println!("{:?} - {}", event.0, name);
assert_eq!(name, expected_events[idx]);
}

println!("{:-^120}", "Application DB Partitions");
Expand All @@ -74,23 +90,26 @@ fn test_stake_reconcilation() {
let mut changed_substates_count = 0;
let mut same_substates_count = 0;

for (_idx, key) in keys.enumerate() {
for (idx, key) in keys.enumerate() {
let partition_entries = test_runner.substate_db().list_entries(&key);
for (_sidx, (sort_key, value)) in partition_entries.enumerate() {
for (sidx, (sort_key, value)) in partition_entries.enumerate() {
if let Some(value_hash) = old_values_map.get(&(key.clone(), sort_key)) {
if value_hash == &hash(value) {
same_substates_count += 1;
} else {
changed_substates_count += 1;
println!("Partition({}) Substate({}) changed", idx, sidx);
}
} else {
new_substates_count += 1;
println!("Partition({}) Substate({}) new", idx, sidx);
}
}
}

println!("{:-^120}", "Report end");

assert_eq!(new_substates_count, 4);
assert_eq!(changed_substates_count, 7);
assert_eq!(same_substates_count, 578);
}

0 comments on commit fa342fd

Please sign in to comment.