-
Notifications
You must be signed in to change notification settings - Fork 478
Add gas_limit host fn
#2691
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
Add gas_limit host fn
#2691
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5030d89
implement `gas_limit` host fn
LucasGrasso f04d729
add tests for `gas_limit` host fn
LucasGrasso 0eec69d
remove off-chain tests for `gas_limit`
LucasGrasso fddfab0
Merge branch 'use-ink:master' into master
LucasGrasso 95162a9
add changes to changelog
LucasGrasso 1e63416
run formatting
LucasGrasso 9c3ab41
fix error in env-access ui test
LucasGrasso e0c8351
run formatting
LucasGrasso eb2f8a3
Apply suggestions from code review
LucasGrasso 4a1f7e3
update versions in gas and misc hostfns internal tests
LucasGrasso 6609561
Merge branch 'master' of https://github.com/LucasGrasso/ink
LucasGrasso 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [package] | ||
| name = "gas_hostfns" | ||
| description = "E2E tests for gas related host functions" | ||
| version = "6.0.0-alpha.1" | ||
LucasGrasso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| authors = ["Use Ink <[email protected]>"] | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [dependencies] | ||
| ink = { path = "../../../crates/ink", default-features = false, features = ["unstable-hostfn"] } | ||
|
|
||
| [dev-dependencies] | ||
| ink_e2e = { path = "../../../crates/e2e" } | ||
|
|
||
| [lib] | ||
| path = "lib.rs" | ||
|
|
||
| [features] | ||
| default = ["std"] | ||
| std = [ | ||
| "ink/std", | ||
| ] | ||
| ink-as-dependency = [] | ||
| e2e-tests = [] | ||
|
|
||
| [package.metadata.ink-lang] | ||
| abi = "ink" | ||
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,55 @@ | ||
| #![cfg_attr(not(feature = "std"), no_std, no_main)] | ||
| #![allow(clippy::new_without_default)] | ||
|
|
||
| #[ink::contract] | ||
| mod gas_hostfns { | ||
| #[ink(storage)] | ||
| pub struct GasHostfns {} | ||
|
|
||
| impl GasHostfns { | ||
| #[ink(constructor)] | ||
| pub fn new() -> Self { | ||
| Self {} | ||
| } | ||
|
|
||
| /// Checks that the host function `gas_limit` works | ||
| #[ink(message)] | ||
| pub fn gas_limit(&self) -> u64 { | ||
| self.env().gas_limit() | ||
| } | ||
| } | ||
|
|
||
| #[cfg(all(test, feature = "e2e-tests"))] | ||
| mod e2e_tests { | ||
| use super::*; | ||
| use ink_e2e::ContractsBackend; | ||
|
|
||
| type E2EResult<T> = std::result::Result<T, Box<dyn std::error::Error>>; | ||
|
|
||
| #[ink_e2e::test] | ||
| async fn e2e_gas_limit_works<Client: E2EBackend>( | ||
| mut client: Client, | ||
| ) -> E2EResult<()> { | ||
| // given | ||
| let contract = client | ||
| .instantiate("gas_hostfns", &ink_e2e::alice(), &mut GasHostfnsRef::new()) | ||
| .submit() | ||
| .await | ||
| .expect("instantiate failed"); | ||
| let call_builder = contract.call_builder::<GasHostfns>(); | ||
|
|
||
| // then | ||
| let _call_res = client | ||
LucasGrasso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .call(&ink_e2e::alice(), &call_builder.gas_limit()) | ||
| .submit() | ||
| .await | ||
| .unwrap_or_else(|err| { | ||
| panic!("call failed: {:#?}", err); | ||
| }); | ||
|
|
||
| assert!(_call_res.return_value() > 0); | ||
LucasGrasso marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
| } | ||
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.