Conversation
✅ Deploy Preview for contracts-stylus ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
qalisander
left a comment
There was a problem hiding this comment.
Awesome @bidzyyys!
Few improvements I have:
| block_timestamp: u64, | ||
| chain_id: u64, | ||
| contract_address: [u8; 42], | ||
| events: Vec<Vec<u8>>, |
There was a problem hiding this comment.
I would better create wrapper type for event, to store them like Vec<Event> (or Vec<EncodedEvent>)
| /// Dummy msg sender set for tests. | ||
| const MSG_SENDER: &[u8; 42] = b"0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF"; | ||
|
|
||
| pub(crate) struct Environment { |
There was a problem hiding this comment.
I remember, that the whole reason of MockStorage was to store not just storage bytes (contract_storage), but also fields that you've put into Environment struct
There was a problem hiding this comment.
Because these data are also "mocked" values for our test cases
| //! 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.
Good! Seems rational for me to move these constants to the other module
| // https://github.com/OffchainLabs/stylus-sdk-rs/blob/v0.6.0/stylus-sdk/src/evm.rs#L38-L52 | ||
| let buffer = read_bytes(data, len); | ||
| let encoded_event: Vec<u8> = | ||
| buffer.clone().into_iter().skip(topics * WORD_BYTES).collect(); |
There was a problem hiding this comment.
If you would have Event struct (or EncodedEvent), you could use here conversion to it from buffer
| /// | ||
| /// The key is the name of the test thread, | ||
| /// and the value is the context of the test case. | ||
| static EVM: Lazy<DashMap<ThreadName, TestCase>> = Lazy::new(DashMap::new); |
There was a problem hiding this comment.
We can call it MOCK_EVM. But yeah, mentioning EVM in the name of the test storage seems quite reasonable to me!
There was a problem hiding this comment.
Since we are trying to mimic its behavior for test cases
| assert!(res.is_ok()); | ||
| assert_eq!(contract.paused(), true); | ||
| let expected_event = Paused { account: msg::sender() }; | ||
| assert!(motsu::emits_event(expected_event.clone())); |
There was a problem hiding this comment.
How about changing logic for motsu::emits_event, that it would take an event from collection in case of match. No need in calling motsu::clear_events() after.
|
Moved to OpenZeppelin/stylus-test-helpers#13. |
Resolves OpenZeppelin/stylus-test-helpers#9
PR Checklist