diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 94d1a3c..6a2de53 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -37,6 +37,6 @@ futures-core = "0.3" reqwest = "0.11" [features] -int_tests = [] -exp_tests = [] -vol_tests = [] +int_tests = [] #integration tests - require a running Rusk node/cluster +exp_tests = [] #expensive tests - integration tests which take longer time to run +vol_tests = [] #volatile tests - integration tests which require constants' update before running diff --git a/integration-tests/tests/int_test_user.rs b/integration-tests/tests/int_test_user.rs index 74252c4..294642b 100644 --- a/integration-tests/tests/int_test_user.rs +++ b/integration-tests/tests/int_test_user.rs @@ -109,7 +109,7 @@ async fn issue_license( /// Calculates and verified proof, sends proof along with public parameters /// as arguments to the license contract's use_license method. /// Awaits for confirmation of the contract-calling transaction. -async fn use_license( +async fn prove_and_send_use_license( client: &RuskHttpClient, blockchain_config: &BlockchainAccessConfig, wallet_path: &WalletPath, @@ -305,7 +305,7 @@ async fn user_round_trip() -> Result<(), Error> { show_state(&client, "before use_license").await?; info!("calling use_license (as a user)"); - let session_id = use_license( + let session_id = prove_and_send_use_license( &client, &blockchain_config, &wallet_path, @@ -333,6 +333,5 @@ async fn user_round_trip() -> Result<(), Error> { ); // if we try to call use_license again, it will be rejected - // (currently, it panics giving Trap(UnreachableCodeReached)) Ok(()) } diff --git a/integration-tests/tests/queries.rs b/integration-tests/tests/queries.rs index f0d8bd4..9d2df31 100644 --- a/integration-tests/tests/queries.rs +++ b/integration-tests/tests/queries.rs @@ -7,12 +7,9 @@ use dusk_wallet::RuskHttpClient; use moat_core::{CitadelInquirer, Error, StreamAux}; use toml_base_config::BaseConfig; -use tracing::debug; +use tracing::trace; use wallet_accessor::BlockchainAccessConfig; -#[allow(dead_code)] -const MAX_CALL_SIZE: usize = 65536; - #[tokio::test(flavor = "multi_thread")] #[cfg_attr(not(feature = "int_tests"), ignore)] async fn call_get_licenses() -> Result<(), Error> { @@ -28,7 +25,7 @@ async fn call_get_licenses() -> Result<(), Error> { const ITEM_LEN: usize = CitadelInquirer::GET_LICENSES_ITEM_LEN; let response = StreamAux::collect_all::<(u64, Vec), ITEM_LEN>(stream)?; - debug!("response={:?}", response); + trace!("response={:?}", response); Ok(()) } @@ -44,7 +41,6 @@ async fn call_get_merkle_opening() -> Result<(), Error> { let pos = 0u64; let response = CitadelInquirer::get_merkle_opening(&client, pos).await?; - - debug!("response={:?}", response); + trace!("response={:?}", response); Ok(()) } diff --git a/integration-tests/tests/retrieve_requests.rs b/integration-tests/tests/retrieve_requests.rs index 95262e7..d75770f 100644 --- a/integration-tests/tests/retrieve_requests.rs +++ b/integration-tests/tests/retrieve_requests.rs @@ -67,7 +67,7 @@ async fn scan_requests_in_last_blocks() -> Result<(), Error> { let requests = RequestScanner::scan_last_blocks(LAST_BLOCKS, &cfg).await?; trace!( - "there were {} requests found in last n={} blocks", + "there were {} requests found in last {} blocks", requests.len(), LAST_BLOCKS ); diff --git a/integration-tests/tests/retrieve_txs.rs b/integration-tests/tests/retrieve_txs.rs index 49f04d9..71b13a1 100644 --- a/integration-tests/tests/retrieve_txs.rs +++ b/integration-tests/tests/retrieve_txs.rs @@ -49,8 +49,6 @@ async fn retrieve_txs_from_block_range() -> Result<(), Error> { ) .await?; - assert!(top_block > 0); - trace!("transactions retrieved={}", txs.transactions.len()); trace!("current top block={}", top_block); diff --git a/integration-tests/tests/send_request.rs b/integration-tests/tests/send_request.rs index 80d3491..6c5e280 100644 --- a/integration-tests/tests/send_request.rs +++ b/integration-tests/tests/send_request.rs @@ -8,6 +8,7 @@ use dusk_jubjub::BlsScalar; use dusk_wallet::{RuskHttpClient, WalletPath}; use moat_core::{ Error, PayloadRetriever, PayloadSender, RequestCreator, RequestJson, + MAX_REQUEST_SIZE, }; use moat_core::{JsonLoader, TxAwaiter}; use rand::rngs::StdRng; @@ -48,7 +49,9 @@ async fn send_request() -> Result<(), Error> { request_json.provider_psk, rng, )?; - let request_vec = rkyv::to_bytes::<_, 8192>(&request).unwrap().to_vec(); + let request_vec = rkyv::to_bytes::<_, MAX_REQUEST_SIZE>(&request) + .unwrap() + .to_vec(); let config = BlockchainAccessConfig::load_path(config_path)?; @@ -74,7 +77,7 @@ async fn send_request() -> Result<(), Error> { get_request_from_blockchain(tx_id_hex, &client).await?; assert_eq!( request_vec, - rkyv::to_bytes::<_, 8192>(&retrieved_request) + rkyv::to_bytes::<_, MAX_REQUEST_SIZE>(&retrieved_request) .unwrap() .to_vec(), "requests not equal" diff --git a/integration-tests/tests/stake_add_owner.rs b/integration-tests/tests/stake_add_owner.rs index d6436b8..7f78397 100644 --- a/integration-tests/tests/stake_add_owner.rs +++ b/integration-tests/tests/stake_add_owner.rs @@ -5,21 +5,15 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use dusk_wallet::{RuskHttpClient, WalletPath}; -use moat_core::{Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter}; -use phoenix_core::transaction::ModuleId; +use moat_core::{ + Error, JsonLoader, PayloadSender, RequestJson, TxAwaiter, + ADD_OWNER_METHOD_NAME, STAKE_CONTRACT_ID, +}; use std::path::PathBuf; use toml_base_config::BaseConfig; use wallet_accessor::BlockchainAccessConfig; use wallet_accessor::Password::PwdHash; -const STAKE_CONTRACT_ID: ModuleId = { - let mut bytes = [0u8; 32]; - bytes[0] = 0x02; - bytes -}; - -const ADD_OWNER_METHOD_NAME: &str = "add_owner"; - const WALLET_PATH: &str = concat!(env!("HOME"), "/.dusk/rusk-wallet"); const PWD_HASH: &str = "7f2611ba158b6dcea4a69c229c303358c5e04493abeadee106a4bfa464d55787"; diff --git a/integration-tests/tests/ws_queries.rs b/integration-tests/tests/websocket/ws_queries.rs similarity index 95% rename from integration-tests/tests/ws_queries.rs rename to integration-tests/tests/websocket/ws_queries.rs index b69eb9b..1663c2e 100644 --- a/integration-tests/tests/ws_queries.rs +++ b/integration-tests/tests/websocket/ws_queries.rs @@ -5,8 +5,6 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use moat_core::{CitadelInquirerWs, Error, LicenseSession, LicenseSessionId}; -pub mod websocket; -use crate::websocket::ws_license_contract_mock_multi_server; use dusk_jubjub::BlsScalar; const TEST_DURATION_SECONDS: u64 = 4; diff --git a/integration-tests/tests/websocket/ws_server.rs b/integration-tests/tests/websocket/ws_server.rs index 5d9b2f0..61f6284 100644 --- a/integration-tests/tests/websocket/ws_server.rs +++ b/integration-tests/tests/websocket/ws_server.rs @@ -7,7 +7,7 @@ use crate::websocket::ws_common::*; use dusk_jubjub::BlsScalar; use futures_util::{SinkExt, StreamExt}; -use moat_core::{Error, LicenseSession}; +use moat_core::{Error, LicenseSession, MAX_RESPONSE_SIZE}; use tokio::net::{TcpListener, TcpStream}; use tokio_tungstenite::tungstenite::Message; use tracing::trace; @@ -33,7 +33,6 @@ pub async fn ws_license_contract_mock_server( Ok(()) } -// todo: remove this redundant server implementation #[allow(dead_code)] pub async fn ws_license_contract_mock_multi_server( seconds: u64, @@ -101,13 +100,13 @@ async fn accept_connection(stream: TcpStream) { let response_data: Option = Some(LicenseSession { public_inputs: vec![BlsScalar::zero()], }); - rkyv::to_bytes::<_, 8192>(&response_data) + rkyv::to_bytes::<_, MAX_RESPONSE_SIZE>(&response_data) .expect("Data should serialize correctly") .to_vec() } "get_licenses" => { let response_data = vec![vec![1u8], vec![2u8]]; - rkyv::to_bytes::<_, 8192>(&response_data) + rkyv::to_bytes::<_, MAX_RESPONSE_SIZE>(&response_data) .expect("Data should serialize correctly") .to_vec() } diff --git a/integration-tests/tests/websocket/ws_test.rs b/integration-tests/tests/websocket/ws_test.rs index 43bcfa6..21db1e8 100644 --- a/integration-tests/tests/websocket/ws_test.rs +++ b/integration-tests/tests/websocket/ws_test.rs @@ -14,7 +14,7 @@ const TEST_DURATION_SECONDS: u64 = 4; const PORT: u32 = 9125; #[tokio::test] -#[cfg_attr(not(feature = "int_tests"), ignore)] +#[ignore] async fn ws_license_contract_mock_call() -> Result<(), Error> { trace!("test driver - spawning ws license contract mock server"); tokio::spawn(ws_license_contract_mock_server(TEST_DURATION_SECONDS, PORT)); diff --git a/license-provider/src/license_issuer.rs b/license-provider/src/license_issuer.rs index 709bf92..64c82c7 100644 --- a/license-provider/src/license_issuer.rs +++ b/license-provider/src/license_issuer.rs @@ -8,7 +8,7 @@ use dusk_jubjub::{BlsScalar, JubJubAffine, JubJubScalar}; use dusk_pki::SecretSpendKey; use dusk_poseidon::sponge; use dusk_wallet::{RuskHttpClient, WalletPath}; -use moat_core::{Error, PayloadSender, TxAwaiter}; +use moat_core::{Error, PayloadSender, TxAwaiter, MAX_LICENSE_SIZE}; use rand::{CryptoRng, RngCore}; use tracing::trace; use wallet_accessor::{BlockchainAccessConfig, Password}; @@ -22,11 +22,8 @@ pub struct LicenseIssuer { gas_price: u64, } -// todo: explain how are user attributes going to be passed in here from the -// user -const USER_ATTRIBUTES: u64 = 1 << 17; //0x9b308734u64; +const USER_ATTRIBUTES: u64 = 1 << 17; -#[allow(dead_code)] impl LicenseIssuer { pub fn new( config: BlockchainAccessConfig, @@ -52,7 +49,7 @@ impl LicenseIssuer { ) -> Result { let attr = JubJubScalar::from(USER_ATTRIBUTES); let license = License::new(&attr, ssk_lp, request, rng); - let license_blob = rkyv::to_bytes::<_, 8192>(&license) + let license_blob = rkyv::to_bytes::<_, MAX_LICENSE_SIZE>(&license) .expect("License should serialize correctly") .to_vec(); let lpk = JubJubAffine::from(license.lsa.pk_r().as_ref()); diff --git a/license-provider/src/reference_lp.rs b/license-provider/src/reference_lp.rs index fb64298..e31cb6a 100644 --- a/license-provider/src/reference_lp.rs +++ b/license-provider/src/reference_lp.rs @@ -7,7 +7,7 @@ use blake3::OUT_LEN; use dusk_bytes::DeserializableSlice; use dusk_pki::{PublicSpendKey, SecretSpendKey, ViewKey}; -use moat_core::{Error, JsonLoader, RequestScanner}; +use moat_core::{Error, JsonLoader, RequestScanner, MAX_REQUEST_SIZE}; use std::collections::BTreeSet; use std::path::Path; use wallet_accessor::BlockchainAccessConfig; @@ -140,7 +140,7 @@ impl ReferenceLP { fn hash_request(request: &Request) -> [u8; OUT_LEN] { *blake3::hash( - rkyv::to_bytes::<_, 4096>(request) + rkyv::to_bytes::<_, MAX_REQUEST_SIZE>(request) .expect("Request should serialize correctly") .as_slice(), ) diff --git a/moat-core/src/blockchain_requests/payload_sender.rs b/moat-core/src/blockchain_requests/payload_sender.rs index 719b560..487a99c 100644 --- a/moat-core/src/blockchain_requests/payload_sender.rs +++ b/moat-core/src/blockchain_requests/payload_sender.rs @@ -5,6 +5,10 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use crate::error::Error; +use crate::{ + ISSUE_LICENSE_METHOD_NAME, LICENSE_CONTRACT_ID, MAX_CALL_SIZE, + NOOP_METHOD_NAME, USE_LICENSE_METHOD_NAME, +}; use dusk_jubjub::BlsScalar; use dusk_wallet::WalletPath; use phoenix_core::transaction::ModuleId; @@ -13,18 +17,6 @@ use wallet_accessor::{BlockchainAccessConfig, Password, WalletAccessor}; pub struct PayloadSender; -const LICENSE_CONTRACT_ID: ModuleId = { - let mut bytes = [0u8; 32]; - bytes[0] = 0x03; - bytes -}; - -const NOOP_METHOD_NAME: &str = "noop"; -const ISSUE_LICENSE_METHOD_NAME: &str = "issue_license"; -const USE_LICENSE_METHOD_NAME: &str = "use_license"; - -const MAX_CALL_SIZE: usize = 65536; - impl PayloadSender { /// Sends a given payload to the noop method pub async fn send_noop

