-
Notifications
You must be signed in to change notification settings - Fork 25
Basic contract mocking #61
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c0c7a27
Base structs
pmikolajczyk41 68f3794
New example contract (delegator)
pmikolajczyk41 9e9bce1
MockingApi
pmikolajczyk41 25e02d1
Building message mock
pmikolajczyk41 bc8cd47
Contract mock
pmikolajczyk41 ff78776
Registering dummy contract
pmikolajczyk41 de38242
Full test (not working yet)
pmikolajczyk41 0192bca
Add new example to the CI
pmikolajczyk41 faf146c
Reorg in drink-debug
pmikolajczyk41 535afe4
Rename extension
pmikolajczyk41 f734d24
Finish runtime side
pmikolajczyk41 9672293
Register extension
pmikolajczyk41 b6a663b
Share registry
pmikolajczyk41 2f2f25a
Somehow connected
pmikolajczyk41 cbbfabf
Woohoo
pmikolajczyk41 e772549
Describe and document the example
pmikolajczyk41 5be192c
CI todo
pmikolajczyk41 035b256
Bump version
pmikolajczyk41 b16f4a9
Docs, errors moved
pmikolajczyk41 ebebecc
Fix imports
pmikolajczyk41 1e090ce
Fatter bump
pmikolajczyk41 8f4f08a
comment fix
pmikolajczyk41 acfb5ca
deploy_mock -> deploy
pmikolajczyk41 49f2acb
Return old mock
pmikolajczyk41 024b208
hacky way to check if we should set flag to revert
pmikolajczyk41 5a15ee8
explanation
pmikolajczyk41 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.