From 8ee6ea5472019981d68d88ba737a359b28c36337 Mon Sep 17 00:00:00 2001 From: Jackliu-miaozi <71253778+Jackliu-miaozi@users.noreply.github.com> Date: Tue, 19 Dec 2023 09:32:36 +0800 Subject: [PATCH] tamgagotchi_nft --- contracts/03-tamagotchi-nft/tests/owning.rs | 73 +++------------------ 1 file changed, 8 insertions(+), 65 deletions(-) diff --git a/contracts/03-tamagotchi-nft/tests/owning.rs b/contracts/03-tamagotchi-nft/tests/owning.rs index f6806bbc..e16f2fbd 100644 --- a/contracts/03-tamagotchi-nft/tests/owning.rs +++ b/contracts/03-tamagotchi-nft/tests/owning.rs @@ -3,65 +3,6 @@ use tamagotchi_nft_io::*; // TODO: 0️⃣ Copy tests from the previous lesson and push changes to the master branch -#[test] -fn smoke_test() { - let sys = System::new(); - sys.init_logger(); - let program = Program::current(&sys); - 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"))); - assert!(result.contains(&log)); - let _result = program.send(2, TmgAction::Age); - // let log = Log::builder().dest(2).payload(TmgEvent::Age(sys.block_timestamp())); - // assert!(result.contains(&log)); - - //How to test the age? -} - -#[test] -fn negative_smoke_test() { - let sys = System::new(); - sys.init_logger(); - let program = Program::current(&sys); - let payload = vec![1, 2, 3]; - let _result = program.send(2, payload); - // assert!(result.main_failed()); - // 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)); -} - -#[test] -fn interaction_test() { - let sys = System::new(); - sys.init_logger(); - let program = Program::current(&sys); - let result = program.send(2, String::from("Goodmoring")); - assert!(!result.main_failed()); - let result = program.send(2, TmgAction::Feed); - let log = Log::builder().dest(2).payload(TmgEvent::Fed); - assert!(result.contains(&log)); - let result = program.send(2, TmgAction::Entertain); - let log = Log::builder().dest(2).payload(TmgEvent::Entertained); - assert!(result.contains(&log)); - let result = program.send(2, TmgAction::Sleep); - let log = Log::builder().dest(2).payload(TmgEvent::Slept); - assert!(result.contains(&log)); - - // let _result = program.send(1, TmgAction::Sleep); - //how to test the panic result? - //negetive test -} - #[test] fn owning_test() { let sys = System::new(); @@ -74,13 +15,15 @@ fn owning_test() { .payload(TmgEvent::Transferred(1.into())); assert!(result.contains(&log)); - // let result = program.send(1, TmgAction::Approve(2.into())); - // let log = Log::builder().dest(1).payload(TmgEvent::Approved(2.into())); - // assert!(result.contains(&log)); + let result = program.send(1, TmgAction::Approve(2.into())); + let log = Log::builder().dest(1).payload(TmgEvent::Approved(2.into())); + assert!(result.contains(&log)); - // let result = program.send(2, TmgAction::Transfer(3.into())); - // let log = Log::builder().dest(2).payload(TmgEvent::Transferred(3.into())); - // assert!(result.contains(&log)); + let result = program.send(2, TmgAction::Transfer(3.into())); + let log = Log::builder() + .dest(2) + .payload(TmgEvent::Transferred(3.into())); + assert!(result.contains(&log)); // let result = program.send(3, TmgAction::RevokeApproval); // let log = Log::builder().dest(3).payload(TmgEvent::ApprovalRevoked);