Skip to content

Commit

Permalink
Moved trait implementation to separate test.
Browse files Browse the repository at this point in the history
  • Loading branch information
xgreenx committed Jul 8, 2021
1 parent 619c480 commit 57f1514
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 35 deletions.
7 changes: 4 additions & 3 deletions crates/lang/macro/tests/compile_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ fn compile_tests() {
t.pass("tests/ui/pass/05-erc721-contract.rs");
t.pass("tests/ui/pass/06-non-ink-items.rs");
t.pass("tests/ui/pass/07-flipper-as-dependency.rs");
t.pass("tests/ui/pass/08-static-env.rs");
t.pass("tests/ui/pass/09-derive-for-storage.rs");
t.pass("tests/ui/pass/10-alias-storage-struct-impl.rs");
t.pass("tests/ui/pass/08-flipper-as-dependency-trait.rs");
t.pass("tests/ui/pass/09-static-env.rs");
t.pass("tests/ui/pass/10-derive-for-storage.rs");
t.pass("tests/ui/pass/11-alias-storage-struct-impl.rs");

t.compile_fail("tests/ui/fail/C-00-constructor-self-ref.rs");
t.compile_fail("tests/ui/fail/C-01-constructor-self-mut.rs");
Expand Down
35 changes: 3 additions & 32 deletions crates/lang/macro/tests/ui/pass/07-flipper-as-dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,14 @@ use ink_lang as ink;

#[ink::contract(compile_as_dependency = true)]
mod flipper {
#[ink_lang::trait_definition]
pub trait FlipperTrait {
#[ink(constructor)]
fn new() -> Self;

#[ink(message)]
fn flip(&mut self);

#[ink(message)]
fn get(&self) -> bool;
}

#[ink(storage)]
pub struct Flipper {
value: bool,
}

impl Flipper {
#[ink(constructor)]
pub fn new2(init_value: bool) -> Self {
pub fn new(init_value: bool) -> Self {
Self { value: init_value }
}

Expand All @@ -31,29 +19,12 @@ mod flipper {
}

#[ink(message)]
pub fn flip2(&mut self) {
self.value = !self.value;
}

#[ink(message)]
pub fn get2(&self) -> bool {
self.value
}
}

impl FlipperTrait for Flipper {
#[ink(constructor)]
fn new() -> Self {
Self::default()
}

#[ink(message)]
fn flip(&mut self) {
pub fn flip(&mut self) {
self.value = !self.value;
}

#[ink(message)]
fn get(&self) -> bool {
pub fn get(&self) -> bool {
self.value
}
}
Expand Down
40 changes: 40 additions & 0 deletions crates/lang/macro/tests/ui/pass/08-flipper-as-dependency-trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use ink_lang as ink;

#[ink::contract(compile_as_dependency = true)]
mod flipper {
#[ink_lang::trait_definition]
pub trait FlipperTrait {
#[ink(constructor)]
fn new() -> Self;

#[ink(message)]
fn flip(&mut self);

#[ink(message)]
fn get(&self) -> bool;
}

#[ink(storage)]
pub struct Flipper {
value: bool,
}

impl FlipperTrait for Flipper {
#[ink(constructor)]
fn new() -> Self {
Self::default()
}

#[ink(message)]
fn flip(&mut self) {
self.value = !self.value;
}

#[ink(message)]
fn get(&self) -> bool {
self.value
}
}
}

fn main() {}

0 comments on commit 57f1514

Please sign in to comment.