Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 012a81857b | |||
| 8c752b3028 |
Generated
+11
@@ -8601,6 +8601,17 @@ dependencies = [
|
||||
"psl-types",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "query-tester"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"nym-network-defaults",
|
||||
"nym-validator-client",
|
||||
"serde",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "2.0.1"
|
||||
|
||||
+1
-1
@@ -166,7 +166,7 @@ members = [
|
||||
"wasm/node-tester",
|
||||
"wasm/zknym-lib",
|
||||
"nym-gateway-probe"
|
||||
]
|
||||
, "query-tester"]
|
||||
|
||||
default-members = [
|
||||
"clients/native",
|
||||
|
||||
@@ -140,7 +140,8 @@ clippy: sdk-wasm-lint
|
||||
|
||||
WASM_CONTRACT_DIR := contracts/target/wasm32-unknown-unknown/release
|
||||
# Find every direct contract folder that contains a Cargo.toml
|
||||
CONTRACT_DIRS := $(shell find contracts -type f -name Cargo.toml \( ! -path "contracts/Cargo.toml" \) | grep -v integration-tests | xargs -n1 dirname | sort -u)
|
||||
#CONTRACT_DIRS := $(shell find contracts -type f -name Cargo.toml \( ! -path "contracts/Cargo.toml" \) | grep -v integration-tests | xargs -n1 dirname | sort -u)
|
||||
CONTRACT_DIRS := contracts/example-contract
|
||||
|
||||
CONTRACTS_OUT_DIR = contracts/artifacts
|
||||
|
||||
|
||||
Generated
+9
@@ -832,6 +832,15 @@ version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
|
||||
|
||||
[[package]]
|
||||
name = "example-contract"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cosmwasm-std",
|
||||
"cw-storage-plus",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ff"
|
||||
version = "0.13.0"
|
||||
|
||||
@@ -9,7 +9,7 @@ members = [
|
||||
"multisig/cw3-flex-multisig",
|
||||
"multisig/cw4-group",
|
||||
"vesting",
|
||||
"performance",
|
||||
"performance", "example-contract",
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
[package]
|
||||
name = "example-contract"
|
||||
version = "0.1.0"
|
||||
authors.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
documentation.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
exclude = [
|
||||
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
|
||||
"contract.wasm",
|
||||
"hash.txt",
|
||||
"artifacts",
|
||||
]
|
||||
|
||||
[lib]
|
||||
name = "example_contract"
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
cosmwasm-std = { workspace = true }
|
||||
cw-storage-plus = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,5 @@
|
||||
wasm:
|
||||
RUSTFLAGS='-C link-arg=-s' cargo build --release --target wasm32-unknown-unknown
|
||||
|
||||
generate-schema:
|
||||
cargo schema
|
||||
@@ -0,0 +1,123 @@
|
||||
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use cosmwasm_std::{
|
||||
entry_point, to_json_binary, Addr, Coin, Deps, DepsMut, Env, Event, MessageInfo, QueryResponse,
|
||||
Response,
|
||||
};
|
||||
use cw_storage_plus::Item;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub(crate) const COUNTER: Item<u32> = Item::new("counter");
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct InstantiateMsg {
|
||||
initial_counter: u32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum ExecuteMsg {
|
||||
IncrementCounter {},
|
||||
DecrementCounter {},
|
||||
SetCounter { to: u32 },
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum QueryMsg {
|
||||
GetCounter {},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct MigrateMsg {}
|
||||
|
||||
#[entry_point]
|
||||
pub fn instantiate(
|
||||
mut deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
msg: InstantiateMsg,
|
||||
) -> Result<Response, String> {
|
||||
COUNTER
|
||||
.save(deps.storage, &msg.initial_counter)
|
||||
.map_err(|err| err.to_string())?;
|
||||
Ok(Response::default())
|
||||
}
|
||||
|
||||
#[entry_point]
|
||||
pub fn execute(
|
||||
deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
msg: ExecuteMsg,
|
||||
) -> Result<Response, String> {
|
||||
match msg {
|
||||
ExecuteMsg::IncrementCounter {} => {
|
||||
let current_value = COUNTER.load(deps.storage).map_err(|err| err.to_string())?;
|
||||
COUNTER
|
||||
.save(deps.storage, &(current_value + 1))
|
||||
.map_err(|err| err.to_string())?;
|
||||
}
|
||||
ExecuteMsg::DecrementCounter {} => {
|
||||
let current_value = COUNTER.load(deps.storage).map_err(|err| err.to_string())?;
|
||||
COUNTER
|
||||
.save(deps.storage, &(current_value - 1))
|
||||
.map_err(|err| err.to_string())?;
|
||||
}
|
||||
ExecuteMsg::SetCounter { to } => {
|
||||
COUNTER
|
||||
.save(deps.storage, &(to))
|
||||
.map_err(|err| err.to_string())?;
|
||||
}
|
||||
}
|
||||
Ok(Response::new().add_event(Event::new("my-amazing-event").add_attribute("key1", "value1")))
|
||||
}
|
||||
|
||||
#[entry_point]
|
||||
pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result<QueryResponse, String> {
|
||||
let query_res = match msg {
|
||||
QueryMsg::GetCounter {} => {
|
||||
to_json_binary(&COUNTER.load(deps.storage).map_err(|err| err.to_string())?)
|
||||
}
|
||||
};
|
||||
|
||||
Ok(query_res.map_err(|err| err.to_string())?)
|
||||
}
|
||||
|
||||
#[entry_point]
|
||||
pub fn migrate(mut deps: DepsMut<'_>, _env: Env, msg: MigrateMsg) -> Result<Response, String> {
|
||||
Ok(Response::default())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use cosmwasm_std::from_json;
|
||||
use cosmwasm_std::testing::{message_info, mock_dependencies, mock_env};
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
let mut deps = mock_dependencies();
|
||||
let env = mock_env();
|
||||
|
||||
let init_msg = InstantiateMsg {
|
||||
initial_counter: 123,
|
||||
};
|
||||
|
||||
let sender = message_info(&deps.api.addr_make("mock-sender"), &[]);
|
||||
instantiate(deps.as_mut(), env, sender, init_msg).unwrap();
|
||||
|
||||
assert_eq!(COUNTER.load(deps.as_ref().storage).unwrap(), 123);
|
||||
|
||||
let msg = ExecuteMsg::IncrementCounter {};
|
||||
let sender = message_info(&deps.api.addr_make("mock-sender"), &[]);
|
||||
|
||||
execute(deps.as_mut(), mock_env(), sender, msg).unwrap();
|
||||
assert_eq!(COUNTER.load(deps.as_ref().storage).unwrap(), 124);
|
||||
|
||||
let msg = QueryMsg::GetCounter {};
|
||||
let query_res = query(deps.as_ref(), mock_env(), msg).unwrap();
|
||||
println!("raw binary: {:?}", query_res);
|
||||
println!("string: {:?}", String::from_utf8_lossy(&query_res));
|
||||
println!("deserialised: {:?}", from_json::<u32>(query_res).unwrap());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod contract;
|
||||
@@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "query-tester"
|
||||
version = "0.1.0"
|
||||
authors.workspace = true
|
||||
repository.workspace = true
|
||||
homepage.workspace = true
|
||||
documentation.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
rust-version.workspace = true
|
||||
readme.workspace = true
|
||||
|
||||
[dependencies]
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
anyhow = { workspace = true }
|
||||
nym-validator-client = { path = "../common/client-libs/validator-client" }
|
||||
nym-network-defaults = { path = "../common/network-defaults" }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -0,0 +1,76 @@
|
||||
use nym_network_defaults::NymNetworkDetails;
|
||||
use nym_network_defaults::setup_env;
|
||||
use nym_validator_client::nyxd::CosmWasmClient;
|
||||
use nym_validator_client::nyxd::contract_traits::{DkgQueryClient, GroupSigningClient};
|
||||
use nym_validator_client::{Config, DirectSigningHttpRpcNyxdClient, QueryHttpRpcValidatorClient};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum QueryMsg {
|
||||
GetCounter {},
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum ExecuteMsg {
|
||||
IncrementCounter {},
|
||||
DecrementCounter {},
|
||||
SetCounter { to: u32 },
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
/*
|
||||
theres map
|
||||
id1 => wasm code 1
|
||||
id2 => wasm code 2
|
||||
id3 => wasm code 3
|
||||
|
||||
//
|
||||
// n1foo => id3
|
||||
// n1bar => id2
|
||||
//
|
||||
|
||||
|
||||
*/
|
||||
|
||||
let contract_address = "n1vwttwvy8e5nqshc35rsn2u88ewfecjwdkmqdwpuqdsfmweans3xs2rjgjx";
|
||||
|
||||
let mnemonic = "cost truly december route shoulder ostrich upon test test deliver moment tent general clutch manual language antenna curious gate library remember cost kidney proud";
|
||||
|
||||
let network = "/Users/jedrzej/workspace/nym/envs/canary.env";
|
||||
setup_env(Some(network));
|
||||
|
||||
let nym_network_details = NymNetworkDetails::new_from_env();
|
||||
|
||||
let signing_client = DirectSigningHttpRpcNyxdClient::connect_with_mnemonic(
|
||||
nym_validator_client::nyxd::Config::try_from_nym_network_details(&nym_network_details)?,
|
||||
"https://rpc.canary-validator.performance.nymte.ch",
|
||||
mnemonic.parse()?,
|
||||
)?;
|
||||
|
||||
let result = signing_client
|
||||
.execute(
|
||||
&contract_address.parse().unwrap(),
|
||||
&ExecuteMsg::SetCounter { to: 200 },
|
||||
None,
|
||||
"executing example contract",
|
||||
vec![],
|
||||
)
|
||||
.await?;
|
||||
println!("transaction got executed at tx {}", result.transaction_hash);
|
||||
println!("with events: {:?}", result.events);
|
||||
|
||||
// queries:
|
||||
let client = QueryHttpRpcValidatorClient::new_query(Config::try_from_nym_network_details(
|
||||
&nym_network_details,
|
||||
)?)?;
|
||||
|
||||
let response: u32 = client
|
||||
.nyxd
|
||||
.query_contract_smart(&contract_address.parse().unwrap(), &QueryMsg::GetCounter {})
|
||||
.await?;
|
||||
|
||||
println!("current counter is at {response}");
|
||||
println!("Hello, world!");
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user