From bc315b80ff21b97bb48ce093301161193d3771e9 Mon Sep 17 00:00:00 2001 From: Milosz Muszynski Date: Fri, 29 Sep 2023 12:51:11 +0200 Subject: [PATCH] More comments and renaming --- integration-tests/tests/int_test_user.rs | 33 +++++++++++++++---- .../src/blockchain_requests/payload_sender.rs | 2 +- wallet-accessor/src/wallet_accessor.rs | 4 ++- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/integration-tests/tests/int_test_user.rs b/integration-tests/tests/int_test_user.rs index 015ebe9..b3a1cda 100644 --- a/integration-tests/tests/int_test_user.rs +++ b/integration-tests/tests/int_test_user.rs @@ -209,6 +209,25 @@ fn find_owned_license( Ok((pos, deserialise_license(&lic_ser))) } +/// +/// test user_round_trip realizes the following scenario: +/// - creates request (User) +/// - based on the request, calls issue_license (LP) +/// - calls get_licenses, obtains license and position (User) +/// - calls get_merkle_opening for a given position, obtains the opening (User) +/// - based on license and opening, computes proof (User) +/// - calls use_license and creates a session_id (User) +/// - use_license verifies the proof, creates the corresponding session (License +/// Contract) +/// - calls get_session based on a session id given to the SP by the User (SP) +/// +/// - Note that session_id is created by the User and not returned by +/// use_license. Although use_license, internally, also creates the same +/// session_id, it is not returned by it because contract state changing +/// methods do not have the ability to return values. It is assumed that +/// license_id created by the user and by contract are the same. +/// - Note that after each contract method call the test waits for transaction +/// to confirm. #[tokio::test(flavor = "multi_thread")] #[cfg_attr(not(feature = "exp_tests"), ignore)] async fn user_round_trip() -> Result<(), Error> { @@ -244,6 +263,14 @@ async fn user_round_trip() -> Result<(), Error> { let blockchain_config = BlockchainAccessConfig::load_path(blockchain_config_path)?; + let wallet_path = WalletPath::from( + PathBuf::from(WALLET_PATH).as_path().join("wallet.dat"), + ); + + let client = RuskHttpClient::new(blockchain_config.rusk_address.clone()); + + // create request + let request_json: RequestJson = RequestJson::from_file(request_path)?; let request = RequestCreator::create_from_hex_args( @@ -255,12 +282,6 @@ async fn user_round_trip() -> Result<(), Error> { let ssk_user_bytes = hex::decode(request_json.user_ssk)?; let ssk_user = SecretSpendKey::from_slice(ssk_user_bytes.as_slice())?; - let wallet_path = WalletPath::from( - PathBuf::from(WALLET_PATH).as_path().join("wallet.dat"), - ); - - let client = RuskHttpClient::new(blockchain_config.rusk_address.clone()); - // as a LP, call issue license, wait for tx to confirm show_state(&client, "before issue_license").await?; diff --git a/moat-core/src/blockchain_requests/payload_sender.rs b/moat-core/src/blockchain_requests/payload_sender.rs index 6d92b9d..6f6be2b 100644 --- a/moat-core/src/blockchain_requests/payload_sender.rs +++ b/moat-core/src/blockchain_requests/payload_sender.rs @@ -34,7 +34,7 @@ impl PayloadSender { let wallet_accessor = WalletAccessor::new(wallet_path.clone(), password.clone()); let tx_id = wallet_accessor - .send( + .execute_contract_method( payload, contract_id, method.as_ref().to_string(), diff --git a/wallet-accessor/src/wallet_accessor.rs b/wallet-accessor/src/wallet_accessor.rs index 07400eb..2623bcc 100644 --- a/wallet-accessor/src/wallet_accessor.rs +++ b/wallet-accessor/src/wallet_accessor.rs @@ -58,7 +58,9 @@ impl WalletAccessor { } } - pub async fn send( + /// submits a transaction which will execute a given method + /// of a given contract + pub async fn execute_contract_method( &self, data: C, contract_id: ModuleId,