Skip to content

Commit b7799f5

Browse files
committed
Merge branch 'master' into hc-bump-substrate-deps
2 parents 3e90251 + f493245 commit b7799f5

File tree

129 files changed

+3305
-1024
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+3305
-1024
lines changed

.github/dependabot.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ updates:
44
directory: "/"
55
schedule:
66
interval: "daily"
7+
# ignore Substrate pallets major updates.
8+
# automated Substrate releases cause dependabot PR spam, so these must be updated manually when required.
9+
ignore:
10+
- dependency-name: "sp-*"
11+
update-types: [ "version-update:semver-major" ]
12+
- dependency-name: "pallet-*"
13+
update-types: [ "version-update:semver-major" ]
714
- package-ecosystem: github-actions
815
directory: '/'
916
schedule:

.github/workflows/examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
substrate-contracts-node -linfo,runtime::contracts=debug 2>&1 | tee /tmp/contracts-node.log &
8383
8484
- name: Rust Cache
85-
uses: Swatinem/rust-cache@v2.0.1
85+
uses: Swatinem/rust-cache@v2.2.0
8686

8787
- name: Install `cargo-contract` `master`
8888
uses: actions-rs/cargo@v1

.gitlab-ci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ variables:
2929
# CI_IMAGE is changed to "-:staging" when the CI image gets rebuilt
3030
# read more https://github.com/paritytech/scripts/pull/244
3131
CI_IMAGE: "paritytech/ink-ci-linux:production"
32-
PURELY_STD_CRATES: "ink/codegen metadata engine"
32+
PURELY_STD_CRATES: "ink/codegen metadata engine e2e e2e/macro"
3333
ALSO_WASM_CRATES: "env storage storage/traits allocator prelude primitives ink ink/macro ink/ir"
3434
ALL_CRATES: "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}"
3535
DELEGATOR_SUBCONTRACTS: "accumulator adder subber"
@@ -311,6 +311,8 @@ docs:
311311
- cargo doc --no-deps --all-features -p ink_ir
312312
- cargo doc --no-deps --all-features -p ink_codegen
313313
- cargo doc --no-deps --all-features -p ink_metadata
314+
- cargo doc --no-deps --all-features -p ink_e2e
315+
- cargo doc --no-deps --all-features -p ink_e2e_macro
314316
- mv ${CARGO_TARGET_DIR}/doc ./crate-docs
315317
# FIXME: remove me after CI image gets nonroot
316318
- chown -R nonroot:nonroot ./crate-docs

