Skip to content

Commit

Permalink
feat:finish task3
Browse files Browse the repository at this point in the history
  • Loading branch information
BazingaJack committed Dec 25, 2024
1 parent 99fe021 commit 1a63ec2
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 4 deletions.
40 changes: 40 additions & 0 deletions mover/Nii11L/code/task3/hello_nft/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "EE1F76C6FE60CAFA64EAAF0DC41FBB9535F13F6BD9A6BA7AA6B695AE423513B4"
deps_digest = "F8BBB0CCB2491CA29A3DF03D6F92277A4F3574266507ACD77214D37ECA3F3082"
dependencies = [
{ id = "Sui", name = "Sui" },
]

[[move.package]]
id = "MoveStdlib"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/move-stdlib" }

[[move.package]]
id = "Sui"
source = { git = "https://github.com/MystenLabs/sui.git", rev = "framework/testnet", subdir = "crates/sui-framework/packages/sui-framework" }

dependencies = [
{ id = "MoveStdlib", name = "MoveStdlib" },
]

[move.toolchain-version]
compiler-version = "1.37.1"
edition = "2024.beta"
flavor = "sui"

[env]

[env.suiscan-testnet-rpc]
chain-id = "4c78adac"
original-published-id = "0xbb3e0dc4f7eb83409e917506725d9bf1c579678fa4393a40c85a98279328a4c4"
latest-published-id = "0xbb3e0dc4f7eb83409e917506725d9bf1c579678fa4393a40c85a98279328a4c4"
published-version = "1"

[env.suiscan-mainnet-rpc]
chain-id = "35834a8a"
original-published-id = "0x1db724adfe00d5e36262f31a4ba4f1227ee11d2e8ecbfe9a5b20497f32d4c4af"
latest-published-id = "0x1db724adfe00d5e36262f31a4ba4f1227ee11d2e8ecbfe9a5b20497f32d4c4af"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/Nii11L/code/task3/hello_nft/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "hello_nft"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
# license = "" # e.g., "MIT", "GPL", "Apache 2.0"
# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"]

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }

# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
# Revision can be a branch, a tag, and a commit hash.
# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" }

# For local dependencies use `local = path`. Path is relative to the package root
# Local = { local = "../path/to" }

# To resolve a version conflict and force a specific version for dependency
# override use `override = true`
# Override = { local = "../conflicting/version", override = true }

[addresses]
hello_nft = "0x0"

# Named addresses will be accessible in Move as `@name`. They're also exported:
# for example, `std = "0x1"` is exported by the Standard Library.
# alice = "0xA11CE"

[dev-dependencies]
# The dev-dependencies section allows overriding dependencies for `--test` and
# `--dev` modes. You can introduce test-only dependencies here.
# Local = { local = "../path/to/dev-build" }

[dev-addresses]
# The dev-addresses section allows overwriting named addresses for the `--test`
# and `--dev` modes.
# alice = "0xB0B"

62 changes: 62 additions & 0 deletions mover/Nii11L/code/task3/hello_nft/sources/hello_nft.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module hello_nft::my_nft{
use std::ascii::String;
use sui::url::{Self, Url};

public struct MyNFT has key, store {
id: UID,
name: String,
description: String,
image_url: Url,
}

#[allow(lint(self_transfer))]
public entry fun mint_to_sender(
name: String,
description: String,
image_url: String,
ctx: &mut TxContext,
) {
let nft = MyNFT {
id: object::new(ctx),
name: name,
description: description,
image_url: url::new_unsafe(image_url),
};

transfer::transfer(nft, ctx.sender());
}

public entry fun mint_to_address(
minter: address,
name: String,
description: String,
image_url: String,
ctx: &mut TxContext,
) {
let nft = MyNFT {
id: object::new(ctx),
name: name,
description: description,
image_url: url::new_unsafe(image_url),
};

transfer::transfer(nft, minter);
}

public fun name(nft: &MyNFT) : String {
nft.name
}

public fun description(nft: &MyNFT) : String {
nft.description
}

public fun image_url(nft: &MyNFT) : String {
nft.image_url.inner_url()
}

public entry fun burn(nft: MyNFT, _: &mut TxContext) {
let MyNFT { id, .. } = nft;
id.delete();
}
}
64 changes: 64 additions & 0 deletions mover/Nii11L/code/task3/hello_nft/tests/hello_nft_tests.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#[test_only]
module hello_nft::hello_nft_tests{
use sui::test_scenario::{Self};
use hello_nft::my_nft::{Self, MyNFT};
use std::ascii;

#[test]
fun test_mint_to_sender() {
let owner = @0xA;
let mut scenario = test_scenario::begin(owner);

scenario.next_tx(owner);
{
my_nft::mint_to_sender(
ascii::string(b"My NFT"),
ascii::string(b"This is my NFT"),
ascii::string(b"https://example.com/image.png"),
scenario.ctx(),
);
};

scenario.next_tx(owner);
{
assert!(test_scenario::has_most_recent_for_sender<MyNFT>(&scenario), 1);
let nft = scenario.take_from_sender<MyNFT>();
assert!(my_nft::name(&nft) == ascii::string(b"My NFT"), 1);
assert!(my_nft::description(&nft) == ascii::string(b"This is my NFT"), 1);
assert!(my_nft::image_url(&nft) == ascii::string(b"https://example.com/image.png"), 1);
test_scenario::return_to_sender(&scenario, nft)
};

scenario.end();
}

#[test]
fun test_mint_to_address() {
let owner = @0xA;
let minter = @0xB;
let mut scenario = test_scenario::begin(owner);

scenario.next_tx(owner);
{
my_nft::mint_to_address(
minter,
ascii::string(b"My NFT"),
ascii::string(b"This is my NFT"),
ascii::string(b"https://example.com/image.png"),
scenario.ctx(),
);
};

scenario.next_tx(owner);
{
assert!(test_scenario::has_most_recent_for_address<MyNFT>( minter), 1);
let nft = scenario.take_from_address<MyNFT>(minter);
assert!(my_nft::name(&nft) == ascii::string(b"My NFT"), 1);
assert!(my_nft::description(&nft) == ascii::string(b"This is my NFT"), 1);
assert!(my_nft::image_url(&nft) == ascii::string(b"https://example.com/image.png"), 1);
test_scenario::return_to_address(minter, nft);
};

scenario.end();
}
}
Binary file added mover/Nii11L/images/task3-nft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions mover/Nii11L/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
- [x] `Faucet Coin` address2 mint hash: 5AkEKoaBpJ289xoX3FVaUTPdATLu2T8HEt86bXp1w4Ep

## 03 move NFT
- [] nft package id :
- [] nft object id :
- [] 转账 nft hash:
- [] scan上的NFT截图:![Scan截图](./images/你的图片地址)
- [x] nft package id : 0x1db724adfe00d5e36262f31a4ba4f1227ee11d2e8ecbfe9a5b20497f32d4c4af
- [x] nft object id : 0x6793be4728f8a42ffafc1c91756a207abfd5bd6f6d788a5419e9bed6218f03c7
- [x] 转账 nft hash: BB8LJ4qQMh5Kp1zWVWTd3wgSUbQ2qw8GJBfs1JiJpSVu
- [x] scan上的NFT截图:![Scan截图](./images/task3-nft.png)

## 04 Move Game
- [] game package id :
Expand Down

0 comments on commit 1a63ec2

Please sign in to comment.