Skip to content

Commit

Permalink
Merge pull request #1809 from zerokk246/main
Browse files Browse the repository at this point in the history
task2
  • Loading branch information
Sifotd authored Nov 13, 2024
2 parents edb4284 + 3cd6903 commit 5f7af0c
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 5 deletions.
34 changes: 34 additions & 0 deletions mover/zerokk246/code/task2/faucet_coin/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "F8CFCF256E2F1BB7CD401C27799A09C40777C5C100F0DFA253E86DD7F0D4ED1B"
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.36.2"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x5d0648b63188eec5a74c027f5bd781dce8a7653bdf64f086efb8af3213c7b214"
latest-published-id = "0x5d0648b63188eec5a74c027f5bd781dce8a7653bdf64f086efb8af3213c7b214"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/zerokk246/code/task2/faucet_coin/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "faucet_coin"
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]
faucet_coin = "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"

31 changes: 31 additions & 0 deletions mover/zerokk246/code/task2/faucet_coin/sources/faucet_coin.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module faucet_coin::faucetcoin {
use sui::coin;

public struct FAUCETCOIN has drop {}

fun init(witness: FAUCETCOIN, ctx: &mut TxContext) {
let (treasury, metadata) = coin::create_currency(
witness,
6,
b"FAUCETCOIN",
b"FAUCETCOIN",
b"",
option::none(),
ctx);
transfer::public_freeze_object(metadata);
transfer::public_share_object(treasury);
}

public entry fun request_coin(
cap: &mut coin::TreasuryCap<FAUCETCOIN>,
ctx: &mut tx_context::TxContext
) {
coin::mint_and_transfer(cap, 1000, ctx.sender(), ctx);
}

#[test_only]
public fun test_init_coin(ctx: &mut TxContext) {
init(FAUCETCOIN {}, ctx);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[test_only]
module faucet_coin::faucetcoin_tests;
use sui::coin::{Coin, TreasuryCap};
use sui::test_scenario::{Self};
use faucet_coin::faucetcoin::{Self, test_init_coin};


#[test]
fun test_faucet_coin() {
let mut scenario_val = test_scenario::begin(@0x01);
let scenario = &mut scenario_val;
test_init_coin(scenario.ctx());

scenario.next_tx(@0x1);
let mut cap = scenario.take_shared<TreasuryCap<faucetcoin::FAUCETCOIN>>();
faucetcoin::request_coin(&mut cap, scenario.ctx());

scenario.next_tx(@0x1);
let c = scenario.take_from_sender<Coin<faucetcoin::FAUCETCOIN>>();
assert!(c.balance().value() > 0, 1);

scenario.return_to_sender(c);
test_scenario::return_shared(cap);
scenario_val.end();
}

34 changes: 34 additions & 0 deletions mover/zerokk246/code/task2/zerokk246_coin/Move.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# @generated by Move, please check-in and do not edit manually.

[move]
version = 3
manifest_digest = "30442FD345AE73859D6BF3BE3E2C8605A59DAE790DA100E456CF1B9900EB537D"
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.36.2"
edition = "2024.beta"
flavor = "sui"

[env]

[env.testnet]
chain-id = "4c78adac"
original-published-id = "0x11ee890df33c22a0ac689959b818e4669d835b68ea947e05e5a45e6915bbc75d"
latest-published-id = "0x11ee890df33c22a0ac689959b818e4669d835b68ea947e05e5a45e6915bbc75d"
published-version = "1"
37 changes: 37 additions & 0 deletions mover/zerokk246/code/task2/zerokk246_coin/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "zerokk246_coion"
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]
zerokk246_coion = "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"

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module zerokk246_coion::zerokkcoin {
use sui::coin;

public struct ZEROKKCOIN has drop {}

fun init(witness: ZEROKKCOIN, ctx: &mut TxContext) {
let (treasury, metadata) = coin::create_currency(
witness,
6,
b"ZEROKK",
b"ZEROKK",
b"zerokk coin",
option::none(),
ctx);
transfer::public_freeze_object(metadata);
transfer::public_transfer(treasury, ctx.sender())
}

public entry fun mint(
cap: &mut coin::TreasuryCap<ZEROKKCOIN>,
value: u64,
recipient: address,
ctx: &mut tx_context::TxContext
) {
coin::mint_and_transfer(cap, value, recipient, ctx);
}

public entry fun burn(
cap: &mut coin::TreasuryCap<ZEROKKCOIN>,
c: coin::Coin<ZEROKKCOIN>
): u64 {
coin::burn(cap, c)
}

#[test_only]
public fun test_init_coin(ctx: &mut TxContext) {
init(ZEROKKCOIN {}, ctx);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#[test_only]
module zerokk246_coion::zerokk246_coion_tests;
use zerokk246_coion::zerokkcoin::{Self,test_init_coin, ZEROKKCOIN};
use sui::coin::{Coin, TreasuryCap};
use sui::test_scenario::{Self};

#[test]
fun test_zerokk246_coin_success() {
let mut scenario_val = test_scenario::begin(@0x01);
let scenario = &mut scenario_val;
test_init_coin(scenario.ctx());

scenario.next_tx(@0x01);
{
let mut treasury_cap = scenario.take_from_sender<TreasuryCap<ZEROKKCOIN>>();
let ctx = test_scenario::ctx(scenario);
zerokkcoin::mint( &mut treasury_cap, 100, @0x01, ctx);
scenario.return_to_sender(treasury_cap);
};

scenario.next_tx(@0x01);
{
let c = scenario.take_from_sender<Coin<ZEROKKCOIN>>();
let balance = c.balance();
assert!(balance.value() == 100, 1);
scenario.return_to_sender(c);
};

scenario.next_tx(@0x01);
{
let mut treasury_cap = scenario.take_from_sender<TreasuryCap<ZEROKKCOIN>>();
let c = scenario.take_from_sender<Coin<ZEROKKCOIN>>();
zerokkcoin::burn(&mut treasury_cap, c);

scenario.return_to_sender(treasury_cap);
};

scenario_val.end();
}


#[test, expected_failure]
fun test_zerokk246_coin_fail() {
let mut scenario_val = test_scenario::begin(@0x01);
let scenario = &mut scenario_val;
test_init_coin(scenario.ctx());

scenario.next_tx(@0x01);
{
let mut treasury_cap = scenario.take_from_sender<TreasuryCap<ZEROKKCOIN>>();
let ctx = test_scenario::ctx(scenario);
zerokkcoin::mint( &mut treasury_cap, 100, @0x1, ctx);
scenario.return_to_sender(treasury_cap);
};

scenario.next_tx(@0x01);
{
let c = scenario.take_from_sender<Coin<ZEROKKCOIN>>();
let balance = c.balance();
assert!(balance.value() == 100, 1);
scenario.return_to_sender(c);
};

scenario.next_tx(@0x01);
{
let mut treasury_cap = scenario.take_from_sender<TreasuryCap<ZEROKKCOIN>>();
let c = scenario.take_from_sender<Coin<ZEROKKCOIN>>();
zerokkcoin::burn(&mut treasury_cap, c);

scenario.return_to_sender(treasury_cap);
};

scenario.next_tx(@0x01);
{
// should fail
let c = scenario.take_from_sender<Coin<ZEROKKCOIN>>();
scenario.return_to_sender(c);
};

scenario_val.end();
}
10 changes: 5 additions & 5 deletions mover/zerokk246/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
- [ x ] package id 在 scan上的查看截图:![Scan截图](./co-learn-2411/images/suivision-package-id.png)

## 02 move coin
- [] My Coin package id :
- [] Faucet package id :
- [] 转账 `My Coin` hash:
- [] `Faucet Coin` address1 mint hash:
- [] `Faucet Coin` address2 mint hash:
- [ x ] My Coin package id : 0x11ee890df33c22a0ac689959b818e4669d835b68ea947e05e5a45e6915bbc75d
- [ x ] Faucet package id : 0x5d0648b63188eec5a74c027f5bd781dce8a7653bdf64f086efb8af3213c7b214
- [ x ] 转账 `My Coin` hash: BEEe4wjeTFA7cnas6ByUSwJpUxEvD6aYdmcHF6MrPLry
- [ x ] `Faucet Coin` address1 mint hash: E41aizriUyQ9qjiRteHgq7V2fgnpR3yRqheRdknJJYKY
- [ x ] `Faucet Coin` address2 mint hash: Cc9nbqeQ76cK9E8hkkuXaeAEt3tjY43oGMf2EsA8f3Pk

## 03 move NFT
- [] nft package id :
Expand Down

0 comments on commit 5f7af0c

Please sign in to comment.