Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integration tests assertions #3902

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions crates/node/src/shell/testing/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,23 +729,23 @@ impl MockNode {
locked.commit();
}

/// Check that applying a tx succeeded.
pub fn success(&self) -> bool {
self.tx_result_codes
.lock()
.unwrap()
.iter()
.all(|r| *r == NodeResults::Ok)
&& self
.tx_results
.lock()
.unwrap()
// Check that applying a tx succeeded.
fn success(&self) -> bool {
let tx_result_codes = self.tx_result_codes.lock().unwrap();
let tx_results = self.tx_results.lock().unwrap();

// If results are empty return false to avoid silently ignoring missing
// results
!tx_result_codes.is_empty()
&& !tx_results.is_empty()
&& tx_result_codes.iter().all(|r| *r == NodeResults::Ok)
&& tx_results
.iter()
.all(|inner_results| inner_results.are_results_successfull())
}

/// Return a tx result if the tx failed in mempool
pub fn is_broadcast_err(&self) -> Option<TxResult> {
// Return a tx result if the tx failed in mempool
fn is_broadcast_err(&self) -> Option<TxResult> {
self.tx_result_codes
.lock()
.unwrap()
Expand All @@ -761,6 +761,12 @@ impl MockNode {
self.tx_results.lock().unwrap().clear();
}

/// WARNING: use this function only if you went through one of the methods
/// of `MockNode` to execute your tx (such as finalize_and_commit). If you
/// just submitted a tx using the Client command avoid calling this function
/// (which would return false since the support fields of MockNode would not
/// be populated or would be populated with stale data) and rely instead on
/// examining the captured output of your command.
pub fn assert_success(&self) {
if !self.success() {
panic!(
Expand Down
17 changes: 10 additions & 7 deletions crates/tests/src/integration/ledger_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ fn proposal_submission() -> Result<()> {
"--data-path",
valid_proposal_json_path.to_str().unwrap(),
"--gas-limit",
"10000000",
"11000000",
"--node",
&validator_one_rpc,
]);
Expand Down Expand Up @@ -1474,7 +1474,7 @@ fn implicit_account_reveal_pk() -> Result<()> {
"--signing-keys",
source,
"--gas-limit",
"3500000",
"11000000",
"--node",
&validator_one_rpc,
]
Expand Down Expand Up @@ -1556,8 +1556,10 @@ fn implicit_account_reveal_pk() -> Result<()> {
"--node",
&validator_one_rpc,
]);
run(&node, Bin::Client, credit_args)?;
node.assert_success();
let captured =
CapturedOutput::of(|| run(&node, Bin::Client, credit_args));
assert!(captured.result.is_ok());
assert!(captured.contains(TX_APPLIED_SUCCESS));

// 2c. Submit the tx with the implicit account as the source.
let captured = CapturedOutput::of(|| {
Expand All @@ -1580,7 +1582,8 @@ fn implicit_account_reveal_pk() -> Result<()> {
)
});
assert!(!captured.contains("Submitting a tx to reveal the public key"));
node.assert_success();
assert!(captured.result.is_ok());
assert!(captured.contains(TX_APPLIED_SUCCESS));
}

Ok(())
Expand Down Expand Up @@ -1839,7 +1842,7 @@ fn enforce_fee_payment() -> Result<()> {
validator_one_rpc,
]),
)?;
node.assert_success();
assert!(captured.result.is_ok());
let file_path = tempdir
.path()
.read_dir()
Expand Down Expand Up @@ -1873,7 +1876,7 @@ fn enforce_fee_payment() -> Result<()> {
validator_one_rpc,
]),
)?;
node.assert_success();
assert!(captured.result.is_ok());
let file_path = tempdir
.path()
.read_dir()
Expand Down
Loading
Loading