Skip to content

Commit

Permalink
Made challenge in test dependent on the number of sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
miloszm committed Oct 5, 2023
1 parent 7d4e966 commit c517536
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 20 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ The request can then be sent to license provider, off-chain or on-chain.
Class: RequestSender
Methods: send_request
Submits the request into blockchain.
It does so by calling a dummy contract method with request as an argument.

Class: RequestScanner
Methods:
scan_transactions,
scan_last_blocks,
scan_block_range
Methods scan requests in a given collection of transactions,
in a given range of blocks,
or in a given number of most recent blocks.
Scan requests in a given collection of transactions,
contained in a given range of blocks or in a given number of most recent blocks.

### citadel queries

Expand All @@ -130,49 +130,53 @@ Methods:
get_merkle_opening,
get_session,
get_info
Execute citadel-specific query methods of the license contract method.

### blockchain payloads

Class: PayloadExtractor
Methods: payload_from_tx
Extracts payload from transaction, errors if payload of a given type is not present
in the transaction or a give transaction is not a contract calling transaction.
Extracts a payload from the given transaction,
errors if payload of a given type is not present or the transaction is not a contract calling transaction.

Class: PayloadRetriever
Methods: retrieve_payload
Retrieves payload of a given transaction in a blockchain, errors if the transaction
is not found or it doesn't contain a payload (e.g., given transaction is not a contract calling transaction)
Retrieves payload of a given transaction id,
errors if transaction is not found, or it does not contain a payload
(for example, given transaction is not a contract calling transaction)

Class: PayloadSender
Methods: execute_contract_method
Executes a given method of a given contract, passing to it the given payload as an argument.
Executes given method of a given contract (identified by a contract id), passing to it the payload as an argument.

### contract queries

Class: ContractInquirer
Methods:
query_contract,
query_contract_with_feeder
query_contract: accepts generic argument A, contract id and method name and returns generic value R
query_contract_with_feeder: accepts generic argument A, contract id and method name and returns a Stream of type Bytes
query_contract - accepts a generic argument, contract id and contract query method name, returns a generic value result
query_contract_with_feeder - accepts a generic argument, contract id and method name, returns result as a Stream of bytes

### blockchain queries

Class: BcInquirer
Methods:
gql_query,
block_height
gql_query - executes a GQL query and returns result as a vector of bytes
block_height - returns the current block height as u64

Class: TxAwaiter
Methods:
wait_for,
wait_for_tx
Waits for transaction identified by a given transaction id to be confirmed on the blockchain.
Waits for a transaction identified by transaction id to be confirmed on the blockchain.

Class: TxInquirer
Methods:
txs_from_block,
txs_from_block_range,
txs_from_last_n_blocks,
retrieve_tx

Retrieve transaction identified by transaction id, or transactions contained in a given block, or a collection of blocks.
15 changes: 11 additions & 4 deletions integration-tests/tests/citadel/int_test_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,14 @@ fn compute_citadel_parameters(
psk_lp: PublicSpendKey,
lic: &License,
merkle_proof: Opening<(), DEPTH, ARITY>,
challenge: &JubJubScalar,
) -> (CitadelProverParameters<DEPTH, ARITY>, SessionCookie) {
const CHALLENGE: u64 = 20221127u64;
let c = JubJubScalar::from(CHALLENGE);
let (cpp, sc) = CitadelProverParameters::compute_parameters(
&ssk,
&lic,
&psk_lp,
&psk_lp,
&c,
challenge,
rng,
merkle_proof,
);
Expand Down Expand Up @@ -121,13 +120,15 @@ async fn prove_and_send_use_license(
license: &License,
opening: Opening<(), DEPTH, ARITY>,
rng: &mut StdRng,
challenge: &JubJubScalar,
) -> Result<BlsScalar, Error> {
let (cpp, sc) = compute_citadel_parameters(
rng,
ssk_user,
reference_lp.psk_lp,
license,
opening,
&challenge,
);
let circuit = LicenseCircuit::new(&cpp, &sc);

Expand Down Expand Up @@ -336,11 +337,16 @@ async fn user_round_trip() -> Result<(), Error> {

// as a User, call get_merkle_opening, obtain opening
info!("calling get_merkle_opening (as a user)");
let opening = CitadelInquirer::get_merkle_opening(&client, pos).await?;
let opening =
CitadelInquirer::get_merkle_opening(&client, pos.clone()).await?;
assert!(opening.is_some());

// as a User, compute proof, call use_license, wait for tx to confirm
show_state(&client, "before use_license").await?;
// for test purposes we make challenge dependent on the number of sessions,
// so that it is different every time we run the test
let (_, _, num_sessions) = CitadelInquirer::get_info(&client).await?;
let challenge = JubJubScalar::from(num_sessions as u64 + 1);
info!("calling use_license (as a user)");
let session_id = prove_and_send_use_license(
&client,
Expand All @@ -353,6 +359,7 @@ async fn user_round_trip() -> Result<(), Error> {
&license,
opening.unwrap(),
rng,
&challenge,
)
.await?;
show_state(&client, "after use_license").await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
//
// Copyright (c) DUSK NETWORK. All rights reserved.

use dusk_bls12_381::BlsScalar;
use dusk_wallet::RuskHttpClient;
use moat_core::{CitadelInquirer, Error, StreamAux};
use moat_core::{CitadelInquirer, Error, LicenseSessionId, StreamAux};
use toml_base_config::BaseConfig;
use tracing::trace;
use wallet_accessor::BlockchainAccessConfig;
Expand Down Expand Up @@ -44,3 +45,37 @@ async fn call_get_merkle_opening() -> Result<(), Error> {
trace!("response={:?}", response);
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn call_get_session() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config = BlockchainAccessConfig::load_path(config_path)?;

let client = RuskHttpClient::new(config.rusk_address);

let response = CitadelInquirer::get_session(
&client,
LicenseSessionId {
id: BlsScalar::one(),
},
)
.await?;
trace!("response={:?}", response);
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
#[cfg_attr(not(feature = "int_tests"), ignore)]
async fn call_get_info() -> Result<(), Error> {
let config_path =
concat!(env!("CARGO_MANIFEST_DIR"), "/tests/config/config.toml");
let config = BlockchainAccessConfig::load_path(config_path)?;

let client = RuskHttpClient::new(config.rusk_address);

let response = CitadelInquirer::get_info(&client).await?;
trace!("response={:?}", response);
Ok(())
}
2 changes: 1 addition & 1 deletion integration-tests/tests/citadel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
mod int_test_lp;
mod int_test_user;
mod issue_license;
mod queries;
mod license_queries;
mod retrieve_requests;
mod send_request;
4 changes: 2 additions & 2 deletions moat-core/src/citadel_requests/request_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl RequestSender {
) -> Result<BlsScalar, Error> {
let tx_id = PayloadSender::execute_contract_method(
request,
&config,
&wallet_path,
config,
wallet_path,
password,
gas_limit,
gas_price,
Expand Down

0 comments on commit c517536

Please sign in to comment.