Skip to content

Commit

Permalink
Update CI (#2280)
Browse files Browse the repository at this point in the history
* Update `ci-unified` to 1.81

* Fix `clippy` errors

* Upgrade linting libraries

* Add `rustc` components in toolchain version

* Change to nightly toolchain of last stable

* Update `clippy-utils` version

* Fix `clippy` errors

* Update dylint dependent versions

* Update code to newer `rustc`

* Apply `cargo fmt`

* Apply `cargo fmt`

* Follow `clippy` recommendations

* Update test fixtures

* Update test fixtures

* Follow `clippy` recommendations

* Apply `clippy` recommendations

* Work around Rust' changes to `cfg`

* Apply `cargo fmt`

* Allow dead code

* Apply `clippy` recommendations

* Apply `clippy` recommendations

* Add default impl

* Apply `clippy` recommendations

* Apply `cargo fmt`

* Update test fixtures

* Add `try-runtime` feature

* Output more version info

* Update test fixtures

* Revert me: Install `cargo-contract` `master`

* Add explainer comment for custom `cargo-contract` installation

* Add clarification comment

* Complete check for storage struct

* Add clarification comments

* Fix typo

* Fix spellcheck
  • Loading branch information
cmichi authored Nov 6, 2024
1 parent 0cd2b89 commit 5ec034c
Show file tree
Hide file tree
Showing 56 changed files with 788 additions and 347 deletions.
11 changes: 11 additions & 0 deletions .github/rust-info/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@ runs:
cargo +nightly --version
cargo spellcheck --version
bash --version
substrate-contracts-node --version
# TODO: The installation of `cargo-contract` here can be removed after
# a new image of https://hub.docker.com/r/paritytech/ci-unified/tags has
# been published. At the time of this commit the Docker image is from
# Sep 11, 2024. This means that the `cargo-contract` binary in the image
# is also that old. There was a bug with `cargo-contract` erring on
# newer Rust versions (https://github.com/use-ink/cargo-contract/pull/1786),
# hence we make sure to use the latest `cargo-contract` here.
cargo install --git https://github.com/paritytech/cargo-contract --locked --branch master --force
cargo-contract --version
shell: bash
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ on:
- 'FILE_HEADER'

env:
IMAGE: paritytech/ci-unified:bullseye-1.75.0
IMAGE: paritytech/ci-unified:bullseye-1.81.0
CARGO_TARGET_DIR: /ci-cache/${{ github.repository }}/targets/${{ github.ref_name }}/${{ github.job }}
CARGO_INCREMENTAL: 0
PURELY_STD_CRATES: ink/codegen metadata engine e2e e2e/macro ink/ir
Expand Down Expand Up @@ -270,6 +270,7 @@ jobs:
# we are using a toolchain file in this directory
# add required components for CI
rustup component add rustfmt clippy
rustup component add rust-src rustc-dev llvm-tools-preview
cargo check --verbose
cargo +nightly fmt --all -- --check
cargo clippy -- -D warnings;
Expand Down Expand Up @@ -504,7 +505,7 @@ jobs:
env:
# Fix linking of `linkme`: https://github.com/dtolnay/linkme/issues/49
RUSTFLAGS: -Clink-arg=-z -Clink-arg=nostart-stop-gc
uses: docker://paritytech/ci-unified:bullseye-1.75.0
uses: docker://paritytech/ci-unified:bullseye-1.81.0
with:
# run all tests with --all-features, which will run the e2e-tests feature if present
args: /bin/bash -c "scripts/for_all_contracts_exec.sh --path integration-tests --ignore public/static-buffer --partition ${{ matrix.partition }}/6 -- cargo test \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/measurements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
run:
shell: bash
container:
image: paritytech/ci-unified:bullseye-1.75.0
image: paritytech/ci-unified:bullseye-1.81.0
strategy:
fail-fast: false
matrix:
Expand Down
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ blake2 = { version = "0.10" }
cargo_metadata = { version = "0.18.0" }
cfg-if = { version = "1.0" }
contract-build = { version = "4.1.1" }
darling = { version = "0.20.8" }
darling = { version = "0.20.10" }
derive_more = { version = "0.99.17", default-features = false }
either = { version = "1.12", default-features = false }
funty = { version = "2.0.0" }
Expand Down
7 changes: 3 additions & 4 deletions crates/allocator/src/bump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ impl InnerAlloc {
/// of a layout in the linear memory.
/// - Initially `self.next` is `0`` and aligned
/// - `layout.align() - 1` accounts for `0` as the first index.
/// - the binary with the inverse of the align creates a
/// bitmask that is used to zero out bits, ensuring alignment according to type
/// requirements and ensures that the next allocated pointer address is of the
/// power of 2.
/// - the binary with the inverse of the align creates a bitmask that is used to zero
/// out bits, ensuring alignment according to type requirements and ensures that the
/// next allocated pointer address is of the power of 2.
fn align_ptr(&self, layout: &Layout) -> usize {
(self.next + layout.align() - 1) & !(layout.align() - 1)
}
Expand Down
1 change: 1 addition & 0 deletions crates/e2e/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub struct SandboxErr {

impl SandboxErr {
/// Create a new `SandboxErr` with the given message.
#[allow(dead_code)]
pub fn new(msg: String) -> Self {
Self { msg }
}
Expand Down
3 changes: 1 addition & 2 deletions crates/e2e/src/xts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,11 @@ where
})
.submit_and_watch()
.await
.map(|tx_progress| {
.inspect(|tx_progress| {
log_info(&format!(
"signed and submitted tx with hash {:?}",
tx_progress.extrinsic_hash()
));
tx_progress
})
.unwrap_or_else(|err| {
panic!("error on call `submit_and_watch`: {err:?}");
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Database {
key: &[u8],
) -> Option<&Vec<u8>> {
let hashed_key = storage_of_contract_key(account_id, key);
self.hmap.get(&hashed_key.to_vec())
self.hmap.get(hashed_key.as_slice())
}

/// Inserts `value` into the contract storage of `account_id` at storage key `key`.
Expand All @@ -91,7 +91,7 @@ impl Database {
key: &[u8],
) -> Option<Vec<u8>> {
let hashed_key = storage_of_contract_key(account_id, key);
self.hmap.remove(&hashed_key.to_vec())
self.hmap.remove(hashed_key.as_slice())
}

/// Removes a key from the storage, returning the value at the key if the key
Expand Down
46 changes: 10 additions & 36 deletions crates/env/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ impl<T> AtLeast32BitUnsigned for T where T: AtLeast32Bit + Unsigned {}

/// Saturating arithmetic operations, returning maximum or minimum values instead of
/// overflowing.
#[allow(dead_code)]
pub trait Saturating {
/// Saturating addition. Compute `self + rhs`, saturating at the numeric bounds
/// instead of overflowing.
Expand Down Expand Up @@ -194,53 +195,26 @@ mod tests {

#[test]
fn saturating_add() {
assert_eq!(
u64::max_value(),
Saturating::saturating_add(u64::max_value(), 1)
)
assert_eq!(u64::MAX, Saturating::saturating_add(u64::MAX, 1))
}

#[test]
fn saturatiung_sub() {
assert_eq!(
u64::min_value(),
Saturating::saturating_sub(u64::min_value(), 1)
)
assert_eq!(u64::MIN, Saturating::saturating_sub(u64::MIN, 1))
}

#[test]
fn saturating_mul() {
assert_eq!(
u64::max_value(),
Saturating::saturating_mul(u64::max_value(), 2)
);
assert_eq!(
i64::max_value(),
Saturating::saturating_mul(i64::max_value(), 2)
);
assert_eq!(
i64::min_value(),
Saturating::saturating_mul(i64::min_value(), 2)
);
assert_eq!(
i64::min_value(),
Saturating::saturating_mul(2, i64::min_value())
);
assert_eq!(u64::MAX, Saturating::saturating_mul(u64::MAX, 2));
assert_eq!(i64::MAX, Saturating::saturating_mul(i64::MAX, 2));
assert_eq!(i64::MIN, Saturating::saturating_mul(i64::MIN, 2));
assert_eq!(i64::MIN, Saturating::saturating_mul(2, i64::MIN));
}

#[test]
fn saturating_pow() {
assert_eq!(
u64::max_value(),
Saturating::saturating_pow(u64::max_value(), 2)
);
assert_eq!(
i64::max_value(),
Saturating::saturating_pow(i64::min_value(), 2)
);
assert_eq!(
i64::min_value(),
Saturating::saturating_pow(i64::min_value(), 3)
);
assert_eq!(u64::MAX, Saturating::saturating_pow(u64::MAX, 2));
assert_eq!(i64::MAX, Saturating::saturating_pow(i64::MIN, 2));
assert_eq!(i64::MIN, Saturating::saturating_pow(i64::MIN, 3));
}
}
2 changes: 1 addition & 1 deletion crates/env/src/chain_extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub trait FromStatusCode: Sized {
/// The type states for type parameter `O` and `ErrorCode` represent 4 different states:
///
/// 1. The chain extension method makes use of the chain extension's error code:
/// `HandleErrorCode(E)`
/// `HandleErrorCode(E)`
/// - **A:** The chain extension method returns a `Result<T, E>` type, i.e.
/// `IS_RESULT` is set to `true`.
/// - **B:** The chain extension method returns a type `O` that is not a `Result`
Expand Down
2 changes: 2 additions & 0 deletions crates/env/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ mod decode_instantiate_result_tests {
struct ContractError(String);

type AccountId = <DefaultEnvironment as Environment>::AccountId;
// The `allow(dead_code)` is for the `AccountId` in the struct.
#[allow(dead_code)]
struct TestContractRef(AccountId);

impl crate::ContractEnv for TestContractRef {
Expand Down
1 change: 1 addition & 0 deletions crates/env/src/engine/on_chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl OnInstance for EnvInstance {
static mut INSTANCE: EnvInstance = EnvInstance {
buffer: StaticBuffer::new(),
};
#[allow(static_mut_refs)]
f(unsafe { &mut INSTANCE })
}
}
10 changes: 8 additions & 2 deletions crates/ink/codegen/src/generator/item_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,14 @@ impl ItemImpls<'_> {
///
/// # Developer Note
///
/// The `__ink_dylint_Constructor` config attribute is used here to convey the
/// The `dragonfly` config attribute is used here to convey the
/// information that the generated function is an ink! constructor to `dylint`.
///
///
/// We decided on this attribute to mark the function, as it has to be a
/// key-value pair that is well known to `cargo`. dragonfly seems like an
/// obscure target which it is highly unlikely that someone will ever
/// compile a contract for.
fn generate_inherent_constructor(constructor: &ir::Constructor) -> TokenStream2 {
let span = constructor.span();
let attrs = constructor.attrs();
Expand All @@ -239,7 +245,7 @@ impl ItemImpls<'_> {
let output = constructor.output();
quote_spanned!(span =>
#( #attrs )*
#[cfg(not(feature = "__ink_dylint_Constructor"))]
#[cfg(not(target_os = "dragonfly"))]
#vis fn #ident( #( #inputs ),* ) -> #output {
#( #statements )*
}
Expand Down
9 changes: 7 additions & 2 deletions crates/ink/codegen/src/generator/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ impl Storage<'_> {
///
/// # Developer Note
///
/// The `__ink_dylint_Storage` config attribute is used here to convey the
/// The `fortanix` config attribute is used here to convey the
/// information that the generated struct is an ink! storage struct to `dylint`.
///
/// We decided on this attribute to mark the function, as it has to be a
/// key-value pair that is well known to `cargo`. `fortanix` seems like an obscure
/// vendor, for which it is highly unlikely that someone will ever compile
/// a contract for.
fn generate_storage_struct(&self) -> TokenStream2 {
let storage = self.contract.module().storage();
let span = storage.span();
Expand All @@ -94,7 +99,7 @@ impl Storage<'_> {
#(#attrs)*
#[::ink::storage_item]
#[cfg_attr(test, derive(::core::fmt::Debug))]
#[cfg(not(feature = "__ink_dylint_Storage"))]
#[cfg(not(target_vendor = "fortanix"))]
pub struct #ident #generics {
#( #fields ),*
}
Expand Down
6 changes: 2 additions & 4 deletions crates/ink/ir/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ impl ExtError for syn::Error {
///
/// On stable Rust this might yield higher quality error span information to the user
/// than [`format_err`](`crate::format_err`).
/// - Source:
/// [`syn::Error::new_spanned`](https://docs.rs/syn/1.0.33/syn/struct.Error.html#method.new_spanned)
/// - Source: [`syn::Error::new_spanned`](https://docs.rs/syn/1.0.33/syn/struct.Error.html#method.new_spanned)
/// - Tracking issue: [`#54725`](https://github.com/rust-lang/rust/issues/54725)
#[macro_export]
macro_rules! format_err_spanned {
Expand Down Expand Up @@ -81,8 +80,7 @@ macro_rules! format_err_spanned_value {
///
/// On stable Rust this might yield worse error span information to the user
/// than [`format_err_spanned`].
/// - Source:
/// [`syn::Error::new_spanned`](https://docs.rs/syn/1.0.33/syn/struct.Error.html#method.new_spanned)
/// - Source: [`syn::Error::new_spanned`](https://docs.rs/syn/1.0.33/syn/struct.Error.html#method.new_spanned)
/// - Tracking issue: [`#54725`](https://github.com/rust-lang/rust/issues/54725)
#[macro_export]
macro_rules! format_err {
Expand Down
6 changes: 3 additions & 3 deletions crates/ink/ir/src/ir/item_impl/callable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ pub trait Callable {
///
/// These recommendation mainly apply to trait implementation blocks:
///
/// - The recommendation by the ink! team is to use the full-path approach
/// wherever possible; OR import the trait and use only its identifier with
/// an additional namespace if required to disambiguate selectors.
/// - The recommendation by the ink! team is to use the full-path approach wherever
/// possible; OR import the trait and use only its identifier with an additional
/// namespace if required to disambiguate selectors.
/// - Try not to intermix the above recommendations.
/// - Avoid directly setting the selector of an ink! message or constructor. Only do this
/// if nothing else helps and you need a very specific selector, e.g. in case of
Expand Down
8 changes: 4 additions & 4 deletions crates/ink/ir/src/ir/item_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ impl ItemMod {
}

/// Ensures that:
/// - At most one wildcard selector exists among ink! messages, as well as
/// ink! constructors.
/// - Where a wildcard selector is defined for a message, at most one other
/// message is defined which must have a well known selector.
/// - At most one wildcard selector exists among ink! messages, as well as ink!
/// constructors.
/// - Where a wildcard selector is defined for a message, at most one other message is
/// defined which must have a well known selector.
fn ensure_valid_wildcard_selector_usage(
items: &[ir::Item],
) -> Result<(), syn::Error> {
Expand Down
Loading

0 comments on commit 5ec034c

Please sign in to comment.