-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99fe021
commit 1a63ec2
Showing
6 changed files
with
207 additions
and
4 deletions.
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,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" |
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,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" | ||
|
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,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
64
mover/Nii11L/code/task3/hello_nft/tests/hello_nft_tests.move
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,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(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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