git.delta.rocks / unique-network / refs/commits / be0c28ab6ce3

difftreelog

source

tests/flipper-src/lib.rs1.9 KiBsourcehistory
1// Copyright 2018-2020 Parity Technologies (UK) Ltd.2//3// Licensed under the Apache License, Version 2.0 (the "License");4// you may not use this file except in compliance with the License.5// You may obtain a copy of the License at6//7//     http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// distributed under the License is distributed on an "AS IS" BASIS,11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12// See the License for the specific language governing permissions and13// limitations under the License.1415#![cfg_attr(not(feature = "std"), no_std)]1617use ink_lang as ink;1819#[ink::contract]20pub mod flipper {21    #[ink(storage)]22    pub struct Flipper {23        value: bool,24    }2526    impl Flipper {27        /// Creates a new flipper smart contract initialized with the given value.28        #[ink(constructor)]29        pub fn new(init_value: bool) -> Self {30            Self { value: init_value }31        }3233        /// Creates a new flipper smart contract initialized to `false`.34        #[ink(constructor)]35        pub fn default() -> Self {36            Self::new(Default::default())37        }3839        /// Flips the current value of the Flipper's bool.40        #[ink(message)]41        pub fn flip(&mut self) {42            self.value = !self.value;43        }4445        /// Returns the current value of the Flipper's bool.46        #[ink(message)]47        pub fn get(&self) -> bool {48            self.value49        }50    }5152    #[cfg(test)]53    mod tests {54        use super::*;5556        #[test]57        fn default_works() {58            let flipper = Flipper::default();59            assert_eq!(flipper.get(), false);60        }6162        #[test]63        fn it_works() {64            let mut flipper = Flipper::new(false);65            assert_eq!(flipper.get(), false);66            flipper.flip();67            assert_eq!(flipper.get(), true);68        }69    }70}