-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cd5965
commit f8d05bc
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use crate::workloads::{FailureType, Payload}; | ||
use crate::ExecutionEffects; | ||
use std::fmt; | ||
use sui_types::base_types::{ObjectID, SuiAddress}; | ||
use sui_types::transaction::{Transaction, TransactionData}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ExpectedFailurePayload { | ||
failure_type: FailureType, | ||
sender: SuiAddress, | ||
} | ||
|
||
impl ExpectedFailurePayload { | ||
pub fn new(failure_type: FailureType, sender: SuiAddress) -> Self { | ||
Self { | ||
failure_type, | ||
sender, | ||
} | ||
} | ||
|
||
fn create_failing_transaction(&self) -> Transaction { | ||
let mut rng = rand::thread_rng(); | ||
let random_object_id = ObjectID::random(); | ||
|
||
match self.failure_type { | ||
FailureType::LowGasBudget => { | ||
// Create a transaction with insufficient gas | ||
let data = TransactionData::new_move_call( | ||
self.sender, | ||
random_object_id, | ||
"dummy_package", | ||
"dummy_module", | ||
"dummy_function", | ||
vec![], | ||
vec![], | ||
1, // Set gas budget to 1, which is insufficient | ||
1000, | ||
) | ||
.unwrap(); | ||
Transaction::new(data) | ||
} | ||
FailureType::InvalidSignature => { | ||
// Create a transaction with an invalid signature | ||
let data = TransactionData::new_transfer( | ||
random_object_id, | ||
self.sender, | ||
self.sender, | ||
random_object_id, | ||
1000, | ||
1000, | ||
); | ||
let mut tx = Transaction::new(data); | ||
tx.signatures_mut().push(vec![0; 32]); // Invalid signature | ||
tx | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Payload for ExpectedFailurePayload { | ||
fn make_new_payload(&mut self, _effects: &ExecutionEffects) { | ||
// For this payload, we don't need to update anything based on effects | ||
} | ||
|
||
fn make_transaction(&mut self) -> Transaction { | ||
self.create_failing_transaction() | ||
} | ||
|
||
fn get_failure_type(&self) -> Option<FailureType> { | ||
Some(self.failure_type) | ||
} | ||
} | ||
|
||
impl fmt::Display for ExpectedFailurePayload { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "ExpectedFailurePayload({:?})", self.failure_type) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters