-
Notifications
You must be signed in to change notification settings - Fork 68
A0-1610: Contract support redux #816
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 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6e17075
Add e2e tests for a simple contract
obrok 8b3e7ec
Fix tests and warnings
obrok a063c84
Run adder test on CI
obrok 9c2426d
Install fmt/clippy/wasm target per package on CI
obrok 3baf23a
Install cargo contract for e2e tests
obrok 813a026
Install cargo-contract only in adder test
obrok dce0aa6
Install rust-src for 1.65.0 on CI
obrok 867dbc3
Set adder metadata on CI
obrok 75bea24
Pass ADDER_METADATA to adder test
obrok 13adbd4
Extend adder test timeout
obrok 561cd1a
Give names to adder arguments in CI
obrok b6581d4
Mount contract dir in e2e tests (for the metadata)
obrok 1f33c99
Fix clippy
obrok dfa03fa
Merge branch 'main' into obrok/contract-support-redux
obrok e280ff3
Bump aleph-client to 2.5.0
obrok f7563d4
Authenticate when installing protoc
obrok 985942f
Revert "Authenticate when installing protoc"
obrok 874a325
Add Option<T> conversion for contract returns
obrok 3df5c2f
Extract variables
obrok 1c29d22
Merge branch 'main' into obrok/contract-support-redux
obrok 4f8a01b
Merge branch 'main' into obrok/contract-support-redux
obrok 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
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 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 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 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 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| [package] | ||
| name = "aleph_client" | ||
| version = "2.4.0" | ||
| version = "2.5.0" | ||
| edition = "2021" | ||
| license = "Apache 2.0" | ||
|
|
||
|
|
||
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,120 @@ | ||
| use std::{ops::Deref, str::FromStr}; | ||
|
|
||
| use anyhow::{anyhow, bail, Result}; | ||
| use contract_transcode::Value; | ||
|
|
||
| use crate::AccountId; | ||
|
|
||
| /// Temporary wrapper for converting from [Value] to primitive types. | ||
| /// | ||
| /// ``` | ||
| /// # #![feature(assert_matches)] | ||
| /// # #![feature(type_ascription)] | ||
| /// # use std::assert_matches::assert_matches; | ||
| /// # use anyhow::{anyhow, Result}; | ||
| /// # use aleph_client::{AccountId, contract::ConvertibleValue}; | ||
| /// use contract_transcode::Value; | ||
| /// | ||
| /// assert_matches!(ConvertibleValue(Value::UInt(42)).try_into(), Ok(42u128)); | ||
| /// assert_matches!(ConvertibleValue(Value::UInt(42)).try_into(), Ok(42u32)); | ||
| /// assert_matches!(ConvertibleValue(Value::UInt(u128::MAX)).try_into(): Result<u32>, Err(_)); | ||
| /// assert_matches!(ConvertibleValue(Value::Bool(true)).try_into(), Ok(true)); | ||
| /// assert_matches!( | ||
| /// ConvertibleValue(Value::Literal("5H8cjBBzCJrAvDn9LHZpzzJi2UKvEGC9VeVYzWX5TrwRyVCA".to_string())). | ||
| /// try_into(): Result<AccountId>, | ||
| /// Ok(_) | ||
| /// ); | ||
| /// assert_matches!( | ||
| /// ConvertibleValue(Value::String("not a number".to_string())).try_into(): Result<u128>, | ||
| /// Err(_) | ||
| /// ); | ||
| /// ``` | ||
| #[derive(Debug, Clone)] | ||
| pub struct ConvertibleValue(pub Value); | ||
|
|
||
| impl Deref for ConvertibleValue { | ||
| type Target = Value; | ||
|
|
||
| fn deref(&self) -> &Value { | ||
| &self.0 | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<ConvertibleValue> for bool { | ||
| type Error = anyhow::Error; | ||
|
|
||
| fn try_from(value: ConvertibleValue) -> Result<bool, Self::Error> { | ||
| match value.0 { | ||
| Value::Bool(value) => Ok(value), | ||
| _ => bail!("Expected {:?} to be a boolean", value.0), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<ConvertibleValue> for u128 { | ||
| type Error = anyhow::Error; | ||
|
|
||
| fn try_from(value: ConvertibleValue) -> Result<u128, Self::Error> { | ||
| match value.0 { | ||
| Value::UInt(value) => Ok(value), | ||
| _ => bail!("Expected {:?} to be an integer", value.0), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<ConvertibleValue> for u32 { | ||
| type Error = anyhow::Error; | ||
|
|
||
| fn try_from(value: ConvertibleValue) -> Result<u32, Self::Error> { | ||
| match value.0 { | ||
| Value::UInt(value) => Ok(value.try_into()?), | ||
| _ => bail!("Expected {:?} to be an integer", value.0), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<ConvertibleValue> for AccountId { | ||
| type Error = anyhow::Error; | ||
|
|
||
| fn try_from(value: ConvertibleValue) -> Result<AccountId, Self::Error> { | ||
| match value.0 { | ||
| Value::Literal(value) => { | ||
| AccountId::from_str(&value).map_err(|_| anyhow!("Invalid account id")) | ||
| } | ||
| _ => bail!("Expected {:?} to be a string", value), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<T> TryFrom<ConvertibleValue> for Result<T> | ||
| where | ||
| ConvertibleValue: TryInto<T, Error = anyhow::Error>, | ||
| { | ||
| type Error = anyhow::Error; | ||
|
|
||
| fn try_from(value: ConvertibleValue) -> Result<Result<T>, Self::Error> { | ||
| if let Value::Tuple(tuple) = &value.0 { | ||
| match tuple.ident() { | ||
| Some(x) if x == "Ok" => { | ||
| if tuple.values().count() == 1 { | ||
| let item = | ||
| ConvertibleValue(tuple.values().next().unwrap().clone()).try_into()?; | ||
| return Ok(Ok(item)); | ||
| } else { | ||
| bail!("Unexpected number of elements in Ok variant: {:?}", &value); | ||
| } | ||
| } | ||
| Some(x) if x == "Err" => { | ||
| if tuple.values().count() == 1 { | ||
| return Ok(Err(anyhow!(value.to_string()))); | ||
| } else { | ||
| bail!("Unexpected number of elements in Err variant: {:?}", &value); | ||
| } | ||
| } | ||
| _ => (), | ||
| } | ||
| } | ||
|
|
||
| bail!("Expected {:?} to be an Ok(_) or Err(_) tuple.", value); | ||
| } | ||
| } | ||
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.