diff --git a/Cargo.lock b/Cargo.lock index 9bf0e465..0a4d77f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -117,6 +117,7 @@ dependencies = [ name = "akli" version = "0.1.0" dependencies = [ + "alloy-primitives", "anyhow", "assert_cmd", "assert_fs", @@ -132,6 +133,38 @@ dependencies = [ "surf", ] +[[package]] +name = "alloy-primitives" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "600d34d8de81e23b6d909c094e23b3d357e01ca36b78a8c5424c501eedbe86f0" +dependencies = [ + "alloy-rlp", + "bytes 1.5.0", + "cfg-if", + "const-hex", + "derive_more", + "hex-literal", + "itoa", + "k256", + "keccak-asm", + "proptest", + "rand 0.8.5", + "ruint", + "serde", + "tiny-keccak", +] + +[[package]] +name = "alloy-rlp" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d58d9f5da7b40e9bfff0b7e7816700be4019db97d4b6359fe7f94a9e22e42ac" +dependencies = [ + "arrayvec", + "bytes 1.5.0", +] + [[package]] name = "anstream" version = "0.6.13" @@ -192,10 +225,10 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" dependencies = [ - "ark-ff", + "ark-ff 0.4.2", "ark-poly", - "ark-serialize", - "ark-std", + "ark-serialize 0.4.2", + "ark-std 0.4.0", "derivative", "hashbrown 0.13.2", "itertools 0.10.5", @@ -204,16 +237,34 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ark-ff" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" +dependencies = [ + "ark-ff-asm 0.3.0", + "ark-ff-macros 0.3.0", + "ark-serialize 0.3.0", + "ark-std 0.3.0", + "derivative", + "num-bigint", + "num-traits", + "paste", + "rustc_version 0.3.3", + "zeroize", +] + [[package]] name = "ark-ff" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" dependencies = [ - "ark-ff-asm", - "ark-ff-macros", - "ark-serialize", - "ark-std", + "ark-ff-asm 0.4.2", + "ark-ff-macros 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", "derivative", "digest 0.10.7", "itertools 0.10.5", @@ -224,6 +275,16 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ark-ff-asm" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" +dependencies = [ + "quote", + "syn 1.0.109", +] + [[package]] name = "ark-ff-asm" version = "0.4.2" @@ -234,6 +295,18 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-ff-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" +dependencies = [ + "num-bigint", + "num-traits", + "quote", + "syn 1.0.109", +] + [[package]] name = "ark-ff-macros" version = "0.4.2" @@ -253,9 +326,9 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" dependencies = [ - "ark-ff", - "ark-serialize", - "ark-std", + "ark-ff 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", "derivative", "hashbrown 0.13.2", ] @@ -267,8 +340,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c02e954eaeb4ddb29613fee20840c2bbc85ca4396d53e33837e11905363c5f2" dependencies = [ "ark-ec", - "ark-ff", - "ark-std", + "ark-ff 0.4.2", + "ark-std 0.4.0", ] [[package]] @@ -278,9 +351,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a87789a7a9397bc3f477e4138859ca4cacf2d0903745a30b22b51b20d9da2c7a" dependencies = [ "ark-ec", - "ark-ff", + "ark-ff 0.4.2", "ark-secp256k1", - "ark-std", + "ark-std 0.4.0", +] + +[[package]] +name = "ark-serialize" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" +dependencies = [ + "ark-std 0.3.0", + "digest 0.9.0", ] [[package]] @@ -290,7 +373,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" dependencies = [ "ark-serialize-derive", - "ark-std", + "ark-std 0.4.0", "digest 0.10.7", "num-bigint", ] @@ -306,6 +389,16 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ark-std" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +dependencies = [ + "num-traits", + "rand 0.8.5", +] + [[package]] name = "ark-std" version = "0.4.0" @@ -1019,6 +1112,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "cookie" version = "0.14.4" @@ -1251,8 +1350,10 @@ version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ + "convert_case", "proc-macro2", "quote", + "rustc_version 0.4.0", "syn 1.0.109", ] @@ -1628,9 +1729,9 @@ dependencies = [ [[package]] name = "ethers-core" -version = "2.0.12" +version = "2.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "918b1a9ba585ea61022647def2f27c29ba19f6d2a4a4c8f68a9ae97fd5769737" +checksum = "aab3cef6cc1c9fd7f787043c81ad3052eff2b96a3878ef1526aa446311bdbfc9" dependencies = [ "arrayvec", "bytes 1.5.0", @@ -1860,6 +1961,17 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +[[package]] +name = "fastrlp" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139834ddba373bbdd213dffe02c8d110508dcf1726c2be27e8d1f7d7e1856418" +dependencies = [ + "arrayvec", + "auto_impl", + "bytes 1.5.0", +] + [[package]] name = "ff" version = "0.13.0" @@ -2260,6 +2372,12 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + [[package]] name = "hkdf" version = "0.10.0" @@ -2659,6 +2777,16 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "keccak-asm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb8515fff80ed850aea4a1595f2e519c003e2a00a82fe168ebf5269196caf444" +dependencies = [ + "digest 0.10.7", + "sha3-asm", +] + [[package]] name = "kv-log-macro" version = "1.0.7" @@ -2799,9 +2927,9 @@ name = "merkle-tree" version = "0.1.0" source = "git+https://github.com/personaelabs/merkle-tree.git#0438708139d94cb0c3642504e851853aebe6affc" dependencies = [ - "ark-ff", + "ark-ff 0.4.2", "ark-secp256k1", - "ark-std", + "ark-std 0.4.0", "csv", "hex", "num-bigint", @@ -2815,11 +2943,11 @@ dependencies = [ name = "merkle-tree-wasm" version = "1.1.0" dependencies = [ - "ark-ff", + "ark-ff 0.4.2", "ark-secp256k1", "ark-secq256k1", - "ark-serialize", - "ark-std", + "ark-serialize 0.4.2", + "ark-std 0.4.0", "console_error_panic_hook", "csv", "hex", @@ -3145,6 +3273,17 @@ version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +[[package]] +name = "pest" +version = "2.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f8023d0fb78c8e03784ea1c7f3fa36e68a723138990b8d5a47d916b651e7a8" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + [[package]] name = "petgraph" version = "0.6.4" @@ -3327,7 +3466,7 @@ name = "poseidon" version = "0.1.0" source = "git+https://github.com/personaelabs/poseidon#b798817998d0f54687a2ab0f6158fea962f3703c" dependencies = [ - "ark-ff", + "ark-ff 0.4.2", "tiny-keccak", ] @@ -3476,6 +3615,8 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ + "bit-set", + "bit-vec", "bitflags 2.4.1", "lazy_static", "num-traits", @@ -3483,9 +3624,17 @@ dependencies = [ "rand_chacha 0.3.1", "rand_xorshift", "regex-syntax 0.8.2", + "rusty-fork", + "tempfile", "unarray", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.35" @@ -3767,6 +3916,36 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "ruint" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49b1d9521f889713d1221270fdd63370feca7e5c71a18745343402fa86e4f04f" +dependencies = [ + "alloy-rlp", + "ark-ff 0.3.0", + "ark-ff 0.4.2", + "bytes 1.5.0", + "fastrlp", + "num-bigint", + "num-traits", + "parity-scale-codec", + "primitive-types", + "proptest", + "rand 0.8.5", + "rlp", + "ruint-macro", + "serde", + "valuable", + "zeroize", +] + +[[package]] +name = "ruint-macro" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f86854cf50259291520509879a5c294c3c9a4c334e9ff65071c51e42ef1e2343" + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -3788,6 +3967,15 @@ dependencies = [ "semver 0.9.0", ] +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", +] + [[package]] name = "rustc_version" version = "0.4.0" @@ -3861,6 +4049,18 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + [[package]] name = "ryu" version = "1.0.16" @@ -3891,11 +4091,11 @@ version = "0.1.0" source = "git+https://github.com/personaelabs/sapir.git?branch=main#6f170ef812c26a342203106672a94cd5c6ed6777" dependencies = [ "ark-ec", - "ark-ff", + "ark-ff 0.4.2", "ark-secp256k1", "ark-secq256k1", - "ark-serialize", - "ark-std", + "ark-serialize 0.4.2", + "ark-std 0.4.0", "console_error_panic_hook", "getrandom 0.2.12", "hex", @@ -3990,7 +4190,16 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser", + "semver-parser 0.7.0", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser 0.10.2", ] [[package]] @@ -4008,6 +4217,15 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + [[package]] name = "send_wrapper" version = "0.4.0" @@ -4143,6 +4361,16 @@ dependencies = [ "keccak", ] +[[package]] +name = "sha3-asm" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bac61da6b35ad76b195eb4771210f947734321a8d81d7738e1580d953bc7a15e" +dependencies = [ + "cc", + "cfg-if", +] + [[package]] name = "signature" version = "2.2.0" @@ -4236,10 +4464,10 @@ name = "spartan-ecdsa-wasm" version = "1.0.0" dependencies = [ "ark-ec", - "ark-ff", + "ark-ff 0.4.2", "ark-secp256k1", "ark-secq256k1", - "ark-serialize", + "ark-serialize 0.4.2", "ethers", "merkle-tree-wasm", "num-bigint", @@ -4820,6 +5048,12 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + [[package]] name = "uint" version = "0.9.5" @@ -4936,6 +5170,12 @@ dependencies = [ "serde", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "value-bag" version = "1.7.0" diff --git a/pkgs/cli/Cargo.toml b/pkgs/cli/Cargo.toml index 86ad7ece..c94fe1df 100644 --- a/pkgs/cli/Cargo.toml +++ b/pkgs/cli/Cargo.toml @@ -16,6 +16,7 @@ name = "akli" path = "bin/main.rs" [dependencies] +alloy-primitives = "0.6.4" anyhow = "1.0.80" async-std = { version="1.12.0", features = ["attributes"] } clap = { version = "4.5.1", features = ["derive"] } @@ -28,6 +29,7 @@ serde_json = "1.0.114" surf = "2.3.2" [dev-dependencies] +alloy-primitives = "0.6.4" assert_cmd = "2.0.14" assert_fs = "1.1.1" predicates = "3.1.0" diff --git a/pkgs/cli/bin/opts.rs b/pkgs/cli/bin/opts.rs index bd9e9c6b..c3cd3fa3 100644 --- a/pkgs/cli/bin/opts.rs +++ b/pkgs/cli/bin/opts.rs @@ -1,4 +1,5 @@ use akli::EnsVoteChoice; +use alloy_primitives::Address; use clap::{Parser, Subcommand}; /// Perform Anonklub operations from the command line @@ -29,8 +30,8 @@ pub enum AkliCommand { pub enum QuerySubcommand { Beacon, Erc20 { - #[clap(short, long)] - address: String, + #[clap(short, long, value_parser(|s: &str|s.parse::
()))] + address: Address, #[clap(short, long)] min: Option, }, @@ -39,8 +40,8 @@ pub enum QuerySubcommand { min: Option, }, Nft { - #[clap(short, long)] - address: String, + #[clap(short, long, value_parser(|s: &str|s.parse::
()))] + address: Address, }, Punks, Ens { diff --git a/pkgs/cli/src/get_anonset/erc20.rs b/pkgs/cli/src/get_anonset/erc20.rs index fd302c6a..29cc9ba7 100644 --- a/pkgs/cli/src/get_anonset/erc20.rs +++ b/pkgs/cli/src/get_anonset/erc20.rs @@ -1,4 +1,7 @@ +#![allow(non_snake_case)] + use crate::{get_anonset, Anonset}; +use alloy_primitives::Address; use anyhow::Result; use serde::{Deserialize, Serialize}; @@ -9,10 +12,10 @@ struct Erc20AnonSetQuery { min: Option, } -pub async fn get_erc20_anonset(address: String, min: Option) -> Result { +pub async fn get_erc20_anonset(address: Address, min: Option) -> Result { get_anonset( Some(Erc20AnonSetQuery { - tokenAddress: address, + tokenAddress: address.to_string(), min, }), "asset/erc20", diff --git a/pkgs/cli/src/get_anonset/nft.rs b/pkgs/cli/src/get_anonset/nft.rs index e52412ba..a73fdc41 100644 --- a/pkgs/cli/src/get_anonset/nft.rs +++ b/pkgs/cli/src/get_anonset/nft.rs @@ -1,4 +1,7 @@ +#![allow(non_snake_case)] + use crate::{get_anonset, Anonset}; +use alloy_primitives::Address; use anyhow::Result; use serde::{Deserialize, Serialize}; @@ -8,10 +11,10 @@ struct NftAnonSetQuery { tokenAddress: String, } -pub async fn get_nft_anonset(address: String) -> Result { +pub async fn get_nft_anonset(address: Address) -> Result { get_anonset( Some(NftAnonSetQuery { - tokenAddress: address, + tokenAddress: address.to_string(), }), "asset/nft", ) diff --git a/pkgs/cli/tests/cli.rs b/pkgs/cli/tests/cli.rs index b7a24749..7a3d8277 100644 --- a/pkgs/cli/tests/cli.rs +++ b/pkgs/cli/tests/cli.rs @@ -1,36 +1,71 @@ use assert_cmd::prelude::*; // Add methods on commands -use assert_fs::prelude::*; use predicates::prelude::*; // Used for writing assertions use std::process::Command; // Run programs -const BIN_NAME: &str = "grrs"; +const BIN_NAME: &str = "akli"; #[test] -fn file_doesnt_exist() -> Result<(), Box> { +fn no_args() -> Result<(), Box> { let mut cmd = Command::cargo_bin(BIN_NAME)?; - cmd.arg("-p foo").arg("-f absent.txt"); cmd.assert() .failure() - .stderr(predicate::str::contains("Could not read file")); + .stderr(predicate::str::contains("Usage")); Ok(()) } + #[test] -fn find_content_in_file() -> Result<(), Box> { - const FILE_NAME: &str = "sample.txt"; - const CONTENT: &str = "A test\nActual content\nMore content\nAnother test"; - const PATTERN: &str = "test"; - - let temp_file = assert_fs::NamedTempFile::new(FILE_NAME)?; - temp_file.write_str(CONTENT)?; - +fn query_eth() -> Result<(), Box> { let mut cmd = Command::cargo_bin(BIN_NAME)?; - cmd.arg("-p").arg(PATTERN).arg("-f").arg(temp_file.path()); + cmd.arg("query").arg("eth").arg("--min").arg("100000"); cmd.assert() .success() - .stdout(predicate::str::contains("A test\nAnother test")); + .stdout(predicate::str::contains("0x")); + Ok(()) +} + +#[test] +fn query_erc20_odd_address() -> Result<(), Box> { + let mut cmd = Command::cargo_bin(BIN_NAME)?; + + cmd.arg("query").arg("erc20").arg("--address").arg("0x0").arg("--min").arg("100000"); + cmd.assert() + .failure() + .stderr(predicate::str::contains("Odd number of digits")); Ok(()) } + +#[test] +fn query_erc20_wrong_length_address() -> Result<(), Box> { + let mut cmd = Command::cargo_bin(BIN_NAME)?; + + cmd.arg("query").arg("erc20").arg("--address").arg("0x2b661d3a28490794000b7FCaA5f9D732501bbb"); + cmd.assert() + .failure() + .stderr(predicate::str::contains("Invalid string length")); + Ok(()) +} + +#[test] +fn query_erc20_wrong_min() { + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + + cmd.arg("query").arg("erc20").arg("--address").arg("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045").arg("--min").arg("abc"); + cmd.assert() + .failure() + .stderr(predicate::str::contains("invalid digit found in string")); +} + +#[test] +fn query_ens_wrong_choice() { + let mut cmd = Command::cargo_bin(BIN_NAME).unwrap(); + + cmd.arg("query").arg("ens").arg("--id").arg("anonklub.eth").arg("--choice").arg("abc"); + cmd.assert() + .failure() + .stderr(predicate::str::contains("invalid value")) + .stderr(predicate::str::contains("possible values: yes, no, abstain")); +}