Skip to content

Commit

Permalink
Merge 0646210 into b61f992
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar authored Aug 9, 2021
2 parents b61f992 + 0646210 commit fd2592c
Show file tree
Hide file tree
Showing 9 changed files with 504 additions and 127 deletions.
Binary file modified genesis/generated/halley/genesis
Binary file not shown.
3 changes: 1 addition & 2 deletions vm/functional-tests/tests/testsuite/nft/nft_card.move
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,11 @@ script {
address creator = {{creator}};
script {
use 0x1::NFTGallery;
use 0x1::Option;
use creator::Card::{Self, L1CardMeta, L1Card};
fun main(sender: signer) {
let first_l1 = NFTGallery::withdraw_one<L1CardMeta, L1Card>(&sender);
let second_l1 = NFTGallery::withdraw_one<L1CardMeta, L1Card>(&sender);
let l2_card = Card::mint_l2(&sender, Option::destroy_some(first_l1), Option::destroy_some(second_l1));
let l2_card = Card::mint_l2(&sender, first_l1, second_l1);
NFTGallery::deposit(&sender, l2_card);
}
}
Expand Down
8 changes: 3 additions & 5 deletions vm/functional-tests/tests/testsuite/nft/nft_metadata.move
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,11 @@ script {
address creator = {{creator}};
script {
use 0x1::NFTGallery;
use 0x1::Option;
use creator::Card::{Self, Card, CardBody};
fun main(sender: signer) {
let first = Option::destroy_some(NFTGallery::withdraw_one<Card, CardBody>(&sender));
let first = NFTGallery::withdraw_one<Card, CardBody>(&sender);
let second = NFTGallery::withdraw_one<Card, CardBody>(&sender);
Card::upgrade_card(&mut first, Option::destroy_some(second));
Card::upgrade_card(&mut first, second);
NFTGallery::deposit(&sender, first);
}
}
Expand All @@ -139,12 +138,11 @@ script {
use creator::Card::{Self, Card, CardBody};
use 0x1::NFTGallery;
use 0x1::Signer;
use 0x1::Option;
use 0x1::NFT;

fun main(sender: signer) {
assert(NFTGallery::count_of<Card, CardBody>(Signer::address_of(&sender)) == 1, 1001);
let card = Option::destroy_some(NFTGallery::withdraw_one<Card, CardBody>(&sender));
let card = NFTGallery::withdraw_one<Card, CardBody>(&sender);
let card_meta = NFT::get_type_meta(&card);
let level = Card::get_level(card_meta);
assert(level == 2, 1002);
Expand Down
275 changes: 275 additions & 0 deletions vm/functional-tests/tests/testsuite/nft/test_gallery.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
//! account: creator
//! account: bob

//! sender: creator
address creator = {{creator}};
module creator::AnyNFT {
use 0x1::NFT::{Self, NFT, MintCapability, BurnCapability};
use 0x1::NFTGallery;
use 0x1::Signer;

struct AnyNFT has copy, store, drop{}
struct AnyNFTBody has store{
}
struct AnyNFTInfo has copy,store,drop{}

struct AnyNFTMintCapability has key{
cap: MintCapability<AnyNFT>,
}

struct AnyNFTBurnCapability has key{
cap: BurnCapability<AnyNFT>,
}

public fun init(sender: &signer){
NFT::register<AnyNFT,AnyNFTInfo>(sender,AnyNFTInfo{});
let cap = NFT::remove_mint_capability<AnyNFT>(sender);
move_to(sender, AnyNFTMintCapability{cap});
let cap = NFT::remove_burn_capability<AnyNFT>(sender);
move_to(sender, AnyNFTBurnCapability{cap});
Self::do_accept(sender);
}

public fun mint(sender: &signer) acquires AnyNFTMintCapability{
let sender_addr = Signer::address_of(sender);
let cap = borrow_global_mut<AnyNFTMintCapability>(@creator);
let metadata = NFT::new_meta_with_image(b"test_nft_1", b"ipfs:://xxxxxx", b"This is a test nft.");
let nft = NFT::mint_with_cap<AnyNFT,AnyNFTBody,AnyNFTInfo>(sender_addr, &mut cap.cap, metadata, AnyNFT{}, AnyNFTBody{});
NFTGallery::deposit(sender, nft);
}

public fun mint_many(sender: &signer, amount: u64) acquires AnyNFTMintCapability{
let i = 0;
while (i < amount ) {
mint(sender);
i = i + 1;
}
}

public fun burn(nft: NFT<AnyNFT, AnyNFTBody>) acquires AnyNFTBurnCapability{
let cap = borrow_global_mut<AnyNFTBurnCapability>(@creator);
let AnyNFTBody{} = NFT::burn_with_cap(&mut cap.cap, nft);
}

public fun do_accept(sender: &signer) {
NFTGallery::accept<AnyNFT, AnyNFTBody>(sender);
}

public(script) fun accept(sender: signer) {
Self::do_accept(&sender);
}

public(script) fun transfer(sender: signer, id: u64, receiver: address) {
NFTGallery::transfer<AnyNFT, AnyNFTBody>(&sender, id, receiver);
}
}

// check: EXECUTED

//! new-transaction
//! sender: creator
address creator = {{creator}};
script {
use creator::AnyNFT;
fun main(sender: signer) {
AnyNFT::init(&sender);
}
}

// check: EXECUTED

//! new-transaction
//! sender: bob
address creator = {{creator}};
script {
use creator::AnyNFT;
fun main(account: signer) {
AnyNFT::accept(account);
}
}

// check: EXECUTED


//! new-transaction
//! sender: bob
address creator = {{creator}};
script {
use 0x1::Option;
use creator::AnyNFT::{AnyNFT, AnyNFTBody};
use 0x1::NFTGallery;
use 0x1::Signer;
use 0x1::Vector;
fun main(sender: signer) {
let sender_addr = Signer::address_of(&sender);
let nft_info = NFTGallery::get_nft_info_by_id<AnyNFT, AnyNFTBody>(sender_addr, 1);
assert(Option::is_none(&nft_info), 1000);
let nft_infos = NFTGallery::get_nft_infos<AnyNFT, AnyNFTBody>(sender_addr);
assert(Vector::is_empty(&nft_infos), 1001);
}
}

//! new-transaction
//! sender: bob
address creator = {{creator}};
script {
use creator::AnyNFT;
fun main(sender: signer) {
AnyNFT::mint(&sender);
}
}

// check: EXECUTED

//! new-transaction
//! sender: bob
address creator = {{creator}};
script {
use 0x1::Option;
use creator::AnyNFT::{AnyNFT, AnyNFTBody};
use 0x1::NFTGallery;
use 0x1::Signer;
use 0x1::Vector;
fun main(sender: signer) {
let sender_addr = Signer::address_of(&sender);
let nft_info = NFTGallery::get_nft_info_by_id<AnyNFT, AnyNFTBody>(sender_addr, 1);
assert(Option::is_some(&nft_info), 1002);
let nft_infos = NFTGallery::get_nft_infos<AnyNFT, AnyNFTBody>(sender_addr);
assert(Vector::length(&nft_infos) == 1, 1003);
}
}

// check: EXECUTED

//! new-transaction
//! sender: bob
//! max-gas: 40000000
address creator = {{creator}};
script {
use creator::AnyNFT;
fun main(sender: signer) {
AnyNFT::mint_many(&sender, 200);
}
}

// check: EXECUTED


//! new-transaction
//! sender: bob
address creator = {{creator}};
script {
use creator::AnyNFT::{AnyNFT, AnyNFTBody};
use 0x1::NFTGallery;
use 0x1::Signer;
use 0x1::Vector;
fun main(sender: signer) {
let sender_addr = Signer::address_of(&sender);
let nft_infos = NFTGallery::get_nft_infos<AnyNFT, AnyNFTBody>(sender_addr);
assert(Vector::length(&nft_infos) == 201, 1004);
}
}

// check: EXECUTED


//! new-transaction
//! sender: bob
//! max-gas: 40000000
address creator = {{creator}};
script {
use creator::AnyNFT::{AnyNFT, AnyNFTBody};
use 0x1::NFTGallery;
use 0x1::Signer;
use 0x1::Option;
fun main(sender: signer) {
let sender_addr = Signer::address_of(&sender);
let id = 1;
loop {
//loop by id use more gas
let info = NFTGallery::get_nft_info_by_id<AnyNFT, AnyNFTBody>(sender_addr, id);
assert(Option::is_some(&info), 1008);
id = id + 1;
if(id > 20){
break
}
}
}
}

// check: EXECUTED

//! new-transaction
//! sender: bob
//! max-gas: 40000000
address creator = {{creator}};
script {
use creator::AnyNFT::{AnyNFT, AnyNFTBody};
use 0x1::NFTGallery;
use 0x1::Signer;
fun main(sender: signer) {
let sender_addr = Signer::address_of(&sender);
let idx = 0;
loop {
//loop by index
let _info = NFTGallery::get_nft_info_by_idx<AnyNFT, AnyNFTBody>(sender_addr, idx);
idx = idx + 1;
if(idx >= 201){
break
}
}
}
}

// check: EXECUTED

//! new-transaction
//! sender: bob
address creator = {{creator}};
script {
use creator::AnyNFT::{AnyNFT, AnyNFTBody};
use 0x1::NFTGallery;
use 0x1::Signer;
fun main(sender: signer) {
let sender_addr = Signer::address_of(&sender);
let count = NFTGallery::count_of<AnyNFT, AnyNFTBody>(sender_addr);
assert(count == 201, 1005);
}
}

// check: EXECUTED



//! new-transaction
//! sender: bob
address creator = {{creator}};
script {
use creator::AnyNFT::{Self, AnyNFT, AnyNFTBody};
use 0x1::NFTGallery;
fun main(sender: signer) {
let nft = NFTGallery::withdraw_one<AnyNFT, AnyNFTBody>(&sender);
AnyNFT::burn(nft);
}
}

// check: EXECUTED


//! new-transaction
//! sender: bob
address creator = {{creator}};
script {
use creator::AnyNFT::{Self, AnyNFT, AnyNFTBody};
use 0x1::NFTGallery;
use 0x1::Option;
fun main(sender: signer) {
//withdraw by id use more gas than withdraw one
let nft = NFTGallery::withdraw<AnyNFT, AnyNFTBody>(&sender, 1);
assert(Option::is_some(&nft), 1007);
let nft = Option::destroy_some(nft);
AnyNFT::burn(nft);
}
}

// check: EXECUTED
10 changes: 6 additions & 4 deletions vm/functional-tests/tests/testsuite/nft/test_nft.move
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ module creator::TestNFT {
Self::do_accept(&sender);
}

public(script) fun transfer(sender: signer, uid: u64, receiver: address) {
NFTGallery::transfer<TestNFT, TestNFTBody>(&sender, uid, receiver);
public(script) fun transfer(sender: signer, id: u64, receiver: address) {
NFTGallery::transfer<TestNFT, TestNFTBody>(&sender, id, receiver);
}
}

Expand Down Expand Up @@ -82,8 +82,10 @@ script {
use 0x1::Option;
use creator::TestNFT::{TestNFT, TestNFTBody};
use 0x1::NFTGallery;
fun main(account: signer) {
let nft = NFTGallery::get_nft_info<TestNFT, TestNFTBody>(&account, 1);
use 0x1::Signer;
fun main(sender: signer) {
let sender_addr = Signer::address_of(&sender);
let nft = NFTGallery::get_nft_info_by_id<TestNFT, TestNFTBody>(sender_addr, 1);
assert(Option::is_some(&nft), 1000);
}
}
Binary file modified vm/stdlib/compiled/latest/stdlib/51_NFT.mv
Binary file not shown.
Binary file modified vm/stdlib/compiled/latest/stdlib/56_NFTGallery.mv
Binary file not shown.
Loading

0 comments on commit fd2592c

Please sign in to comment.