-
Notifications
You must be signed in to change notification settings - Fork 856
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1809 from zerokk246/main
task2
- Loading branch information
Showing
9 changed files
with
324 additions
and
5 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,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" |
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 = "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
31
mover/zerokk246/code/task2/faucet_coin/sources/faucet_coin.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,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); | ||
} | ||
} | ||
|
26 changes: 26 additions & 0 deletions
26
mover/zerokk246/code/task2/faucet_coin/tests/faucet_coin_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,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(); | ||
} | ||
|
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,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" |
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 = "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" | ||
|
39 changes: 39 additions & 0 deletions
39
mover/zerokk246/code/task2/zerokk246_coin/sources/zerokk246_coin.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,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); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
mover/zerokk246/code/task2/zerokk246_coin/tests/zerokk246_coion_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,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(); | ||
} |
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