paritytech / ink

Compare d9c17b6 ... +2 ... e646ddd

Coverage Reach
lang/ir/src/ir/item_impl/mod.rs lang/ir/src/ir/item_impl/callable.rs lang/ir/src/ir/item_impl/message.rs lang/ir/src/ir/item_impl/constructor.rs lang/ir/src/ir/item_impl/impl_item.rs lang/ir/src/ir/item_impl/iter.rs lang/ir/src/ir/item_impl/tests.rs lang/ir/src/ir/attrs.rs lang/ir/src/ir/trait_def/item/mod.rs lang/ir/src/ir/trait_def/item/trait_item.rs lang/ir/src/ir/trait_def/item/iter.rs lang/ir/src/ir/trait_def/config.rs lang/ir/src/ir/trait_def/mod.rs lang/ir/src/ir/trait_def/tests.rs lang/ir/src/ir/item/mod.rs lang/ir/src/ir/item/event.rs lang/ir/src/ir/item/storage.rs lang/ir/src/ir/item_mod.rs lang/ir/src/ir/chain_extension.rs lang/ir/src/ir/selector.rs lang/ir/src/ir/config.rs lang/ir/src/ir/blake2.rs lang/ir/src/ir/idents_lint.rs lang/ir/src/ir/utils.rs lang/ir/src/ir/contract.rs lang/ir/src/ir/ink_test.rs lang/ir/src/ast/attr_args.rs lang/ir/src/literal.rs lang/ir/src/error.rs lang/codegen/src/generator/trait_def/trait_registry.rs lang/codegen/src/generator/trait_def/call_forwarder.rs lang/codegen/src/generator/trait_def/call_builder.rs lang/codegen/src/generator/trait_def/definition.rs lang/codegen/src/generator/trait_def/mod.rs lang/codegen/src/generator/dispatch.rs lang/codegen/src/generator/as_dependency/contract_ref.rs lang/codegen/src/generator/as_dependency/call_builder.rs lang/codegen/src/generator/as_dependency/mod.rs lang/codegen/src/generator/metadata.rs lang/codegen/src/generator/item_impls.rs lang/codegen/src/generator/events.rs lang/codegen/src/generator/chain_extension.rs lang/codegen/src/generator/arg_list.rs lang/codegen/src/generator/storage.rs lang/codegen/src/generator/ink_test.rs lang/codegen/src/generator/contract.rs lang/codegen/src/generator/selector.rs lang/codegen/src/generator/blake2b.rs lang/codegen/src/generator/env.rs lang/codegen/src/generator/mod.rs lang/codegen/src/enforced_error.rs lang/codegen/src/traits.rs lang/codegen/src/lib.rs lang/tests/ui/contract/pass/example-erc721-works.rs lang/tests/ui/contract/pass/example-erc20-works.rs lang/tests/ui/contract/pass/dispatch-decoder-works.rs lang/tests/ui/contract/pass/event-topics.rs lang/tests/ui/contract/pass/event-anonymous.rs lang/tests/ui/contract/pass/event-many-definitions.rs lang/tests/ui/contract/pass/example-trait-incrementer-works.rs lang/tests/ui/contract/pass/event-config-more-topics.rs lang/tests/ui/contract/pass/message-many-outputs.rs lang/tests/ui/contract/pass/message-many-inputs.rs lang/tests/ui/contract/pass/env-access.rs lang/tests/ui/contract/pass/example-trait-flipper-works.rs lang/tests/ui/contract/pass/constructor-many-inputs.rs lang/tests/ui/contract/pass/example-incrementer-works.rs lang/tests/ui/contract/pass/example-flipper-works.rs lang/tests/ui/contract/pass/message-selector.rs lang/tests/ui/contract/pass/constructor-selector.rs lang/tests/ui/contract/pass/impl-block-using-env.rs lang/tests/ui/contract/pass/module-non-ink-items.rs lang/tests/ui/contract/pass/trait-message-payable-guard.rs lang/tests/ui/contract/pass/trait-message-selector-guard.rs lang/tests/ui/contract/pass/message-payable.rs lang/tests/ui/contract/pass/constructor-payable-multiple.rs lang/tests/ui/contract/pass/constructor-non-payable-multiple.rs lang/tests/ui/contract/pass/message-wildcard-selector.rs lang/tests/ui/contract/pass/storage-packed-fields.rs lang/tests/ui/contract/pass/constructor-payable.rs lang/tests/ui/contract/pass/event-single-definition.rs lang/tests/ui/contract/pass/storage-with-derives.rs lang/tests/ui/contract/pass/storage-many-fields.rs lang/tests/ui/contract/pass/module-env-types.rs lang/tests/ui/contract/pass/storage-single-field.rs lang/tests/ui/contract/pass/constructor-non-payable.rs lang/tests/ui/contract/pass/constructor-wildcard-selector.rs lang/tests/ui/contract/pass/no-implicit-prelude.rs lang/tests/ui/contract/pass/config-dynamic-storage-allocator-false.rs lang/tests/ui/contract/pass/impl-with-property.rs lang/tests/ui/contract/pass/config-compile-as-dependency-false.rs lang/tests/ui/contract/pass/impl-alias-storage.rs lang/tests/ui/contract/pass/config-dynamic-storage-allocator-true.rs lang/tests/ui/contract/pass/minimal-contract.rs lang/tests/ui/contract/pass/impl-block-namespace.rs lang/tests/ui/contract/pass/config-custom-env.rs lang/tests/ui/contract/pass/config-compile-as-dependency-true.rs lang/tests/ui/chain_extension/E-01-simple.rs lang/tests/ui/trait_def/pass/payable_message.rs lang/tests/ui/trait_def/pass/valid_selectors_namespace.rs lang/tests/ui/trait_def/pass/valid_selectors.rs lang/tests/ui/trait_def/pass/avoid_overlap_with_namespace.rs lang/tests/ui/trait_def/pass/many_outputs.rs lang/tests/ui/trait_def/pass/using-env-types.rs lang/tests/ui/trait_def/pass/simple_definition.rs lang/tests/ui/trait_def/pass/many_inputs.rs lang/tests/ui/trait_def/pass/with_namespace.rs lang/tests/ui/trait_def/pass/no-implicit-prelude.rs lang/tests/ui/selector_id/pass/string_input.rs lang/tests/ui/selector_id/pass/bytestring_input.rs lang/tests/ui/selector_id/pass/no_implicit_prelude.rs lang/tests/ui/blake2b/pass/bytestring_input.rs lang/tests/ui/blake2b/pass/string_input.rs lang/tests/ui/blake2b/pass/no_implicit_prelude.rs lang/tests/ui/selector_bytes/pass/bytestring_input.rs lang/tests/ui/selector_bytes/pass/string_input.rs lang/tests/ui/selector_bytes/pass/no_implicit_prelude.rs lang/tests/unique_topics.rs lang/src/codegen/dispatch/execution.rs lang/src/env_access.rs lang/src/reflect/dispatch.rs lang/src/result_info.rs lang/macro/src/lib.rs lang/macro/src/selector.rs lang/macro/src/blake2b.rs lang/macro/src/contract.rs lang/macro/src/chain_extension.rs lang/macro/src/trait_def.rs lang/macro/src/ink_test.rs storage/src/collections/bitvec/iter.rs storage/src/collections/bitvec/bits256.rs storage/src/collections/bitvec/mod.rs storage/src/collections/bitvec/storage.rs storage/src/collections/bitvec/bitsref.rs storage/src/collections/bitvec/impls.rs storage/src/collections/bitvec/bitref.rs storage/src/collections/bitvec/tests.rs storage/src/collections/stash/mod.rs storage/src/collections/stash/iter.rs storage/src/collections/stash/tests.rs storage/src/collections/stash/storage.rs storage/src/collections/stash/impls.rs storage/src/collections/hashmap/mod.rs storage/src/collections/hashmap/fuzz_tests.rs storage/src/collections/hashmap/iter.rs storage/src/collections/hashmap/storage.rs storage/src/collections/hashmap/impls.rs storage/src/collections/hashmap/tests.rs storage/src/collections/vec/mod.rs storage/src/collections/vec/fuzz_tests.rs storage/src/collections/vec/iter.rs storage/src/collections/vec/impls.rs storage/src/collections/vec/storage.rs storage/src/collections/vec/tests.rs storage/src/collections/binary_heap/children_vec.rs storage/src/collections/binary_heap/tests.rs storage/src/collections/binary_heap/mod.rs storage/src/collections/binary_heap/children.rs storage/src/collections/binary_heap/reverse.rs storage/src/collections/binary_heap/storage.rs storage/src/collections/binary_heap/impls.rs storage/src/collections/smallvec/mod.rs storage/src/collections/smallvec/iter.rs storage/src/collections/smallvec/impls.rs storage/src/collections/smallvec/storage.rs storage/src/collections/smallvec/tests.rs storage/src/collections/bitstash/mod.rs storage/src/collections/bitstash/storage.rs storage/src/collections/bitstash/counts.rs storage/src/collections/bitstash/fuzz_tests.rs storage/src/collections/bitstash/tests.rs storage/src/collections/mod.rs storage/src/lazy/lazy_hmap.rs storage/src/lazy/lazy_array.rs storage/src/lazy/lazy_imap.rs storage/src/lazy/lazy_cell.rs storage/src/lazy/entry.rs storage/src/lazy/mapping.rs storage/src/lazy/mod.rs storage/src/lazy/cache_cell.rs storage/src/traits/impls/prims.rs storage/src/traits/impls/fuzz_tests.rs storage/src/traits/impls/tuples.rs storage/src/traits/impls/mod.rs storage/src/traits/impls/arrays.rs storage/src/traits/optspec.rs storage/src/traits/mod.rs storage/src/traits/layout/impls.rs storage/src/traits/layout/mod.rs storage/src/traits/keyptr.rs storage/src/hashmap_entry_api_tests.rs storage/src/alloc/boxed/storage.rs storage/src/alloc/boxed/impls.rs storage/src/alloc/boxed/mod.rs storage/src/alloc/boxed/tests.rs storage/src/alloc/init.rs storage/src/alloc/allocation.rs storage/src/alloc/allocator.rs storage/src/alloc/tests.rs storage/src/alloc/mod.rs storage/src/test_utils.rs storage/src/pack.rs storage/src/memory.rs storage/derive/src/spread_layout.rs storage/derive/src/storage_layout.rs storage/derive/src/spread_allocate.rs storage/derive/src/packed_layout.rs env/src/engine/off_chain/db/accounts.rs env/src/engine/off_chain/db/exec_context.rs env/src/engine/off_chain/db/chain_spec.rs env/src/engine/off_chain/db/events.rs env/src/engine/off_chain/db/debug_buf.rs env/src/engine/off_chain/db/block.rs env/src/engine/off_chain/impls.rs env/src/engine/off_chain/mod.rs env/src/engine/off_chain/test_api.rs env/src/engine/off_chain/typed_encoded.rs env/src/engine/off_chain/chain_extension.rs env/src/engine/off_chain/hashing.rs env/src/engine/off_chain/call_data.rs env/src/engine/off_chain/tests.rs env/src/engine/experimental_off_chain/impls.rs env/src/engine/experimental_off_chain/test_api.rs env/src/engine/experimental_off_chain/types.rs env/src/engine/experimental_off_chain/mod.rs env/src/call/call_builder.rs env/src/call/execution_input.rs env/src/call/create_builder.rs env/src/call/common.rs env/src/call/selector.rs env/src/api.rs env/src/chain_extension.rs env/src/types.rs env/src/backend.rs env/src/topics.rs env/src/arithmetic.rs metadata/src/specs.rs metadata/src/layout/mod.rs metadata/src/layout/tests.rs metadata/src/lib.rs metadata/src/utils.rs engine/src/ext.rs engine/src/test_api.rs engine/src/database.rs engine/src/hashing.rs engine/src/exec_context.rs engine/src/types.rs engine/src/tests.rs primitives/src/key.rs primitives/src/key_ptr.rs allocator/src/bump.rs eth_compatibility/src/lib.rs

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -73,6 +73,8 @@
Loading
73 73
/// Configuration for execution of ink! constructor.
74 74
#[derive(Debug, Copy, Clone)]
75 75
pub struct ExecuteConstructorConfig {
76 +
    /// Yields `true` if the ink! constructor accepts payment.
77 +
    pub payable: bool,
76 78
    /// Yields `true` if the dynamic storage allocator has been enabled.
77 79
    ///
78 80
    /// # Note
@@ -93,11 +95,14 @@
Loading
93 95
    f: F,
94 96
) -> Result<(), DispatchError>
95 97
where
96 -
    Contract: SpreadLayout + ContractRootKey,
