-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tamagotchi_nft #5
base: master
Are you sure you want to change the base?
Changes from 1 commit
34baecc
fb83563
8ee6ea5
a8f5aa6
56a0365
a900359
253b305
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ pub struct Tamagotchi { | |
pub entertained_block: u64, | ||
pub slept: u64, | ||
pub slept_block: u64, | ||
pub approved_account: Option<ActorId>, | ||
} | ||
impl Tamagotchi { | ||
fn current_fed(&mut self) -> u64 { | ||
|
@@ -55,6 +56,7 @@ extern fn init() { | |
entertained_block: entertainedblock, | ||
slept: 2000, | ||
slept_block: sleptblock, | ||
approved_account: None, | ||
}; | ||
unsafe { | ||
TAMAGOTCHI = Some(tmg); | ||
|
@@ -129,6 +131,32 @@ extern fn handle() { | |
msg::reply(TmgEvent::Slept, 1).expect("Error in a reply'tamagotchi::slept'"); | ||
} | ||
} | ||
TmgAction::Transfer(account) => { | ||
tmg.owner = account; | ||
msg::reply(TmgEvent::Transferred(account), 0) | ||
.expect("Error in a reply'tamagotchi::transferred'"); | ||
} | ||
TmgAction::Approve(account) => { | ||
tmg.approved_account = Some(account); | ||
msg::reply(TmgEvent::Approved(account), 0) | ||
.expect("Error in a reply'tamagotchi::approved'"); | ||
} | ||
TmgAction::RevokeApproval => { | ||
tmg.approved_account = None; | ||
msg::reply(TmgEvent::ApprovalRevoked, 0) | ||
.expect("Error in a reply'tamagotchi::approval_revoked'"); | ||
} | ||
} | ||
} else if msg::source() == tmg.approved_account.unwrap_or_default() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better would be better to check the account permissions inside the Also, it is better to not call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
match action { | ||
TmgAction::Transfer(account) => { | ||
tmg.owner = account; | ||
msg::reply(TmgEvent::Transferred(account), 0) | ||
.expect("Error in a reply'tamagotchi::transfered'"); | ||
} | ||
_ => { | ||
panic!("You are not the approved people of this tamagotchi"); | ||
} | ||
} | ||
} else { | ||
panic!("You are not the owner of this tamagotchi"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ fn interaction_test() { | |
let log = Log::builder().dest(2).payload(TmgEvent::Slept); | ||
assert!(result.contains(&log)); | ||
|
||
let _result = program.send(1, TmgAction::Sleep); | ||
// let _result = program.send(1, TmgAction::Sleep); | ||
//how to test the panic result? | ||
//negetive test | ||
} | ||
|
@@ -66,7 +66,28 @@ fn interaction_test() { | |
fn owning_test() { | ||
let sys = System::new(); | ||
sys.init_logger(); | ||
let _program = Program::current(&sys); | ||
let program = Program::current(&sys); | ||
let _result = program.send(2, String::from("Goodmoring")); | ||
let result = program.send(2, TmgAction::Transfer(1.into())); | ||
let log = Log::builder() | ||
.dest(2) | ||
.payload(TmgEvent::Transferred(1.into())); | ||
assert!(result.contains(&log)); | ||
|
||
// let result = program.send(1, TmgAction::Approve(2.into())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to check the transfer from approved and not approved accounts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// 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(3, TmgAction::RevokeApproval); | ||
// let log = Log::builder().dest(3).payload(TmgEvent::ApprovalRevoked); | ||
// assert!(result.contains(&log)); | ||
|
||
//why the test is panic? | ||
//TODO: I don't know how to test the code. | ||
|
||
// TODO: 6️⃣ Test new functionality | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One should reset the
approved_account
after transferring the ownership.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.