Skip to content

Commit

Permalink
[framework] spoofup DevNetNFT to allows transfers and updates
Browse files Browse the repository at this point in the history
These are cool features to demonstrate that complement the simple creation case. Added relevant functions and tests.
  • Loading branch information
sblackshear committed May 5, 2022
1 parent 6a4a976 commit d5958b6
Showing 1 changed file with 76 additions and 1 deletion.
77 changes: 76 additions & 1 deletion sui_programmability/framework/sources/DevNetNFT.move
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module Sui::DevNetNFT {
use Sui::Url::{Self, Url};
use Sui::UTF8;
use Sui::ID::VersionedID;
use Sui::ID::{Self, VersionedID};
use Sui::Transfer;
use Sui::TxContext::{Self, TxContext};

Expand Down Expand Up @@ -39,4 +39,79 @@ module Sui::DevNetNFT {
};
Transfer::transfer(nft, TxContext::sender(ctx))
}

/// Transfer `nft` to `recipient`
public(script) fun transfer(
nft: DevNetNFT, recipient: address, _: &mut TxContext
) {
Transfer::transfer(nft, recipient)
}

/// Update the `description` of `nft` to `new_description`
public(script) fun update_description(
nft: &mut DevNetNFT,
new_description: vector<u8>,
_: &mut TxContext
) {
nft.description = UTF8::string_unsafe(new_description)
}

/// Permanently delete `nft`
public(script) fun burn(nft: DevNetNFT, _: &mut TxContext) {
let DevNetNFT { id, name: _, description: _, url: _ } = nft;
ID::delete(id)
}

/// Get the NFT's `name`
public fun name(nft: &DevNetNFT): &UTF8::String {
&nft.name
}

/// Get the NFT's `description`
public fun description(nft: &DevNetNFT): &UTF8::String {
&nft.description
}

/// Get the NFT's `url`
public fun url(nft: &DevNetNFT): &Url {
&nft.url
}
}

#[test_only]
module Sui::DevNetNFTTests {
use Sui::DevNetNFT::{Self, DevNetNFT};
use Sui::TestScenario;
use Sui::UTF8;

#[test]
public(script) fun mint_transfer_update() {
let addr1 = @0xA;
let addr2 = @0xB;
// create the NFT
let scenario = TestScenario::begin(&addr1);
{
DevNetNFT::mint(b"test", b"a test", b"https://www.sui.io", TestScenario::ctx(&mut scenario))
};
// send it from A to B
TestScenario::next_tx(&mut scenario, &addr1);
{
let nft = TestScenario::take_owned<DevNetNFT>(&mut scenario);
DevNetNFT::transfer(nft, addr2, TestScenario::ctx(&mut scenario));
};
// update its description
TestScenario::next_tx(&mut scenario, &addr2);
{
let nft = TestScenario::take_owned<DevNetNFT>(&mut scenario);
DevNetNFT::update_description(&mut nft, b"a new description", TestScenario::ctx(&mut scenario)) ;
assert!(*UTF8::bytes(DevNetNFT::description(&nft)) == b"a new description", 0);
TestScenario::return_owned(&mut scenario, nft);
};
// burn it
TestScenario::next_tx(&mut scenario, &addr2);
{
let nft = TestScenario::take_owned<DevNetNFT>(&mut scenario);
DevNetNFT::burn(nft, TestScenario::ctx(&mut scenario))
}
}
}

0 comments on commit d5958b6

Please sign in to comment.