Skip to content

Commit

Permalink
fix: start verifying tx after they are all executed (#41)
Browse files Browse the repository at this point in the history
* Replace Goose sequencing with on stop transactions

* Fix wrong ensure! for erc721
  • Loading branch information
Angel-Petrov committed Feb 16, 2024
1 parent 93cb64e commit 7f554df
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions src/actions/goose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ pub async fn erc20(shooter: &GatlingShooterSetup) -> color_eyre::Result<()> {
.register_transaction(
Transaction::new(transfer_wait)
.set_name("Transfer Finalizing")
.set_sequence(2),
.set_sequence(2)
.set_on_stop(),
)
.register_transaction(
transaction!(verify_transactions)
.set_name("Transfer Verification")
.set_sequence(3),
.set_sequence(3)
.set_on_stop(),
),
)
.execute()
Expand All @@ -103,7 +105,7 @@ pub async fn erc721(shooter: &GatlingShooterSetup) -> color_eyre::Result<()> {
let environment = shooter.environment()?;

ensure!(
config.run.num_erc20_transfers >= config.run.concurrency,
config.run.num_erc721_mints >= config.run.concurrency,
"Too few erc721 mints for the amount of concurrency"
);

Expand Down Expand Up @@ -166,12 +168,14 @@ pub async fn erc721(shooter: &GatlingShooterSetup) -> color_eyre::Result<()> {
.register_transaction(
Transaction::new(mint_wait)
.set_name("Mint Finalizing")
.set_sequence(2),
.set_sequence(2)
.set_on_stop(),
)
.register_transaction(
transaction!(verify_transactions)
.set_name("Mint Verification")
.set_sequence(3),
.set_sequence(3)
.set_on_stop(),
),
)
.execute()
Expand Down Expand Up @@ -331,27 +335,31 @@ async fn mint(
}

async fn verify_transactions(user: &mut GooseUser) -> TransactionResult {
let transaction = user
.get_session_data_mut::<GooseUserState>()
.expect("Should be in a goose user with GooseUserState session data")
.prev_tx
.pop()
.expect("There should be enough previous transactions for every verification");

let receipt: MaybePendingTransactionReceipt =
send_request(user, JsonRpcMethod::GetTransactionReceipt, transaction).await?;
let transactions = mem::take(
&mut user
.get_session_data_mut::<GooseUserState>()
.expect("Should be in a goose user with GooseUserState session data")
.prev_tx,
);

match receipt {
MaybePendingTransactionReceipt::Receipt(receipt) => match receipt.execution_result() {
ExecutionResult::Succeeded => Ok(()),
ExecutionResult::Reverted { reason } => {
panic!("Transaction {transaction:#064x} has been rejected/reverted: {reason}");
for tx in transactions {
let receipt: MaybePendingTransactionReceipt =
send_request(user, JsonRpcMethod::GetTransactionReceipt, tx).await?;

match receipt {
MaybePendingTransactionReceipt::Receipt(receipt) => match receipt.execution_result() {
ExecutionResult::Succeeded => {}
ExecutionResult::Reverted { reason } => {
panic!("Transaction {tx:#064x} has been rejected/reverted: {reason}");
}
},
MaybePendingTransactionReceipt::PendingReceipt(_) => {
panic!("Transaction {tx:#064x} is pending when no transactions should be")
}
},
MaybePendingTransactionReceipt::PendingReceipt(_) => {
panic!("Transaction {transaction:#064x} is pending when no transactions should be")
}
}

Ok(())
}

pub async fn send_execution<T: DeserializeOwned>(
Expand Down

0 comments on commit 7f554df

Please sign in to comment.