1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617// Original License18// Copyright 2018-2020 Parity Technologies (UK) Ltd.19//20// Licensed under the Apache License, Version 2.0 (the "License");21// you may not use this file except in compliance with the License.22// You may obtain a copy of the License at23//24// http://www.apache.org/licenses/LICENSE-2.025//26// Unless required by applicable law or agreed to in writing, software27// distributed under the License is distributed on an "AS IS" BASIS,28// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.29// See the License for the specific language governing permissions and30// limitations under the License.3132#![cfg_attr(not(feature = "std"), no_std)]3334use ink_lang as ink;3536#[ink::contract]37pub mod flipper {38 #[ink(storage)]39 pub struct Flipper {40 value: bool,41 }4243 impl Flipper {44 /// Creates a new flipper smart contract initialized with the given value.45 #[ink(constructor)]46 pub fn new(init_value: bool) -> Self {47 Self { value: init_value }48 }4950 /// Creates a new flipper smart contract initialized to `false`.51 #[ink(constructor)]52 pub fn default() -> Self {53 Self::new(Default::default())54 }5556 /// Flips the current value of the Flipper's bool.57 #[ink(message)]58 pub fn flip(&mut self) {59 self.value = !self.value;60 }6162 /// Returns the current value of the Flipper's bool.63 #[ink(message)]64 pub fn get(&self) -> bool {65 self.value66 }67 }6869 #[cfg(test)]70 mod tests {71 use super::*;7273 #[test]74 fn default_works() {75 let flipper = Flipper::default();76 assert_eq!(flipper.get(), false);77 }7879 #[test]80 fn it_works() {81 let mut flipper = Flipper::new(false);82 assert_eq!(flipper.get(), false);83 flipper.flip();84 assert_eq!(flipper.get(), true);85 }86 }87}difftreelog
source
tests/flipper-src/lib.rs2.7 KiBsourcehistory