Skip to content

Commit

Permalink
[Move] Add module for creating example NFT on CLI (MystenLabs#1411)
Browse files Browse the repository at this point in the history
* [Move] Add module for creating example NFT on CLI

* Address comment to remove the TokenMetadata struct

* ExampleNFT -> DevNetNFT

* [Wallet CLI] Add command to create example NFT (MystenLabs#1412)
  • Loading branch information
666lcz authored Apr 21, 2022
1 parent 688c706 commit 1030d1e
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 209 deletions.
188 changes: 63 additions & 125 deletions sui/src/unit_tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::str;
use std::time::Duration;

use crate::cli_tests::sui_network::start_test_network;
use anyhow::anyhow;
use move_core_types::identifier::Identifier;
use serde_json::{json, Value};
use std::fmt::Write;
Expand All @@ -18,7 +19,7 @@ use sui::config::{
};
use sui::gateway_config::{GatewayConfig, GatewayType};
use sui::keystore::KeystoreType;
use sui::sui_commands::SuiCommand;
use sui::sui_commands::{SuiCommand, SuiNetwork};
use sui::sui_json::SuiJsonValue;
use sui::wallet_commands::{WalletCommandResult, WalletCommands, WalletContext};
use sui::{SUI_GATEWAY_CONFIG, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG};
Expand Down Expand Up @@ -275,21 +276,7 @@ async fn airdrop_call_move_and_get_created_object(
#[traced_test]
#[tokio::test]
async fn test_objects_command() -> Result<(), anyhow::Error> {
let working_dir = tempfile::tempdir()?;

let network = start_test_network(working_dir.path(), None).await?;

// Create Wallet context.
let mut context = WalletContext::new(&working_dir.path().join(SUI_WALLET_CONFIG))?;
let address = context.config.accounts.first().cloned().unwrap();

// Sync client to retrieve objects from the network.
WalletCommands::SyncClientState {
address: Some(address),
}
.execute(&mut context)
.await?
.print(true);
let (network, mut context, address) = setup_network_and_wallet().await?;

// Print objects owned by `address`
WalletCommands::Objects {
Expand All @@ -310,6 +297,39 @@ async fn test_objects_command() -> Result<(), anyhow::Error> {
Ok(())
}

#[traced_test]
#[tokio::test]
async fn test_create_example_nft_command() -> Result<(), anyhow::Error> {
let (network, mut context, address) = setup_network_and_wallet().await?;

let result = WalletCommands::CreateExampleNFT {
name: Option::None,
description: Option::None,
url: Option::None,
gas: Option::None,
gas_budget: Option::None,
}
.execute(&mut context)
.await?;

match result {
WalletCommandResult::CreateExampleNFT(ObjectRead::Exists(_, obj, layout)) => {
assert_eq!(obj.owner, address);
assert_eq!(
obj.type_().unwrap().to_string(),
"0x2::DevNetNFT::DevNetNFT"
);
Ok(obj.to_json(&layout).unwrap_or_else(|_| json!("")))
}
_ => Err(anyhow!(
"WalletCommands::CreateExampleNFT returns wrong type"
)),
}?;

network.kill().await?;
Ok(())
}

#[traced_test]
#[tokio::test]
async fn test_custom_genesis() -> Result<(), anyhow::Error> {
Expand Down Expand Up @@ -406,22 +426,7 @@ async fn test_custom_genesis_with_custom_move_package() -> Result<(), anyhow::Er
#[traced_test]
#[tokio::test]
async fn test_object_info_get_command() -> Result<(), anyhow::Error> {
let working_dir = tempfile::tempdir()?;

let network = start_test_network(working_dir.path(), None).await?;

// Create Wallet context.
let wallet_conf = working_dir.path().join(SUI_WALLET_CONFIG);
let mut context = WalletContext::new(&wallet_conf)?;
let address = context.config.accounts.first().cloned().unwrap();

// Sync client to retrieve objects from the network.
WalletCommands::SyncClientState {
address: Some(address),
}
.execute(&mut context)
.await?
.print(true);
let (network, mut context, address) = setup_network_and_wallet().await?;

let object_refs = context.gateway.get_owned_objects(address).await?;

Expand All @@ -446,22 +451,9 @@ async fn test_object_info_get_command() -> Result<(), anyhow::Error> {
#[traced_test]
#[tokio::test]
async fn test_gas_command() -> Result<(), anyhow::Error> {
let working_dir = tempfile::tempdir()?;
let network = start_test_network(working_dir.path(), None).await?;

// Create Wallet context.
let wallet_conf = working_dir.path().join(SUI_WALLET_CONFIG);
let mut context = WalletContext::new(&wallet_conf)?;
let address = context.config.accounts.first().cloned().unwrap();
let (network, mut context, address) = setup_network_and_wallet().await?;
let recipient = context.config.accounts.get(1).cloned().unwrap();

// Sync client to retrieve objects from the network.
WalletCommands::SyncClientState {
address: Some(address),
}
.execute(&mut context)
.await?;

let object_refs = context.gateway.get_owned_objects(address).await?;

let object_id = object_refs.first().unwrap().0;
Expand Down Expand Up @@ -636,23 +628,10 @@ async fn get_move_object(
#[traced_test]
#[tokio::test]
async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> {
let working_dir = tempfile::tempdir()?;
let network = start_test_network(working_dir.path(), None).await?;

// Create Wallet context.
let wallet_conf = working_dir.path().join(SUI_WALLET_CONFIG);

let mut context = WalletContext::new(&wallet_conf)?;
let address1 = context.config.accounts.first().cloned().unwrap();
let (network, mut context, address1) = setup_network_and_wallet().await?;
let address2 = context.config.accounts.get(1).cloned().unwrap();

// Sync client to retrieve objects from the network.
WalletCommands::SyncClientState {
address: Some(address1),
}
.execute(&mut context)
.await?
.print(true);
WalletCommands::SyncClientState {
address: Some(address2),
}
Expand Down Expand Up @@ -821,22 +800,7 @@ async fn test_move_call_args_linter_command() -> Result<(), anyhow::Error> {
#[traced_test]
#[tokio::test]
async fn test_package_publish_command() -> Result<(), anyhow::Error> {
let working_dir = tempfile::tempdir()?;

let network = start_test_network(working_dir.path(), None).await?;

// Create Wallet context.
let wallet_conf = working_dir.path().join(SUI_WALLET_CONFIG);
let mut context = WalletContext::new(&wallet_conf)?;
let address = context.config.accounts.first().cloned().unwrap();

// Sync client to retrieve objects from the network.
WalletCommands::SyncClientState {
address: Some(address),
}
.execute(&mut context)
.await?
.print(true);
let (network, mut context, address) = setup_network_and_wallet().await?;

let object_refs = context.gateway.get_owned_objects(address).await?;

Expand Down Expand Up @@ -902,23 +866,8 @@ async fn test_package_publish_command() -> Result<(), anyhow::Error> {
#[traced_test]
#[tokio::test]
async fn test_native_transfer() -> Result<(), anyhow::Error> {
let working_dir = tempfile::tempdir()?;

let network = start_test_network(working_dir.path(), None).await?;

// Create Wallet context.
let wallet_conf = working_dir.path().join(SUI_WALLET_CONFIG);

let mut context = WalletContext::new(&wallet_conf)?;
let address = context.config.accounts.first().cloned().unwrap();
let (network, mut context, address) = setup_network_and_wallet().await?;
let recipient = context.config.accounts.get(1).cloned().unwrap();
// Sync client to retrieve objects from the network.
WalletCommands::SyncClientState {
address: Some(address),
}
.execute(&mut context)
.await?
.print(true);

let object_refs = context.gateway.get_owned_objects(address).await?;

Expand Down Expand Up @@ -1219,22 +1168,7 @@ async fn get_object(id: ObjectID, context: &mut WalletContext) -> Option<Object>
#[traced_test]
#[tokio::test]
async fn test_merge_coin() -> Result<(), anyhow::Error> {
let working_dir = tempfile::tempdir()?;

let network = start_test_network(working_dir.path(), None).await?;

// Create Wallet context.
let wallet_conf = working_dir.path().join(SUI_WALLET_CONFIG);

let mut context = WalletContext::new(&wallet_conf)?;
let address = context.config.accounts.first().cloned().unwrap();
// Sync client to retrieve objects from the network.
WalletCommands::SyncClientState {
address: Some(address),
}
.execute(&mut context)
.await?
.print(true);
let (network, mut context, address) = setup_network_and_wallet().await?;

let object_refs = context.gateway.get_owned_objects(address).await?;

Expand Down Expand Up @@ -1312,23 +1246,7 @@ async fn test_merge_coin() -> Result<(), anyhow::Error> {
#[traced_test]
#[tokio::test]
async fn test_split_coin() -> Result<(), anyhow::Error> {
let working_dir = tempfile::tempdir()?;

let network = start_test_network(working_dir.path(), None).await?;

// Create Wallet context.
let wallet_conf = working_dir.path().join(SUI_WALLET_CONFIG);

let mut context = WalletContext::new(&wallet_conf)?;
let address = context.config.accounts.first().cloned().unwrap();
// Sync client to retrieve objects from the network.
WalletCommands::SyncClientState {
address: Some(address),
}
.execute(&mut context)
.await?
.print(true);

let (network, mut context, address) = setup_network_and_wallet().await?;
let object_refs = context.gateway.get_owned_objects(address).await?;

// Check log output contains all object ids.
Expand Down Expand Up @@ -1398,3 +1316,23 @@ async fn test_split_coin() -> Result<(), anyhow::Error> {
network.kill().await?;
Ok(())
}

async fn setup_network_and_wallet() -> Result<(SuiNetwork, WalletContext, SuiAddress), anyhow::Error>
{
let working_dir = tempfile::tempdir()?;

let network = start_test_network(working_dir.path(), None).await?;

// Create Wallet context.
let wallet_conf = working_dir.path().join(SUI_WALLET_CONFIG);
let mut context = WalletContext::new(&wallet_conf)?;
let address = context.config.accounts.first().cloned().unwrap();

// Sync client to retrieve objects from the network.
WalletCommands::SyncClientState {
address: Some(address),
}
.execute(&mut context)
.await?;
Ok((network, context, address))
}
Loading

0 comments on commit 1030d1e

Please sign in to comment.