98 +
    Contract: SpreadLayout + ContractRootKey + ContractEnv,
97 99
    F: FnOnce() -> R,
98 100
    <private::Seal<R> as ConstructorReturnType<Contract>>::ReturnValue: scale::Encode,
99 101
    private::Seal<R>: ConstructorReturnType<Contract>,
100 102
{
103 +
    if !config.payable {
104 +
        deny_payment::<<Contract as ContractEnv>::Env>()?;
105 +
    }
101 106
    if config.dynamic_storage_alloc {
102 107
        alloc::initialize(ContractPhase::Deploy);
103 108
    }
@@ -280,12 +285,6 @@
Loading
280 285
#[derive(Debug, Copy, Clone)]
281 286
pub struct ExecuteMessageConfig {
282 287
    /// Yields `true` if the ink! message accepts payment.
283 -
    ///
284 -
    /// # Note
285 -
    ///
286 -
    /// If no ink! message within the same ink! smart contract
287 -
    /// is payable then this flag will be `true` since the check
288 -
    /// then is moved before the message dispatch as an optimization.
289 288
    pub payable: bool,
290 289
    /// Yields `true` if the ink! message might mutate contract storage.
291 290
    ///

@@ -67,6 +67,8 @@
Loading
67 67
pub struct Constructor {
68 68
    /// The underlying Rust method item.
69 69
    pub(super) item: syn::ImplItemMethod,
70 +
    /// If the ink! constructor can receive funds.
71 +
    is_payable: bool,
70 72
    /// An optional user provided selector.
71 73
    ///
72 74
    /// # Note
@@ -158,15 +160,9 @@
Loading
158 160
            &ir::AttributeArgKind::Constructor,
159 161
            |arg| {
160 162
                match arg.kind() {
161 -
                    ir::AttributeArg::Constructor | ir::AttributeArg::Selector(_) => {
162 -
                        Ok(())
163 -
                    }
164 -
                    ir::AttributeArg::Payable => {
165 -
                        Err(Some(format_err!(
166 -
                            arg.span(),
167 -
                            "constructors are implicitly payable"
168 -
                        )))
169 -
                    }
163 +
                    ir::AttributeArg::Constructor
164 +
                    | ir::AttributeArg::Payable
165 +
                    | ir::AttributeArg::Selector(_) => Ok(()),
170 166
                    _ => Err(None),
171 167
                }
172 168
            },
@@ -182,9 +178,11 @@
Loading
182 178
        Self::ensure_valid_return_type(&method_item)?;
183 179
        Self::ensure_no_self_receiver(&method_item)?;
184 180
        let (ink_attrs, other_attrs) = Self::sanitize_attributes(&method_item)?;
181 +
        let is_payable = ink_attrs.is_payable();
185 182
        let selector = ink_attrs.selector();
186 183
        Ok(Constructor {
187 184
            selector,
185 +
            is_payable,
188 186
            item: syn::ImplItemMethod {
189 187
                attrs: other_attrs,
190 188
                ..method_item
@@ -217,7 +215,7 @@
Loading
217 215
    }
218 216
219 217
    fn is_payable(&self) -> bool {
220 -
        true
218 +
        self.is_payable
221 219
    }
222 220
223 221
    fn visibility(&self) -> Visibility {
@@ -302,6 +300,52 @@
Loading
302 300
        }
303 301
    }
304 302
303 +
    #[test]
304 +
    fn is_payable_works() {
305 +
        let test_inputs: Vec<(bool, syn::ImplItemMethod)> = vec![
306 +
            // Not payable.
307 +
            (
308 +
                false,
309 +
                syn::parse_quote! {
310 +
                    #[ink(constructor)]
311 +
                    fn my_constructor() -> Self {}
312 +
                },
313 +
            ),
314 +
            // Normalized ink! attribute.
315 +
            (
316 +
                true,
317 +
                syn::parse_quote! {
318 +
                    #[ink(constructor, payable)]
319 +
                    pub fn my_constructor() -> Self {}
320 +
                },
321 +
            ),
322 +
            // Different ink! attributes.
323 +
            (
324 +
                true,
325 +
                syn::parse_quote! {
326 +
                    #[ink(constructor)]
327 +
                    #[ink(payable)]
328 +
                    pub fn my_constructor() -> Self {}
329 +
                },
330 +
            ),
331 +
            // Another ink! attribute, separate and normalized attribute.
332 +
            (
333 +
                true,
334 +
                syn::parse_quote! {
335 +
                    #[ink(constructor)]
336 +
                    #[ink(selector = 0xDEADBEEF, payable)]
337 +
                    pub fn my_constructor() -> Self {}
338 +
                },
339 +
            ),
340 +
        ];
341 +
        for (expect_payable, item_method) in test_inputs {
342 +
            let is_payable = <ir::Constructor as TryFrom<_>>::try_from(item_method)
343 +
                .unwrap()
344 +
                .is_payable();
345 +
            assert_eq!(is_payable, expect_payable);
346 +
        }
347 +
    }
348 +
305 349
    #[test]
306 350
    fn visibility_works() {
307 351
        let test_inputs: Vec<(bool, syn::ImplItemMethod)> = vec![
@@ -577,12 +621,6 @@
Loading
577 621
                #[ink(event)]
578 622
                fn my_constructor() -> Self {}
579 623
            },
580 -
            // constructor + payable
581 -
            syn::parse_quote! {
582 -
                #[ink(constructor)]
583 -
                #[ink(payable)]
584 -
                fn my_constructor() -> Self {}
585 -
            },
586 624
        ];
587 625
        for item_method in item_methods {
588 626
            assert_try_from_fails(

@@ -386,7 +386,7 @@
Loading
386 386
        output: &mut [u8; 33],
387 387
    ) -> Result {
388 388
        use secp256k1::{
389 -
            recovery::{
389 +
            ecdsa::{
390 390
                RecoverableSignature,
391 391
                RecoveryId,
392 392
            },
@@ -415,7 +415,7 @@
Loading
415 415
                });
416 416
417 417
        let secp = Secp256k1::new();
418 -
        let pub_key = secp.recover(&message, &signature);
418 +
        let pub_key = secp.recover_ecdsa(&message, &signature);
419 419
        match pub_key {
420 420
            Ok(pub_key) => {
421 421
                *output = pub_key.serialize();

@@ -0,0 +1,23 @@
Loading
1 +
use ink_lang as ink;
2 +
3 +
#[ink::contract]
4 +
mod contract {
5 +
    #[ink(storage)]
6 +
    pub struct Contract {}
7 +
8 +
    impl Contract {
9 +
        #[ink(constructor, selector = 0)]
10 +
        pub fn constructor() -> Self {
11 +
            Self {}
12 +
        }
13 +
14 +
        #[ink(message)]
15 +
        pub fn message(&self) {}
16 +
    }
17 +
}
18 +
19 +
use contract::Contract;
20 +
21 +
fn main() {
22 +
    assert!(!<Contract as ::ink_lang::reflect::DispatchableConstructorInfo<0>>::PAYABLE);
23 +
}

@@ -252,7 +252,7 @@
Loading
252 252
        output: &mut [u8; 33],
253 253
    ) -> Result<()> {
254 254
        use secp256k1::{
255 -
            recovery::{
255 +
            ecdsa::{
256 256
                RecoverableSignature,
257 257
                RecoveryId,
258 258
            },
@@ -279,7 +279,7 @@
Loading
279 279
                });
280 280
281 281
        let secp = Secp256k1::new();
282 -
        let pub_key = secp.recover(&message, &signature);
282 +
        let pub_key = secp.recover_ecdsa(&message, &signature);
283 283
        match pub_key {
284 284
            Ok(pub_key) => {
285 285
                *output = pub_key.serialize();

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 5 files with coverage changes found.

Changes in crates/lang/ir/src/ir/attrs.rs
-2
+2
Loading file...
New file crates/lang/tests/ui/contract/pass/constructor-non-payable-multiple.rs
New
Loading file...
New file crates/lang/tests/ui/contract/pass/constructor-non-payable.rs
New
Loading file...
New file crates/lang/tests/ui/contract/pass/constructor-payable.rs
New
Loading file...
New file crates/lang/tests/ui/contract/pass/constructor-payable-multiple.rs
New
Loading file...
Files Coverage
ir -0.06% 85.69%
ast/attr_args.rs 82.61%
error.rs 100.00%
literal.rs 100.00%
Folder Totals (4 files) 85.73%
Project Totals (252 files) 78.83%
Loading