From 9f4aa1e9da9cbf47b6552caf4b869f34eb6b7954 Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Thu, 15 May 2025 02:10:58 +0000 Subject: [PATCH 01/36] test: basic tests --- tests/test_basics.rs | 54 +++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/tests/test_basics.rs b/tests/test_basics.rs index b79cecc..727a4d3 100644 --- a/tests/test_basics.rs +++ b/tests/test_basics.rs @@ -1,28 +1,40 @@ -// use serde_json::json; +use serde_json::json; +use std::time::SystemTime; -// #[tokio::test] -// async fn test_contract_is_operational() -> Result<(), Box> { -// let contract_wasm = near_workspaces::compile_project("./").await?; +#[tokio::test] +async fn test_contract_is_operational() -> Result<(), Box> { + let contract_wasm = near_workspaces::compile_project("./").await?; -// test_basics_on(&contract_wasm).await?; -// Ok(()) -// } + test_initialization(&contract_wasm).await?; + Ok(()) +} -// async fn test_basics_on(contract_wasm: &[u8]) -> Result<(), Box> { -// let sandbox = near_workspaces::sandbox().await?; -// let contract = sandbox.dev_deploy(contract_wasm).await?; +async fn test_initialization(contract_wasm: &[u8]) -> Result<(), Box> { + let sandbox = near_workspaces::sandbox().await?; + let contract = sandbox.dev_deploy(contract_wasm).await?; -// let user_account = sandbox.dev_create_account().await?; + // Initialize contract + let proposal = "test_proposal"; + let deadline_timestamp_ms = SystemTime::now() + 10 * 60 * 1000; + contract + .call(contract.id(), "new") + .args_json(json!({ + "proposal": proposal, + "deadline_timestamp_md": deadline_timestamp_ms, + })) + .transact() + .await?; -// let outcome = user_account -// .call(contract.id(), "set_greeting") -// .args_json(json!({"greeting": "Hello World!"})) -// .transact() -// .await?; -// assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + let user_account = sandbox.dev_create_account().await?; + let outcome = user_account + .call(contract.id(), "vote") + .args_json(json!({"is_vote": true})) + .transact() + .await?; + assert!(outcome.is_failure(), "{:#?}", outcome.into_result().unwrap_err()); -// let user_message_outcome = contract.view("get_greeting").args_json(json!({})).await?; -// assert_eq!(user_message_outcome.json::()?, "Hello World!"); + let contract_proposal = contract.view("get_proposal").args_json(json!({})).await?; + assert_eq!(contract_proposal.json::()?, proposal); -// Ok(()) -// } + Ok(()) +} From 225fa0ee9f5f6b7b3c1da1110b4e368d8636a842 Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Thu, 15 May 2025 03:52:52 +0000 Subject: [PATCH 02/36] test: initialization --- tests/test_basics.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/test_basics.rs b/tests/test_basics.rs index 727a4d3..3ec7ebf 100644 --- a/tests/test_basics.rs +++ b/tests/test_basics.rs @@ -1,5 +1,5 @@ use serde_json::json; -use std::time::SystemTime; +use std::time::{SystemTime, UNIX_EPOCH}; #[tokio::test] async fn test_contract_is_operational() -> Result<(), Box> { @@ -15,9 +15,12 @@ async fn test_initialization(contract_wasm: &[u8]) -> Result<(), Box Result<(), Box()?, deadline_timestamp_ms); + + let contract_proposal = contract.view("get_proposal").args_json(json!({})).await?; + assert_eq!(contract_proposal.json::()?, proposal); + let user_account = sandbox.dev_create_account().await?; let outcome = user_account .call(contract.id(), "vote") @@ -33,8 +42,5 @@ async fn test_initialization(contract_wasm: &[u8]) -> Result<(), Box()?, proposal); - Ok(()) } From 24e097ab478c217df2e61754b1a226ff4c44eeac Mon Sep 17 00:00:00 2001 From: Linguists <95207870+linguists@users.noreply.github.com> Date: Thu, 15 May 2025 03:58:07 +0000 Subject: [PATCH 03/36] test: fix test failure --- tests/test_basics.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_basics.rs b/tests/test_basics.rs index 3ec7ebf..cca38e5 100644 --- a/tests/test_basics.rs +++ b/tests/test_basics.rs @@ -23,7 +23,7 @@ async fn test_initialization(contract_wasm: &[u8]) -> Result<(), Box Date: Thu, 15 May 2025 04:02:14 +0000 Subject: [PATCH 04/36] chore: near-workspaces --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cb5d064..1d1b6ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ near-sdk = "5.12.0" [dev-dependencies] near-sdk = { version = "5.12.0", features = ["unit-testing"] } -# near-workspaces = { version = "0.18", features = ["unstable"] } +near-workspaces = { version = "0.18", features = ["unstable"] } tokio = { version = "1.12.0", features = ["full"] } serde_json = "1" From 9da9e84d4e3c8c53c5dc01544df7775f4daa4960 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Thu, 15 May 2025 05:34:30 +0000 Subject: [PATCH 05/36] chore: cargo lock --- .gitpod.yml | 8 + Cargo.lock | 2512 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 2426 insertions(+), 94 deletions(-) create mode 100644 .gitpod.yml diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..6da0cde --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,8 @@ +# This configuration file was automatically generated by Gitpod. +# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml) +# and commit this file to your remote git repository to share the goodness with others. + +# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart + +tasks: + - init: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/latest/download/cargo-near-installer.sh | sh diff --git a/Cargo.lock b/Cargo.lock index 6ad186e..27651ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7,6 +7,10 @@ name = "Inflector" version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] [[package]] name = "addr2line" @@ -14,7 +18,7 @@ version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" dependencies = [ - "gimli", + "gimli 0.31.1", ] [[package]] @@ -23,6 +27,26 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" +[[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if 1.0.0", + "cipher", + "cpufeatures", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "allocator-api2" version = "0.2.21" @@ -44,6 +68,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + [[package]] name = "anyhow" version = "1.0.98" @@ -59,6 +89,29 @@ dependencies = [ "derive_arbitrary", ] +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "async-trait" +version = "0.1.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "autocfg" version = "1.4.0" @@ -77,7 +130,7 @@ dependencies = [ "miniz_oxide", "object", "rustc-demangle", - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -92,6 +145,36 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" +[[package]] +name = "base64ct" +version = "1.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89e25b6adfb930f02d1981565a6e5d9c547ac15a96606256d3b59040e5cd4ca3" + +[[package]] +name = "binary-install" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93bff426ff93f3610dd2b946f3eb8cb2d1285ca8682834d43be531a3f93db2ff" +dependencies = [ + "anyhow", + "dirs-next", + "flate2", + "fs2", + "hex", + "is_executable", + "siphasher 0.3.11", + "tar", + "ureq", + "zip 0.6.6", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.9.0" @@ -140,6 +223,29 @@ dependencies = [ "zeroize", ] +[[package]] +name = "bon" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97493a391b4b18ee918675fb8663e53646fd09321c58b46afa04e8ce2499c869" +dependencies = [ + "bon-macros", + "rustversion", +] + +[[package]] +name = "bon-macros" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2af3eac944c12cdf4423eab70d310da0a8e5851a18ffb192c0a5e3f7ae1663" +dependencies = [ + "darling", + "ident_case", + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "borsh" version = "1.5.7" @@ -163,6 +269,15 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "brownstone" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "030ea61398f34f1395ccbeb046fb68c87b631d1f34567fed0f0f11fa35d18d8d" +dependencies = [ + "arrayvec", +] + [[package]] name = "bs58" version = "0.4.0" @@ -205,6 +320,87 @@ dependencies = [ "serde", ] +[[package]] +name = "bzip2" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdb116a6ef3f6c3698828873ad02c3014b3c85cadb88496095628e3ef1e347f8" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.13+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225bff33b2141874fe80d71e07d6eec4f85c5c216453dd96388240f96e1acc14" +dependencies = [ + "cc", + "pkg-config", +] + +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-near-build" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1621369df7842f8fcaefab24e9f922f86ec24da22d80e3c44183c3717a885dce" +dependencies = [ + "bon", + "bs58 0.5.1", + "camino", + "cargo_metadata", + "colored", + "dunce", + "eyre", + "hex", + "humantime", + "indenter", + "libloading", + "near-abi", + "rustc_version", + "schemars", + "serde_json", + "sha2", + "symbolic-debuginfo", + "tempfile", + "tracing", + "wasm-opt", + "zstd 0.13.3", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror 1.0.69", +] + [[package]] name = "cc" version = "1.2.22" @@ -242,11 +438,92 @@ checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "android-tzdata", "iana-time-zone", + "js-sys", "num-traits", "serde", + "wasm-bindgen", "windows-link", ] +[[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] +name = "clap" +version = "4.5.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed93b9805f8ba930df42c2590f05453d5ec36cbb85d018868a5b24d31f6ac000" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.5.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "379026ff283facf611b0ea629334361c4211d1b12ee01024eec1591133b04120" +dependencies = [ + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "codespan-reporting" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe6d2e5af09e8c8ad56c969f2157a3d4238cebc7c55f0a517728c38f7b200f81" +dependencies = [ + "serde", + "termcolor", + "unicode-width", +] + +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys 0.59.0", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "convert_case" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a24b1aaf0fd0ce8b45161144d6f42cd91677fd5940fd431183eb023b3a2b8" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -262,6 +539,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if 1.0.0", +] + [[package]] name = "crossbeam-deque" version = "0.8.6" @@ -330,6 +616,65 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "cxx" +version = "1.0.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a71ea7f29c73f7ffa64c50b83c9fe4d3a6d4be89a86b009eb80d5a6d3429d741" +dependencies = [ + "cc", + "cxxbridge-cmd", + "cxxbridge-flags", + "cxxbridge-macro", + "foldhash", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36a8232661d66dcf713394726157d3cfe0a89bfc85f52d6e9f9bbc2306797fe7" +dependencies = [ + "cc", + "codespan-reporting", + "proc-macro2", + "quote", + "scratch", + "syn 2.0.101", +] + +[[package]] +name = "cxxbridge-cmd" +version = "1.0.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f44296c8693e9ea226a48f6a122727f77aa9e9e338380cb021accaeeb7ee279" +dependencies = [ + "clap", + "codespan-reporting", + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f69c181c176981ae44ba9876e2ea41ce8e574c296b38d06925ce9214fb8e4" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8faff5d4467e0709448187df29ccbf3b0982cc426ee444a193f87b11afb565a8" +dependencies = [ + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.101", +] + [[package]] name = "darling" version = "0.20.11" @@ -365,6 +710,15 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "debugid" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6ee87af31d84ef885378aebca32be3d682b0e0dc119d5b4860a2c5bb5046730" +dependencies = [ + "uuid", +] + [[package]] name = "deranged" version = "0.4.0" @@ -417,6 +771,56 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "dmsort" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0bc8fbe9441c17c9f46f75dfe27fa1ddb6c68a461ccaed0481419219d4f10d3" + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "dyn-clone" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c7a8fb8a9fbf66c1f703fe16184d10ca0ee9d23be5b4436400408ba54a95005" + [[package]] name = "easy-ext" version = "0.2.9" @@ -440,6 +844,7 @@ checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek", "ed25519", + "rand_core", "sha2", "subtle", ] @@ -451,12 +856,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] -name = "enum-map" -version = "2.7.3" +name = "elementtree" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6866f3bfdf8207509a033af1a75a7b08abda06bbaaeae6669323fd5a097df2e9" +checksum = "5f6319c9433cf1e95c60c8533978bccf0614f27f03bb4e514253468eeeaa7fe3" dependencies = [ - "enum-map-derive", + "string_cache", + "xml-rs", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "enum-map" +version = "2.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6866f3bfdf8207509a033af1a75a7b08abda06bbaaeae6669323fd5a097df2e9" +dependencies = [ + "enum-map-derive", ] [[package]] @@ -486,6 +910,22 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "eyre" +version = "0.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" +dependencies = [ + "indenter", + "once_cell", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + [[package]] name = "fastrand" version = "2.3.0" @@ -498,6 +938,18 @@ version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" +[[package]] +name = "filetime" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "libredox", + "windows-sys 0.59.0", +] + [[package]] name = "fixed-hash" version = "0.7.0" @@ -507,6 +959,25 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "flate2" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fluent-uri" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17c704e9dbe1ddd863da1e6ff3567795087b1eb201ce80d8fa81162e1516500d" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "fnv" version = "1.0.7" @@ -519,12 +990,85 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "funty" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -535,6 +1079,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + [[package]] name = "getrandom" version = "0.3.3" @@ -547,6 +1102,16 @@ dependencies = [ "wasi 0.14.2+wasi-0.2.4", ] +[[package]] +name = "gimli" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" +dependencies = [ + "fallible-iterator", + "stable_deref_trait", +] + [[package]] name = "gimli" version = "0.31.1" @@ -559,6 +1124,36 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" +[[package]] +name = "goblin" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7666983ed0dd8d21a6f6576ee00053ca0926fb281a5522577a4dbd0f1b54143" +dependencies = [ + "log", + "plain", + "scroll 0.11.0", +] + +[[package]] +name = "h2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9421a676d1b147b16b82c9225157dc629087ef8ec4d5e2960f9437a90dac0a5" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap 2.9.0", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -603,6 +1198,143 @@ dependencies = [ "serde", ] +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest", +] + +[[package]] +name = "home" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "http" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "humantime" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f" + +[[package]] +name = "hyper" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d191583f3da1305256f22463b9bb0471acad48a4e534a5218b9963e9c1f59b2" +dependencies = [ + "futures-util", + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "libc", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.63" @@ -627,12 +1359,131 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_collections" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "200072f5d0e3614556f94a9930d5dc3e0662a652823904c3a75dc3b0af7fee47" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cde2700ccaed3872079a65fb1a78f6c0a36c91570f28755dda67bc8f7d9f00a" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436880e8e18df4d7bbc06d58432329d6458cc84531f7ac5f024e93deadb37979" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" + +[[package]] +name = "icu_properties" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2549ca8c7241c82f59c80ba2a6f415d931c5b58d24fb8412caa1a1f02c49139a" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "potential_utf", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8197e866e47b68f8f7d95249e172903bec06004b18b2937f1095d40a0c57de04" + +[[package]] +name = "icu_provider" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c80da27b5f4187909049ee2d72f276f0d9f99a42c306bd0131ecfe04d8e5af" +dependencies = [ + "displaydoc", + "icu_locale_core", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + [[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +[[package]] +name = "idna" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indent_write" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cfe9645a18782869361d9c8732246be7b410ad4e919d3609ebabdac00ba12c3" + +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "1.9.3" @@ -655,6 +1506,30 @@ dependencies = [ "serde", ] +[[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "is_executable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302d553b8abc8187beb7d663e34c065ac4570b273bc9511a50e940e99409c577" +dependencies = [ + "winapi", +] + [[package]] name = "itertools" version = "0.12.1" @@ -676,10 +1551,16 @@ version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" dependencies = [ - "getrandom", + "getrandom 0.3.3", "libc", ] +[[package]] +name = "joinery" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72167d68f5fce3b8655487b8038691a3c9984ee769590f93f2a631f4ad64e4f5" + [[package]] name = "js-sys" version = "0.3.77" @@ -690,12 +1571,35 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "json-patch" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b1fb8864823fad91877e6caea0baca82e49e8db50f8e5c9f9a453e27d3330fc" +dependencies = [ + "jsonptr", + "serde", + "serde_json", + "thiserror 1.0.69", +] + [[package]] name = "json_comments" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9dbbfed4e59ba9750e15ba154fdfd9329cee16ff3df539c2666b70f58cc32105" +[[package]] +name = "jsonptr" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c6e529149475ca0b2820835d3dce8fcc41c6b943ca608d32f35b449255e4627" +dependencies = [ + "fluent-uri", + "serde", + "serde_json", +] + [[package]] name = "keccak" version = "0.1.5" @@ -714,12 +1618,48 @@ dependencies = [ "spin", ] +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + [[package]] name = "libc" version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" +[[package]] +name = "libloading" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a793df0d7afeac54f95b471d3af7f0d4fb975699f972341a4b76988d49cdf0c" +dependencies = [ + "cfg-if 1.0.0", + "windows-targets 0.52.6", +] + +[[package]] +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.9.0", + "libc", + "redox_syscall", +] + +[[package]] +name = "link-cplusplus" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6f6da007f968f9def0d65a05b187e2960183de70c160204ecfccf0ee330212" +dependencies = [ + "cc", +] + [[package]] name = "linux-raw-sys" version = "0.4.15" @@ -732,6 +1672,12 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" +[[package]] +name = "litemap" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" + [[package]] name = "lock_api" version = "0.4.12" @@ -763,12 +1709,33 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + [[package]] name = "memory_units" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.8.8" @@ -789,6 +1756,75 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "native-tls" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87de3442987e9dbec73158d5c715e7ad9072fda936bb03d19d7fa10e00520f0e" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "near-abi" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c49593c9e94454a2368a4c0a511bf4bf1413aff4d23f16e1d8f4e64b5215351" +dependencies = [ + "borsh", + "schemars", + "semver", + "serde", +] + +[[package]] +name = "near-abi-client" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879ac02b2e8d6498294adce1de7a2424a5474b35a73e9262c851be39c89d7f92" +dependencies = [ + "anyhow", + "convert_case", + "near-abi-client-impl", + "near-abi-client-macros", + "prettyplease", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "near-abi-client-impl" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1139e8a6f60fd8ed1c53c700b67bcecbf6deb4b1f47bbe9a9d5eea760d8a8e91" +dependencies = [ + "anyhow", + "near-abi", + "near_schemafy_lib", + "proc-macro2", + "quote", + "schemars", + "serde_json", +] + +[[package]] +name = "near-abi-client-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebaf2aae80086b310bf96e657bbee0c599c3452afd35e72999f8d6764d6b1899" +dependencies = [ + "near-abi-client-impl", + "syn 1.0.109", +] + [[package]] name = "near-account-id" version = "1.1.1" @@ -799,6 +1835,30 @@ dependencies = [ "serde", ] +[[package]] +name = "near-chain-configs" +version = "0.29.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82d98e77d25ba905d16e91179a33e215da3226d62fadf73c471ef88a9b9d58c2" +dependencies = [ + "anyhow", + "bytesize", + "chrono", + "derive_more", + "near-config-utils", + "near-crypto", + "near-parameters", + "near-primitives", + "near-time", + "num-rational", + "serde", + "serde_json", + "sha2", + "smart-default", + "time", + "tracing", +] + [[package]] name = "near-config-utils" version = "0.29.2" @@ -807,7 +1867,7 @@ checksum = "6b992cca8d3b00f34b37f638c9632a97b734656151294e7a29b60b93b8a92948" dependencies = [ "anyhow", "json_comments", - "thiserror", + "thiserror 2.0.12", "tracing", ] @@ -829,11 +1889,12 @@ dependencies = [ "near-schema-checker-lib", "near-stdx", "primitive-types", + "rand", "secp256k1", "serde", "serde_json", "subtle", - "thiserror", + "thiserror 2.0.12", ] [[package]] @@ -852,7 +1913,44 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180edcc7dc2fac41f93570d0c7b759c1b6d492f6ad093d749d644a40b4310a97" dependencies = [ "borsh", + "schemars", + "serde", +] + +[[package]] +name = "near-jsonrpc-client" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "752aa5d0080f6c3bad8ba349046069a406e7536ab101d6cfc7db3e157144b921" +dependencies = [ + "borsh", + "lazy_static", + "log", + "near-chain-configs", + "near-crypto", + "near-jsonrpc-primitives", + "near-primitives", + "reqwest", + "serde", + "serde_json", + "thiserror 2.0.12", +] + +[[package]] +name = "near-jsonrpc-primitives" +version = "0.29.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f003113d08e1f0ab9e6335efb1f7167662954804274653904ef57a9b5f8e687" +dependencies = [ + "arbitrary", + "near-chain-configs", + "near-crypto", + "near-primitives", + "near-schema-checker-lib", "serde", + "serde_json", + "thiserror 2.0.12", + "time", ] [[package]] @@ -871,7 +1969,7 @@ dependencies = [ "serde_repr", "serde_yaml", "strum 0.24.1", - "thiserror", + "thiserror 2.0.12", ] [[package]] @@ -903,15 +2001,17 @@ dependencies = [ "num-rational", "ordered-float", "primitive-types", + "rand", + "rand_chacha", "serde", "serde_json", "serde_with", "sha3", "smart-default", "strum 0.24.1", - "thiserror", + "thiserror 2.0.12", "tracing", - "zstd", + "zstd 0.13.3", ] [[package]] @@ -932,7 +2032,20 @@ dependencies = [ "serde", "serde_repr", "sha2", - "thiserror", + "thiserror 2.0.12", +] + +[[package]] +name = "near-sandbox-utils" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65921a949220d53f4e346694f7ecae018320003d88582d4bbe45da26c5c35aa7" +dependencies = [ + "anyhow", + "binary-install", + "fs2", + "home", + "tokio", ] [[package]] @@ -1032,35 +2145,127 @@ dependencies = [ ] [[package]] -name = "near-vm-runner" -version = "0.29.2" +name = "near-vm-runner" +version = "0.29.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fca3f18ed6a87b334b93b53e4c2c98cf185fd1fde5a4b538980508fb7e51b147" +dependencies = [ + "blst", + "borsh", + "bytesize", + "ed25519-dalek", + "enum-map", + "lru", + "near-crypto", + "near-parameters", + "near-primitives-core", + "near-schema-checker-lib", + "near-stdx", + "num-rational", + "rayon", + "ripemd", + "rustix 0.38.44", + "serde", + "serde_repr", + "sha2", + "sha3", + "strum 0.24.1", + "tempfile", + "thiserror 2.0.12", + "tracing", + "zeropool-bn", +] + +[[package]] +name = "near-workspaces" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c43e44fc77e3491076daaec62c9be3a1b4d63c299702569b5eca3dd2057f8330" +dependencies = [ + "async-trait", + "base64 0.22.1", + "bs58 0.5.1", + "cargo-near-build", + "chrono", + "fs2", + "json-patch", + "libc", + "near-abi-client", + "near-account-id", + "near-crypto", + "near-gas", + "near-jsonrpc-client", + "near-jsonrpc-primitives", + "near-primitives", + "near-sandbox-utils", + "near-token", + "rand", + "reqwest", + "serde", + "serde_json", + "sha2", + "tempfile", + "thiserror 1.0.69", + "tokio", + "tokio-retry", + "tracing", + "url", +] + +[[package]] +name = "near_schemafy_core" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d7a1f809a319578773329389529dbf8c8f0abfbb05a429b37f437105f7caf6" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "near_schemafy_lib" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39ccae55df51adaa1a4e567b7a79ab4380826a695121cebf41f518076d8c3dd" +dependencies = [ + "Inflector", + "near_schemafy_core", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "syn 1.0.109", + "uriparse", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "nom-supreme" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fca3f18ed6a87b334b93b53e4c2c98cf185fd1fde5a4b538980508fb7e51b147" +checksum = "aadc66631948f6b65da03be4c4cd8bd104d481697ecbb9bbd65719b1ec60bc9f" dependencies = [ - "blst", - "borsh", - "bytesize", - "ed25519-dalek", - "enum-map", - "lru", - "near-crypto", - "near-parameters", - "near-primitives-core", - "near-schema-checker-lib", - "near-stdx", - "num-rational", - "rayon", - "ripemd", - "rustix 0.38.44", - "serde", - "serde_repr", - "sha2", - "sha3", - "strum 0.24.1", - "tempfile", - "thiserror", - "tracing", - "zeropool-bn", + "brownstone", + "indent_write", + "joinery", + "memchr", + "nom", ] [[package]] @@ -1136,6 +2341,50 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "openssl" +version = "0.10.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fedfea7d58a1f73118430a55da6a286e7b044961736ce96a16a17068ea25e5da" +dependencies = [ + "bitflags 2.9.0", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "openssl-probe" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d05e27ee213611ffe7d6348b942e8f942b37114c00cc03cec254295a4a17852e" + +[[package]] +name = "openssl-sys" +version = "0.9.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e145e1651e858e820e4860f7b9c5e169bc1d8ce1c86043be79fa7b7634821847" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "ordered-float" version = "4.6.0" @@ -1168,7 +2417,76 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "password-hash" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700" +dependencies = [ + "base64ct", + "rand_core", + "subtle", +] + +[[package]] +name = "pbkdf2" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" +dependencies = [ + "digest", + "hmac", + "password-hash", + "sha2", +] + +[[package]] +name = "pdb" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13f4d162ecaaa1467de5afbe62d597757b674b51da8bb4e587430c5fdb2af7aa" +dependencies = [ + "fallible-iterator", + "scroll 0.10.2", + "uuid", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "phf_shared" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67eabc2ef2a60eb7faa00097bd1ffdb5bd28e62bf39990626a582201b7a754e5" +dependencies = [ + "siphasher 1.0.1", +] + +[[package]] +name = "pin-project" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", ] [[package]] @@ -1177,18 +2495,64 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + +[[package]] +name = "potential_utf" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5a7c30837279ca13e7c867e9e40053bc68740f988cb07f7ca6df43cc734b585" +dependencies = [ + "zerovec", +] + [[package]] name = "powerfmt" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "prettyplease" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +dependencies = [ + "proc-macro2", + "syn 1.0.109", +] + [[package]] name = "primitive-types" version = "0.10.1" @@ -1244,16 +2608,29 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ + "libc", + "rand_chacha", "rand_core", "serde", ] +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + [[package]] name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ + "getrandom 0.2.16", "serde", ] @@ -1283,7 +2660,105 @@ version = "0.5.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "928fca9cf2aa042393a8325b9ead81d2f0df4cb12e1e24cef072922ccd99c5af" dependencies = [ - "bitflags", + "bitflags 2.9.0", +] + +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom 0.2.16", + "libredox", + "thiserror 1.0.69", +] + +[[package]] +name = "regex" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + +[[package]] +name = "reqwest" +version = "0.12.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d19c46a6fdd48bc4dab94b6103fccc55d34c67cc0ad04653aad4ea2a07cd7bbb" +dependencies = [ + "base64 0.22.1", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-registry", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if 1.0.0", + "getrandom 0.2.16", + "libc", + "untrusted", + "windows-sys 0.52.0", ] [[package]] @@ -1322,7 +2797,7 @@ version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ - "bitflags", + "bitflags 2.9.0", "errno", "libc", "linux-raw-sys 0.4.15", @@ -1333,32 +2808,141 @@ dependencies = [ name = "rustix" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" -dependencies = [ - "bitflags", - "errno", - "libc", - "linux-raw-sys 0.9.4", - "windows-sys 0.59.0", -] +checksum = "c71e83d6afe7ff64890ec6b71d6a69bb8a610ab78ce364b3352876bb4c801266" +dependencies = [ + "bitflags 2.9.0", + "errno", + "libc", + "linux-raw-sys 0.9.4", + "windows-sys 0.59.0", +] + +[[package]] +name = "rustls" +version = "0.23.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "730944ca083c1c233a75c09f199e973ca499344a2b7ba9e755c457e86fb4a321" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pemfile" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dce314e5fee3f39953d46bb63bb8a46d40c2f8fb7cc5a3b6cab2bde9721d6e50" +dependencies = [ + "rustls-pki-types", +] + +[[package]] +name = "rustls-pki-types" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a72fe2bcf7a6ac6fd7d0b9e5cb68aeb7d4c0a0271730218b3e92d43b4eb435" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "schannel" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f29ebaa345f945cec9fbbc532eb307f0fdad8161f281b6369539c8d84876b3d" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "schemars" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e265784ad618884abaea0600a9adf15393368d840e0222d101a072f3f7534d" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.101", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scratch" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f6280af86e5f559536da57a45ebc84948833b3bee313a7dd25232e09c878a52" [[package]] -name = "rustversion" -version = "1.0.20" +name = "scroll" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" +checksum = "fda28d4b4830b807a8b43f7b0e6b5df875311b3e7621d84577188c175b6ec1ec" [[package]] -name = "ryu" -version = "1.0.20" +name = "scroll" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" +checksum = "04c565b551bafbef4157586fa379538366e4385d42082f255bfd96e4fe8519da" +dependencies = [ + "scroll_derive", +] [[package]] -name = "scopeguard" -version = "1.2.0" +name = "scroll_derive" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +checksum = "1db149f81d46d2deba7cd3c50772474707729550221e69588478ebf9ada425ae" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] [[package]] name = "secp256k1" @@ -1366,6 +2950,7 @@ version = "0.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25996b82292a7a57ed3508f052cfff8640d38d32018784acd714758b43da9c8f" dependencies = [ + "rand", "secp256k1-sys", ] @@ -1378,11 +2963,37 @@ dependencies = [ "cc", ] +[[package]] +name = "security-framework" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" +dependencies = [ + "bitflags 2.9.0", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49db231d56a190491cb4aeda9527f1ad45345af50b0851622a7adb8c03b01c32" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "semver" version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" +dependencies = [ + "serde", +] [[package]] name = "serde" @@ -1404,6 +3015,17 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + [[package]] name = "serde_json" version = "1.0.140" @@ -1427,6 +3049,18 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + [[package]] name = "serde_with" version = "3.12.0" @@ -1470,6 +3104,17 @@ dependencies = [ "unsafe-libyaml", ] +[[package]] +name = "sha1" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] + [[package]] name = "sha2" version = "0.10.9" @@ -1512,6 +3157,27 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +[[package]] +name = "siphasher" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b58827f4464d87d377d175e90bf58eb00fd8716ff0a62f80356b5e61555d0d" + +[[package]] +name = "siphasher" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + [[package]] name = "smallvec" version = "1.15.0" @@ -1545,12 +3211,31 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "string_cache" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf776ba3fa74f83bf4b63c3dcbbf82173db2632ed8452cb2d891d33f459de70f" +dependencies = [ + "new_debug_unreachable", + "parking_lot", + "phf_shared", + "precomputed-hash", + "serde", +] + [[package]] name = "strsim" version = "0.11.1" @@ -1604,6 +3289,48 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "symbolic-common" +version = "8.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f551f902d5642e58039aee6a9021a61037926af96e071816361644983966f540" +dependencies = [ + "debugid", + "memmap2", + "stable_deref_trait", + "uuid", +] + +[[package]] +name = "symbolic-debuginfo" +version = "8.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1165dabf9fc1d6bb6819c2c0e27c8dd0e3068d2c53cf186d319788e96517f0d6" +dependencies = [ + "bitvec", + "dmsort", + "elementtree", + "fallible-iterator", + "flate2", + "gimli 0.26.2", + "goblin", + "lazy_static", + "lazycell", + "nom", + "nom-supreme", + "parking_lot", + "pdb", + "regex", + "scroll 0.11.0", + "serde", + "serde_json", + "smallvec", + "symbolic-common", + "thiserror 1.0.69", + "wasmparser", + "zip 0.5.13", +] + [[package]] name = "syn" version = "1.0.109" @@ -1626,12 +3353,64 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "system-configuration" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" +dependencies = [ + "bitflags 2.9.0", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tap" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "tar" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d863878d212c87a19c1a610eb53bb01fe12951c0501cf5a0d65f724914a667a" +dependencies = [ + "filetime", + "libc", + "xattr", +] + [[package]] name = "tempfile" version = "3.20.0" @@ -1639,19 +3418,48 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" dependencies = [ "fastrand", - "getrandom", + "getrandom 0.3.3", "once_cell", "rustix 1.0.7", "windows-sys 0.59.0", ] +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + [[package]] name = "thiserror" version = "2.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" dependencies = [ - "thiserror-impl", + "thiserror-impl 2.0.12", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", ] [[package]] @@ -1705,6 +3513,16 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinystr" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d4f6d1145dcb577acf783d4e601bc1d76a13337bb54e6233add580b07344c8b" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.9.0" @@ -1749,6 +3567,50 @@ dependencies = [ "syn 2.0.101", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-retry" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f57eb36ecbe0fc510036adff84824dd3c24bb781e21bfa67b69d556aa85214f" +dependencies = [ + "pin-project", + "rand", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e727b36a1a0e8b74c376ac2211e40c2c8af09fb4013c60d910495810f008e9b" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66a539a9ad6d5d281510d5bd368c973d636c02dbf8a67300bfb6b950696ad7df" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + [[package]] name = "toml_datetime" version = "0.6.9" @@ -1766,6 +3628,33 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + [[package]] name = "tracing" version = "0.1.41" @@ -1789,59 +3678,143 @@ dependencies = [ ] [[package]] -name = "tracing-core" -version = "0.1.33" +name = "tracing-core" +version = "0.1.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + +[[package]] +name = "untrusted" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d1a66277ed75f640d608235660df48c8e3c19f3b4edb6a263315626cc3c01d" dependencies = [ + "base64 0.22.1", + "flate2", + "log", "once_cell", + "rustls", + "rustls-pki-types", + "url", + "webpki-roots 0.26.11", ] [[package]] -name = "typenum" -version = "1.18.0" +name = "uriparse" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dccffe3ce07af9386bfd29e80c0ab1a8205a2fc34e4bcd40364df902cfa8f3f" +checksum = "0200d0fc04d809396c2ad43f3c95da3582a2556eba8d453c1087f4120ee352ff" +dependencies = [ + "fnv", + "lazy_static", +] [[package]] -name = "uint" -version = "0.9.5" +name = "url" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ - "byteorder", - "crunchy", - "hex", - "static_assertions", + "form_urlencoded", + "idna", + "percent-encoding", + "serde", ] [[package]] -name = "unicode-ident" -version = "1.0.18" +name = "utf8_iter" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" [[package]] -name = "unsafe-libyaml" -version = "0.2.11" +name = "uuid" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" +checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" [[package]] name = "validator-voting" version = "0.1.0" dependencies = [ "near-sdk", + "near-workspaces", "serde_json", "tokio", ] +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1883,6 +3856,19 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.100" @@ -1915,6 +3901,80 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "wasm-opt" +version = "0.116.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd87a4c135535ffed86123b6fb0f0a5a0bc89e50416c942c5f0662c645f679c" +dependencies = [ + "anyhow", + "libc", + "strum 0.24.1", + "strum_macros 0.24.3", + "tempfile", + "thiserror 1.0.69", + "wasm-opt-cxx-sys", + "wasm-opt-sys", +] + +[[package]] +name = "wasm-opt-cxx-sys" +version = "0.116.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c57b28207aa724318fcec6575fe74803c23f6f266fce10cbc9f3f116762f12e" +dependencies = [ + "anyhow", + "cxx", + "cxx-build", + "wasm-opt-sys", +] + +[[package]] +name = "wasm-opt-sys" +version = "0.116.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a1cce564dc768dacbdb718fc29df2dba80bd21cb47d8f77ae7e3d95ceb98cbe" +dependencies = [ + "anyhow", + "cc", + "cxx", + "cxx-build", +] + +[[package]] +name = "wasmparser" +version = "0.83.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "718ed7c55c2add6548cca3ddd6383d738cd73b892df400e96b9aa876f0141d7a" + +[[package]] +name = "web-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "0.26.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521bc38abb08001b01866da9f51eb7c5d647a19260e00054a8c7fd5f9e57f7a9" +dependencies = [ + "webpki-roots 1.0.0", +] + +[[package]] +name = "webpki-roots" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2853738d1cc4f2da3a225c18ec6c3721abb31961096e9dbf5ab35fa88b19cfdb" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "wee_alloc" version = "0.4.5" @@ -1943,6 +4003,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -1959,7 +4028,7 @@ dependencies = [ "windows-interface", "windows-link", "windows-result", - "windows-strings", + "windows-strings 0.4.0", ] [[package]] @@ -1990,6 +4059,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38" +[[package]] +name = "windows-registry" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3" +dependencies = [ + "windows-result", + "windows-strings 0.3.1", + "windows-targets 0.53.0", +] + [[package]] name = "windows-result" version = "0.3.2" @@ -1999,6 +4079,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-strings" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-strings" version = "0.4.0" @@ -2014,7 +4103,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -2023,7 +4112,7 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", ] [[package]] @@ -2032,14 +4121,30 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b" +dependencies = [ + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", ] [[package]] @@ -2048,48 +4153,96 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + [[package]] name = "winnow" version = "0.7.10" @@ -2105,9 +4258,15 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" dependencies = [ - "bitflags", + "bitflags 2.9.0", ] +[[package]] +name = "writeable" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" + [[package]] name = "wyz" version = "0.5.1" @@ -2117,6 +4276,87 @@ dependencies = [ "tap", ] +[[package]] +name = "xattr" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d65cbf2f12c15564212d48f4e3dfb87923d25d611f2aed18f4cb23f0413d89e" +dependencies = [ + "libc", + "rustix 1.0.7", +] + +[[package]] +name = "xml-rs" +version = "0.8.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62ce76d9b56901b19a74f19431b0d8b3bc7ca4ad685a746dfd78ca8f4fc6bda" + +[[package]] +name = "yoke" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", + "synstructure", +] + +[[package]] +name = "zerocopy" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1702d9583232ddb9174e01bb7c15a2ab8fb1bc6f227aa1233858c351a3ba0cb" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28a6e20d751156648aa063f3800b706ee209a32c0b4d9f24be3d980b01be55ef" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", + "synstructure", +] + [[package]] name = "zeroize" version = "1.8.1" @@ -2150,13 +4390,97 @@ dependencies = [ "rustc-hex", ] +[[package]] +name = "zerotrie" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a05eb080e015ba39cc9e23bbe5e7fb04d5fb040350f99f34e338d5fdd294428" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.101", +] + +[[package]] +name = "zip" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815" +dependencies = [ + "byteorder", + "crc32fast", + "flate2", + "thiserror 1.0.69", +] + +[[package]] +name = "zip" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "760394e246e4c28189f19d488c058bf16f564016aefac5d32bb1f3b51d5e9261" +dependencies = [ + "aes", + "byteorder", + "bzip2", + "constant_time_eq", + "crc32fast", + "crossbeam-utils", + "flate2", + "hmac", + "pbkdf2", + "sha1", + "time", + "zstd 0.11.2+zstd.1.5.2", +] + +[[package]] +name = "zstd" +version = "0.11.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20cc960326ece64f010d2d2107537f26dc589a6573a316bd5b1dba685fa5fde4" +dependencies = [ + "zstd-safe 5.0.2+zstd.1.5.2", +] + [[package]] name = "zstd" version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a" dependencies = [ - "zstd-safe", + "zstd-safe 7.2.4", +] + +[[package]] +name = "zstd-safe" +version = "5.0.2+zstd.1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d2a5585e04f9eea4b2a3d1eca508c4dee9592a89ef6f450c11719da0726f4db" +dependencies = [ + "libc", + "zstd-sys", ] [[package]] From f94126b374946f1c9827a1e7ea1bd9dc37a00901 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Thu, 15 May 2025 05:36:55 +0000 Subject: [PATCH 06/36] style: format code --- tests/test_basics.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/test_basics.rs b/tests/test_basics.rs index cca38e5..3c110a3 100644 --- a/tests/test_basics.rs +++ b/tests/test_basics.rs @@ -18,7 +18,8 @@ async fn test_initialization(contract_wasm: &[u8]) -> Result<(), Box Result<(), Box()?, deadline_timestamp_ms); let contract_proposal = contract.view("get_proposal").args_json(json!({})).await?; @@ -40,7 +44,11 @@ async fn test_initialization(contract_wasm: &[u8]) -> Result<(), Box Date: Thu, 15 May 2025 07:14:13 +0000 Subject: [PATCH 07/36] test: refactor test utils --- tests/test_basics.rs | 54 -------------------------------------------- tests/test_init.rs | 23 +++++++++++++++++++ tests/test_vote.rs | 23 +++++++++++++++++++ tests/utils/mod.rs | 35 ++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 54 deletions(-) delete mode 100644 tests/test_basics.rs create mode 100644 tests/test_init.rs create mode 100644 tests/test_vote.rs create mode 100644 tests/utils/mod.rs diff --git a/tests/test_basics.rs b/tests/test_basics.rs deleted file mode 100644 index 3c110a3..0000000 --- a/tests/test_basics.rs +++ /dev/null @@ -1,54 +0,0 @@ -use serde_json::json; -use std::time::{SystemTime, UNIX_EPOCH}; - -#[tokio::test] -async fn test_contract_is_operational() -> Result<(), Box> { - let contract_wasm = near_workspaces::compile_project("./").await?; - - test_initialization(&contract_wasm).await?; - Ok(()) -} - -async fn test_initialization(contract_wasm: &[u8]) -> Result<(), Box> { - let sandbox = near_workspaces::sandbox().await?; - let contract = sandbox.dev_deploy(contract_wasm).await?; - - // Initialize contract - let proposal = "test_proposal"; - let deadline_timestamp_ms = (SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis() - + 10 * 60 * 1000) as u64; - let _ = contract - .call("new") - .args_json(json!({ - "proposal": proposal, - "deadline_timestamp_ms": deadline_timestamp_ms, - })) - .transact() - .await?; - - let contract_deadline = contract - .view("get_deadline_timestamp") - .args_json(json!({})) - .await?; - assert_eq!(contract_deadline.json::()?, deadline_timestamp_ms); - - let contract_proposal = contract.view("get_proposal").args_json(json!({})).await?; - assert_eq!(contract_proposal.json::()?, proposal); - - let user_account = sandbox.dev_create_account().await?; - let outcome = user_account - .call(contract.id(), "vote") - .args_json(json!({"is_vote": true})) - .transact() - .await?; - assert!( - outcome.is_failure(), - "{:#?}", - outcome.into_result().unwrap_err() - ); - - Ok(()) -} diff --git a/tests/test_init.rs b/tests/test_init.rs new file mode 100644 index 0000000..c77252a --- /dev/null +++ b/tests/test_init.rs @@ -0,0 +1,23 @@ +use serde_json::json; + +mod utils; +use utils::*; + +#[tokio::test] +async fn test_initialization() -> Result<(), Box> { + let (contract, _, init_args) = deploy_voting_contract().await?; + + let contract_deadline = contract + .view("get_deadline_timestamp") + .args_json(json!({})) + .await?; + assert_eq!( + contract_deadline.json::()?, + init_args.deadline_timestamp_ms + ); + + let contract_proposal = contract.view("get_proposal").args_json(json!({})).await?; + assert_eq!(contract_proposal.json::()?, init_args.proposal); + + Ok(()) +} diff --git a/tests/test_vote.rs b/tests/test_vote.rs new file mode 100644 index 0000000..d7f0cec --- /dev/null +++ b/tests/test_vote.rs @@ -0,0 +1,23 @@ +use serde_json::json; + +mod utils; +use utils::*; + +#[tokio::test] +async fn test_non_validator_cannot_vote() -> Result<(), Box> { + let (contract, sandbox, _) = deploy_voting_contract().await?; + + let user_account = sandbox.dev_create_account().await?; + let outcome = user_account + .call(contract.id(), "vote") + .args_json(json!({"is_vote": true})) + .transact() + .await?; + assert!( + outcome.is_failure(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + Ok(()) +} diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs new file mode 100644 index 0000000..badcda9 --- /dev/null +++ b/tests/utils/mod.rs @@ -0,0 +1,35 @@ +use near_sdk::near; +use near_workspaces::{network::Sandbox, Contract, Worker}; +use serde_json::json; +use std::time::{SystemTime, UNIX_EPOCH}; + +#[near(serializers = [json])] +pub struct InitArgs { + pub proposal: String, + pub deadline_timestamp_ms: u64, +} + +pub async fn deploy_voting_contract( +) -> Result<(Contract, Worker, InitArgs), Box> { + let contract_wasm = near_workspaces::compile_project("./").await?; + let sandbox = near_workspaces::sandbox().await?; + let contract = sandbox.dev_deploy(&contract_wasm).await?; + + // Initialize contract + let init_args = InitArgs { + proposal: "test_proposal".to_string(), + deadline_timestamp_ms: (SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() + + 10 * 60 * 1000) as u64, + }; + + let _ = contract + .call("new") + .args_json(json!(init_args)) + .transact() + .await?; + + Ok((contract, sandbox, init_args)) +} From 4f965aadb5c93da13fcfda55fcaea7800c0a40a5 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Thu, 15 May 2025 08:13:33 +0000 Subject: [PATCH 08/36] test: mock staking pool contract --- .gitignore | 2 +- tests/contracts/mock-staking-pool/Cargo.lock | 425 +++++++++++++++++++ tests/contracts/mock-staking-pool/Cargo.toml | 20 + tests/contracts/mock-staking-pool/src/lib.rs | 90 ++++ 4 files changed, 536 insertions(+), 1 deletion(-) create mode 100644 tests/contracts/mock-staking-pool/Cargo.lock create mode 100644 tests/contracts/mock-staking-pool/Cargo.toml create mode 100644 tests/contracts/mock-staking-pool/src/lib.rs diff --git a/.gitignore b/.gitignore index ea8c4bf..b60de5b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -/target +**/target diff --git a/tests/contracts/mock-staking-pool/Cargo.lock b/tests/contracts/mock-staking-pool/Cargo.lock new file mode 100644 index 0000000..629fdd5 --- /dev/null +++ b/tests/contracts/mock-staking-pool/Cargo.lock @@ -0,0 +1,425 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "borsh" +version = "1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8646f98db542e39fc66e68a20b2144f6a732636df7c2354e74645faaa433ce" +dependencies = [ + "borsh-derive", + "cfg_aliases", +] + +[[package]] +name = "borsh-derive" +version = "1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdd1d3c0c2f5833f22386f252fe8ed005c7f59fdcddeef025c01b4c3b9fd9ac3" +dependencies = [ + "once_cell", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "darling" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" +dependencies = [ + "darling_core", + "quote", + "syn", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "hashbrown" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "indexmap" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" + +[[package]] +name = "libc" +version = "0.2.172" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "mock-staing-pool" +version = "0.1.0" +dependencies = [ + "near-sdk", +] + +[[package]] +name = "near-account-id" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ed69d94899cfdfba16182bd681ad9e6b7f888e29532b04c56da9ae05a4c5bc4" +dependencies = [ + "borsh", + "serde", +] + +[[package]] +name = "near-gas" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180edcc7dc2fac41f93570d0c7b759c1b6d492f6ad093d749d644a40b4310a97" +dependencies = [ + "borsh", + "serde", +] + +[[package]] +name = "near-sdk" +version = "5.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad9bb847fb4458b00b64e28c4a7adac5d0658603d988c4b4d12eb18104767b80" +dependencies = [ + "base64", + "borsh", + "bs58", + "near-account-id", + "near-gas", + "near-sdk-macros", + "near-sys", + "near-token", + "once_cell", + "serde", + "serde_json", + "wee_alloc", +] + +[[package]] +name = "near-sdk-macros" +version = "5.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0562cf707a41f2f71976f2baa48989369175a96e75b65a4297c815f49327bde" +dependencies = [ + "Inflector", + "darling", + "proc-macro2", + "quote", + "serde", + "serde_json", + "strum", + "strum_macros", + "syn", +] + +[[package]] +name = "near-sys" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ee6acd2229cde1f13daabca434022900ab371d2c19de6be6a5a0497dc942ef7" + +[[package]] +name = "near-token" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd3e60aa26a74dc514b1b6408fdd06cefe2eb0ff029020956c1c6517594048fd" +dependencies = [ + "borsh", + "serde", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "proc-macro-crate" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro2" +version = "1.0.95" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustversion" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" + +[[package]] +name = "ryu" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" + +[[package]] +name = "serde" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.219" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.140" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + +[[package]] +name = "strum" +version = "0.26.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" + +[[package]] +name = "strum_macros" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.101" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tinyvec" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09b3661f17e86524eccd4371ab0429194e0d7c008abb45f7a7495b1719463c71" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "toml_datetime" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" + +[[package]] +name = "toml_edit" +version = "0.22.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if", + "libc", + "memory_units", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "winnow" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" +dependencies = [ + "memchr", +] diff --git a/tests/contracts/mock-staking-pool/Cargo.toml b/tests/contracts/mock-staking-pool/Cargo.toml new file mode 100644 index 0000000..9ee2e4f --- /dev/null +++ b/tests/contracts/mock-staking-pool/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "mock-staing-pool" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +near-sdk = "5.12.0" + +[profile.release] +codegen-units = 1 +# Tell `rustc` to optimize for small code size. +opt-level = "z" +lto = true +debug = false +panic = "abort" +# Opt into extra safety checks on arithmetic operations https://stackoverflow.com/a/64136471/249801 +overflow-checks = true diff --git a/tests/contracts/mock-staking-pool/src/lib.rs b/tests/contracts/mock-staking-pool/src/lib.rs new file mode 100644 index 0000000..f871720 --- /dev/null +++ b/tests/contracts/mock-staking-pool/src/lib.rs @@ -0,0 +1,90 @@ +use near_sdk::{near, env, AccountId, Gas, require, ext_contract, PublicKey, Promise, BorshStorageKey, NearToken, PanicOnDefault}; +use near_sdk::store::LookupMap; +use near_sdk::json_types::U128; + +type Balance = u128; + +const VOTE_GAS: Gas = Gas::from_tgas(100); + +#[ext_contract(ext_voting)] +trait VotingContract { + fn vote(&mut self, is_vote: bool); +} + +#[near] +#[derive(BorshStorageKey)] +pub enum Prefix { + Accounts +} + +#[near(contract_state)] +#[derive(PanicOnDefault)] +struct MockStakingPool { + owner_id: AccountId, + stake_public_key: PublicKey, + accounts: LookupMap, + total_staked_balance: Balance, +} + +#[near] +impl MockStakingPool { + #[init] + #[private] + pub fn new(owner_id: AccountId, stake_public_key: PublicKey) -> Self { + Self { + owner_id, + stake_public_key, + accounts: LookupMap::new(Prefix::Accounts), + total_staked_balance: 0, + } + } + + #[payable] + pub fn stake(&mut self) { + let amount = env::attached_deposit().as_yoctonear(); + require!(amount > 0u128, "Invalid stake amount"); + + let account_id = env::predecessor_account_id(); + let balance = self.internal_account_staked_balance(&account_id); + self.accounts.insert(account_id, balance + amount); + self.total_staked_balance += amount; + + self.internal_restake(); + } + + pub fn unstake(&mut self, amount: U128) { + let amount = amount.0; + require!(amount > 0u128, "Invalid unstake amount"); + + let account_id = env::predecessor_account_id(); + let balance = self.internal_account_staked_balance(&account_id); + require!(balance >= amount, "Not enough stake"); + + self.accounts.insert(account_id, balance - amount); + self.total_staked_balance -= amount; + + self.internal_restake(); + } + + /// Owner's method. + /// Calls `vote(is_vote)` on the given voting contract account ID on behalf of the pool. + pub fn vote(&mut self, voting_account_id: AccountId, is_vote: bool) -> Promise { + self.assert_owner(); + ext_voting::ext(voting_account_id) + .with_static_gas(VOTE_GAS) + .vote(is_vote) + } + + fn internal_account_staked_balance(&self, account_id: &AccountId) -> Balance { + *self.accounts.get(account_id).unwrap_or(&0u128) + } + + fn internal_restake(&self) { + Promise::new(env::current_account_id()) + .stake(NearToken::from_yoctonear(self.total_staked_balance), self.stake_public_key.clone()); + } + + fn assert_owner(&self) { + require!(env::predecessor_account_id() == self.owner_id, "Not owner"); + } +} From 94ace616b16cc094ec54994404d229d20710b260 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Thu, 15 May 2025 10:18:58 +0000 Subject: [PATCH 09/36] test: simple vote with mock staking pool --- tests/contracts/mock-staking-pool/src/lib.rs | 32 ++++++--- tests/test_init.rs | 3 +- tests/test_vote.rs | 46 +++++++++++- tests/utils/mod.rs | 76 +++++++++++++++++--- 4 files changed, 136 insertions(+), 21 deletions(-) diff --git a/tests/contracts/mock-staking-pool/src/lib.rs b/tests/contracts/mock-staking-pool/src/lib.rs index f871720..f13bb9f 100644 --- a/tests/contracts/mock-staking-pool/src/lib.rs +++ b/tests/contracts/mock-staking-pool/src/lib.rs @@ -1,6 +1,9 @@ -use near_sdk::{near, env, AccountId, Gas, require, ext_contract, PublicKey, Promise, BorshStorageKey, NearToken, PanicOnDefault}; -use near_sdk::store::LookupMap; use near_sdk::json_types::U128; +use near_sdk::store::LookupMap; +use near_sdk::{ + env, ext_contract, near, require, AccountId, BorshStorageKey, Gas, NearToken, PanicOnDefault, + Promise, PublicKey, +}; type Balance = u128; @@ -14,7 +17,7 @@ trait VotingContract { #[near] #[derive(BorshStorageKey)] pub enum Prefix { - Accounts + Accounts, } #[near(contract_state)] @@ -40,7 +43,7 @@ impl MockStakingPool { } #[payable] - pub fn stake(&mut self) { + pub fn stake(&mut self) -> Promise { let amount = env::attached_deposit().as_yoctonear(); require!(amount > 0u128, "Invalid stake amount"); @@ -49,10 +52,10 @@ impl MockStakingPool { self.accounts.insert(account_id, balance + amount); self.total_staked_balance += amount; - self.internal_restake(); + self.internal_restake() } - pub fn unstake(&mut self, amount: U128) { + pub fn unstake(&mut self, amount: U128) -> Promise { let amount = amount.0; require!(amount > 0u128, "Invalid unstake amount"); @@ -63,7 +66,7 @@ impl MockStakingPool { self.accounts.insert(account_id, balance - amount); self.total_staked_balance -= amount; - self.internal_restake(); + self.internal_restake() } /// Owner's method. @@ -75,13 +78,22 @@ impl MockStakingPool { .vote(is_vote) } + pub fn get_staked_balance(&self) -> (U128, U128) { + ( + U128::from(env::validator_stake(&env::current_account_id()).as_yoctonear()), + U128::from(self.total_staked_balance) + ) + } + fn internal_account_staked_balance(&self, account_id: &AccountId) -> Balance { *self.accounts.get(account_id).unwrap_or(&0u128) } - fn internal_restake(&self) { - Promise::new(env::current_account_id()) - .stake(NearToken::from_yoctonear(self.total_staked_balance), self.stake_public_key.clone()); + fn internal_restake(&self) -> Promise { + Promise::new(env::current_account_id()).stake( + NearToken::from_yoctonear(self.total_staked_balance), + self.stake_public_key.clone(), + ) } fn assert_owner(&self) { diff --git a/tests/test_init.rs b/tests/test_init.rs index c77252a..673c5e9 100644 --- a/tests/test_init.rs +++ b/tests/test_init.rs @@ -5,7 +5,8 @@ use utils::*; #[tokio::test] async fn test_initialization() -> Result<(), Box> { - let (contract, _, init_args) = deploy_voting_contract().await?; + let sandbox = near_workspaces::sandbox().await?; + let (contract, init_args) = deploy_voting_contract(&sandbox).await?; let contract_deadline = contract .view("get_deadline_timestamp") diff --git a/tests/test_vote.rs b/tests/test_vote.rs index d7f0cec..38a7399 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -1,3 +1,4 @@ +use near_sdk::{Gas, NearToken}; use serde_json::json; mod utils; @@ -5,8 +6,10 @@ use utils::*; #[tokio::test] async fn test_non_validator_cannot_vote() -> Result<(), Box> { - let (contract, sandbox, _) = deploy_voting_contract().await?; + let sandbox = near_workspaces::sandbox().await?; + let (contract, _) = deploy_voting_contract(&sandbox).await?; + let sandbox = near_workspaces::sandbox().await?; let user_account = sandbox.dev_create_account().await?; let outcome = user_account .call(contract.id(), "vote") @@ -21,3 +24,44 @@ async fn test_non_validator_cannot_vote() -> Result<(), Box Result<(), Box> { + let (staking_pool_contract, voting_contract, sandbox, owner) = setup_env().await?; + + let alice = create_account(&sandbox, "alice", 10000).await?; + let outcome = alice + .call(staking_pool_contract.id(), "stake") + .args_json(json!({})) + .deposit(NearToken::from_near(1000)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + let staked_balance = staking_pool_contract + .view("get_staked_balance") + .args_json(json!({})) + .await?; + println!("user account: {}, {:#?}", alice.id(), staked_balance.json::<(String, String)>()?); + + let outcome = owner + .call(staking_pool_contract.id(), "vote") + .args_json(json!({ + "voting_account_id": voting_contract.id(), + "is_vote": true + })) + .gas(Gas::from_tgas(200)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + Ok(()) +} diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index badcda9..89c468e 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -1,22 +1,32 @@ -use near_sdk::near; -use near_workspaces::{network::Sandbox, Contract, Worker}; +use near_sdk::{near, AccountId, NearToken, PublicKey}; +use near_workspaces::{network::Sandbox, Account, Contract, Worker}; use serde_json::json; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::{ + str::FromStr, + time::{SystemTime, UNIX_EPOCH}, +}; #[near(serializers = [json])] -pub struct InitArgs { +pub struct VotingInitArgs { pub proposal: String, pub deadline_timestamp_ms: u64, } +#[near(serializers = [json])] +pub struct MockStakingPoolInitArgs { + pub owner_id: AccountId, + pub stake_public_key: PublicKey, +} + pub async fn deploy_voting_contract( -) -> Result<(Contract, Worker, InitArgs), Box> { + sandbox: &Worker, +) -> Result<(Contract, VotingInitArgs), Box> { let contract_wasm = near_workspaces::compile_project("./").await?; - let sandbox = near_workspaces::sandbox().await?; - let contract = sandbox.dev_deploy(&contract_wasm).await?; + let contract_account = create_account(sandbox, "voting", 100).await?; + let contract = contract_account.deploy(&contract_wasm).await?.result; // Initialize contract - let init_args = InitArgs { + let init_args = VotingInitArgs { proposal: "test_proposal".to_string(), deadline_timestamp_ms: (SystemTime::now() .duration_since(UNIX_EPOCH) @@ -31,5 +41,53 @@ pub async fn deploy_voting_contract( .transact() .await?; - Ok((contract, sandbox, init_args)) + Ok((contract, init_args)) +} + +pub async fn deploy_mock_staking_pool_contract( + sandbox: &Worker, +) -> Result<(Contract, Account, MockStakingPoolInitArgs), Box> { + let contract_wasm = + near_workspaces::compile_project("./tests/contracts/mock-staking-pool").await?; + let contract_account = create_account(sandbox, "stakign-pool", 100).await?; + let contract = contract_account.deploy(&contract_wasm).await?.result; + + let owner = create_account(sandbox, "owner", 10000).await?; + let init_args = MockStakingPoolInitArgs { + owner_id: owner.id().clone(), + stake_public_key: PublicKey::from_str( + "ed25519:6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp", + ) + .unwrap(), + }; + let _ = contract + .call("new") + .args_json(json!(init_args)) + .transact() + .await?; + + Ok((contract, owner, init_args)) +} + +pub async fn setup_env( +) -> Result<(Contract, Contract, Worker, Account), Box> { + let sandbox = near_workspaces::sandbox().await?; + let (staking_pool_contract, owner, _) = deploy_mock_staking_pool_contract(&sandbox).await?; + let (voting_contract, _) = deploy_voting_contract(&sandbox).await?; + + Ok((staking_pool_contract, voting_contract, sandbox, owner)) +} + +pub async fn create_account( + sandbox: &Worker, + prefix: &str, + balance: u128, +) -> Result> { + let root = sandbox.root_account().unwrap(); + Ok(root + .create_subaccount(prefix) + .initial_balance(NearToken::from_near(balance)) + .transact() + .await? + .result) } From e3bf88b7095fd760426743a71a722787acac47dd Mon Sep 17 00:00:00 2001 From: Linguists B Date: Thu, 15 May 2025 10:21:46 +0000 Subject: [PATCH 10/36] style: cargo fmt --- tests/test_vote.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 38a7399..4b4f412 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -46,7 +46,11 @@ async fn test_simple_vote() -> Result<(), Box> { .view("get_staked_balance") .args_json(json!({})) .await?; - println!("user account: {}, {:#?}", alice.id(), staked_balance.json::<(String, String)>()?); + println!( + "user account: {}, {:#?}", + alice.id(), + staked_balance.json::<(String, String)>()? + ); let outcome = owner .call(staking_pool_contract.id(), "vote") From ccd21be0cd78c340310df7997e03c0446ebdcb38 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Fri, 16 May 2025 04:08:43 +0000 Subject: [PATCH 11/36] test: view validate stake after stake --- tests/contracts/mock-staking-pool/src/lib.rs | 36 +++++++++++++++----- tests/test_vote.rs | 2 +- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/tests/contracts/mock-staking-pool/src/lib.rs b/tests/contracts/mock-staking-pool/src/lib.rs index f13bb9f..0cffc84 100644 --- a/tests/contracts/mock-staking-pool/src/lib.rs +++ b/tests/contracts/mock-staking-pool/src/lib.rs @@ -1,13 +1,14 @@ use near_sdk::json_types::U128; use near_sdk::store::LookupMap; use near_sdk::{ - env, ext_contract, near, require, AccountId, BorshStorageKey, Gas, NearToken, PanicOnDefault, - Promise, PublicKey, + env, ext_contract, log, near, require, AccountId, BorshStorageKey, Gas, NearToken, + PanicOnDefault, Promise, PromiseError, PublicKey, }; type Balance = u128; const VOTE_GAS: Gas = Gas::from_tgas(100); +const STAKE_CALLBACK_GAS: Gas = Gas::from_tgas(5); #[ext_contract(ext_voting)] trait VotingContract { @@ -43,7 +44,7 @@ impl MockStakingPool { } #[payable] - pub fn stake(&mut self) -> Promise { + pub fn deposit_and_stake(&mut self) -> Promise { let amount = env::attached_deposit().as_yoctonear(); require!(amount > 0u128, "Invalid stake amount"); @@ -81,19 +82,38 @@ impl MockStakingPool { pub fn get_staked_balance(&self) -> (U128, U128) { ( U128::from(env::validator_stake(&env::current_account_id()).as_yoctonear()), - U128::from(self.total_staked_balance) + U128::from(self.total_staked_balance), ) } + #[private] + pub fn on_stake_action(&self, #[callback_result] result: Result) { + if result.is_err() { + log!("Stake action failed"); + return; + } + + log!( + "Validator stake amount: {}", + env::validator_stake(&env::current_account_id()) + ); + } + fn internal_account_staked_balance(&self, account_id: &AccountId) -> Balance { *self.accounts.get(account_id).unwrap_or(&0u128) } fn internal_restake(&self) -> Promise { - Promise::new(env::current_account_id()).stake( - NearToken::from_yoctonear(self.total_staked_balance), - self.stake_public_key.clone(), - ) + Promise::new(env::current_account_id()) + .stake( + NearToken::from_yoctonear(self.total_staked_balance), + self.stake_public_key.clone(), + ) + .then( + Self::ext(env::current_account_id()) + .with_static_gas(STAKE_CALLBACK_GAS) + .on_stake_action(), + ) } fn assert_owner(&self) { diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 4b4f412..36e9de2 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -31,7 +31,7 @@ async fn test_simple_vote() -> Result<(), Box> { let alice = create_account(&sandbox, "alice", 10000).await?; let outcome = alice - .call(staking_pool_contract.id(), "stake") + .call(staking_pool_contract.id(), "deposit_and_stake") .args_json(json!({})) .deposit(NearToken::from_near(1000)) .transact() From ad7672b372919905f3ccb1b460b2c2b83d7dbd7f Mon Sep 17 00:00:00 2001 From: Linguists B Date: Fri, 16 May 2025 04:31:45 +0000 Subject: [PATCH 12/36] chore: rust version 1.86.0 --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index a82ade3..24238bd 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "stable" +channel = "1.86.0" components = ["rustfmt"] targets = ["wasm32-unknown-unknown"] From 5860416b86da186c4f0884c2d21f61216e59a933 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Fri, 16 May 2025 04:57:04 +0000 Subject: [PATCH 13/36] fix: callback function --- tests/contracts/mock-staking-pool/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/contracts/mock-staking-pool/src/lib.rs b/tests/contracts/mock-staking-pool/src/lib.rs index 0cffc84..d0bd4c1 100644 --- a/tests/contracts/mock-staking-pool/src/lib.rs +++ b/tests/contracts/mock-staking-pool/src/lib.rs @@ -87,7 +87,7 @@ impl MockStakingPool { } #[private] - pub fn on_stake_action(&self, #[callback_result] result: Result) { + pub fn on_stake_action(&self, #[callback_result] result: Result<(), PromiseError>) { if result.is_err() { log!("Stake action failed"); return; From 3d39015094e18d9beecd61dfa70c193dd355d3eb Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Mon, 19 May 2025 14:38:26 +0800 Subject: [PATCH 14/36] refactor: test --- .gitignore | 2 + Cargo.toml | 4 ++ makefile | 25 ++++++++ src/events.rs | 2 +- src/lib.rs | 37 ++++++++---- src/utils.rs | 47 +++++++++++++++ tests/contracts/mock-staking-pool/Cargo.lock | 2 +- tests/contracts/mock-staking-pool/Cargo.toml | 2 +- tests/contracts/mock-staking-pool/src/lib.rs | 63 ++++++++++---------- tests/test_vote.rs | 11 ++-- tests/utils/mod.rs | 10 +++- 11 files changed, 154 insertions(+), 51 deletions(-) create mode 100644 makefile create mode 100644 src/utils.rs diff --git a/.gitignore b/.gitignore index b60de5b..a4e7216 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ **/target +tests/res +res diff --git a/Cargo.toml b/Cargo.toml index 1d1b6ec..2dfe36d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,10 @@ near-workspaces = { version = "0.18", features = ["unstable"] } tokio = { version = "1.12.0", features = ["full"] } serde_json = "1" +[features] +default = [] +integration-test = [] + [profile.release] codegen-units = 1 # Tell `rustc` to optimize for small code size. diff --git a/makefile b/makefile new file mode 100644 index 0000000..69a4a7e --- /dev/null +++ b/makefile @@ -0,0 +1,25 @@ +RUSTFLAGS = "-C link-arg=-s" + +all: validator-voting validator-voting-integration-test + +lint: + @cargo fmt --all + @cargo clippy --fix --allow-dirty --allow-staged + +validator-voting: + $(call compile-release,validator-voting) + @mkdir -p res + @cp target/wasm32-unknown-unknown/release/validator_voting.wasm ./res/validator_voting.wasm + +validator-voting-integration-test: + $(call compile-release,validator-voting,integration-test) + @mkdir -p tests/res + @cp target/wasm32-unknown-unknown/release/validator_voting.wasm ./tests/res/validator_voting.wasm + +test: + @cargo test + +define compile-release + @rustup target add wasm32-unknown-unknown + RUSTFLAGS=$(RUSTFLAGS) cargo build --package $(1) --target wasm32-unknown-unknown --release $(if $(2),--features $(2)) +endef diff --git a/src/events.rs b/src/events.rs index dc92734..9b3c1f9 100644 --- a/src/events.rs +++ b/src/events.rs @@ -31,7 +31,7 @@ pub enum Event<'a> { }, } -impl<'a> Event<'a> { +impl Event<'_> { pub fn emit(&self) { let json = json!(self); let event_json = json!({ diff --git a/src/lib.rs b/src/lib.rs index 890a4a0..b5e233d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,11 @@ +mod events; +mod utils; + +use events::Event; use near_sdk::json_types::{U128, U64}; -use near_sdk::{env, near, require, AccountId, EpochHeight}; +use near_sdk::{env, near, require, AccountId, EpochHeight, PanicOnDefault}; use std::collections::HashMap; - -mod events; -use crate::events::Event; +use utils::{validator_stake, validator_total_stake}; /// Balance in yocto NEAR type Balance = u128; @@ -13,7 +15,7 @@ type Timestamp = u64; /// Voting contract for any specific proposal. Once the majority of the stake holders agree to /// the proposal, the time will be recorded and the voting ends. #[near(contract_state)] -#[derive(Default)] +#[derive(PanicOnDefault)] pub struct Contract { proposal: String, deadline_timestamp_ms: Timestamp, @@ -50,7 +52,7 @@ impl Contract { self.ping(); let account_id = env::predecessor_account_id(); let account_stake = if is_vote { - let stake = env::validator_stake(&account_id).as_yoctonear(); + let stake = validator_stake(&account_id); require!(stake > 0, format!("{} is not a validator", account_id)); stake } else { @@ -95,7 +97,7 @@ impl Contract { let votes = std::mem::take(&mut self.votes); self.total_voted_stake = 0; for (account_id, _) in votes { - let account_current_stake = env::validator_stake(&account_id).as_yoctonear(); + let account_current_stake = validator_stake(&account_id); self.total_voted_stake += account_current_stake; if account_current_stake > 0 { self.votes.insert(account_id, account_current_stake); @@ -112,7 +114,7 @@ impl Contract { self.result.is_none(), "check result is called after result is already set" ); - let total_stake = env::validator_total_stake().as_yoctonear(); + let total_stake = validator_total_stake(); if self.total_voted_stake > total_stake * 2 / 3 { self.result = Some(env::block_timestamp_ms()); Event::ProposalApproved { @@ -133,7 +135,7 @@ impl Contract { pub fn get_total_voted_stake(&self) -> (U128, U128) { ( self.total_voted_stake.into(), - env::validator_total_stake().as_yoctonear().into(), + validator_total_stake().into(), ) } @@ -163,6 +165,19 @@ impl Contract { } } +#[near] +impl Contract { + #[cfg(feature = "integration-test")] + pub fn set_validator_stake(&mut self, validator_account_id: AccountId, amount: U128) { + utils::set_validator_stake(validator_account_id, amount.0) + } + + #[cfg(feature = "integration-test")] + pub fn get_validator_stake(&self, validator_account_id: AccountId) -> U128 { + utils::get_validator_stake(&validator_account_id).into() + } +} + #[cfg(test)] mod tests { use super::*; @@ -409,7 +424,7 @@ mod tests { let mut context = get_context(&validator(0)); // vote after deadline - set_context(&context.block_timestamp(env::block_timestamp_ms() + 2000 * 1_000_000)); + set_context(context.block_timestamp(env::block_timestamp_ms() + 2000 * 1_000_000)); contract.vote(true); } @@ -425,7 +440,7 @@ mod tests { // ping at epoch 2 after deadline set_context( - &context + context .block_timestamp(env::block_timestamp_ms() + 2000 * 1_000_000) .epoch_height(2), ); diff --git a/src/utils.rs b/src/utils.rs new file mode 100644 index 0000000..77d1d28 --- /dev/null +++ b/src/utils.rs @@ -0,0 +1,47 @@ +use crate::Balance; + +#[cfg(feature = "integration-test")] +pub fn get_validators() -> std::collections::HashMap { + near_sdk::env::storage_read(b"__validators__") + .map_or_else(std::collections::HashMap::new, |validators| { + near_sdk::borsh::from_slice(&validators).unwrap() + }) +} + +#[cfg(feature = "integration-test")] +pub fn set_validators(validators: std::collections::HashMap) { + near_sdk::env::storage_write( + b"__validators__", + &near_sdk::borsh::to_vec(&validators).unwrap(), + ); +} + +#[cfg(feature = "integration-test")] +pub fn get_validator_stake(validator_account_id: &near_sdk::AccountId) -> Balance { + let validators = get_validators(); + validators + .get(validator_account_id) + .copied() + .unwrap_or_default() +} + +#[cfg(feature = "integration-test")] +pub fn set_validator_stake(validator_account_id: near_sdk::AccountId, amount: Balance) { + let mut validators = get_validators(); + validators.insert(validator_account_id, amount); + set_validators(validators); +} + +pub fn validator_stake(validator_account_id: &near_sdk::AccountId) -> Balance { + #[cfg(feature = "integration-test")] + return get_validator_stake(validator_account_id); + #[cfg(not(feature = "integration-test"))] + near_sdk::env::validator_stake(validator_account_id).as_yoctonear() +} + +pub fn validator_total_stake() -> Balance { + #[cfg(feature = "integration-test")] + return get_validators().values().sum(); + #[cfg(not(feature = "integration-test"))] + near_sdk::env::validator_total_stake().as_yoctonear() +} diff --git a/tests/contracts/mock-staking-pool/Cargo.lock b/tests/contracts/mock-staking-pool/Cargo.lock index 629fdd5..15e82f1 100644 --- a/tests/contracts/mock-staking-pool/Cargo.lock +++ b/tests/contracts/mock-staking-pool/Cargo.lock @@ -157,7 +157,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" [[package]] -name = "mock-staing-pool" +name = "mock-staking-pool" version = "0.1.0" dependencies = [ "near-sdk", diff --git a/tests/contracts/mock-staking-pool/Cargo.toml b/tests/contracts/mock-staking-pool/Cargo.toml index 9ee2e4f..c0caf25 100644 --- a/tests/contracts/mock-staking-pool/Cargo.toml +++ b/tests/contracts/mock-staking-pool/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "mock-staing-pool" +name = "mock-staking-pool" version = "0.1.0" edition = "2021" diff --git a/tests/contracts/mock-staking-pool/src/lib.rs b/tests/contracts/mock-staking-pool/src/lib.rs index d0bd4c1..ed86f64 100644 --- a/tests/contracts/mock-staking-pool/src/lib.rs +++ b/tests/contracts/mock-staking-pool/src/lib.rs @@ -9,10 +9,13 @@ type Balance = u128; const VOTE_GAS: Gas = Gas::from_tgas(100); const STAKE_CALLBACK_GAS: Gas = Gas::from_tgas(5); +const SET_VALIDATOR_STAKE_GAS: Gas = Gas::from_tgas(200); #[ext_contract(ext_voting)] trait VotingContract { fn vote(&mut self, is_vote: bool); + + fn set_validator_stake(validator_account_id: AccountId, amount: U128); } #[near] @@ -28,18 +31,20 @@ struct MockStakingPool { stake_public_key: PublicKey, accounts: LookupMap, total_staked_balance: Balance, + voting_account_id: AccountId, } #[near] impl MockStakingPool { #[init] #[private] - pub fn new(owner_id: AccountId, stake_public_key: PublicKey) -> Self { + pub fn new(owner_id: AccountId, stake_public_key: PublicKey, voting_account_id: AccountId) -> Self { Self { owner_id, stake_public_key, accounts: LookupMap::new(Prefix::Accounts), total_staked_balance: 0, + voting_account_id, } } @@ -73,47 +78,45 @@ impl MockStakingPool { /// Owner's method. /// Calls `vote(is_vote)` on the given voting contract account ID on behalf of the pool. pub fn vote(&mut self, voting_account_id: AccountId, is_vote: bool) -> Promise { + require!(self.voting_account_id == voting_account_id, "Voting account id mismatching"); self.assert_owner(); ext_voting::ext(voting_account_id) .with_static_gas(VOTE_GAS) .vote(is_vote) } - pub fn get_staked_balance(&self) -> (U128, U128) { - ( - U128::from(env::validator_stake(&env::current_account_id()).as_yoctonear()), - U128::from(self.total_staked_balance), - ) - } - - #[private] - pub fn on_stake_action(&self, #[callback_result] result: Result<(), PromiseError>) { - if result.is_err() { - log!("Stake action failed"); - return; - } - - log!( - "Validator stake amount: {}", - env::validator_stake(&env::current_account_id()) - ); - } + // #[private] + // pub fn on_stake_action(&self, #[callback_result] result: Result<(), PromiseError>) { + // if result.is_err() { + // log!("Stake action failed"); + // return; + // } + // + // log!( + // "Validator stake amount: {}", + // env::validator_stake(&env::current_account_id()) + // ); + // } fn internal_account_staked_balance(&self, account_id: &AccountId) -> Balance { *self.accounts.get(account_id).unwrap_or(&0u128) } fn internal_restake(&self) -> Promise { - Promise::new(env::current_account_id()) - .stake( - NearToken::from_yoctonear(self.total_staked_balance), - self.stake_public_key.clone(), - ) - .then( - Self::ext(env::current_account_id()) - .with_static_gas(STAKE_CALLBACK_GAS) - .on_stake_action(), - ) + // Promise::new(env::current_account_id()) + // .stake( + // NearToken::from_yoctonear(self.total_staked_balance), + // self.stake_public_key.clone(), + // ) + // .then( + // Self::ext(env::current_account_id()) + // .with_static_gas(STAKE_CALLBACK_GAS) + // .on_stake_action(), + // ) + + ext_voting::ext(self.voting_account_id.clone()) + .with_static_gas(SET_VALIDATOR_STAKE_GAS) + .set_validator_stake(env::current_account_id(), self.total_staked_balance.into()) } fn assert_owner(&self) { diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 36e9de2..26fb074 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -33,6 +33,7 @@ async fn test_simple_vote() -> Result<(), Box> { let outcome = alice .call(staking_pool_contract.id(), "deposit_and_stake") .args_json(json!({})) + .gas(Gas::from_tgas(250)) .deposit(NearToken::from_near(1000)) .transact() .await?; @@ -42,14 +43,16 @@ async fn test_simple_vote() -> Result<(), Box> { outcome.into_result().unwrap_err() ); - let staked_balance = staking_pool_contract - .view("get_staked_balance") - .args_json(json!({})) + let staked_balance = voting_contract + .view("get_validator_stake") + .args_json(json!({ + "validator_account_id": staking_pool_contract.id() + })) .await?; println!( "user account: {}, {:#?}", alice.id(), - staked_balance.json::<(String, String)>()? + staked_balance.json::()? ); let outcome = owner diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 89c468e..65f7ae1 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -16,14 +16,15 @@ pub struct VotingInitArgs { pub struct MockStakingPoolInitArgs { pub owner_id: AccountId, pub stake_public_key: PublicKey, + pub voting_account_id: AccountId, } pub async fn deploy_voting_contract( sandbox: &Worker, ) -> Result<(Contract, VotingInitArgs), Box> { - let contract_wasm = near_workspaces::compile_project("./").await?; + let contract_wasm = include_bytes!("../res/validator_voting.wasm"); let contract_account = create_account(sandbox, "voting", 100).await?; - let contract = contract_account.deploy(&contract_wasm).await?.result; + let contract = contract_account.deploy(contract_wasm).await?.result; // Initialize contract let init_args = VotingInitArgs { @@ -46,6 +47,7 @@ pub async fn deploy_voting_contract( pub async fn deploy_mock_staking_pool_contract( sandbox: &Worker, + voting_account_id: AccountId, ) -> Result<(Contract, Account, MockStakingPoolInitArgs), Box> { let contract_wasm = near_workspaces::compile_project("./tests/contracts/mock-staking-pool").await?; @@ -59,6 +61,7 @@ pub async fn deploy_mock_staking_pool_contract( "ed25519:6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp", ) .unwrap(), + voting_account_id, }; let _ = contract .call("new") @@ -72,8 +75,9 @@ pub async fn deploy_mock_staking_pool_contract( pub async fn setup_env( ) -> Result<(Contract, Contract, Worker, Account), Box> { let sandbox = near_workspaces::sandbox().await?; - let (staking_pool_contract, owner, _) = deploy_mock_staking_pool_contract(&sandbox).await?; let (voting_contract, _) = deploy_voting_contract(&sandbox).await?; + let (staking_pool_contract, owner, _) = + deploy_mock_staking_pool_contract(&sandbox, voting_contract.id().clone()).await?; Ok((staking_pool_contract, voting_contract, sandbox, owner)) } From 4702ce30ebfb46fd2c37d77917633011eedacabf Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Tue, 20 May 2025 11:26:10 +0800 Subject: [PATCH 15/36] fix: build --- makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/makefile b/makefile index 69a4a7e..3dd9176 100644 --- a/makefile +++ b/makefile @@ -9,17 +9,17 @@ lint: validator-voting: $(call compile-release,validator-voting) @mkdir -p res - @cp target/wasm32-unknown-unknown/release/validator_voting.wasm ./res/validator_voting.wasm + @cp target/near/validator_voting.wasm ./res/validator_voting.wasm validator-voting-integration-test: $(call compile-release,validator-voting,integration-test) @mkdir -p tests/res - @cp target/wasm32-unknown-unknown/release/validator_voting.wasm ./tests/res/validator_voting.wasm + @cp target/near/validator_voting.wasm ./tests/res/validator_voting.wasm test: @cargo test define compile-release @rustup target add wasm32-unknown-unknown - RUSTFLAGS=$(RUSTFLAGS) cargo build --package $(1) --target wasm32-unknown-unknown --release $(if $(2),--features $(2)) + @cargo near build non-reproducible-wasm $(if $(2),--features $(2)) endef From b1b18c37f7b45ddd454964a7ea18f38304c0fa71 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Tue, 20 May 2025 13:47:34 +0800 Subject: [PATCH 16/36] test: vote many --- makefile | 2 +- src/lib.rs | 5 ++ tests/contracts/mock-staking-pool/src/lib.rs | 2 - tests/test_init.rs | 2 +- tests/test_vote.rs | 53 ++++++++++++++++++-- tests/utils/mod.rs | 47 ++++++++++++++++- 6 files changed, 102 insertions(+), 9 deletions(-) diff --git a/makefile b/makefile index 3dd9176..76ed5b4 100644 --- a/makefile +++ b/makefile @@ -17,7 +17,7 @@ validator-voting-integration-test: @cp target/near/validator_voting.wasm ./tests/res/validator_voting.wasm test: - @cargo test + @cargo test -- --nocapture define compile-release @rustup target add wasm32-unknown-unknown diff --git a/src/lib.rs b/src/lib.rs index b5e233d..63ba556 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -176,6 +176,11 @@ impl Contract { pub fn get_validator_stake(&self, validator_account_id: AccountId) -> U128 { utils::get_validator_stake(&validator_account_id).into() } + + #[cfg(feature = "integration-test")] + pub fn get_validator_total_stake(&self) -> U128 { + self.get_validator_total_stake().into() + } } #[cfg(test)] diff --git a/tests/contracts/mock-staking-pool/src/lib.rs b/tests/contracts/mock-staking-pool/src/lib.rs index ed86f64..6a1efb3 100644 --- a/tests/contracts/mock-staking-pool/src/lib.rs +++ b/tests/contracts/mock-staking-pool/src/lib.rs @@ -8,7 +8,6 @@ use near_sdk::{ type Balance = u128; const VOTE_GAS: Gas = Gas::from_tgas(100); -const STAKE_CALLBACK_GAS: Gas = Gas::from_tgas(5); const SET_VALIDATOR_STAKE_GAS: Gas = Gas::from_tgas(200); #[ext_contract(ext_voting)] @@ -115,7 +114,6 @@ impl MockStakingPool { // ) ext_voting::ext(self.voting_account_id.clone()) - .with_static_gas(SET_VALIDATOR_STAKE_GAS) .set_validator_stake(env::current_account_id(), self.total_staked_balance.into()) } diff --git a/tests/test_init.rs b/tests/test_init.rs index 673c5e9..cd74c70 100644 --- a/tests/test_init.rs +++ b/tests/test_init.rs @@ -3,7 +3,7 @@ use serde_json::json; mod utils; use utils::*; -#[tokio::test] +// #[tokio::test] async fn test_initialization() -> Result<(), Box> { let sandbox = near_workspaces::sandbox().await?; let (contract, init_args) = deploy_voting_contract(&sandbox).await?; diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 26fb074..d10b452 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -4,7 +4,7 @@ use serde_json::json; mod utils; use utils::*; -#[tokio::test] +// #[tokio::test] async fn test_non_validator_cannot_vote() -> Result<(), Box> { let sandbox = near_workspaces::sandbox().await?; let (contract, _) = deploy_voting_contract(&sandbox).await?; @@ -18,14 +18,12 @@ async fn test_non_validator_cannot_vote() -> Result<(), Box Result<(), Box> { let (staking_pool_contract, voting_contract, sandbox, owner) = setup_env().await?; @@ -72,3 +70,50 @@ async fn test_simple_vote() -> Result<(), Box> { Ok(()) } + +#[tokio::test] +async fn test_many_votes() -> Result<(), Box> { + let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many(3).await?; + let alice = create_account(&sandbox, "alice", 50000).await?; + + for staking_pool_contract in staking_pool_contracts.iter() { + let outcome = alice + .call(staking_pool_contract.id(), "deposit_and_stake") + .gas(Gas::from_tgas(250)) + .deposit(NearToken::from_near(100)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + let staked_balance = voting_contract + .view("get_validator_total_stake") + .await?; + println!( + "user account: {}, {:#?}", + alice.id(), + staked_balance.json::()? + ); + } + + for staking_pool_contract in staking_pool_contracts.iter() { + let outcome = alice.call(staking_pool_contract.id(), "vote") + .args_json(json!({ + "voting_account_id": voting_contract.id(), + "is_vote": true + })) + .gas(Gas::from_tgas(200)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + } + + Ok(()) +} diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 65f7ae1..5cbfa11 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -51,7 +51,7 @@ pub async fn deploy_mock_staking_pool_contract( ) -> Result<(Contract, Account, MockStakingPoolInitArgs), Box> { let contract_wasm = near_workspaces::compile_project("./tests/contracts/mock-staking-pool").await?; - let contract_account = create_account(sandbox, "stakign-pool", 100).await?; + let contract_account = create_account(sandbox, "staking-pool", 100).await?; let contract = contract_account.deploy(&contract_wasm).await?.result; let owner = create_account(sandbox, "owner", 10000).await?; @@ -72,6 +72,40 @@ pub async fn deploy_mock_staking_pool_contract( Ok((contract, owner, init_args)) } +pub async fn deploy_mock_staking_pool_contracts( + sandbox: &Worker, + voting_account_id: AccountId, + num: usize, +) -> Result<(Vec, Account, MockStakingPoolInitArgs), Box> { + let contract_wasm = + near_workspaces::compile_project("./tests/contracts/mock-staking-pool").await?; + + let owner = create_account(sandbox, "owner", 10000).await?; + let init_args = MockStakingPoolInitArgs { + owner_id: owner.id().clone(), + stake_public_key: PublicKey::from_str( + "ed25519:6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp", + ) + .unwrap(), + voting_account_id, + }; + + let mut contracts = Vec::::with_capacity(num); + for i in 0..num { + let contract_account = create_account(sandbox, &format!("staking-pool-{i}"), 100).await?; + let contract = contract_account.deploy(&contract_wasm).await?.result; + let outcome = contract + .call("new") + .args_json(json!(init_args)) + .transact() + .await?; + assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + contracts.push(contract); + } + + Ok((contracts, owner, init_args)) +} + pub async fn setup_env( ) -> Result<(Contract, Contract, Worker, Account), Box> { let sandbox = near_workspaces::sandbox().await?; @@ -82,6 +116,17 @@ pub async fn setup_env( Ok((staking_pool_contract, voting_contract, sandbox, owner)) } +pub async fn setup_env_many( + staking_pool_num: usize, +) -> Result<(Vec, Contract, Worker, Account), Box> { + let sandbox = near_workspaces::sandbox().await?; + let (voting_contract, _) = deploy_voting_contract(&sandbox).await?; + let (staking_pool_contracts, owner, _) = + deploy_mock_staking_pool_contracts(&sandbox, voting_contract.id().clone(), staking_pool_num).await?; + + Ok((staking_pool_contracts, voting_contract, sandbox, owner)) +} + pub async fn create_account( sandbox: &Worker, prefix: &str, From d8c6e4d91cb4a3ea13266fbd13dffcf16d6b86e5 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Tue, 20 May 2025 07:53:49 +0000 Subject: [PATCH 17/36] test: fix integration test --- .github/workflows/test.yml | 2 +- makefile | 2 +- src/lib.rs | 2 +- tests/test_init.rs | 2 +- tests/test_vote.rs | 14 ++++++++------ 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 973c3d6..40e7677 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,4 +32,4 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - name: Run cargo test - run: cargo test + run: make test diff --git a/makefile b/makefile index 76ed5b4..3bbdfd8 100644 --- a/makefile +++ b/makefile @@ -16,7 +16,7 @@ validator-voting-integration-test: @mkdir -p tests/res @cp target/near/validator_voting.wasm ./tests/res/validator_voting.wasm -test: +test: validator-voting-integration-test @cargo test -- --nocapture define compile-release diff --git a/src/lib.rs b/src/lib.rs index 63ba556..1da7aaf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -179,7 +179,7 @@ impl Contract { #[cfg(feature = "integration-test")] pub fn get_validator_total_stake(&self) -> U128 { - self.get_validator_total_stake().into() + utils::validator_total_stake().into() } } diff --git a/tests/test_init.rs b/tests/test_init.rs index cd74c70..673c5e9 100644 --- a/tests/test_init.rs +++ b/tests/test_init.rs @@ -3,7 +3,7 @@ use serde_json::json; mod utils; use utils::*; -// #[tokio::test] +#[tokio::test] async fn test_initialization() -> Result<(), Box> { let sandbox = near_workspaces::sandbox().await?; let (contract, init_args) = deploy_voting_contract(&sandbox).await?; diff --git a/tests/test_vote.rs b/tests/test_vote.rs index d10b452..d78466c 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -4,7 +4,7 @@ use serde_json::json; mod utils; use utils::*; -// #[tokio::test] +#[tokio::test] async fn test_non_validator_cannot_vote() -> Result<(), Box> { let sandbox = near_workspaces::sandbox().await?; let (contract, _) = deploy_voting_contract(&sandbox).await?; @@ -23,7 +23,7 @@ async fn test_non_validator_cannot_vote() -> Result<(), Box Result<(), Box> { let (staking_pool_contract, voting_contract, sandbox, owner) = setup_env().await?; @@ -74,11 +74,13 @@ async fn test_simple_vote() -> Result<(), Box> { #[tokio::test] async fn test_many_votes() -> Result<(), Box> { let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many(3).await?; + let alice = create_account(&sandbox, "alice", 50000).await?; for staking_pool_contract in staking_pool_contracts.iter() { let outcome = alice .call(staking_pool_contract.id(), "deposit_and_stake") + .args_json(json!({})) .gas(Gas::from_tgas(250)) .deposit(NearToken::from_near(100)) .transact() @@ -89,18 +91,18 @@ async fn test_many_votes() -> Result<(), Box> { outcome.into_result().unwrap_err() ); - let staked_balance = voting_contract + let total_staked = voting_contract .view("get_validator_total_stake") .await?; println!( - "user account: {}, {:#?}", + "total staked: {}, {:#?}", alice.id(), - staked_balance.json::()? + total_staked.json::()? ); } for staking_pool_contract in staking_pool_contracts.iter() { - let outcome = alice.call(staking_pool_contract.id(), "vote") + let outcome = owner.call(staking_pool_contract.id(), "vote") .args_json(json!({ "voting_account_id": voting_contract.id(), "is_vote": true From b200c97f24f7f02c2c8977e8c4ac77b9f317da16 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Tue, 20 May 2025 07:57:09 +0000 Subject: [PATCH 18/36] style: cargo fmt --- tests/test_vote.rs | 17 +++++++---------- tests/utils/mod.rs | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/tests/test_vote.rs b/tests/test_vote.rs index d78466c..5da5942 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -16,9 +16,7 @@ async fn test_non_validator_cannot_vote() -> Result<(), Box Result<(), Box> { outcome.into_result().unwrap_err() ); - let total_staked = voting_contract - .view("get_validator_total_stake") - .await?; + let total_staked = voting_contract.view("get_validator_total_stake").await?; println!( "total staked: {}, {:#?}", alice.id(), @@ -102,11 +98,12 @@ async fn test_many_votes() -> Result<(), Box> { } for staking_pool_contract in staking_pool_contracts.iter() { - let outcome = owner.call(staking_pool_contract.id(), "vote") + let outcome = owner + .call(staking_pool_contract.id(), "vote") .args_json(json!({ - "voting_account_id": voting_contract.id(), - "is_vote": true - })) + "voting_account_id": voting_contract.id(), + "is_vote": true + })) .gas(Gas::from_tgas(200)) .transact() .await?; diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 5cbfa11..bf2bacb 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -86,7 +86,7 @@ pub async fn deploy_mock_staking_pool_contracts( stake_public_key: PublicKey::from_str( "ed25519:6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp", ) - .unwrap(), + .unwrap(), voting_account_id, }; @@ -99,7 +99,11 @@ pub async fn deploy_mock_staking_pool_contracts( .args_json(json!(init_args)) .transact() .await?; - assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); contracts.push(contract); } @@ -121,8 +125,12 @@ pub async fn setup_env_many( ) -> Result<(Vec, Contract, Worker, Account), Box> { let sandbox = near_workspaces::sandbox().await?; let (voting_contract, _) = deploy_voting_contract(&sandbox).await?; - let (staking_pool_contracts, owner, _) = - deploy_mock_staking_pool_contracts(&sandbox, voting_contract.id().clone(), staking_pool_num).await?; + let (staking_pool_contracts, owner, _) = deploy_mock_staking_pool_contracts( + &sandbox, + voting_contract.id().clone(), + staking_pool_num, + ) + .await?; Ok((staking_pool_contracts, voting_contract, sandbox, owner)) } From a921c2ece4ae699d84b0296e94e205f8d370ca01 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Tue, 20 May 2025 07:58:20 +0000 Subject: [PATCH 19/36] ci: install cargo near before test --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 40e7677..55e18e8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,5 +31,7 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v4 + - name: Install cargo-near CLI + run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/near/cargo-near/releases/download/cargo-near-v0.14.2/cargo-near-installer.sh | sh - name: Run cargo test run: make test From 0d0e31b17a797cc86cdec839813246d3afe681cc Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Tue, 20 May 2025 18:26:39 +0800 Subject: [PATCH 20/36] fix: test --- src/lib.rs | 2 +- src/utils.rs | 34 ++++++++++++++++++++++++++++------ tests/test_vote.rs | 28 +++++++++++++++++++++++++--- tests/utils/mod.rs | 2 +- 4 files changed, 55 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1da7aaf..0f9836f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -179,7 +179,7 @@ impl Contract { #[cfg(feature = "integration-test")] pub fn get_validator_total_stake(&self) -> U128 { - utils::validator_total_stake().into() + validator_total_stake().into() } } diff --git a/src/utils.rs b/src/utils.rs index 77d1d28..1df80df 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,21 +1,34 @@ use crate::Balance; #[cfg(feature = "integration-test")] -pub fn get_validators() -> std::collections::HashMap { - near_sdk::env::storage_read(b"__validators__") - .map_or_else(std::collections::HashMap::new, |validators| { +fn get_validators() -> near_sdk::store::LookupMap { + near_sdk::env::storage_read("__validators_map__".as_bytes()) + .map_or_else(|| { + near_sdk::store::LookupMap::new("__validators__".as_bytes()) + }, |validators| { near_sdk::borsh::from_slice(&validators).unwrap() }) } #[cfg(feature = "integration-test")] -pub fn set_validators(validators: std::collections::HashMap) { +fn set_validators(validators: near_sdk::store::LookupMap) { near_sdk::env::storage_write( - b"__validators__", + "__validators_map__".as_bytes(), &near_sdk::borsh::to_vec(&validators).unwrap(), ); } +fn get_validator_total_stake() -> Balance { + near_sdk::env::storage_read("__validator_total_stake__".as_bytes()) + .map_or(0, |amount| { + near_sdk::borsh::from_slice(&amount).unwrap() + }) +} + +fn set_validator_total_stake(amount: Balance) { + near_sdk::env::storage_write("__validator_total_stake__".as_bytes(), &near_sdk::borsh::to_vec(&amount).unwrap()); +} + #[cfg(feature = "integration-test")] pub fn get_validator_stake(validator_account_id: &near_sdk::AccountId) -> Balance { let validators = get_validators(); @@ -28,8 +41,17 @@ pub fn get_validator_stake(validator_account_id: &near_sdk::AccountId) -> Balanc #[cfg(feature = "integration-test")] pub fn set_validator_stake(validator_account_id: near_sdk::AccountId, amount: Balance) { let mut validators = get_validators(); + + let old_amount = validators + .get(&validator_account_id) + .copied() + .unwrap_or_default(); + + let total = get_validator_total_stake(); + validators.insert(validator_account_id, amount); set_validators(validators); + set_validator_total_stake(total + amount - old_amount); } pub fn validator_stake(validator_account_id: &near_sdk::AccountId) -> Balance { @@ -41,7 +63,7 @@ pub fn validator_stake(validator_account_id: &near_sdk::AccountId) -> Balance { pub fn validator_total_stake() -> Balance { #[cfg(feature = "integration-test")] - return get_validators().values().sum(); + return get_validator_total_stake(); #[cfg(not(feature = "integration-test"))] near_sdk::env::validator_total_stake().as_yoctonear() } diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 5da5942..efdcad5 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -1,4 +1,4 @@ -use near_sdk::{Gas, NearToken}; +use near_sdk::{require, Gas, NearToken}; use serde_json::json; mod utils; @@ -71,7 +71,7 @@ async fn test_simple_vote() -> Result<(), Box> { #[tokio::test] async fn test_many_votes() -> Result<(), Box> { - let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many(3).await?; + let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many(300).await?; let alice = create_account(&sandbox, "alice", 50000).await?; @@ -97,7 +97,27 @@ async fn test_many_votes() -> Result<(), Box> { ); } - for staking_pool_contract in staking_pool_contracts.iter() { + for (index, staking_pool_contract) in staking_pool_contracts.iter().enumerate() { + let outcome = owner + .call(voting_contract.id(), "ping") + .gas(Gas::from_tgas(300)) + .transact() + .await?; + + if index <= 200 { + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + } else { + assert!( + outcome.is_failure(), + "Ping should failed since vote is finished", + ); + break; + } + let outcome = owner .call(staking_pool_contract.id(), "vote") .args_json(json!({ @@ -107,11 +127,13 @@ async fn test_many_votes() -> Result<(), Box> { .gas(Gas::from_tgas(200)) .transact() .await?; + assert!( outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err() ); + println!("validator #{index} voted"); } Ok(()) diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index bf2bacb..2be13af 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -33,7 +33,7 @@ pub async fn deploy_voting_contract( .duration_since(UNIX_EPOCH) .unwrap() .as_millis() - + 10 * 60 * 1000) as u64, + + 60 * 60 * 1000) as u64, }; let _ = contract From 6952f98eb7acd5f13a9f31b6e8d449ef012ddd26 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Tue, 20 May 2025 18:28:37 +0800 Subject: [PATCH 21/36] fix: test --- src/utils.rs | 21 +++++++++++---------- tests/test_vote.rs | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/utils.rs b/src/utils.rs index 1df80df..0277099 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,12 +2,10 @@ use crate::Balance; #[cfg(feature = "integration-test")] fn get_validators() -> near_sdk::store::LookupMap { - near_sdk::env::storage_read("__validators_map__".as_bytes()) - .map_or_else(|| { - near_sdk::store::LookupMap::new("__validators__".as_bytes()) - }, |validators| { - near_sdk::borsh::from_slice(&validators).unwrap() - }) + near_sdk::env::storage_read("__validators_map__".as_bytes()).map_or_else( + || near_sdk::store::LookupMap::new("__validators__".as_bytes()), + |validators| near_sdk::borsh::from_slice(&validators).unwrap(), + ) } #[cfg(feature = "integration-test")] @@ -18,15 +16,18 @@ fn set_validators(validators: near_sdk::store::LookupMap Balance { near_sdk::env::storage_read("__validator_total_stake__".as_bytes()) - .map_or(0, |amount| { - near_sdk::borsh::from_slice(&amount).unwrap() - }) + .map_or(0, |amount| near_sdk::borsh::from_slice(&amount).unwrap()) } +#[cfg(feature = "integration-test")] fn set_validator_total_stake(amount: Balance) { - near_sdk::env::storage_write("__validator_total_stake__".as_bytes(), &near_sdk::borsh::to_vec(&amount).unwrap()); + near_sdk::env::storage_write( + "__validator_total_stake__".as_bytes(), + &near_sdk::borsh::to_vec(&amount).unwrap(), + ); } #[cfg(feature = "integration-test")] diff --git a/tests/test_vote.rs b/tests/test_vote.rs index efdcad5..f854892 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -1,4 +1,4 @@ -use near_sdk::{require, Gas, NearToken}; +use near_sdk::{Gas, NearToken}; use serde_json::json; mod utils; From 95eafb5ed1167cbc8d03a92d64fc15d1dc4eb124 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Wed, 21 May 2025 10:55:27 +0800 Subject: [PATCH 22/36] fix: read file --- tests/utils/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 2be13af..c3e6622 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -22,9 +22,9 @@ pub struct MockStakingPoolInitArgs { pub async fn deploy_voting_contract( sandbox: &Worker, ) -> Result<(Contract, VotingInitArgs), Box> { - let contract_wasm = include_bytes!("../res/validator_voting.wasm"); + let contract_wasm = std::fs::read("tests/res/validator_voting.wasm")?; let contract_account = create_account(sandbox, "voting", 100).await?; - let contract = contract_account.deploy(contract_wasm).await?.result; + let contract = contract_account.deploy(&contract_wasm).await?.result; // Initialize contract let init_args = VotingInitArgs { From 5a097451dacc81ba1cc6b855d9d758c3dc12e763 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Thu, 22 May 2025 14:10:33 +0800 Subject: [PATCH 23/36] refactor: test in different epochs --- tests/test_init.rs | 10 +++++++++- tests/test_vote.rs | 15 +++++++++++++-- tests/utils/mod.rs | 25 ++++++++++++++++++------- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/tests/test_init.rs b/tests/test_init.rs index 673c5e9..b40e49c 100644 --- a/tests/test_init.rs +++ b/tests/test_init.rs @@ -1,3 +1,4 @@ +use std::time::{SystemTime, UNIX_EPOCH}; use serde_json::json; mod utils; @@ -6,7 +7,14 @@ use utils::*; #[tokio::test] async fn test_initialization() -> Result<(), Box> { let sandbox = near_workspaces::sandbox().await?; - let (contract, init_args) = deploy_voting_contract(&sandbox).await?; + let (contract, init_args) = deploy_voting_contract( + &sandbox, + (SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() + + 10 * 60 * 1000) as u64 + ).await?; let contract_deadline = contract .view("get_deadline_timestamp") diff --git a/tests/test_vote.rs b/tests/test_vote.rs index f854892..7374a74 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -1,3 +1,4 @@ +use std::time::{SystemTime, UNIX_EPOCH}; use near_sdk::{Gas, NearToken}; use serde_json::json; @@ -7,7 +8,14 @@ use utils::*; #[tokio::test] async fn test_non_validator_cannot_vote() -> Result<(), Box> { let sandbox = near_workspaces::sandbox().await?; - let (contract, _) = deploy_voting_contract(&sandbox).await?; + let (contract, _) = deploy_voting_contract( + &sandbox, + (SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() + + 10 * 60 * 1000) as u64 + ).await?; let sandbox = near_workspaces::sandbox().await?; let user_account = sandbox.dev_create_account().await?; @@ -98,6 +106,9 @@ async fn test_many_votes() -> Result<(), Box> { } for (index, staking_pool_contract) in staking_pool_contracts.iter().enumerate() { + sandbox.fast_forward(500).await?; + let block = sandbox.view_block().await?; + let outcome = owner .call(voting_contract.id(), "ping") .gas(Gas::from_tgas(300)) @@ -133,7 +144,7 @@ async fn test_many_votes() -> Result<(), Box> { "{:#?}", outcome.into_result().unwrap_err() ); - println!("validator #{index} voted"); + println!("validator #{} voted at epoch ({})", index, block.epoch_id()); } Ok(()) diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index c3e6622..819b03a 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -21,6 +21,7 @@ pub struct MockStakingPoolInitArgs { pub async fn deploy_voting_contract( sandbox: &Worker, + deadline_timestamp_ms: u64, ) -> Result<(Contract, VotingInitArgs), Box> { let contract_wasm = std::fs::read("tests/res/validator_voting.wasm")?; let contract_account = create_account(sandbox, "voting", 100).await?; @@ -29,11 +30,7 @@ pub async fn deploy_voting_contract( // Initialize contract let init_args = VotingInitArgs { proposal: "test_proposal".to_string(), - deadline_timestamp_ms: (SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis() - + 60 * 60 * 1000) as u64, + deadline_timestamp_ms, }; let _ = contract @@ -113,7 +110,14 @@ pub async fn deploy_mock_staking_pool_contracts( pub async fn setup_env( ) -> Result<(Contract, Contract, Worker, Account), Box> { let sandbox = near_workspaces::sandbox().await?; - let (voting_contract, _) = deploy_voting_contract(&sandbox).await?; + let (voting_contract, _) = deploy_voting_contract( + &sandbox, + (SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() + + 10 * 60 * 1000) as u64 + ).await?; let (staking_pool_contract, owner, _) = deploy_mock_staking_pool_contract(&sandbox, voting_contract.id().clone()).await?; @@ -124,7 +128,14 @@ pub async fn setup_env_many( staking_pool_num: usize, ) -> Result<(Vec, Contract, Worker, Account), Box> { let sandbox = near_workspaces::sandbox().await?; - let (voting_contract, _) = deploy_voting_contract(&sandbox).await?; + let (voting_contract, _) = deploy_voting_contract( + &sandbox, + (SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() + + 24 * 60 * 60 * 1000) as u64 + ).await?; let (staking_pool_contracts, owner, _) = deploy_mock_staking_pool_contracts( &sandbox, voting_contract.id().clone(), From a598ff0e82359a54fb9298fdc672dbc3ea309cc4 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Thu, 22 May 2025 15:40:06 +0800 Subject: [PATCH 24/36] chore: lint --- tests/test_init.rs | 7 ++++--- tests/test_vote.rs | 7 ++++--- tests/utils/mod.rs | 10 ++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/test_init.rs b/tests/test_init.rs index b40e49c..0b65bbe 100644 --- a/tests/test_init.rs +++ b/tests/test_init.rs @@ -1,5 +1,5 @@ -use std::time::{SystemTime, UNIX_EPOCH}; use serde_json::json; +use std::time::{SystemTime, UNIX_EPOCH}; mod utils; use utils::*; @@ -13,8 +13,9 @@ async fn test_initialization() -> Result<(), Box> { .duration_since(UNIX_EPOCH) .unwrap() .as_millis() - + 10 * 60 * 1000) as u64 - ).await?; + + 10 * 60 * 1000) as u64, + ) + .await?; let contract_deadline = contract .view("get_deadline_timestamp") diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 7374a74..dd18108 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -1,6 +1,6 @@ -use std::time::{SystemTime, UNIX_EPOCH}; use near_sdk::{Gas, NearToken}; use serde_json::json; +use std::time::{SystemTime, UNIX_EPOCH}; mod utils; use utils::*; @@ -14,8 +14,9 @@ async fn test_non_validator_cannot_vote() -> Result<(), Box Date: Thu, 22 May 2025 15:40:48 +0800 Subject: [PATCH 25/36] chore: skip test_many_votes --- tests/test_vote.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_vote.rs b/tests/test_vote.rs index dd18108..45183ea 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -78,7 +78,7 @@ async fn test_simple_vote() -> Result<(), Box> { Ok(()) } -#[tokio::test] +// #[tokio::test] // it takes around 50 minutes async fn test_many_votes() -> Result<(), Box> { let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many(300).await?; From 2608bdf0f579b61108a9695a9a6126521761e651 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Fri, 23 May 2025 10:34:10 +0800 Subject: [PATCH 26/36] test: view --- makefile | 2 +- tests/test_vote.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/makefile b/makefile index 3bbdfd8..3faecb2 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,6 @@ RUSTFLAGS = "-C link-arg=-s" -all: validator-voting validator-voting-integration-test +all: lint validator-voting validator-voting-integration-test lint: @cargo fmt --all diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 45183ea..56e8d69 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -1,5 +1,6 @@ -use near_sdk::{Gas, NearToken}; +use near_sdk::{AccountId, Gas, NearToken}; use serde_json::json; +use std::collections::HashMap; use std::time::{SystemTime, UNIX_EPOCH}; mod utils; @@ -78,7 +79,7 @@ async fn test_simple_vote() -> Result<(), Box> { Ok(()) } -// #[tokio::test] // it takes around 50 minutes +#[tokio::test] // it takes around 50 minutes async fn test_many_votes() -> Result<(), Box> { let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many(300).await?; @@ -146,6 +147,13 @@ async fn test_many_votes() -> Result<(), Box> { outcome.into_result().unwrap_err() ); println!("validator #{} voted at epoch ({})", index, block.epoch_id()); + println!( + "Votes: {:#?}", + voting_contract + .view("get_votes") + .await? + .json::>()? + ); } Ok(()) From ffdab32730afcc499b2080a6a57f96098dcdd058 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Fri, 23 May 2025 16:17:27 +0800 Subject: [PATCH 27/36] test: expiration --- tests/test_vote.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++- tests/utils/mod.rs | 5 +++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 56e8d69..98a2751 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -33,7 +33,7 @@ async fn test_non_validator_cannot_vote() -> Result<(), Box Result<(), Box> { - let (staking_pool_contract, voting_contract, sandbox, owner) = setup_env().await?; + let (staking_pool_contract, voting_contract, sandbox, owner) = setup_env(None).await?; let alice = create_account(&sandbox, "alice", 10000).await?; let outcome = alice @@ -158,3 +158,56 @@ async fn test_many_votes() -> Result<(), Box> { Ok(()) } + +#[tokio::test] +async fn test_vote_expiration() -> Result<(), Box> { + let (staking_pool_contract, voting_contract, sandbox, owner) = setup_env( + Some((SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() + + 1 * 60 * 1000) as u64) + ).await?; + + let alice = create_account(&sandbox, "alice", 10000).await?; + let outcome = alice + .call(staking_pool_contract.id(), "deposit_and_stake") + .args_json(json!({})) + .gas(Gas::from_tgas(250)) + .deposit(NearToken::from_near(1000)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + let staked_balance = voting_contract + .view("get_validator_stake") + .args_json(json!({ + "validator_account_id": staking_pool_contract.id() + })) + .await?; + println!( + "user account: {}, {:#?}", + alice.id(), + staked_balance.json::()? + ); + + sandbox.fast_forward(500).await?; // let vote expire + + let outcome = owner + .call(staking_pool_contract.id(), "vote") + .args_json(json!({ + "voting_account_id": voting_contract.id(), + "is_vote": true + })) + .gas(Gas::from_tgas(200)) + .transact() + .await?; + + assert!(outcome.into_result().unwrap_err().to_string().contains("Smart contract panicked: Voting deadline has already passed")); + + Ok(()) +} diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index e1900c0..1509ebd 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -108,15 +108,16 @@ pub async fn deploy_mock_staking_pool_contracts( } pub async fn setup_env( + deadline_timestamp_ms: Option, ) -> Result<(Contract, Contract, Worker, Account), Box> { let sandbox = near_workspaces::sandbox().await?; let (voting_contract, _) = deploy_voting_contract( &sandbox, - (SystemTime::now() + deadline_timestamp_ms.unwrap_or_else(|| (SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() .as_millis() - + 10 * 60 * 1000) as u64, + + 10 * 60 * 1000) as u64), ) .await?; let (staking_pool_contract, owner, _) = From 8b6c7cc0dda2162ae5565648125c1a2e79219817 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Tue, 27 May 2025 13:28:01 +0800 Subject: [PATCH 28/36] test: withdraw vote --- tests/test_vote.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 98a2751..54882d1 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -211,3 +211,68 @@ async fn test_vote_expiration() -> Result<(), Box> { Ok(()) } + +#[tokio::test] +async fn test_withdraw_vote() -> Result<(), Box> { + let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many( + 2 + ).await?; + + let alice = create_account(&sandbox, "alice", 10000).await?; + + let outcome = alice + .call(staking_pool_contracts[0].id(), "deposit_and_stake") + .gas(Gas::from_tgas(250)) + .deposit(NearToken::from_near(1000)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + let outcome = alice + .call(staking_pool_contracts[1].id(), "deposit_and_stake") + .gas(Gas::from_tgas(250)) + .deposit(NearToken::from_near(1000)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + let outcome = owner + .call(staking_pool_contracts[0].id(), "vote") + .args_json(json!({ + "voting_account_id": voting_contract.id(), + "is_vote": true + })) + .gas(Gas::from_tgas(200)) + .transact() + .await?; + + assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + + let votes = owner.view(voting_contract.id(), "get_votes").await?; + assert_eq!(votes.json::>()?.len(), 1); + + let outcome = owner + .call(staking_pool_contracts[0].id(), "vote") + .args_json(json!({ + "voting_account_id": voting_contract.id(), + "is_vote": false + })) + .gas(Gas::from_tgas(200)) + .transact() + .await?; + + assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + + let votes = owner.view(voting_contract.id(), "get_votes").await?; + assert_eq!(votes.json::>()?.len(), 0); + + Ok(()) +} From 84c5ee02de424d633f682bb983da26ed44a5b74b Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Tue, 27 May 2025 13:48:40 +0800 Subject: [PATCH 29/36] test: unstake after voting --- tests/test_vote.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 54882d1..2b8fecb 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -276,3 +276,88 @@ async fn test_withdraw_vote() -> Result<(), Box> { Ok(()) } + +#[tokio::test] +async fn test_unstake_after_voting() -> Result<(), Box> { + let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many( + 2 + ).await?; + + let alice = create_account(&sandbox, "alice", 10000).await?; + + let outcome = alice + .call(staking_pool_contracts[0].id(), "deposit_and_stake") + .gas(Gas::from_tgas(250)) + .deposit(NearToken::from_near(1000)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + let outcome = alice + .call(staking_pool_contracts[1].id(), "deposit_and_stake") + .gas(Gas::from_tgas(250)) + .deposit(NearToken::from_near(1000)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + let outcome = owner + .call(staking_pool_contracts[0].id(), "vote") + .args_json(json!({ + "voting_account_id": voting_contract.id(), + "is_vote": true + })) + .gas(Gas::from_tgas(200)) + .transact() + .await?; + + assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + + let outcome = alice + .call(staking_pool_contracts[0].id(), "unstake") + .args_json(json!({ + "amount": NearToken::from_near(1000).as_yoctonear().to_string() + })) + .gas(Gas::from_tgas(250)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + let votes = owner.view(voting_contract.id(), "get_votes").await?; + let votes = votes.json::>()?; + assert_eq!(votes.len(), 1); + assert!(votes.contains_key(staking_pool_contracts[0].id())); + + sandbox.fast_forward(500).await?; + + let outcome = owner + .call(staking_pool_contracts[1].id(), "vote") + .args_json(json!({ + "voting_account_id": voting_contract.id(), + "is_vote": true + })) + .gas(Gas::from_tgas(200)) + .transact() + .await?; + + assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + + let votes = owner.view(voting_contract.id(), "get_votes").await?; + let votes = votes.json::>()?; + assert_eq!(votes.len(), 1); + assert!(votes.contains_key(staking_pool_contracts[1].id())); + + Ok(()) +} From 3776197654df8955229dce1976c1437f719fab63 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Tue, 27 May 2025 13:49:09 +0800 Subject: [PATCH 30/36] style: lint --- tests/test_vote.rs | 47 +++++++++++++++++++++++++++++++--------------- tests/utils/mod.rs | 12 +++++++----- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 2b8fecb..4e332b2 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -161,13 +161,14 @@ async fn test_many_votes() -> Result<(), Box> { #[tokio::test] async fn test_vote_expiration() -> Result<(), Box> { - let (staking_pool_contract, voting_contract, sandbox, owner) = setup_env( - Some((SystemTime::now() + let (staking_pool_contract, voting_contract, sandbox, owner) = setup_env(Some( + (SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() .as_millis() - + 1 * 60 * 1000) as u64) - ).await?; + + 60 * 1000) as u64, + )) + .await?; let alice = create_account(&sandbox, "alice", 10000).await?; let outcome = alice @@ -207,16 +208,18 @@ async fn test_vote_expiration() -> Result<(), Box> { .transact() .await?; - assert!(outcome.into_result().unwrap_err().to_string().contains("Smart contract panicked: Voting deadline has already passed")); + assert!(outcome + .into_result() + .unwrap_err() + .to_string() + .contains("Smart contract panicked: Voting deadline has already passed")); Ok(()) } #[tokio::test] async fn test_withdraw_vote() -> Result<(), Box> { - let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many( - 2 - ).await?; + let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many(2).await?; let alice = create_account(&sandbox, "alice", 10000).await?; @@ -254,7 +257,11 @@ async fn test_withdraw_vote() -> Result<(), Box> { .transact() .await?; - assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); let votes = owner.view(voting_contract.id(), "get_votes").await?; assert_eq!(votes.json::>()?.len(), 1); @@ -269,7 +276,11 @@ async fn test_withdraw_vote() -> Result<(), Box> { .transact() .await?; - assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); let votes = owner.view(voting_contract.id(), "get_votes").await?; assert_eq!(votes.json::>()?.len(), 0); @@ -279,9 +290,7 @@ async fn test_withdraw_vote() -> Result<(), Box> { #[tokio::test] async fn test_unstake_after_voting() -> Result<(), Box> { - let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many( - 2 - ).await?; + let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many(2).await?; let alice = create_account(&sandbox, "alice", 10000).await?; @@ -319,7 +328,11 @@ async fn test_unstake_after_voting() -> Result<(), Box> { .transact() .await?; - assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); let outcome = alice .call(staking_pool_contracts[0].id(), "unstake") @@ -352,7 +365,11 @@ async fn test_unstake_after_voting() -> Result<(), Box> { .transact() .await?; - assert!(outcome.is_success(), "{:#?}", outcome.into_result().unwrap_err()); + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); let votes = owner.view(voting_contract.id(), "get_votes").await?; let votes = votes.json::>()?; diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 1509ebd..488435b 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -113,11 +113,13 @@ pub async fn setup_env( let sandbox = near_workspaces::sandbox().await?; let (voting_contract, _) = deploy_voting_contract( &sandbox, - deadline_timestamp_ms.unwrap_or_else(|| (SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis() - + 10 * 60 * 1000) as u64), + deadline_timestamp_ms.unwrap_or_else(|| { + (SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() + + 10 * 60 * 1000) as u64 + }), ) .await?; let (staking_pool_contract, owner, _) = From 808ea282150dbb65f4f93b3ce3e5d7e71ae26e91 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Wed, 28 May 2025 06:55:08 +0000 Subject: [PATCH 31/36] test: update mock staking pool --- tests/contracts/mock-staking-pool/src/lib.rs | 51 +++++++++----------- tests/scripts/create-validators.sh | 15 ++++++ tests/scripts/vote.sh | 13 +++++ tests/test_vote.rs | 13 +---- tests/utils/mod.rs | 2 + 5 files changed, 56 insertions(+), 38 deletions(-) create mode 100644 tests/scripts/create-validators.sh create mode 100644 tests/scripts/vote.sh diff --git a/tests/contracts/mock-staking-pool/src/lib.rs b/tests/contracts/mock-staking-pool/src/lib.rs index 6a1efb3..82b9f07 100644 --- a/tests/contracts/mock-staking-pool/src/lib.rs +++ b/tests/contracts/mock-staking-pool/src/lib.rs @@ -1,15 +1,15 @@ use near_sdk::json_types::U128; use near_sdk::store::LookupMap; use near_sdk::{ - env, ext_contract, log, near, require, AccountId, BorshStorageKey, Gas, NearToken, - PanicOnDefault, Promise, PromiseError, PublicKey, + env, ext_contract, near, require, AccountId, BorshStorageKey, Gas, NearToken, + PanicOnDefault, Promise, PublicKey, }; type Balance = u128; const VOTE_GAS: Gas = Gas::from_tgas(100); -const SET_VALIDATOR_STAKE_GAS: Gas = Gas::from_tgas(200); +#[allow(dead_code)] #[ext_contract(ext_voting)] trait VotingContract { fn vote(&mut self, is_vote: bool); @@ -68,9 +68,11 @@ impl MockStakingPool { let balance = self.internal_account_staked_balance(&account_id); require!(balance >= amount, "Not enough stake"); - self.accounts.insert(account_id, balance - amount); + self.accounts.insert(account_id.clone(), balance - amount); self.total_staked_balance -= amount; + Promise::new(account_id).transfer(NearToken::from_yoctonear(amount)); + self.internal_restake() } @@ -84,35 +86,30 @@ impl MockStakingPool { .vote(is_vote) } - // #[private] - // pub fn on_stake_action(&self, #[callback_result] result: Result<(), PromiseError>) { - // if result.is_err() { - // log!("Stake action failed"); - // return; - // } - // - // log!( - // "Validator stake amount: {}", - // env::validator_stake(&env::current_account_id()) - // ); - // } + /// Owner's method. + /// Update voting account ID + pub fn set_voting_account_id(&mut self, voting_account_id: AccountId) -> Promise { + self.assert_owner(); + self.voting_account_id = voting_account_id; + self.internal_restake() + } + + /// Returns the default voting account ID + pub fn get_voting_account_id(&self) -> AccountId { + self.voting_account_id.clone() + } + + /// Returns the total staking balance. + pub fn get_total_staked_balance(&self) -> U128 { + self.total_staked_balance.into() + } fn internal_account_staked_balance(&self, account_id: &AccountId) -> Balance { *self.accounts.get(account_id).unwrap_or(&0u128) } + /// Sync stake amount to voting contract fn internal_restake(&self) -> Promise { - // Promise::new(env::current_account_id()) - // .stake( - // NearToken::from_yoctonear(self.total_staked_balance), - // self.stake_public_key.clone(), - // ) - // .then( - // Self::ext(env::current_account_id()) - // .with_static_gas(STAKE_CALLBACK_GAS) - // .on_stake_action(), - // ) - ext_voting::ext(self.voting_account_id.clone()) .set_validator_stake(env::current_account_id(), self.total_staked_balance.into()) } diff --git a/tests/scripts/create-validators.sh b/tests/scripts/create-validators.sh new file mode 100644 index 0000000..68fd380 --- /dev/null +++ b/tests/scripts/create-validators.sh @@ -0,0 +1,15 @@ +export OWNER_ID=mock-owner.testnet +export STAKE_ACCOUNT_ID=mock-staker.testnet +export VOTING_ACCOUNT_ID=mock-proposal.testnet +export STAKE_PUBLIC_KEY=ed25519:6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp + +for i in {1..300}; do + VALIDATOR_ID="mock-validator-"${i}".testnet" + # create validator account + # near account create-account sponsor-by-faucet-service $VALIDATOR_ID autogenerate-new-keypair save-to-legacy-keychain network-config testnet create + near account create-account fund-myself $VALIDATOR_ID '2 NEAR' autogenerate-new-keypair save-to-legacy-keychain sign-as $STAKE_ACCOUNT_ID network-config testnet sign-with-legacy-keychain send + # deploy mock staking pool contract + near contract deploy $VALIDATOR_ID use-file mock_staking_pool.wasm with-init-call new json-args '{"owner_id":"'$OWNER_ID'","stake_public_key":"'$STAKE_PUBLIC_KEY'","voting_account_id":"'$VOTING_ACCOUNT_ID'"}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' network-config testnet sign-with-legacy-keychain send + # stake some NEAR to + near contract call-function as-transaction $VALIDATOR_ID deposit_and_stake json-args {} prepaid-gas '200.0 Tgas' attached-deposit '1 NEAR' sign-as $STAKE_ACCOUNT_ID network-config testnet sign-with-legacy-keychain send +done diff --git a/tests/scripts/vote.sh b/tests/scripts/vote.sh new file mode 100644 index 0000000..e5615eb --- /dev/null +++ b/tests/scripts/vote.sh @@ -0,0 +1,13 @@ +export OWNER_ID=mock-owner.testnet +export VOTING_ACCOUNT_ID=mock-proposal.testnet + +for i in {101..200}; do + VALIDATOR_ID="mock-validator-"${i}".testnet" + # vote by validator + near contract call-function as-transaction $VALIDATOR_ID vote json-args '{"voting_account_id":"'$VOTING_ACCOUNT_ID'","is_vote":true}' prepaid-gas '200.0 Tgas' attached-deposit '0 NEAR' sign-as $OWNER_ID network-config testnet sign-with-legacy-keychain send +done + +# get total voted stake +near contract call-function as-read-only $VOTING_ACCOUNT_ID get_total_voted_stake json-args {} network-config testnet now +# get votes +near contract call-function as-read-only $VOTING_ACCOUNT_ID get_votes json-args {} network-config testnet now diff --git a/tests/test_vote.rs b/tests/test_vote.rs index 4e332b2..e5fc5ea 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -55,11 +55,6 @@ async fn test_simple_vote() -> Result<(), Box> { "validator_account_id": staking_pool_contract.id() })) .await?; - println!( - "user account: {}, {:#?}", - alice.id(), - staked_balance.json::()? - ); let outcome = owner .call(staking_pool_contract.id(), "vote") @@ -79,7 +74,8 @@ async fn test_simple_vote() -> Result<(), Box> { Ok(()) } -#[tokio::test] // it takes around 50 minutes +#[tokio::test] +#[ignore = "test is time consuming"] // Test takes around 50 minutes async fn test_many_votes() -> Result<(), Box> { let (staking_pool_contracts, voting_contract, sandbox, owner) = setup_env_many(300).await?; @@ -190,11 +186,6 @@ async fn test_vote_expiration() -> Result<(), Box> { "validator_account_id": staking_pool_contract.id() })) .await?; - println!( - "user account: {}, {:#?}", - alice.id(), - staked_balance.json::()? - ); sandbox.fast_forward(500).await?; // let vote expire diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 488435b..94b59f9 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use near_sdk::{near, AccountId, NearToken, PublicKey}; use near_workspaces::{network::Sandbox, Account, Contract, Worker}; use serde_json::json; From f3469c8c4307cfecae75f02ab4ef64572db986d1 Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Wed, 28 May 2025 15:03:22 +0800 Subject: [PATCH 32/36] chore: rename feature --- Cargo.toml | 2 +- makefile | 8 ++++---- src/lib.rs | 6 +++--- src/utils.rs | 20 ++++++++++---------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2dfe36d..bca4cb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -46,7 +46,7 @@ serde_json = "1" [features] default = [] -integration-test = [] +test = [] [profile.release] codegen-units = 1 diff --git a/makefile b/makefile index 3faecb2..03fdc4e 100644 --- a/makefile +++ b/makefile @@ -1,6 +1,6 @@ RUSTFLAGS = "-C link-arg=-s" -all: lint validator-voting validator-voting-integration-test +all: lint validator-voting validator-voting-test lint: @cargo fmt --all @@ -11,12 +11,12 @@ validator-voting: @mkdir -p res @cp target/near/validator_voting.wasm ./res/validator_voting.wasm -validator-voting-integration-test: - $(call compile-release,validator-voting,integration-test) +validator-voting-test: + $(call compile-release,validator-voting,test) @mkdir -p tests/res @cp target/near/validator_voting.wasm ./tests/res/validator_voting.wasm -test: validator-voting-integration-test +test: validator-voting-test @cargo test -- --nocapture define compile-release diff --git a/src/lib.rs b/src/lib.rs index 0f9836f..7963694 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,17 +167,17 @@ impl Contract { #[near] impl Contract { - #[cfg(feature = "integration-test")] + #[cfg(feature = "test")] pub fn set_validator_stake(&mut self, validator_account_id: AccountId, amount: U128) { utils::set_validator_stake(validator_account_id, amount.0) } - #[cfg(feature = "integration-test")] + #[cfg(feature = "test")] pub fn get_validator_stake(&self, validator_account_id: AccountId) -> U128 { utils::get_validator_stake(&validator_account_id).into() } - #[cfg(feature = "integration-test")] + #[cfg(feature = "test")] pub fn get_validator_total_stake(&self) -> U128 { validator_total_stake().into() } diff --git a/src/utils.rs b/src/utils.rs index 0277099..853abdd 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,6 @@ use crate::Balance; -#[cfg(feature = "integration-test")] +#[cfg(feature = "test")] fn get_validators() -> near_sdk::store::LookupMap { near_sdk::env::storage_read("__validators_map__".as_bytes()).map_or_else( || near_sdk::store::LookupMap::new("__validators__".as_bytes()), @@ -8,7 +8,7 @@ fn get_validators() -> near_sdk::store::LookupMap ) } -#[cfg(feature = "integration-test")] +#[cfg(feature = "test")] fn set_validators(validators: near_sdk::store::LookupMap) { near_sdk::env::storage_write( "__validators_map__".as_bytes(), @@ -16,13 +16,13 @@ fn set_validators(validators: near_sdk::store::LookupMap Balance { near_sdk::env::storage_read("__validator_total_stake__".as_bytes()) .map_or(0, |amount| near_sdk::borsh::from_slice(&amount).unwrap()) } -#[cfg(feature = "integration-test")] +#[cfg(feature = "test")] fn set_validator_total_stake(amount: Balance) { near_sdk::env::storage_write( "__validator_total_stake__".as_bytes(), @@ -30,7 +30,7 @@ fn set_validator_total_stake(amount: Balance) { ); } -#[cfg(feature = "integration-test")] +#[cfg(feature = "test")] pub fn get_validator_stake(validator_account_id: &near_sdk::AccountId) -> Balance { let validators = get_validators(); validators @@ -39,7 +39,7 @@ pub fn get_validator_stake(validator_account_id: &near_sdk::AccountId) -> Balanc .unwrap_or_default() } -#[cfg(feature = "integration-test")] +#[cfg(feature = "test")] pub fn set_validator_stake(validator_account_id: near_sdk::AccountId, amount: Balance) { let mut validators = get_validators(); @@ -56,15 +56,15 @@ pub fn set_validator_stake(validator_account_id: near_sdk::AccountId, amount: Ba } pub fn validator_stake(validator_account_id: &near_sdk::AccountId) -> Balance { - #[cfg(feature = "integration-test")] + #[cfg(feature = "test")] return get_validator_stake(validator_account_id); - #[cfg(not(feature = "integration-test"))] + #[cfg(not(feature = "test"))] near_sdk::env::validator_stake(validator_account_id).as_yoctonear() } pub fn validator_total_stake() -> Balance { - #[cfg(feature = "integration-test")] + #[cfg(feature = "test")] return get_validator_total_stake(); - #[cfg(not(feature = "integration-test"))] + #[cfg(not(feature = "test"))] near_sdk::env::validator_total_stake().as_yoctonear() } From 1c933d7316eadfb6df69a85939af285163aa435c Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Wed, 28 May 2025 16:15:25 +0800 Subject: [PATCH 33/36] test: mock staking pool --- tests/test_staking_pool.rs | 94 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 tests/test_staking_pool.rs diff --git a/tests/test_staking_pool.rs b/tests/test_staking_pool.rs new file mode 100644 index 0000000..b47302c --- /dev/null +++ b/tests/test_staking_pool.rs @@ -0,0 +1,94 @@ +use std::time::{SystemTime, UNIX_EPOCH}; +use near_sdk::{Gas, NearToken}; +use near_workspaces::AccountId; +use serde_json::json; +use crate::utils::{create_account, deploy_voting_contract, setup_env}; + +mod utils; + +#[tokio::test] +async fn test_stake_unstake() -> Result<(), Box> { + let (staking_pool_contract, _, sandbox, _) = setup_env(None).await?; + let alice = create_account(&sandbox, "alice", 10000).await?; + let outcome = alice + .call(staking_pool_contract.id(), "deposit_and_stake") + .gas(Gas::from_tgas(250)) + .deposit(NearToken::from_near(1000)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + let balance = alice.view_account().await?.balance.as_near(); + assert!(balance >= 8999 && balance < 9000); + + let outcome = alice + .call(staking_pool_contract.id(), "unstake") + .args_json(json!({ + "amount": NearToken::from_near(1000).as_yoctonear().to_string() + })) + .gas(Gas::from_tgas(250)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + let balance = alice.view_account().await?.balance.as_near(); + assert!(balance >= 9999 && balance < 10000); + + Ok(()) +} + +#[tokio::test] +async fn test_get_set_voting_account_id() -> Result<(), Box> { + let (staking_pool_contract, _, sandbox, owner) = setup_env(None).await?; + let (new_voting_contract, _) = deploy_voting_contract( + &sandbox, + (SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() + + 10 * 60 * 1000) as u64, + ).await?; + + let alice = create_account(&sandbox, "alice", 10000).await?; + let outcome = alice + .call(staking_pool_contract.id(), "deposit_and_stake") + .gas(Gas::from_tgas(250)) + .deposit(NearToken::from_near(1000)) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + + let outcome = owner + .call(staking_pool_contract.id(), "set_voting_account_id") + .args_json(json!({ + "voting_account_id": new_voting_contract.id(), + })) + .transact() + .await?; + assert!( + outcome.is_success(), + "{:#?}", + outcome.into_result().unwrap_err() + ); + let voting_account_id = staking_pool_contract.view("get_voting_account_id").await?.json::()?; + assert_eq!(&voting_account_id, new_voting_contract.id()); + + let validator_stake = new_voting_contract.view("get_validator_stake") + .args_json(json!({ + "validator_account_id": staking_pool_contract.id(), + })).await?.json::()?; + + assert_eq!(validator_stake, NearToken::from_near(1000).as_yoctonear().to_string()); + + Ok(()) +} From a7e3f1f77c7a4461afb58a3eac621c4dfd5bf09a Mon Sep 17 00:00:00 2001 From: arkff <109507401+arkff202310@users.noreply.github.com> Date: Wed, 28 May 2025 16:15:42 +0800 Subject: [PATCH 34/36] test: mock staking pool --- tests/test_staking_pool.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/tests/test_staking_pool.rs b/tests/test_staking_pool.rs index b47302c..01a8ff2 100644 --- a/tests/test_staking_pool.rs +++ b/tests/test_staking_pool.rs @@ -1,8 +1,8 @@ -use std::time::{SystemTime, UNIX_EPOCH}; +use crate::utils::{create_account, deploy_voting_contract, setup_env}; use near_sdk::{Gas, NearToken}; use near_workspaces::AccountId; use serde_json::json; -use crate::utils::{create_account, deploy_voting_contract, setup_env}; +use std::time::{SystemTime, UNIX_EPOCH}; mod utils; @@ -22,7 +22,7 @@ async fn test_stake_unstake() -> Result<(), Box> { outcome.into_result().unwrap_err() ); let balance = alice.view_account().await?.balance.as_near(); - assert!(balance >= 8999 && balance < 9000); + assert!((8999..9000).contains(&balance)); let outcome = alice .call(staking_pool_contract.id(), "unstake") @@ -38,7 +38,7 @@ async fn test_stake_unstake() -> Result<(), Box> { outcome.into_result().unwrap_err() ); let balance = alice.view_account().await?.balance.as_near(); - assert!(balance >= 9999 && balance < 10000); + assert!((9999..10000).contains(&balance)); Ok(()) } @@ -53,7 +53,8 @@ async fn test_get_set_voting_account_id() -> Result<(), Box Result<(), Box()?; + let voting_account_id = staking_pool_contract + .view("get_voting_account_id") + .await? + .json::()?; assert_eq!(&voting_account_id, new_voting_contract.id()); - let validator_stake = new_voting_contract.view("get_validator_stake") + let validator_stake = new_voting_contract + .view("get_validator_stake") .args_json(json!({ "validator_account_id": staking_pool_contract.id(), - })).await?.json::()?; + })) + .await? + .json::()?; - assert_eq!(validator_stake, NearToken::from_near(1000).as_yoctonear().to_string()); + assert_eq!( + validator_stake, + NearToken::from_near(1000).as_yoctonear().to_string() + ); Ok(()) } From d002a57e9054bd335a98b05064201abf41a74868 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Tue, 3 Jun 2025 02:28:51 +0000 Subject: [PATCH 35/36] feat: update test scritps --- tests/scripts/create-proposal.sh | 10 ++++++++++ tests/scripts/create-validators.sh | 7 ++++--- tests/scripts/vote.sh | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/scripts/create-proposal.sh diff --git a/tests/scripts/create-proposal.sh b/tests/scripts/create-proposal.sh new file mode 100644 index 0000000..ed21d19 --- /dev/null +++ b/tests/scripts/create-proposal.sh @@ -0,0 +1,10 @@ +#!/bin/bash +export VOTING_ACCOUNT_ID=reduce-inflation.testnet +export PROPOSAL_DESCRIPTION="reduce inflation rate" +export DEADLINE_TIMESTAMP=1749715200000 + +# create account +near account create-account sponsor-by-faucet-service $VOTING_ACCOUNT_ID autogenerate-new-keypair save-to-legacy-keychain network-config testnet create + +# deploy contract +near contract deploy $VOTING_ACCOUNT_ID use-file validator_voting.wasm with-init-call new json-args '{"proposal":"'$PROPOSAL_DESCRIPTION'","deadline_timestamp_ms":'$DEADLINE_TIMESTAMP'}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' network-config testnet sign-with-legacy-keychain send diff --git a/tests/scripts/create-validators.sh b/tests/scripts/create-validators.sh index 68fd380..b613fcc 100644 --- a/tests/scripts/create-validators.sh +++ b/tests/scripts/create-validators.sh @@ -1,10 +1,11 @@ +#!/bin/bash export OWNER_ID=mock-owner.testnet export STAKE_ACCOUNT_ID=mock-staker.testnet -export VOTING_ACCOUNT_ID=mock-proposal.testnet +export VOTING_ACCOUNT_ID=reduce-inflation.testnet export STAKE_PUBLIC_KEY=ed25519:6E8sCci9badyRkXb3JoRpBj5p8C6Tw41ELDZoiihKEtp -for i in {1..300}; do - VALIDATOR_ID="mock-validator-"${i}".testnet" +for i in {1..1}; do + VALIDATOR_ID="mock-node-"${i}".testnet" # create validator account # near account create-account sponsor-by-faucet-service $VALIDATOR_ID autogenerate-new-keypair save-to-legacy-keychain network-config testnet create near account create-account fund-myself $VALIDATOR_ID '2 NEAR' autogenerate-new-keypair save-to-legacy-keychain sign-as $STAKE_ACCOUNT_ID network-config testnet sign-with-legacy-keychain send diff --git a/tests/scripts/vote.sh b/tests/scripts/vote.sh index e5615eb..715ee7c 100644 --- a/tests/scripts/vote.sh +++ b/tests/scripts/vote.sh @@ -1,3 +1,4 @@ +#!/bin/bash export OWNER_ID=mock-owner.testnet export VOTING_ACCOUNT_ID=mock-proposal.testnet From 5aca39f10a8581790d466ac9b1d49debee14dc81 Mon Sep 17 00:00:00 2001 From: Linguists B Date: Tue, 3 Jun 2025 03:49:18 +0000 Subject: [PATCH 36/36] test: remove redundant sandbox --- tests/test_vote.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_vote.rs b/tests/test_vote.rs index e5fc5ea..d8ba849 100644 --- a/tests/test_vote.rs +++ b/tests/test_vote.rs @@ -19,7 +19,6 @@ async fn test_non_validator_cannot_vote() -> Result<(), Box