diff --git a/contracts/01-tamagotchi/src/lib.rs b/contracts/01-tamagotchi/src/lib.rs index cde6c75b..8df96e29 100644 --- a/contracts/01-tamagotchi/src/lib.rs +++ b/contracts/01-tamagotchi/src/lib.rs @@ -1,9 +1,9 @@ #![no_std] #[allow(unused_imports)] -use gstd::{msg,exec,prelude::*}; +use gstd::{exec, msg, prelude::*}; use tamagotchi_io::*; -static mut TAMAGOTCHI :Option = None; +static mut TAMAGOTCHI: Option = None; #[no_mangle] extern fn init() { @@ -11,7 +11,7 @@ extern fn init() { let initname = msg::load().expect("unable to load name"); let birthdate = exec::block_timestamp(); let tmg = Tamagotchi { - name:initname, + name: initname, date_of_birth: birthdate, }; unsafe { @@ -22,18 +22,17 @@ extern fn init() { #[no_mangle] extern fn handle() { // TODO: 6️⃣ Add handling of `Name` and `Age` actions - let action:TmgAction = msg::load().expect("unable to load action"); - let tmg = unsafe { - TAMAGOTCHI.get_or_insert(Default::default()) - }; + let action: TmgAction = msg::load().expect("unable to load action"); + let tmg = unsafe { TAMAGOTCHI.get_or_insert(Default::default()) }; match action { TmgAction::Name => { - msg::reply(TmgEvent::Name(tmg.name.clone()),0).expect("Error in a reply'tamagotchi::name'"); - }, + msg::reply(TmgEvent::Name(tmg.name.clone()), 0) + .expect("Error in a reply'tamagotchi::name'"); + } TmgAction::Age => { let age = exec::block_timestamp() - tmg.date_of_birth; - msg::reply(TmgEvent::Age(age),0).expect("Error in a reply'tamagotchi::age'"); - }, + msg::reply(TmgEvent::Age(age), 0).expect("Error in a reply'tamagotchi::age'"); + } } } diff --git a/contracts/01-tamagotchi/tests/smoke.rs b/contracts/01-tamagotchi/tests/smoke.rs index c83b317f..be5b2faa 100644 --- a/contracts/01-tamagotchi/tests/smoke.rs +++ b/contracts/01-tamagotchi/tests/smoke.rs @@ -1,6 +1,4 @@ - - -use gtest::{Program, System,Log}; +use gtest::{Log, Program, System}; use tamagotchi_io::*; #[test] @@ -11,7 +9,9 @@ fn smoke_test() { let result = program.send(2, String::from("Goodmoring")); assert!(!result.main_failed()); let result = program.send(2, TmgAction::Name); - let log = Log::builder().dest(2).payload(TmgEvent::Name(String::from("Goodmoring"))); + let log = Log::builder() + .dest(2) + .payload(TmgEvent::Name(String::from("Goodmoring"))); assert!(result.contains(&log)); let _result = program.send(2, TmgAction::Age); // let log = Log::builder().dest(2).payload(TmgEvent::Age(sys.block_timestamp())); @@ -25,15 +25,15 @@ fn negative_smoke_test() { let sys = System::new(); sys.init_logger(); let program = Program::current(&sys); - let payload = vec![1,2,3]; + let payload = vec![1, 2, 3]; let _result = program.send(2, payload); // assert!(result.main_failed()); -// Why the assert is panic? + // Why the assert is panic? // let result = program.send(1, TmgAction::Name); // let log = Log::builder().dest(2).payload(TmgEvent::Name("Goodmoring".to_string())); // assert!(!result.contains(&log)); // let result = program.send(1, TmgAction::Age); -// let log = Log::builder().dest(2).payload(TmgEvent::Age(sys.block_timestamp())); -// assert!(!result.contains(&log)); + // let log = Log::builder().dest(2).payload(TmgEvent::Age(sys.block_timestamp())); + // assert!(!result.contains(&log)); }