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

feat(test): parallel unit test execution #379

Merged
merged 7 commits into from
Oct 30, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
renaming
  • Loading branch information
qalisander committed Oct 24, 2024
commit 30aa0a3ac8a6fc0d0e76b450f53f5bbc6870870d
19 changes: 10 additions & 9 deletions lib/motsu/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl TestContext {

/// Get the value at `key` in storage.
pub(crate) fn get_bytes(self, key: &Bytes32) -> Bytes32 {
let storage = TESTS_STORAGE.entry(self.thread_name).or_default();
storage.contract.get(key).copied().unwrap_or_default()
let storage = MOCK_STORAGE.entry(self.thread_name).or_default();
storage.contract_data.get(key).copied().unwrap_or_default()
}

/// Get the raw value at raw `key` in storage.
qalisander marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -36,8 +36,8 @@ impl TestContext {

/// Set the value at `key` in storage to `val`.
pub(crate) fn set_bytes(self, key: Bytes32, val: Bytes32) {
let mut storage = TESTS_STORAGE.entry(self.thread_name).or_default();
storage.contract.insert(key, val);
let mut storage = MOCK_STORAGE.entry(self.thread_name).or_default();
storage.contract_data.insert(key, val);
}

/// Set the raw value at `key` in storage to raw `val`.
qalisander marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -49,7 +49,7 @@ impl TestContext {
/// Clears storage, removing all key-value pairs associated with the current
/// test thread.
pub fn reset_storage(self) {
TESTS_STORAGE.remove(&self.thread_name);
MOCK_STORAGE.remove(&self.thread_name);
}
}

Expand All @@ -58,7 +58,7 @@ impl TestContext {
///
/// The key is the name of the test thread, and the value is the storage of the
/// test case.
static TESTS_STORAGE: Lazy<DashMap<TestThreadName, TestStorage>> =
static MOCK_STORAGE: Lazy<DashMap<TestThreadName, MockStorage>> =
qalisander marked this conversation as resolved.
Show resolved Hide resolved
Lazy::new(DashMap::new);

/// Test thread name metadata.
Expand All @@ -76,10 +76,11 @@ impl TestThreadName {
}
}

/// Context of the test case.
/// Storage for unit test's mock data.
#[derive(Default)]
struct TestStorage {
pub contract: HashMap<Bytes32, Bytes32>,
struct MockStorage {
qalisander marked this conversation as resolved.
Show resolved Hide resolved
/// Contract's mock data storage.
contract_data: HashMap<Bytes32, Bytes32>,
}

/// Read the word at address `key`.
Expand Down
Loading