-
Notifications
You must be signed in to change notification settings - Fork 47
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
Homework - Tamagotchi 3 NFT #76
Open
TerratekMusic
wants to merge
12
commits into
gear-foundation:master
Choose a base branch
from
TerratekMusic:tamagotchi-3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
8b522f8
Create rust.yml
TerratekMusic 049aa8a
io update
TerratekMusic d152b5b
test init
TerratekMusic 993a0c2
home-work Tamagotchi 01
TerratekMusic 6c3517f
Tamagotchi 02 update from past hw
TerratekMusic 69dd589
Merge branch 'homework-tamagotchi'
TerratekMusic 6337bf4
Create node.js.yml
TerratekMusic 34999b8
tamagotchi copy form last session
TerratekMusic a24c5f0
test init completed
TerratekMusic a74f7a2
test transfer
TerratekMusic 14918e2
Tests Completed
TerratekMusic 08cd5e5
comments in progress
TerratekMusic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs | ||
|
||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [14.x, 16.x, 18.x] | ||
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/ | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm run build --if-present | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: Rust | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build | ||
run: cargo build --verbose | ||
- name: Run tests | ||
run: cargo test --verbose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ publish.workspace = true | |
[dependencies] | ||
gmeta.workspace = true | ||
gstd.workspace = true | ||
gear-core.workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,74 @@ | ||
#![no_std] | ||
|
||
|
||
#[allow(unused_imports)] | ||
use gstd::prelude::*; | ||
use gstd::{ActorId, msg, prelude::*, debug, exec}; | ||
use tamagotchi_io::{Tamagotchi, TmgAction, TmgEvent}; | ||
|
||
|
||
static mut TAMAGOTCHI: Option<Tamagotchi> = None; | ||
|
||
#[no_mangle] | ||
extern fn init() { | ||
// TODO: 5️⃣ Initialize the Tamagotchi program | ||
let tamagochi: Tamagotchi = Tamagotchi { | ||
name: String::from("Ivan"), | ||
date_of_birth: 45, | ||
}; | ||
let init_msg: String = msg::load().expect("Can't decode an init message"); | ||
|
||
let tamagotchi = Tamagotchi { | ||
name: "Ivan".to_string(), | ||
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. It must be set from incoming message |
||
date_of_birth: exec::block_timestamp(), | ||
}; | ||
debug!( | ||
"The Tamagotchi Program was initialized with name {:?} and birth date {:?}", | ||
tamagotchi.name, tamagotchi.date_of_birth | ||
); | ||
unsafe { TAMAGOTCHI = Some(tamagotchi) }; | ||
|
||
|
||
debug!("Program was initialized with message {:?}", | ||
init_msg); | ||
let block = exec::block_timestamp(); | ||
debug!("Current block timestamp is {}", block); | ||
|
||
} | ||
|
||
#[no_mangle] | ||
extern fn handle() { | ||
// TODO: 6️⃣ Add handling of `Name` and `Age` actions | ||
let _tamagotchi = unsafe { | ||
TAMAGOTCHI | ||
.as_mut() | ||
.expect("The contract is not initialized") | ||
}; | ||
|
||
let name = &_tamagotchi.name; | ||
let current_time = exec::block_timestamp(); | ||
let age = current_time - _tamagotchi.date_of_birth; | ||
let action: TmgAction = msg::load().expect("Can't decode an action message"); | ||
|
||
// | ||
|
||
let _event = match action { | ||
TmgAction::Name => { | ||
msg::reply(name, 0).expect("Error in sending name"); | ||
} | ||
TmgAction::Age =>{ | ||
msg::reply(age, 0).expect("Error in sending age"); | ||
|
||
} | ||
}; | ||
|
||
} | ||
|
||
#[no_mangle] | ||
extern fn state() { | ||
// TODO: 7️⃣ Return the Tamagotchi state | ||
let tamagotchi = unsafe { | ||
TAMAGOTCHI | ||
.as_ref() | ||
.expect("The contract is not initialized") | ||
}; | ||
msg::reply(tamagotchi, 0).expect("Failed to share state"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,31 @@ | ||
use gtest::{Program, System}; | ||
use gstd::debug; | ||
use gtest::{Log, Program, System}; | ||
use tamagotchi_io:: TmgAction; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
#[test] | ||
fn smoke_test() { | ||
let sys = System::new(); | ||
sys.init_logger(); | ||
let _program = Program::current(&sys); | ||
let program: Program<'_> = Program::current(&sys); | ||
|
||
let res = program.send(2, String::from("Init Tamagotchi")); | ||
|
||
assert!(!res.main_failed()); | ||
|
||
let res_tmgAction_name = program.send(2, TmgAction::Name); | ||
|
||
let expected_log = Log::builder() | ||
.dest(2) | ||
.payload(String::from("Ivan")); | ||
assert!(res_tmgAction_name.contains(&expected_log)); | ||
|
||
// TODO: 8️⃣ Test the program initialization and message handling | ||
// let res_tmgAction_age = program.send(2, TmgAction::Age); | ||
// debug!("tamagotchi age is: {:?}", res_tmgAction_age); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,20 +3,73 @@ | |
#[allow(unused_imports)] | ||
use gstd::prelude::*; | ||
|
||
use tamagotchi_io::{Tamagotchi, TmgAction, TmgEvent}; | ||
|
||
// TODO: 4️⃣ Define constants | ||
|
||
static mut TAMAGOTCHI: Option<Tamagotchi> = None; | ||
|
||
#[no_mangle] | ||
extern fn init() { | ||
// TODO: 0️⃣ Copy the `init` function from the previous lesson and push changes to the master branch | ||
let tamagochi: Tamagotchi = Tamagotchi { | ||
name: String::from("Ivan"), | ||
date_of_birth: 45, | ||
}; | ||
let init_msg: String = msg::load().expect("Can't decode an init message"); | ||
|
||
let tamagotchi = Tamagotchi { | ||
name: "Ivan".to_string(), | ||
date_of_birth: exec::block_timestamp(), | ||
}; | ||
debug!( | ||
"The Tamagotchi Program was initialized with name {:?} and birth date {:?}", | ||
tamagotchi.name, tamagotchi.date_of_birth | ||
); | ||
unsafe { TAMAGOTCHI = Some(tamagotchi) }; | ||
|
||
|
||
debug!("Program was initialized with message {:?}", | ||
init_msg); | ||
let block = exec::block_timestamp(); | ||
debug!("Current block timestamp is {}", block); | ||
} | ||
|
||
#[no_mangle] | ||
extern fn handle() { | ||
// TODO: 0️⃣ Copy the `handle` function from the previous lesson and push changes to the master branch | ||
let _tamagotchi = unsafe { | ||
TAMAGOTCHI | ||
.as_mut() | ||
.expect("The contract is not initialized") | ||
}; | ||
|
||
let name = &_tamagotchi.name; | ||
let current_time = exec::block_timestamp(); | ||
let age = current_time - _tamagotchi.date_of_birth; | ||
let action: TmgAction = msg::load().expect("Can't decode an action message"); | ||
|
||
// | ||
|
||
let _event = match action { | ||
TmgAction::Name => { | ||
msg::reply(name, 0).expect("Error in sending name"); | ||
} | ||
TmgAction::Age =>{ | ||
msg::reply(age, 0).expect("Error in sending age"); | ||
|
||
} | ||
}; | ||
// TODO: 5️⃣ Add new logic for calculating the `fed`, `entertained` and `slept` levels | ||
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. No implementation that is requires |
||
} | ||
|
||
#[no_mangle] | ||
extern fn state() { | ||
// TODO: 0️⃣ Copy the `handle` function from the previous lesson and push changes to the master branch | ||
let tamagotchi = unsafe { | ||
TAMAGOTCHI | ||
.as_ref() | ||
.expect("The contract is not initialized") | ||
}; | ||
msg::reply(tamagotchi, 0).expect("Failed to share state"); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why 45?