ARCHITECTURE.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ ink! is composed of a number of crates that are all found in the
1919
The ink! language itself.
2020
* [`allocator`](https://github.com/paritytech/ink/tree/master/crates/allocator):
2121
The allocator used for dynamic memory allocation in a contract.
22-
* [`engine`](https://github.com/paritytech/ink/tree/master/crates/engine):
23-
An off-chain testing engine, it simulates a blockchain environment and allows
24-
mocking specified conditions.
2522
* [`env`](https://github.com/paritytech/ink/tree/master/crates/env):
2623
Serves two roles:
2724
* Exposes environmental functions, like information about the caller
28-
of a contract call, getting random entropy, or e.g. self-terminating the
29-
contract.
25+
of a contract call or e.g. self-terminating the contract.
3026
* Provides the connection to the [`pallet-contracts`](https://github.com/paritytech/substrate/tree/master/frame/contracts),
3127
so anything that calls into the underlying execution engine of the smart contract.
3228
This includes getting and setting a smart contracts storage, as well
@@ -44,6 +40,15 @@ ink! is composed of a number of crates that are all found in the
4440
* [`storage`](https://github.com/paritytech/ink/tree/master/crates/prelude):
4541
The collections that are available for contract developers to put in
4642
a smart contracts storage.
43+
* [`engine`](https://github.com/paritytech/ink/tree/master/crates/engine):
44+
An off-chain testing engine, it simulates a blockchain environment and allows
45+
mocking specified conditions.
46+
* [`e2e`](https://github.com/paritytech/ink/tree/master/crates/e2e):
47+
An end-to-end testing framework for ink! contracts. It requires a Substrate node
48+
which includes `pallet-contracts` running in the background. The crate provides a
49+
macro which can be used
50+
to write an idiomatic Rust test that will in the background create transactions,
51+
submit it to the Substrate chain and return the state changes, gas costs, etc.
4752

4853
An important thing to note is that the crates are primarily run in
4954
a `no_std` environment.
@@ -96,14 +101,27 @@ gas costs) and a lower transaction throughput. Freeing memory is
96101
irrelevant for our use-case anyway, as the entire memory instance
97102
is set up fresh for each individual contract call anyway.
98103

99-
## Nightly Rust features in ink!
104+
## Unstable Rust features in ink!
100105

101-
We would like to get away from nightly features of Rust in ink!, so
106+
We would like to get away from unstable features of Rust in ink!, so
102107
that users can just use stable Rust for building their contracts.
103108
At the moment we're still stuck with one nightly feature though:
104109
[alloc_error_handler](https://github.com/rust-lang/rust/issues/51540).
105110
It's needed because we use a specialized memory allocation handler,
106111
the `ink_allocator` crate.
112+
It's unclear when or if this feature will ever make it to stable.
113+
114+
We had a lot of issues when requiring users to use Rust nightly. Mostly
115+
because there were regularly bugs in the nightly Rust compiler that
116+
often took days to be fixed.
117+
As a consequence we decided on having `cargo-contract` `v2.0.0` run
118+
`cargo +stable build` with `RUSTC_BOOTSTRAP=1`. This is kind of a hack,
119+
the env variable enables unstable features in the stable Rust toolchain.
120+
But it enabled us to switch tutorials/guides to Rust stable.
121+
122+
One advantage is that users don't deal with an ever-changing nightly
123+
compiler. It's easier for us to support. If you build a contract without
124+
`cargo-contract` you will have to set this env variable too or use nightly.
107125

108126
## Interaction with `pallet-contracts`
109127

@@ -170,3 +188,35 @@ one point.
170188

171189
The prefix `seal` here is for historic reasons. There is some analogy to sealing a
172190
contract. And we found seals to be a cute animal as well ‒ like squids!
191+
192+
## `Environment` Trait
193+
194+
You can use ink! on any blockchain that was built with the [Substrate](https://substrate.io)
195+
framework and includes the [`pallet-contracts`](https://github.com/paritytech/substrate/tree/master/frame/contracts)
196+
module.
197+
Substrate does not define specific types for a blockchain, it uses
198+
generic types throughout.
199+
Chains built on Substrate can decide on their own which types they want
200+
to use for e.g. the chain's block number or account id's. For example,
201+
chains that intend to be compatible to Ethereum typically use the same
202+
type as Ethereum for their `AccountId`.
203+
204+
The `Environment` trait is how ink! knows the concretes types of the chain
205+
to which the contract will be deployed to.
206+
Specifically, our `ink_env` crate defines a trait [`Environment`](https://paritytech.github.io/ink/ink_env/trait.Environment.html)
207+
which specifies the types.
208+
By default, ink! uses the default Substrate types, the `ink_env` crate
209+
exports an implementation of the `Environment` trait for that:
210+
[`DefaultEnvironment`](https://paritytech.github.io/ink/ink_env/enum.DefaultEnvironment.html).
211+
212+
If you are developing for a chain that uses different types than the
213+
Substrate default types you can configure a different environment in
214+
the contract macro ([documentation here](https://paritytech.github.io/ink/ink/attr.contract.html#header-arguments)):
215+
216+
```rust
217+
#[ink::contract(env = MyCustomTypes)]
218+
```
219+
220+
__Important:__ If a developer writes a contract for a chain that deviates
221+
from the default Substrate types, they have to make sure to use that
222+
chain's `Environment`.

CHANGELOG.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,60 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## Unreleased
7+
## [Unreleased]
8+
- Rename `_checked` codegen call methods with `try_`[#1621](https://github.com/paritytech/ink/pull/1621)
9+
10+
### Breaking Changes
11+
12+
1. We've renamed some of the generated message methods on the `ContractRef` struct. They
13+
have been changed from `_checked` to `try_` ([#1621](https://github.com/paritytech/ink/pull/1621))
14+
15+
## Version 4.0.0-beta.1
16+
The coolest feature included in this release is the first first published version of
17+
ink!'s native ["end-to-end" (E2E) testing framework](https://github.com/paritytech/ink/issues/1234).
18+
19+
This enables testing of a contract by deploying and calling it on a Substrate node with
20+
`pallet-contracts`. See the [`erc20` example](./examples/erc20/lib.rs) for usage.
21+
22+
### Breaking Changes
23+
This release includes a couple of breaking changes.
24+
25+
1. The `CallBuilder::returns()` method does not require an extra `MessageResult` anymore
26+
as the type is now added under the hood [(#1525)](https://github.com/paritytech/ink/pull/1525)
27+
1. The `CallBuilder::invoke()` and `CreateBuilder::instantiate() `methods now unwrap the
28+
`Result` from `pallet-contracts` under the hood ([#1602](https://github.com/paritytech/ink/pull/1602))
29+
If you wish to handle the error use the new `try_` variants of those methods instead.
30+
1. The `CallBuilder::fire()` method has been renamed to `invoke()`
31+
([#1604](https://github.com/paritytech/ink/pull/1604))
32+
1. The `returns_result` flag has been removed from the `#[ink(extension = …)]` attribute
33+
([#1569](https://github.com/paritytech/ink/pull/1569))
34+
We now infer this information at compile time. If `handle_status` is set to `true`,
35+
the return type will still be wrapped into `Result` as before.
36+
1. The Minimum Supported Rust Version (MSRV) has been set to `1.63.0`. This was already
37+
the case, but previously it was enforced by `cargo-contract` instead of ink!
38+
([#1609](https://github.com/paritytech/ink/pull/1609))
39+
40+
### Added
841
- Add E2E testing framework MVP ‒ [#1395](https://github.com/paritytech/ink/pull/1395)
42+
- Add E2E tests for `Mapping` functions - [#1492](https://github.com/paritytech/ink/pull/1492)
43+
44+
### Fixed
45+
- Add Determinism enum from pallet-contracts ‒ [#1547](https://github.com/paritytech/ink/pull/1547)
46+
- Added missed `WhereClosure` for the generics into `storage_item`[#1536](https://github.com/paritytech/ink/pull/1536) (thanks [@xgreenx](https://github.com/xgreenx))
47+
48+
### Changed
49+
- Handle `LangError` from instantiate ‒ [#1512](https://github.com/paritytech/ink/pull/1512)
50+
- FFI: no more `__unstable__` wasm import module ‒ [#1522](https://github.com/paritytech/ink/pull/1522)
51+
- Clean up CallBuilder `return()` type ‒ [#1525](https://github.com/paritytech/ink/pull/1525)
52+
- Fix trait message return type metadata ‒ [#1531](https://github.com/paritytech/ink/pull/1531)
53+
- Bump Dylint dependencies ‒ [#1551](https://github.com/paritytech/ink/pull/1551)
54+
- Stabilize `take_storage`[#1568](https://github.com/paritytech/ink/pull/1568)
55+
- Chain Extension: Evaluation of method return type at compile time ‒ [#1569](https://github.com/paritytech/ink/pull/1569)
56+
- Make more functions be const ‒ [#1574](https://github.com/paritytech/ink/pull/1574) (thanks [@yjhmelody](https://github.com/yjhmelody))
57+
- Unify fallible and non fallible `instantiate` methods ‒ [#1591](https://github.com/paritytech/ink/pull/1591)
58+
- Make `CallBuilder` and `CreateBuilder` error handling optional ‒ [#1602](https://github.com/paritytech/ink/pull/1602)
59+
- Rename `CallBuilder::fire()` method to `invoke()`[#1604](https://github.com/paritytech/ink/pull/1604)
60+
- chore: add minimum rust version to the ink crate ‒ [#1609](https://github.com/paritytech/ink/pull/1609) (thanks [@Kurtsley](https://github.com/Kurtsley))
961

1062
## Version 4.0.0-beta
1163

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
[j1]: https://img.shields.io/badge/click-blue.svg
2424
[j2]: https://paritytech.github.io/ink/ink
2525
[k1]: https://img.shields.io/badge/matrix-chat-brightgreen.svg?style=flat
26-
[k2]: https://riot.im/app/#/room/#ink:matrix.parity.io
26+
[k2]: https://app.element.io/#/room/#ink:matrix.parity.io
2727
[l1]: https://img.shields.io/discord/722223075629727774?style=flat-square&label=discord
2828
[l2]: https://discord.com/invite/wGUDt2p
2929
[s1]: https://img.shields.io/badge/click-white.svg?logo=StackExchange&label=ink!%20Support%20on%20StackExchange&labelColor=white&color=blue
@@ -74,7 +74,7 @@ It's a simple Substrate blockchain which includes the Substrate module for smart
7474

7575
We also have a live testnet on [Rococo](https://github.com/paritytech/cumulus/#rococo-). Rococo is a Substrate based
7676
parachain which supports ink! smart contracts. For further instructions on using this
77-
testnet, follow the instructions in the
77+
testnet, follow the instructions in
7878
[our documentation](https://use.ink/testnet).
7979

8080
For both types of chains the [Contracts UI](https://contracts-ui.substrate.io/)
@@ -109,7 +109,7 @@ In order to build the contract just execute this command in the `flipper` folder
109109
cargo +nightly contract build
110110
```
111111

112-
As a result you'll get a file `target/flipper.wasm` file, a `metadata.json` file and a `<contract-name>.contract` file in the `target` folder of your contract.
112+
As a result you'll get a `target/flipper.wasm` file, a `metadata.json` file and a `<contract-name>.contract` file in the `target` folder of your contract.
113113
The `.contract` file combines the Wasm and metadata into one file and needs to be used when instantiating the contract.
114114

115115

@@ -175,12 +175,12 @@ mod flipper {
175175
```
176176

177177
The [`flipper/src/lib.rs`](https://github.com/paritytech/ink/blob/master/examples/flipper/lib.rs)
178-
file in our examples folder contains exactly this code. Run `cargo contract build` to build your
178+
file in our examples folder contains exactly this code. Run `cargo +nightly contract build` to build your
179179
first ink! smart contract.
180180

181181
## Examples
182182

183-
In the `examples` folder you'll find a number of examples written in ink!.
183+
In the [`examples`](https://github.com/paritytech/ink/tree/master/examples) folder you'll find a number of examples written in ink!.
184184

185185
Some of the most interesting ones:
186186

@@ -192,7 +192,7 @@ Some of the most interesting ones:
192192

193193
To build a single example navigate to the root of the example and run:
194194
```
195-
cargo contract build
195+
cargo contract +nightly build
196196
```
197197

198198
You should now have an `<name>.contract` file in the `target` folder of the contract.
@@ -208,7 +208,7 @@ This module is called the `contracts` pallet,
208208
* The `contracts` pallet requires smart contracts to be uploaded to the blockchain as a Wasm blob.
209209
* ink! is a smart contract language which targets the API exposed by `contracts`.
210210
Hence ink! contracts are compiled to Wasm.
211-
* When executing `cargo contract build` an additional file `metadata.json` is created.
211+
* When executing `cargo contract +nightly build` an additional file `metadata.json` is created.
212212
It contains information about e.g. what methods the contract provides for others to call.
213213

214214
## ink! Macros & Attributes Overview
@@ -224,7 +224,7 @@ In a module annotated with `#[ink::contract]` these attributes are available:
224224
| `#[ink(constructor)]` | Applicable to method. | Flags a method for the ink! storage struct as constructor making it available to the API for instantiating the contract. |
225225
| `#[ink(event)]` | On `struct` definitions. | Defines an ink! event. A contract can define multiple such ink! events. |
226226
| `#[ink(anonymous)]` | Applicable to ink! events. | Tells the ink! codegen to treat the ink! event as anonymous which omits the event signature as topic upon emitting. Very similar to anonymous events in Solidity. |
227-
| `#[ink(topic)]` | Applicable on ink! event field. | Tells the ink! codegen to provide a topic hash for the given field. Every ink! event can only have a limited number of such topic field. Similar semantics as to indexed event arguments in Solidity. |
227+
| `#[ink(topic)]` | Applicable on ink! event field. | Tells the ink! codegen to provide a topic hash for the given field. Every ink! event can only have a limited number of such topic fields. Similar semantics as to indexed event arguments in Solidity. |
228228
| `#[ink(payable)]` | Applicable to ink! messages. | Allows receiving value as part of the call of the ink! message. ink! constructors are implicitly payable. |
229229
| `#[ink(selector = S:u32)]` | Applicable to ink! messages and ink! constructors. | Specifies a concrete dispatch selector for the flagged entity. This allows a contract author to precisely control the selectors of their APIs making it possible to rename their API without breakage. |
230230
| `#[ink(selector = _)]` | Applicable to ink! messages. | Specifies a fallback message that is invoked if no other ink! message matches a selector. |

SECURITY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Reporting a vulnerability
2+
3+
If you find something that can be treated as a security vulnerability, please do not use the issue tracker or discuss it in the public forum/channels, as it can cause more damage rather than giving real help to the ecosystem.
4+
5+
Security vulnerabilities should be reported using [this contact form](https://security-submission.parity.io/).
6+
7+
If you think that your report might be eligible for the Bug Bounty Program, please mark this during the submission. Please check up-to-date [Parity Bug Bounty Program rules](https://www.parity.io/bug-bounty) for more information about our Bug Bounty Program.
8+
9+
**Warning:** This is an unified `SECURITY.md` file for the Paritytech GitHub Organization. The presence of this file does not mean that this repository is covered by the Bug Bounty program. Please always check the Bug Bounty Program scope for the information.

crates/allocator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ink_allocator"
3-
version = "4.0.0-beta"
3+
version = "4.0.0-beta.1"
44
authors = ["Parity Technologies <[email protected]>", "Robin Freyler <[email protected]>"]
55
edition = "2021"
66

crates/e2e/Cargo.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
[package]
22
name = "ink_e2e"
3-
version = "4.0.0-beta"
3+
version = "4.0.0-beta.1"
44
authors = ["Parity Technologies <[email protected]>"]
55
edition = "2021"
6-
publish = false
76

87
license = "Apache-2.0"
98
readme = "README.md"
@@ -16,12 +15,12 @@ categories = ["no-std", "embedded"]
1615
include = ["/Cargo.toml", "src/**/*.rs", "/README.md", "/LICENSE"]
1716

1817
[dependencies]
19-
ink_e2e_macro = { version = "4.0.0-beta", path = "./macro" }
20-
ink = { version = "4.0.0-beta", path = "../ink" }
21-
ink_env = { version = "4.0.0-beta", path = "../env" }
22-
ink_primitives = { version = "4.0.0-beta", path = "../primitives" }
18+
ink_e2e_macro = { version = "4.0.0-beta.1", path = "./macro" }
19+
ink = { version = "4.0.0-beta.1", path = "../ink" }
20+
ink_env = { version = "4.0.0-beta.1", path = "../env" }
21+
ink_primitives = { version = "4.0.0-beta.1", path = "../primitives" }
2322

24-
contract-metadata = { version = "2.0.0-beta.1" }
23+
contract-metadata = { version = "2.0.0-rc" }
2524
funty = "2.0.0"
2625
impl-serde = { version = "0.3.1", default-features = false }
2726
jsonrpsee = { version = "0.16.0", features = ["ws-client"] }

crates/e2e/macro/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
[package]
22
name = "ink_e2e_macro"
3-
version = "4.0.0-beta"
3+
version = "4.0.0-beta.1"
44
authors = ["Parity Technologies <[email protected]>"]
55
edition = "2021"
6-
publish = false
76

87
license = "Apache-2.0"
98
readme = "../README.md"
@@ -20,7 +19,7 @@ name = "ink_e2e_macro"
2019
proc-macro = true
2120

2221
[dependencies]
23-
ink_ir = { version = "4.0.0-beta", path = "../../ink/ir" }
22+
ink_ir = { version = "4.0.0-beta.1", path = "../../ink/ir" }
2423
contract-build = "2.0.0-beta.1"
2524
derive_more = "0.99.17"
2625
env_logger = "0.10.0"

0 commit comments

Comments
 (0)