Skip to content

Commit f967986

Browse files
committed
UI tests for a new codegen.
Can't highlight something unusual here=)
1 parent d6db8de commit f967986

27 files changed

+825
-32
lines changed

crates/lang/tests/compile_tests.rs

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ fn ui_tests() {
2828
t.pass("tests/ui/contract/pass/*.rs");
2929
t.compile_fail("tests/ui/contract/fail/*.rs");
3030

31+
t.pass("tests/ui/storage_item/pass/*.rs");
32+
t.compile_fail("tests/ui/storage_item/fail/*.rs");
33+
3134
t.pass("tests/ui/trait_def/pass/*.rs");
3235
t.compile_fail("tests/ui/trait_def/fail/*.rs");
3336

crates/lang/tests/ui/contract/fail/message-returns-non-codec.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ error[E0599]: the method `fire` exists for struct `ink_env::call::CallBuilder<De
6060
= note: the following trait bounds were not satisfied:
6161
`NonCodecType: parity_scale_codec::Decode`
6262
note: the following trait must be implemented
63-
--> $CARGO/parity-scale-codec-3.1.5/src/codec.rs
63+
--> $CARGO/parity-scale-codec-3.1.2/src/codec.rs
6464
|
6565
| pub trait Decode: Sized {
6666
| ^^^^^^^^^^^^^^^^^^^^^^^

crates/lang/tests/ui/contract/pass/example-erc20-works.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ use ink_lang as ink;
22

33
#[ink::contract]
44
mod erc20 {
5-
use ink_storage::{
6-
traits::SpreadAllocate,
7-
Mapping,
8-
};
5+
use ink_storage::Mapping;
96

107
/// A simple ERC-20 contract.
118
#[ink(storage)]
12-
#[derive(SpreadAllocate)]
9+
#[derive(Default)]
1310
pub struct Erc20 {
1411
/// Total token supply.
1512
total_supply: Balance,
@@ -58,9 +55,9 @@ mod erc20 {
5855
/// Creates a new ERC-20 contract with the specified initial supply.
5956
#[ink(constructor)]
6057
pub fn new(initial_supply: Balance) -> Self {
61-
ink_lang::utils::initialize_contract(|contract| {
62-
Self::new_init(contract, initial_supply)
63-
})
58+
let mut instance = Self::default();
59+
instance.new_init(initial_supply);
60+
instance
6461
}
6562

6663
/// Default initializes the ERC-20 contract with the specified initial supply.

crates/lang/tests/ui/contract/pass/example-erc721-works.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use ink_lang as ink;
22

33
#[ink::contract]
44
mod erc721 {
5-
use ink_storage::{
6-
traits::SpreadAllocate,
7-
Mapping,
8-
};
5+
use ink_storage::Mapping;
96

107
use scale::{
118
Decode,
@@ -16,7 +13,7 @@ mod erc721 {
1613
pub type TokenId = u32;
1714

1815
#[ink(storage)]
19-
#[derive(Default, SpreadAllocate)]
16+
#[derive(Default)]
2017
pub struct Erc721 {
2118
/// Mapping from token to owner.
2219
token_owner: Mapping<TokenId, AccountId>,
@@ -77,9 +74,7 @@ mod erc721 {
7774
/// Creates a new ERC-721 token contract.
7875
#[ink(constructor)]
7976
pub fn new() -> Self {
80-
// This call is required in order to correctly initialize the
81-
// `Mapping`s of our contract.
82-
ink_lang::utils::initialize_contract(|_| {})
77+
Self::default()
8378
}
8479

8580
/// Returns the balance of the owner.

crates/lang/tests/ui/contract/pass/storage-packed-fields.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,15 @@ use ink_lang as ink;
22

33
#[ink::contract]
44
mod contract {
5-
use ink_storage::traits::{
6-
PackedLayout,
7-
SpreadLayout,
8-
StorageLayout,
9-
};
5+
use ink_storage::traits::StorageLayout;
106

117
#[ink(storage)]
128
pub struct Contract {
139
packed: PackedFields,
1410
}
1511

16-
#[derive(
17-
Debug,
18-
Default,
19-
SpreadLayout,
20-
PackedLayout,
21-
StorageLayout,
22-
scale::Encode,
23-
scale::Decode,
24-
)]
12+
#[derive(Debug, Default, scale::Decode, scale::Encode)]
13+
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo, StorageLayout))]
2514
pub struct PackedFields {
2615
field_1: i8,
2716
field_2: i16,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[ink_lang::storage_item(derive = "false")]
2+
#[derive(Default)]
3+
struct Contract<KEY: KeyHolder = ManualKey<123>> {
4+
a: u16,
5+
b: u64,
6+
c: u128,
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: expected a bool literal for `derive` ink! storage item configuration argument
2+
--> tests/ui/storage_item/fail/argument_derive_invalid_type.rs:1:26
3+
|
4+
1 | #[ink_lang::storage_item(derive = "false")]
5+
| ^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#[ink_lang::storage_item(derive)]
2+
#[derive(Default)]
3+
struct Contract<KEY: KeyHolder = ManualKey<123>> {
4+
a: u16,
5+
b: u64,
6+
c: u128,
7+
}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: ink! config options require an argument separated by '='
2+
--> tests/ui/storage_item/fail/argument_derive_missing_arg.rs:1:26
3+
|
4+
1 | #[ink_lang::storage_item(derive)]
5+
| ^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use ink_prelude::vec::Vec;
2+
use ink_storage::Lazy;
3+
4+
#[ink_lang::storage_item]
5+
struct NonPacked {
6+
a: Lazy<u128>,
7+
}
8+
9+
#[ink_lang::storage_item]
10+
struct Contract {
11+
a: Vec<NonPacked>,
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
error[E0277]: the trait bound `Vec<NonPacked>: Decode` is not satisfied
2+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:11:8
3+
|
4+
11 | a: Vec<NonPacked>,
5+
| ^^^^^^^^^^^^^^ the trait `Decode` is not implemented for `Vec<NonPacked>`
6+
|
7+
= help: the trait `Decode` is implemented for `Vec<T>`
8+
= note: required because of the requirements on the impl of `Packed` for `Vec<NonPacked>`
9+
= note: required because of the requirements on the impl of `Item<()>` for `Vec<NonPacked>`
10+
= note: required because of the requirements on the impl of `AutoItem<ManualKey<2085512762_u32>>` for `Vec<NonPacked>`
11+
12+
error[E0277]: the trait bound `[NonPacked]: Encode` is not satisfied
13+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:11:8
14+
|
15+
11 | a: Vec<NonPacked>,
16+
| ^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `[NonPacked]`
17+
|
18+
= help: the following other types implement trait `Encode`:
19+
[T; N]
20+
[T]
21+
= note: required because of the requirements on the impl of `Encode` for `Vec<NonPacked>`
22+
= note: required because of the requirements on the impl of `Packed` for `Vec<NonPacked>`
23+
= note: required because of the requirements on the impl of `Item<()>` for `Vec<NonPacked>`
24+
= note: required because of the requirements on the impl of `AutoItem<ManualKey<2085512762_u32>>` for `Vec<NonPacked>`
25+
26+
error[E0277]: the trait bound `Vec<NonPacked>: Decode` is not satisfied
27+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:9:1
28+
|
29+
9 | #[ink_lang::storage_item]
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Decode` is not implemented for `Vec<NonPacked>`
31+
|
32+
= help: the trait `Decode` is implemented for `Vec<T>`
33+
= note: required because of the requirements on the impl of `Packed` for `Vec<NonPacked>`
34+
= note: required because of the requirements on the impl of `Item<()>` for `Vec<NonPacked>`
35+
= note: required because of the requirements on the impl of `AutoItem<ManualKey<2085512762_u32>>` for `Vec<NonPacked>`
36+
note: required because it appears within the type `Contract`
37+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:10:8
38+
|
39+
10 | struct Contract {
40+
| ^^^^^^^^
41+
note: required by a bound in `Storable`
42+
--> $WORKSPACE/crates/storage/src/traits/storage.rs
43+
|
44+
| pub trait Storable: Sized {
45+
| ^^^^^ required by this bound in `Storable`
46+
= note: this error originates in the derive macro `::ink_storage::traits::Storable` (in Nightly builds, run with -Z macro-backtrace for more info)
47+
48+
error[E0277]: the trait bound `[NonPacked]: Encode` is not satisfied
49+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:9:1
50+
|
51+
9 | #[ink_lang::storage_item]
52+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `[NonPacked]`
53+
|
54+
= help: the following other types implement trait `Encode`:
55+
[T; N]
56+
[T]
57+
= note: required because of the requirements on the impl of `Encode` for `Vec<NonPacked>`
58+
= note: required because of the requirements on the impl of `Packed` for `Vec<NonPacked>`
59+
= note: required because of the requirements on the impl of `Item<()>` for `Vec<NonPacked>`
60+
= note: required because of the requirements on the impl of `AutoItem<ManualKey<2085512762_u32>>` for `Vec<NonPacked>`
61+
note: required because it appears within the type `Contract`
62+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:10:8
63+
|
64+
10 | struct Contract {
65+
| ^^^^^^^^
66+
note: required by a bound in `Storable`
67+
--> $WORKSPACE/crates/storage/src/traits/storage.rs
68+
|
69+
| pub trait Storable: Sized {
70+
| ^^^^^ required by this bound in `Storable`
71+
= note: this error originates in the derive macro `::ink_storage::traits::Storable` (in Nightly builds, run with -Z macro-backtrace for more info)
72+
73+
error[E0277]: the trait bound `Vec<NonPacked>: Decode` is not satisfied
74+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:9:1
75+
|
76+
9 | #[ink_lang::storage_item]
77+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Decode` is not implemented for `Vec<NonPacked>`
78+
|
79+
= help: the trait `Decode` is implemented for `Vec<T>`
80+
= note: required because of the requirements on the impl of `Packed` for `Vec<NonPacked>`
81+
= note: required because of the requirements on the impl of `Item<()>` for `Vec<NonPacked>`
82+
= note: required because of the requirements on the impl of `AutoItem<ManualKey<2085512762_u32>>` for `Vec<NonPacked>`
83+
note: required because it appears within the type `Contract`
84+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:10:8
85+
|
86+
10 | struct Contract {
87+
| ^^^^^^^^
88+
note: required by a bound in `Result`
89+
--> $RUST/core/src/result.rs
90+
|
91+
| pub enum Result<T, E> {
92+
| ^ required by this bound in `Result`
93+
= note: this error originates in the derive macro `::ink_storage::traits::Storable` (in Nightly builds, run with -Z macro-backtrace for more info)
94+
95+
error[E0277]: the trait bound `[NonPacked]: Encode` is not satisfied
96+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:9:1
97+
|
98+
9 | #[ink_lang::storage_item]
99+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Encode` is not implemented for `[NonPacked]`
100+
|
101+
= help: the following other types implement trait `Encode`:
102+
[T; N]
103+
[T]
104+
= note: required because of the requirements on the impl of `Encode` for `Vec<NonPacked>`
105+
= note: required because of the requirements on the impl of `Packed` for `Vec<NonPacked>`
106+
= note: required because of the requirements on the impl of `Item<()>` for `Vec<NonPacked>`
107+
= note: required because of the requirements on the impl of `AutoItem<ManualKey<2085512762_u32>>` for `Vec<NonPacked>`
108+
note: required because it appears within the type `Contract`
109+
--> tests/ui/storage_item/fail/collections_only_packed_1.rs:10:8
110+
|
111+
10 | struct Contract {
112+
| ^^^^^^^^
113+
note: required by a bound in `Result`
114+
--> $RUST/core/src/result.rs
115+
|
116+
| pub enum Result<T, E> {
117+
| ^ required by this bound in `Result`
118+
= note: this error originates in the derive macro `::ink_storage::traits::Storable` (in Nightly builds, run with -Z macro-backtrace for more info)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use ink_prelude::collections::BTreeMap;
2+
use ink_storage::Lazy;
3+
4+
#[ink_lang::storage_item]
5+
struct NonPacked {
6+
a: Lazy<u128>,
7+
}
8+
9+
#[ink_lang::storage_item]
10+
struct Contract {
11+
a: BTreeMap<u128, NonPacked>,
12+
}
13+
14+
fn main() {}

0 commit comments

Comments
 (0)