Skip to content
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

Temporarily add Determinism enum from pallet-contracts #1547

Merged
merged 6 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ variables:
CARGO_TARGET_DIR: "/ci-cache/${CI_PROJECT_NAME}/targets/${CI_COMMIT_REF_NAME}/${CI_JOB_NAME}"
# CI_IMAGE is changed to "-:staging" when the CI image gets rebuilt
# read more https://github.com/paritytech/scripts/pull/244
CI_IMAGE: "paritytech/ink-ci-linux:production"
CI_IMAGE: "paritytech/ink-ci-linux:staging"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should've been rolled back before merging

PURELY_STD_CRATES: "ink/codegen metadata engine"
ALSO_WASM_CRATES: "env storage storage/traits allocator prelude primitives ink ink/macro ink/ir"
ALL_CRATES: "${PURELY_STD_CRATES} ${ALSO_WASM_CRATES}"
Expand Down
24 changes: 24 additions & 0 deletions crates/e2e/src/xts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,32 @@ pub struct Call<E: Environment, B> {
data: Vec<u8>,
}

#[derive(
Debug, Clone, Copy, scale::Encode, scale::Decode, PartialEq, Eq, serde::Serialize,
)]
pub enum Determinism {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing docs

/// The execution should be deterministic and hence no indeterministic instructions are
/// allowed.
///
/// Dispatchables always use this mode in order to make on-chain execution deterministic.
Deterministic,
/// Allow calling or uploading an indeterministic code.
///
/// This is only possible when calling into `pallet-contracts` directly via
/// [`crate::Pallet::bare_call`].
///
/// # Note
///
/// **Never** use this mode for on-chain execution.
AllowIndeterminism,
}

/// A raw call to `pallet-contracts`'s `upload`.
#[derive(Debug, scale::Encode, scale::Decode)]
pub struct UploadCode<B> {
code: Vec<u8>,
storage_deposit_limit: Option<B>,
determinism: Determinism,
}

/// A struct that encodes RPC parameters required to instantiate a new smart contract.
Expand All @@ -105,6 +126,7 @@ where
origin: C::AccountId,
code: Vec<u8>,
storage_deposit_limit: Option<E::Balance>,
determinism: Determinism,
}

