Skip to content

Commit

Permalink
Fixes for simple-nft-module (#990)
Browse files Browse the repository at this point in the history
* Clap support for simple-nft-module

* Add test_config_serialization to simple-nft-module

* hide cli import behing native flag

* Test for NonFungibleTokenConfig serialization

* fix lint

* move runtime to sov_nft_module

* read nft genesis from a file

* Add missing nft path

* Update TEST_GENESIS_PATHS

* change nft to nft_path
  • Loading branch information
bkolad authored Oct 6, 2023
1 parent 3a2ed4b commit 5d50c32
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/demo-prover/benches/prover_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
value_setter_genesis_path: "../test-data/genesis/demo-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/demo-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/demo-tests/chain_state.json",
nft_path: "../test-data/genesis/demo-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/demo-tests/evm.json",
};
Expand Down
12 changes: 12 additions & 0 deletions examples/demo-prover/methods/guest-celestia/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/demo-prover/methods/guest-mock/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/demo-prover/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
value_setter_genesis_path: "../test-data/genesis/demo-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/demo-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/demo-tests/chain_state.json",
nft_path: "../test-data/genesis/demo-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/demo-tests/evm.json",
};
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/benches/rollup_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/benches/rollup_coarse_measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};
Expand Down
2 changes: 2 additions & 0 deletions examples/demo-rollup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DEMO_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
value_setter_genesis_path: "../test-data/genesis/demo-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/demo-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/demo-tests/chain_state.json",
nft_path: "../test-data/genesis/demo-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/demo-tests/evm.json",
};
Expand All @@ -23,6 +24,7 @@ const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/tests/bank/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};
Expand Down
1 change: 1 addition & 0 deletions examples/demo-rollup/tests/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};
Expand Down
2 changes: 2 additions & 0 deletions examples/demo-stf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sov-sequencer-registry = { path = "../../module-system/module-implementations/so
sov-blob-storage = { path = "../../module-system/module-implementations/sov-blob-storage" }
sov-bank = { path = "../../module-system/module-implementations/sov-bank" }
sov-nft-module = { path = "../../module-system/module-implementations/sov-nft-module" }
simple-nft-module = { path = "../simple-nft-module" }

sov-chain-state = { path = "../../module-system/module-implementations/sov-chain-state" }
sov-modules-stf-template = { path = "../../module-system/sov-modules-stf-template" }
Expand Down Expand Up @@ -57,6 +58,7 @@ native = [
"sov-stf-runner/native",
"sov-bank/native",
"sov-nft-module/native",
"simple-nft-module/native",
"sov-cli",
"sov-accounts/native",
"sov-sequencer-registry/native",
Expand Down
4 changes: 2 additions & 2 deletions examples/demo-stf/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct GenesisPaths<P: AsRef<Path>> {
pub value_setter_genesis_path: P,
pub accounts_genesis_path: P,
pub chain_state_genesis_path: P,
pub nft_path: P,
#[cfg(feature = "experimental")]
pub evm_genesis_path: P,
}
Expand Down Expand Up @@ -92,8 +93,7 @@ fn create_genesis_config<C: Context, Da: DaSpec, P: AsRef<Path>>(
read_json_file(&genesis_paths.value_setter_genesis_path)?;

let accounts_config: AccountConfig<C> = read_json_file(&genesis_paths.accounts_genesis_path)?;

let nft_config: NonFungibleTokenConfig = NonFungibleTokenConfig {};
let nft_config: NonFungibleTokenConfig = read_json_file(&genesis_paths.nft_path)?;

let chain_state_config: ChainStateConfig =
read_json_file(&genesis_paths.chain_state_genesis_path)?;
Expand Down
1 change: 1 addition & 0 deletions examples/demo-stf/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const TEST_GENESIS_PATHS: GenesisPaths<&str> = GenesisPaths {
value_setter_genesis_path: "../test-data/genesis/integration-tests/value_setter.json",
accounts_genesis_path: "../test-data/genesis/integration-tests/accounts.json",
chain_state_genesis_path: "../test-data/genesis/integration-tests/chain_state.json",
nft_path: "../test-data/genesis/integration-tests/nft.json",
#[cfg(feature = "experimental")]
evm_genesis_path: "../test-data/genesis/integration-tests/evm.json",
};
Expand Down
5 changes: 4 additions & 1 deletion examples/simple-nft-module/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ serde = { workspace = true }
sov-modules-api = { path = "../../module-system/sov-modules-api" }
sov-state = { path = "../../module-system/sov-state" }

clap = { workspace = true, optional = true, features = ["derive"] }
schemars = { workspace = true, optional = true }
serde_json = { workspace = true, optional = true }
jsonrpsee = { workspace = true, features = ["macros", "client-core", "server"], optional = true }

[dev-dependencies]
Expand All @@ -27,5 +30,5 @@ simple-nft-module = { version = "*", features = ["native"], path = "." }

[features]
default = []
native = ["sov-state/native", "sov-modules-api/native", "jsonrpsee"]
native = ["sov-state/native", "sov-modules-api/native", "jsonrpsee", "schemars", "serde_json", "clap"]
test = ["native"]
7 changes: 6 additions & 1 deletion examples/simple-nft-module/src/call.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use anyhow::{bail, Result};
#[cfg(feature = "native")]
use sov_modules_api::macros::CliWalletArg;
use sov_modules_api::{CallResponse, Context, WorkingSet};

use crate::NonFungibleToken;

#[cfg_attr(
feature = "native",
derive(serde::Serialize),
derive(serde::Deserialize)
derive(serde::Deserialize),
derive(CliWalletArg),
derive(schemars::JsonSchema),
schemars(bound = "C::Address: ::schemars::JsonSchema", rename = "CallMessage")
)]
#[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq, Clone)]
/// A transaction handled by the NFT module. Mints, Transfers, or Burns an NFT by id
Expand Down
5 changes: 4 additions & 1 deletion examples/simple-nft-module/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![doc = include_str!("../README.md")]

mod call;
#[cfg(test)]
mod tests;
pub use call::CallMessage;
mod genesis;
#[cfg(feature = "native")]
Expand All @@ -11,6 +13,7 @@ pub use query::*;
use serde::{Deserialize, Serialize};
use sov_modules_api::{CallResponse, Context, Error, Module, ModuleInfo, WorkingSet};

#[cfg_attr(feature = "native", derive(sov_modules_api::ModuleCallJsonSchema))]
#[derive(ModuleInfo, Clone)]
/// Module for non-fungible tokens (NFT).
/// Each token is represented by a unique ID.
Expand All @@ -30,7 +33,7 @@ pub struct NonFungibleToken<C: Context> {

/// Config for the NonFungibleToken module.
/// Sets admin and existing owners.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct NonFungibleTokenConfig<C: Context> {
/// Admin of the NonFungibleToken module.
pub admin: C::Address,
Expand Down
27 changes: 27 additions & 0 deletions examples/simple-nft-module/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use sov_modules_api::default_context::DefaultContext;
use sov_modules_api::utils::generate_address as gen_addr_generic;
use sov_modules_api::Spec;

use crate::NonFungibleTokenConfig;

#[test]
fn test_config_serialization() {
let address: <DefaultContext as Spec>::Address = gen_addr_generic::<DefaultContext>("admin");
let owner: <DefaultContext as Spec>::Address = gen_addr_generic::<DefaultContext>("owner");

let config = NonFungibleTokenConfig::<DefaultContext> {
admin: address,
owners: vec![(0, owner)],
};

let data = r#"
{
"admin":"sov1335hded4gyzpt00fpz75mms4m7ck02wgw07yhw9grahj4dzg4yvqk63pml",
"owners":[
[0,"sov1fsgzj6t7udv8zhf6zj32mkqhcjcpv52yph5qsdcl0qt94jgdckqsczjm2y"]
]
}"#;

let parsed_config: NonFungibleTokenConfig<DefaultContext> = serde_json::from_str(data).unwrap();
assert_eq!(config, parsed_config)
}
1 change: 1 addition & 0 deletions examples/test-data/genesis/demo-tests/nft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions examples/test-data/genesis/integration-tests/nft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod call;
pub use call::CallMessage;
mod address;
mod genesis;
#[cfg(test)]
mod tests;
pub use address::*;
mod collection;
use collection::*;
Expand Down Expand Up @@ -42,7 +44,7 @@ pub struct NonFungibleToken<C: Context> {

/// Config for the NonFungibleToken module.
/// Sets admin and existing owners.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
pub struct NonFungibleTokenConfig {}

impl<C: Context> Module for NonFungibleToken<C> {
Expand Down
14 changes: 14 additions & 0 deletions module-system/module-implementations/sov-nft-module/src/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use crate::NonFungibleTokenConfig;

#[test]
fn test_config_serialization() {
let config = NonFungibleTokenConfig {};

let data = r#"
{
}"#;

let parsed_config: NonFungibleTokenConfig = serde_json::from_str(data).unwrap();
assert_eq!(config, parsed_config)
}

0 comments on commit 5d50c32

Please sign in to comment.