( diff --git a/moat-core/src/contract_queries/citadel_inquirer.rs b/moat-core/src/contract_queries/citadel_inquirer.rs index 2f30948..c6ed158 100644 --- a/moat-core/src/contract_queries/citadel_inquirer.rs +++ b/moat-core/src/contract_queries/citadel_inquirer.rs @@ -6,26 +6,18 @@ use crate::contract_queries::block::Block; use crate::error::Error; -use crate::{ContractInquirer, LicenseSession, LicenseSessionId, ARITY, DEPTH}; +use crate::{ + ContractInquirer, LicenseSession, LicenseSessionId, ARITY, DEPTH, + GET_INFO_METHOD_NAME, GET_LICENSES_METHOD_NAME, + GET_MERKLE_OPENING_METHOD_NAME, GET_SESSION_METHOD_NAME, + LICENSE_CONTRACT_ID, +}; use bytes::Bytes; use dusk_wallet::RuskHttpClient; -use phoenix_core::transaction::ModuleId; use poseidon_merkle::Opening; use std::ops::Range; use zk_citadel::license::License; -// todo: refactor such consts to some common location -const LICENSE_CONTRACT_ID: ModuleId = { - let mut bytes = [0u8; 32]; - bytes[0] = 0x03; - bytes -}; - -const GET_LICENSES_METHOD_NAME: &str = "get_licenses"; -const GET_MERKLE_OPENING_METHOD_NAME: &str = "get_merkle_opening"; -const GET_SESSION_METHOD_NAME: &str = "get_session"; -const GET_INFO_METHOD_NAME: &str = "get_info"; - pub struct CitadelInquirer {} impl CitadelInquirer { diff --git a/moat-core/src/contract_queries/citadel_inquirer_ws.rs b/moat-core/src/contract_queries/citadel_inquirer_ws.rs index 5fb87f0..5628c74 100644 --- a/moat-core/src/contract_queries/citadel_inquirer_ws.rs +++ b/moat-core/src/contract_queries/citadel_inquirer_ws.rs @@ -5,19 +5,11 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use crate::error::Error; -use crate::{ContractInquirerWs, LicenseSession, LicenseSessionId}; -use phoenix_core::transaction::ModuleId; -use std::ops::Range; - -// todo: refactor such consts to some common location -const LICENSE_CONTRACT_ID: ModuleId = { - let mut bytes = [0u8; 32]; - bytes[0] = 0x03; - bytes +use crate::{ + ContractInquirerWs, LicenseSession, LicenseSessionId, + GET_LICENSES_METHOD_NAME, GET_SESSION_METHOD_NAME, LICENSE_CONTRACT_ID, }; - -const GET_LICENSES_METHOD_NAME: &str = "get_licenses"; -const GET_SESSION_METHOD_NAME: &str = "get_session"; +use std::ops::Range; pub struct CitadelInquirerWs {} diff --git a/moat-core/src/contract_queries/contract_inquirer.rs b/moat-core/src/contract_queries/contract_inquirer.rs index e7c2a53..8aa2ef8 100644 --- a/moat-core/src/contract_queries/contract_inquirer.rs +++ b/moat-core/src/contract_queries/contract_inquirer.rs @@ -7,6 +7,7 @@ use crate::contract_queries::block::Block; use crate::error::Error; use crate::Error::InvalidQueryResponse; +use crate::MAX_CALL_SIZE; use bytecheck::CheckBytes; use bytes::Bytes; use dusk_wallet::{RuskHttpClient, RuskRequest}; @@ -14,13 +15,8 @@ use phoenix_core::transaction::ModuleId; use rkyv::validation::validators::DefaultValidator; use rkyv::{check_archived_root, Archive, Deserialize, Infallible}; -#[allow(dead_code)] pub struct ContractInquirer {} -#[allow(dead_code)] -const MAX_CALL_SIZE: usize = 65536; - -#[allow(dead_code)] impl ContractInquirer { pub async fn query_contract( client: &RuskHttpClient, diff --git a/moat-core/src/contract_queries/contract_inquirer_ws.rs b/moat-core/src/contract_queries/contract_inquirer_ws.rs index abc3f7f..422c456 100644 --- a/moat-core/src/contract_queries/contract_inquirer_ws.rs +++ b/moat-core/src/contract_queries/contract_inquirer_ws.rs @@ -7,6 +7,7 @@ use crate::contract_queries::ws_types::{ExecutionRequest, ExecutionResponse}; use crate::error::Error; use crate::Error::{InvalidQueryResponse, WebSocketStreamClosed}; +use crate::MAX_CALL_SIZE; use bytecheck::CheckBytes; use futures_util::{SinkExt, StreamExt}; use phoenix_core::transaction::ModuleId; @@ -17,13 +18,8 @@ use tokio::net::TcpStream; use tokio_tungstenite::client_async; use tokio_tungstenite::tungstenite::Message; -#[allow(dead_code)] pub struct ContractInquirerWs {} -#[allow(dead_code)] -const MAX_CALL_SIZE: usize = 65536; - -#[allow(dead_code)] impl ContractInquirerWs { pub async fn query_contract( url: impl AsRef, @@ -40,7 +36,7 @@ impl ContractInquirerWs { { let stream = TcpStream::connect(url.as_ref()).await?; - let url = format!("ws://{}", url.as_ref()); // todo: find a more elegant way // /01/stream + let url = format!("ws://{}", url.as_ref()); let (mut ws_stream, _) = client_async(url, stream).await?; diff --git a/moat-core/src/types.rs b/moat-core/src/types.rs index 56326db..25d7cdb 100644 --- a/moat-core/src/types.rs +++ b/moat-core/src/types.rs @@ -5,6 +5,35 @@ // Copyright (c) DUSK NETWORK. All rights reserved. use crate::JsonLoader; +use phoenix_core::transaction::ModuleId; + +pub const STAKE_CONTRACT_ID: ModuleId = { + let mut bytes = [0u8; 32]; + bytes[0] = 0x02; + bytes +}; +pub const LICENSE_CONTRACT_ID: ModuleId = { + let mut bytes = [0u8; 32]; + bytes[0] = 0x03; + bytes +}; + +// license contract method names +pub const NOOP_METHOD_NAME: &str = "noop"; +pub const ISSUE_LICENSE_METHOD_NAME: &str = "issue_license"; +pub const USE_LICENSE_METHOD_NAME: &str = "use_license"; +pub const GET_LICENSES_METHOD_NAME: &str = "get_licenses"; +pub const GET_MERKLE_OPENING_METHOD_NAME: &str = "get_merkle_opening"; +pub const GET_SESSION_METHOD_NAME: &str = "get_session"; +pub const GET_INFO_METHOD_NAME: &str = "get_info"; + +// stake contract method names +pub const ADD_OWNER_METHOD_NAME: &str = "add_owner"; + +pub const MAX_CALL_SIZE: usize = 65536; +pub const MAX_REQUEST_SIZE: usize = 8192; +pub const MAX_LICENSE_SIZE: usize = 16384; +pub const MAX_RESPONSE_SIZE: usize = 65536; #[derive(Debug, Default, serde::Deserialize, serde::Serialize)] pub struct RequestJson { diff --git a/moat-core/tests/utils.rs b/moat-core/tests/utils.rs index bb68475..85d979c 100644 --- a/moat-core/tests/utils.rs +++ b/moat-core/tests/utils.rs @@ -6,7 +6,7 @@ use dusk_bytes::{DeserializableSlice, Serializable}; use dusk_pki::SecretSpendKey; -use moat_core::{Error, RequestCreator}; +use moat_core::{Error, RequestCreator, MAX_REQUEST_SIZE}; use rand::rngs::StdRng; use rand::SeedableRng; use sha2::Digest; @@ -32,7 +32,7 @@ fn create_serialized_request() -> Result<(), Error> { "29c4336ef24e585f4506e32e269c5363a71f7dcd74586b210c56e569ad2644e832c785f102dd3c985c705008ec188be819bac85b65c9f70decb9adcf4a72cc43", rng, )?; - let v = rkyv::to_bytes::<_, 8192>(&request) + let v = rkyv::to_bytes::<_, MAX_REQUEST_SIZE>(&request) .expect("Infallible") .to_vec(); println!("request={}", hex::encode(v)); diff --git a/wallet-accessor/src/wallet_accessor.rs b/wallet-accessor/src/wallet_accessor.rs index cd6cf97..07400eb 100644 --- a/wallet-accessor/src/wallet_accessor.rs +++ b/wallet-accessor/src/wallet_accessor.rs @@ -50,9 +50,9 @@ impl WalletAccessor { hasher.update(s.as_bytes()); hasher.finalize().to_vec() } - PwdHash(h) => { - hex::decode(h.as_str()).unwrap_or([0u8; 32].to_vec()) - } // todo - how do we react to invalid hex of the hash + PwdHash(h) => hex::decode(h.as_str()) + .expect("Password hash should be valid hex string") + .to_vec(), } }, }