-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for language level errors (
LangError
) (#1450)
* Add example cross-chain contract * Update `CallBuilder`'s return type to a `Result` We're gonna try and handle an ink! error later * Write to output buffer on dispatch error * Whoops, reduce value of `u8` * Add some `cargo-contract` automation helpers * Set default if no input is given * Return type expected by call builder after succesful dispatch * Fix typo * Return an actual `DispatchError` back to the caller * Temporarily stop generating contract ref code * Manually change message return type to Result * Transform message return type in the IR * Change message return type when generating contract reference * Return message output directly in the codegen * Add error type for handling language errors * Clean up some things * Remove some unused code * Add DispatchError type metadata * Use language error over dispatch error * Change message body's visibility based on message signature * Fix unreachable code warning * Appease Clippy * Rustfmt cross-contract example * Fix formatting * Write `lang_error` into metadata using spec builder * Use `parse_quote` macro over the `syn::parse` function * Use correct span in call builder * Always return `Type` instead of `Option` from `wrapped_output` * Temporarily appease Clippy * Another temporary Clippy fix * Generate checked and unchecked versions of contract messages We're now able to specify if we want to use an unchecked or checked version of the message functions in our code. This means that existing code, such as in tests, doesn't need to worry about the new wrapped `Result` type. At the same time, as far as external callers are concerned they are always calling the checked version of the messages. * Use non-checked message as checked message implementation * Remove error handling from test * Add method for generating checked message idents * Fix UI tests related to `no_implicit_prelude` * Remove unneccessary import * Add `Default` implementation for `cross_chain_test` * Bless some UI tests * Update `Output` type for doc test * Update `cross_chain_test` to appease Clippy * Generate `*_checked` functions for `ContractRef` calls * Implement `Debug` for Multisig Wasm builds * Add another `Debug` impl * Add `lang_error` to metadata tests * Add example which uses ContractRefs * Handle dispatch error in example * Add UI test for checking that messages now return `Result`s * Add test for message hygiene (or lack thereof) * Add test to check that `*_checked` messages are generated * Remove debug logging from macro code * Appease Clippy * Remove `--skip-linting` from scripts This is because I've updated my local version of `cargo-contract` * Fix fallible constructor revert, make `Ok` explicit * Hack together E2E test example for `LangError` * Add a couple of type aliases to E2E test * Add E2E test which demonstrates write-on-err bug Currently using a single test for all E2E tests since there seems to be some problem with the nonce management that isn't letting me split the tests out into seperate functions. * Split out E2E tests into seperate functions Had to use make calls using different accounts * Tweak E2E tests to make them pass given Andrew's fixes * Remove outdated UI test * Fix a couple more tests * Unify output type and arrow in codegen * Allow `result_unit_err` Clippy lint * Move `Flipper` functionality into integration example * Rename `cross_chain_test` to indicate that its an integration test * Remove test helper scripts * Remove `ContractRef` example/compile test It would be nice to have this as a proper compile test at some point, but right now the set of delegator contracts can be used as an indication for breakages. * Appease Clippy * Add `MessageResult` type alias * Remove `Ref` re-export from Flipper * Remove TODOs related to E2E issues These have now been logged in the issue tracker. * Work around `additional_contracts` bug by moving tests * Clean up `lang_err_integration_tests` a bit * Fix spellcheck lint * Place E2E tests behind feature flag * Apply suggestions from code review Co-authored-by: Andrew Jones <ascjones@gmail.com> * Unwrap message result in delegator E2E tests * Revert "Remove `ContractRef` example/compile test" This reverts commit 6c24543. * Move `LangError` integration tests into single workspace * Move flip related E2E tests to `integration_flipper` * Move `integration_flipper` into its own folder This way we can refer to it from the `additional_contracts` argument of the `ink_e2e::test` macro. * Update `call_builder` test to use `integration_flipper` * Get `contract_ref` E2E test working again * Fill out author and version metadata * Add integration tests to CI * Remove leftover .gitignore * Skip default checks if it's a lang error integration test * Fix UI test * Skip a few CI stages * Add back Clippy stage * Revert "Skip a few CI stages" This reverts commit 1a74375. * Run `LangError` E2E tests in CI * Rename tests using kabob-case instead of snake_case * Try running with `staging` image * Change image back to `production` Didn't help either way * Try cleaning some things * Guess there was no lockfile * Clean up the cleanup * Clean em up again * Use `MessageResult` typedef in one more place * Poke CI * Move comment location * Update contract name Co-authored-by: Andrew Jones <ascjones@gmail.com> Co-authored-by: xermicus <cyrill@parity.io>
- Loading branch information
1 parent
6c1a5e8
commit 6c6e51a
Showing
26 changed files
with
811 additions
and
69 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
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 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 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 |
---|---|---|
|
@@ -71,3 +71,7 @@ pub use ink_macro::{ | |
test, | ||
trait_definition, | ||
}; | ||
pub use ink_primitives::{ | ||
LangError, | ||
MessageResult, | ||
}; |
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
20 changes: 20 additions & 0 deletions
20
crates/ink/tests/ui/contract/fail/message-hygiene-checked.rs
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,20 @@ | ||
#[ink::contract] | ||
mod contract { | ||
#[ink(storage)] | ||
pub struct Contract {} | ||
|
||
impl Contract { | ||
#[ink(constructor)] | ||
pub fn constructor() -> Self { | ||
Self {} | ||
} | ||
|
||
#[ink(message)] | ||
pub fn message(&self) {} | ||
|
||
#[ink(message)] | ||
pub fn message_checked(&self) {} | ||
} | ||
} | ||
|
||
fn main() {} |
8 changes: 8 additions & 0 deletions
8
crates/ink/tests/ui/contract/fail/message-hygiene-checked.stderr
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,8 @@ | ||
error[E0201]: duplicate definitions with name `message_checked`: | ||
--> tests/ui/contract/fail/message-hygiene-checked.rs:16:9 | ||
| | ||
1 | #[ink::contract] | ||
| ---------------- previous definition of `message_checked` here | ||
... | ||
16 | pub fn message_checked(&self) {} | ||
| ^^^ duplicate definition |
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
Oops, something went wrong.