-
Notifications
You must be signed in to change notification settings - Fork 32
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
feat: add event checks to motsu #441
Changes from all commits
5b02877
5085d10
abcce73
d39e714
9963902
2c5e0c6
f1aa080
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
//! Module with unit test EVM environment for Stylus contracts. | ||
|
||
/// Block Timestamp - Epoch timestamp: 1st January 2025 `00::00::00`. | ||
const BLOCK_TIMESTAMP: u64 = 1_735_689_600; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good! Seems rational for me to move these constants to the other module |
||
/// Arbitrum's CHAID ID. | ||
const CHAIN_ID: u64 = 42161; | ||
|
||
/// Dummy contract address set for tests. | ||
const CONTRACT_ADDRESS: &[u8; 42] = | ||
b"0xdCE82b5f92C98F27F116F70491a487EFFDb6a2a9"; | ||
|
||
/// Externally Owned Account (EOA) code hash. | ||
const EOA_CODEHASH: &[u8; 66] = | ||
b"0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; | ||
|
||
/// Dummy msg sender set for tests. | ||
const MSG_SENDER: &[u8; 42] = b"0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"; | ||
|
||
pub(crate) struct Environment { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember, that the whole reason of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because these data are also "mocked" values for our test cases |
||
account_codehash: [u8; 66], | ||
block_timestamp: u64, | ||
chain_id: u64, | ||
contract_address: [u8; 42], | ||
events: Vec<Vec<u8>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would better create wrapper type for event, to store them like |
||
msg_sender: [u8; 42], | ||
} | ||
|
||
impl Default for Environment { | ||
/// Creates default environment for a test case. | ||
fn default() -> Environment { | ||
Self { | ||
account_codehash: *EOA_CODEHASH, | ||
block_timestamp: BLOCK_TIMESTAMP, | ||
chain_id: CHAIN_ID, | ||
contract_address: *CONTRACT_ADDRESS, | ||
events: Vec::new(), | ||
msg_sender: *MSG_SENDER, | ||
} | ||
} | ||
} | ||
|
||
impl Environment { | ||
/// Gets the code hash of the account at the given address. | ||
pub(crate) fn account_codehash(&self) -> [u8; 66] { | ||
self.account_codehash | ||
} | ||
|
||
/// Gets a bounded estimate of the Unix timestamp at which the Sequencer | ||
/// sequenced the transaction. | ||
pub(crate) fn block_timestamp(&self) -> u64 { | ||
self.block_timestamp | ||
} | ||
|
||
/// Gets the chain ID of the current chain. | ||
pub(crate) fn chain_id(&self) -> u64 { | ||
self.chain_id | ||
} | ||
|
||
/// Gets the address of the current program. | ||
pub(crate) fn contract_address(&self) -> [u8; 42] { | ||
self.contract_address | ||
} | ||
|
||
/// Gets the address of the account that called the program. | ||
pub(crate) fn msg_sender(&self) -> [u8; 42] { | ||
self.msg_sender | ||
} | ||
|
||
/// Stores emitted event. | ||
pub(crate) fn store_event(&mut self, event: &[u8]) { | ||
self.events.push(Vec::from(event)); | ||
} | ||
|
||
/// Removes all the stored events. | ||
pub(crate) fn clear_events(&mut self) { | ||
self.events.clear(); | ||
} | ||
|
||
/// Gets all emitted events. | ||
pub(crate) fn events(&self) -> Vec<Vec<u8>> { | ||
self.events.clone() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about changing logic for
motsu::emits_event
, that it would take an event from collection in case of match. No need in callingmotsu::clear_events()
after.