-
Notifications
You must be signed in to change notification settings - Fork 15
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
ae2e356
commit ec376f5
Showing
21 changed files
with
633 additions
and
167 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
//! Module gathering common error and result types. | ||
|
||
use thiserror::Error; | ||
|
||
/// Main error type for the drink crate. | ||
#[derive(Error, Debug)] | ||
pub enum Error { | ||
/// Externalities could not be initialized. | ||
#[error("Failed to build storage: {0}")] | ||
StorageBuilding(String), | ||
/// Block couldn't have been initialized. | ||
#[error("Failed to initialize block: {0}")] | ||
BlockInitialize(String), | ||
/// Block couldn't have been finalized. | ||
#[error("Failed to finalize block: {0}")] | ||
BlockFinalize(String), | ||
} | ||
|
||
/// Every contract message wraps its return value in `Result<T, LangResult>`. This is the error | ||
/// type. | ||
/// | ||
/// Copied from ink primitives. | ||
#[non_exhaustive] | ||
#[repr(u32)] | ||
#[derive( | ||
Debug, | ||
Copy, | ||
Clone, | ||
PartialEq, | ||
Eq, | ||
parity_scale_codec::Encode, | ||
parity_scale_codec::Decode, | ||
scale_info::TypeInfo, | ||
Error, | ||
)] | ||
pub enum LangError { | ||
/// Failed to read execution input for the dispatchable. | ||
#[error("Failed to read execution input for the dispatchable.")] | ||
CouldNotReadInput = 1u32, | ||
} | ||
|
||
/// The `Result` type for ink! messages. | ||
pub type MessageResult<T> = Result<T, LangError>; |
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,36 @@ | ||
mod contract; | ||
mod error; | ||
mod mocking_api; | ||
|
||
use std::collections::BTreeMap; | ||
|
||
pub use contract::{mock_message, ContractMock, MessageMock, Selector}; | ||
use error::MockingError; | ||
pub use mocking_api::MockingApi; | ||
|
||
/// Untyped result of a mocked call. | ||
pub type MockedCallResult = Result<Vec<u8>, MockingError>; | ||
|
||
/// A registry of mocked contracts. | ||
pub(crate) struct MockRegistry<AccountId: Ord> { | ||
mocked_contracts: BTreeMap<AccountId, ContractMock>, | ||
} | ||
|
||
impl<AccountId: Ord> MockRegistry<AccountId> { | ||
/// Creates a new registry. | ||
pub fn new() -> Self { | ||
Self { | ||
mocked_contracts: BTreeMap::new(), | ||
} | ||
} | ||
|
||
/// Registers `mock` for `address`. Returns the previous mock, if any. | ||
pub fn register(&mut self, address: AccountId, mock: ContractMock) -> Option<ContractMock> { | ||
self.mocked_contracts.insert(address, mock) | ||
} | ||
|
||
/// Returns the mock for `address`, if any. | ||
pub fn get(&self, address: &AccountId) -> Option<&ContractMock> { | ||
self.mocked_contracts.get(address) | ||
} | ||
} |
Oops, something went wrong.