/// A struct that encodes RPC parameters required for a call to a smart contract.
Expand Down Expand Up @@ -278,6 +300,7 @@ where
origin: signer.account_id().clone(),
code,
storage_deposit_limit,
determinism: Determinism::Deterministic,
};
let func = "ContractsApi_upload_code";
let params = rpc_params![func, Bytes(scale::Encode::encode(&call_request))];
Expand Down Expand Up @@ -308,6 +331,7 @@ where
UploadCode::<E::Balance> {
code,
storage_deposit_limit,
determinism: Determinism::Deterministic,
},
Default::default(),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0201]: duplicate definitions with name `message_checked`:
error[E0592]: 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
| ---------------- other definition for `message_checked`
...
16 | pub fn message_checked(&self) {}
| ^^^ duplicate definition
| ^^^ duplicate definitions for `message_checked`
4 changes: 2 additions & 2 deletions examples/flipper/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod flipper {

/// Creates a new flipper smart contract initialized to `false`.
#[ink(constructor)]
pub fn default() -> Self {
pub fn new_default() -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the new_default changes necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New clippy lints do not allow methods with default() name as they can be confused with the Default::default() implementation. See the the previous clippy output: https://gitlab.parity.io/parity/mirrors/ink/-/jobs/2171790

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this lint's been around a very long time, why is it only being triggered now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this new_default method, it made sense to have a default method for the contract. Maybe we can work around it using a the Default trait impl instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of this new_default method, it made sense to have a default method for the contract. Maybe we can work around it using a the Default trait impl instead?

Can you open a follow up issue for this please?

Self::new(Default::default())
}

Expand All @@ -39,7 +39,7 @@ pub mod flipper {

#[ink::test]
fn default_works() {
let flipper = Flipper::default();
let flipper = Flipper::new_default();
assert!(!flipper.get());
}

Expand Down
4 changes: 2 additions & 2 deletions examples/incrementer/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod incrementer {
}

#[ink(constructor)]
pub fn default() -> Self {
pub fn new_default() -> Self {
Self::new(Default::default())
}

Expand All @@ -35,7 +35,7 @@ mod incrementer {

#[ink::test]
fn default_works() {
let contract = Incrementer::default();
let contract = Incrementer::new_default();
assert_eq!(contract.get(), 0);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/lang-err-integration-tests/call-builder/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ mod call_builder {
.expect("instantiate failed")
.account_id;

let flipper_constructor = FlipperRef::default();
let flipper_constructor = FlipperRef::new_default();
let flipper_acc_id = client
.instantiate(
"integration_flipper",
Expand Down
2 changes: 1 addition & 1 deletion examples/lang-err-integration-tests/contract-ref/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod contract_ref {
#[ink(constructor)]
pub fn new(version: u32, flipper_code_hash: Hash) -> Self {
let salt = version.to_le_bytes();
let flipper = FlipperRef::default()
let flipper = FlipperRef::new_default()
.endowment(0)
.code_hash(flipper_code_hash)
.salt_bytes(salt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub mod integration_flipper {

/// Creates a new integration_flipper smart contract initialized to `false`.
#[ink(constructor)]
pub fn default() -> Self {
pub fn new_default() -> Self {
Self::new(Default::default())
}

Expand Down Expand Up @@ -58,7 +58,7 @@ pub mod integration_flipper {
async fn e2e_can_flip_correctly(
mut client: ink_e2e::Client<C, E>,
) -> E2EResult<()> {
let constructor = FlipperRef::default();
let constructor = FlipperRef::new_default();
let contract_acc_id = client
.instantiate(
"integration_flipper",
Expand Down Expand Up @@ -110,7 +110,7 @@ pub mod integration_flipper {
async fn e2e_message_error_reverts_state(
mut client: ink_e2e::Client<C, E>,
) -> E2EResult<()> {
let constructor = FlipperRef::default();
let constructor = FlipperRef::new_default();
let contract_acc_id = client
.instantiate("integration_flipper", &ink_e2e::bob(), constructor, 0, None)
.await
Expand Down
4 changes: 2 additions & 2 deletions examples/mother/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ mod mother {
}

#[ink(constructor)]
pub fn default() -> Self {
pub fn new_default() -> Self {
Default::default()
}

Expand Down Expand Up @@ -197,7 +197,7 @@ mod mother {
#[ink::test]
fn echo_auction_works() {
let auction = Auction::default();
let mut contract = Mother::default();
let mut contract = Mother::new_default();
assert_eq!(contract.echo_auction(auction.clone()), auction);
}

Expand Down
6 changes: 3 additions & 3 deletions examples/rand-extension/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ mod rand_extension {
///
/// Constructors may delegate to other constructors.
#[ink(constructor)]
pub fn default() -> Self {
pub fn new_default() -> Self {
Self::new(Default::default())
}

Expand Down Expand Up @@ -114,7 +114,7 @@ mod rand_extension {
/// We test if the default constructor does its job.
#[ink::test]
fn default_works() {
let rand_extension = RandExtension::default();
let rand_extension = RandExtension::new_default();
assert_eq!(rand_extension.get(), [0; 32]);
}

Expand All @@ -141,7 +141,7 @@ mod rand_extension {
}
}
ink::env::test::register_chain_extension(MockedExtension);
let mut rand_extension = RandExtension::default();
let mut rand_extension = RandExtension::new_default();
assert_eq!(rand_extension.get(), [0; 32]);

// when
Expand Down
2 changes: 1 addition & 1 deletion examples/upgradeable-contracts/set-code-hash/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod incrementer {

/// Creates a new counter smart contract initialized to `0`.
#[ink(constructor)]
pub fn default() -> Self {
pub fn new_default() -> Self {
Self::new(0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub mod incrementer {

/// Creates a new counter smart contract initialized to `0`.
#[ink(constructor)]
pub fn default() -> Self {
pub fn new_default() -> Self {
Self::new(0)
}

Expand Down