Skip to content

Commit

Permalink
tests: merkle, darkpool: enable feature flags in e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
akirillo committed Sep 4, 2023
1 parent acef506 commit e8a057e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 21 deletions.
10 changes: 8 additions & 2 deletions src/testing/tests/merkle_tests.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use traits::Into;


use renegade_contracts::merkle::{Merkle, Merkle::ContractState, IMerkle};
use renegade_contracts::{
merkle::{Merkle, Merkle::ContractState, IMerkle}, darkpool::types::FeatureFlags
};


const TEST_MERKLE_HEIGHT: u8 = 3;
Expand Down Expand Up @@ -50,6 +52,10 @@ fn test_multi_insert_root_history() {

fn setup_merkle() -> ContractState {
let mut merkle = Merkle::contract_state_for_testing();
merkle.initialize(TEST_MERKLE_HEIGHT, false);
merkle
.initialize(
TEST_MERKLE_HEIGHT,
FeatureFlags { use_base_field_poseidon: true, disable_verification: true }
);
merkle
}
6 changes: 5 additions & 1 deletion starknet_scripts/src/commands/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ pub async fn deploy_darkpool(

// Deploy darkpool
debug!("Deploying darkpool contract...");
let calldata = vec![account.address()];
let calldata = vec![
account.address(),
FieldElement::ZERO, /* serialization of boolean `false` indicating that poseidon over the base field should not be used */
FieldElement::ZERO, /* serialization of boolean `false` indicating that the verifier should not be disabled */
];
let InvokeTransactionResult {
transaction_hash, ..
} = deploy(account, darkpool_class_hash_felt, &calldata).await?;
Expand Down
28 changes: 15 additions & 13 deletions tests/src/darkpool/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::{
get_sierra_class_hash_from_artifact, global_setup, invoke_contract, parameterize_circuit,
random_felt, scalar_to_felt, setup_sequencer, singleprover_prove, CalldataSerializable,
Circuit, DummyValidCommitments, DummyValidMatchMpc, DummyValidReblind, DummyValidSettle,
DummyValidWalletCreate, DummyValidWalletUpdate, MatchPayload, NewWalletArgs,
DummyValidWalletCreate, DummyValidWalletUpdate, FeatureFlags, MatchPayload, NewWalletArgs,
ProcessMatchArgs, TestConfig, UpdateWalletArgs, ARTIFACTS_PATH_ENV_VAR, DUMMY_VALUE,
SK_ROOT,
},
Expand Down Expand Up @@ -188,10 +188,14 @@ pub async fn init_darkpool_test_state() -> Result<TestSequencer> {
pub fn init_darkpool_test_statics(account: &ScriptAccount) -> Result<()> {
let artifacts_path = env::var(ARTIFACTS_PATH_ENV_VAR).unwrap();

let constructor_calldata: Vec<FieldElement> = iter::once(account.address())
.chain(FeatureFlags::default().to_calldata())
.collect();

let darkpool_address = get_contract_address_from_artifact(
&artifacts_path,
DARKPOOL_CONTRACT_NAME,
&[account.address()],
&constructor_calldata,
)?;
if DARKPOOL_ADDRESS.get().is_none() {
DARKPOOL_ADDRESS.set(darkpool_address).unwrap();
Expand Down Expand Up @@ -459,27 +463,27 @@ pub async fn process_match(

pub async fn poll_process_match(
account: &ScriptAccount,
verification_job_ids: Vec<FieldElement>,
verification_job_id: FieldElement,
) -> Result<()> {
invoke_contract(
account,
*DARKPOOL_ADDRESS.get().unwrap(),
POLL_PROCESS_MATCH_FN_NAME,
verification_job_ids.to_calldata(),
vec![verification_job_id],
)
.await
.map(|_| ())
}

pub async fn process_match_verification_jobs_are_done(
account: &ScriptAccount,
verification_job_ids: &[FieldElement],
verification_job_id: FieldElement,
) -> Result<bool> {
for verification_job_id in verification_job_ids {
for i in 0..PROCESS_MATCH_NUM_PROOFS {
let verification_job_status = check_verification_job_status(
account,
*DARKPOOL_ADDRESS.get().unwrap(),
*verification_job_id,
verification_job_id + i.into(),
)
.await?;
if verification_job_status.is_none() {
Expand All @@ -498,8 +502,8 @@ pub async fn poll_process_match_to_completion(
) -> Result<FieldElement> {
let tx_hash = process_match(account, args).await?;

while !process_match_verification_jobs_are_done(account, &args.verification_job_ids).await? {
poll_process_match(account, args.verification_job_ids.clone()).await?;
while !process_match_verification_jobs_are_done(account, args.verification_job_id).await? {
poll_process_match(account, args.verification_job_id).await?;
}

Ok(tx_hash)
Expand Down Expand Up @@ -612,9 +616,7 @@ pub fn get_dummy_process_match_args(
create_witness_statement(party0_wallet, party1_wallet, match_res);
let (_, valid_settle_proof) =
singleprover_prove::<DummyValidSettle>((), valid_settle_statement.clone())?;
let verification_job_ids = (0..PROCESS_MATCH_NUM_PROOFS)
.map(|_| random_felt())
.collect();
let verification_job_id = random_felt();

Ok(ProcessMatchArgs {
party_0_match_payload,
Expand All @@ -624,6 +626,6 @@ pub fn get_dummy_process_match_args(
valid_settle_statement,
valid_settle_witness_commitments: vec![],
valid_settle_proof,
verification_job_ids,
verification_job_id,
})
}
11 changes: 8 additions & 3 deletions tests/src/merkle/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use starknet::core::types::FieldElement;
use starknet_scripts::commands::utils::{
deploy_merkle, initialize, ScriptAccount, MERKLE_CONTRACT_NAME,
};
use std::env;
use std::{env, iter};
use tracing::debug;

use crate::utils::{
get_contract_address_from_artifact, global_setup, insert_scalar_to_ark_merkle_tree,
invoke_contract, setup_sequencer, TestConfig, ARTIFACTS_PATH_ENV_VAR,
invoke_contract, setup_sequencer, CalldataSerializable, FeatureFlags, TestConfig,
ARTIFACTS_PATH_ENV_VAR,
};

use super::ark_merkle::{setup_empty_tree, ScalarMerkleTree};
Expand Down Expand Up @@ -72,7 +73,11 @@ pub async fn initialize_merkle(
merkle_address: FieldElement,
merkle_height: FieldElement,
) -> Result<()> {
initialize(account, merkle_address, vec![merkle_height])
let calldata: Vec<FieldElement> = iter::once(merkle_height)
.chain(FeatureFlags::default().to_calldata())
.collect();

initialize(account, merkle_address, calldata)
.await
.map(|_| ())
}
Expand Down
21 changes: 19 additions & 2 deletions tests/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,15 @@ pub struct ProcessMatchArgs {
pub valid_settle_statement: SizedValidSettleStatement,
pub valid_settle_witness_commitments: Vec<StarkPoint>,
pub valid_settle_proof: R1CSProof,
pub verification_job_ids: Vec<FieldElement>,
pub verification_job_id: FieldElement,
}

#[derive(Default)]
pub struct FeatureFlags {
/// Whether or not to use Poseidon over the base field
pub use_base_field_poseidon: bool,
/// Whether or not to verify proofs
pub disable_verification: bool,
}

pub trait CalldataSerializable {
Expand Down Expand Up @@ -887,11 +895,20 @@ impl CalldataSerializable for ProcessMatchArgs {
.chain(self.valid_settle_statement.to_calldata())
.chain(self.valid_settle_witness_commitments.to_calldata())
.chain(self.valid_settle_proof.to_calldata())
.chain(self.verification_job_ids.to_calldata())
.chain(self.verification_job_id.to_calldata())
.collect()
}
}

impl CalldataSerializable for FeatureFlags {
fn to_calldata(&self) -> Vec<FieldElement> {
vec![
FieldElement::from(self.use_base_field_poseidon as u8),
FieldElement::from(self.disable_verification as u8),
]
}
}

// ------------------
// | DUMMY CIRCUITS |
// ------------------
Expand Down

0 comments on commit e8a057e

Please sign in to comment.