Skip to content

Commit

Permalink
update cucumbers to include reciprocal claim key in claim
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Mar 13, 2023
1 parent 809707c commit 20e1e64
Show file tree
Hide file tree
Showing 5 changed files with 4,682 additions and 14 deletions.
1 change: 1 addition & 0 deletions applications/tari_validator_node/tests/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub struct TariWorld {
addresses: IndexMap<String, String>,
num_databases_saved: usize,
account_public_keys: IndexMap<String, (RistrettoSecretKey, PublicKey)>,
claim_public_keys: IndexMap<String, PublicKey>,
}

impl TariWorld {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Feature: Claim Burn
# When I create a component SECOND_LAYER_TARI of template "fees" on VN using "new"
When I create an account ACC_1 on VN

When I burn 10T on wallet WALLET into commitment COMMITMENT with proof PROOF for ACC_1 and range proof RANGEPROOF
When I burn 10T on wallet WALLET into commitment COMMITMENT with proof PROOF for ACC_1, range proof RANGEPROOF and claim public key CLAIM_PUBKEY

# unfortunately have to wait for this to get into the mempool....
Then there is 1 transaction in the mempool of BASE within 10 seconds
Expand All @@ -36,7 +36,7 @@ Feature: Claim Burn
When miner MINER mines 5 new blocks

When I save the state database of VN
When I claim burn COMMITMENT with PROOF and RANGEPROOF and spend it into account ACC_1 on VN
When I claim burn COMMITMENT with PROOF, RANGEPROOF and CLAIM_PUBKEY and spend it into account ACC_1 on VN
# Then account ACC_1 has one confidential bucket in it

@serial
Expand Down
25 changes: 16 additions & 9 deletions applications/tari_validator_node/tests/steps/validator_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::{convert::TryInto, str::FromStr};

use cucumber::{then, when};
use tari_common_types::types::PublicKey;
use tari_crypto::tari_utilities::{hex::Hex, ByteArray};
use tari_dan_common_types::{Epoch, ShardId};
use tari_engine_types::{confidential::ConfidentialClaim, instruction::Instruction, substate::SubstateAddress};
Expand Down Expand Up @@ -32,12 +31,13 @@ async fn then_validator_node_has_state_at(world: &mut TariWorld, vn_name: String
client.get_state(GetStateRequest { shard_id }).await.unwrap();
}

#[when(expr = "I claim burn {word} with {word} and {word} and spend it into account {word} on {word}")]
#[when(expr = "I claim burn {word} with {word}, {word} and {word} and spend it into account {word} on {word}")]
async fn when_i_claim_burn(
world: &mut TariWorld,
commitment_name: String,
proof_name: String,
rangeproof_name: String,
claim_public_key_name: String,
account_name: String,
vn_name: String,
) -> Result<(), anyhow::Error> {
Expand All @@ -62,18 +62,23 @@ async fn when_i_claim_burn(
0,
);

let account = world
let (account_secret, _) = world
.account_public_keys
.get(&account_name)
.unwrap_or_else(|| panic!("Account {} not found", account_name));

let account_address = world.get_account_component_address(&account_name).unwrap();
let component_address = ComponentAddress::from_str(&account_address).expect("Invalid account address");

let reciprocal_public_key = world
.claim_public_keys
.get(&claim_public_key_name)
.unwrap_or_else(|| panic!("Claim public key {} not found", claim_public_key_name));

let instructions = [
Instruction::ClaimBurn {
claim: Box::new(ConfidentialClaim {
public_key: PublicKey::default(),
public_key: reciprocal_public_key.clone(),
output_address: commitment.as_slice().try_into()?,
range_proof: rangeproof.clone(),
proof_of_knowledge: proof.clone(),
Expand All @@ -97,7 +102,7 @@ async fn when_i_claim_burn(
.with_inputs(vec![commitment_shard, account_shard])
.with_fee(1)
.with_new_outputs(1)
.sign(&account.0);
.sign(account_secret);
let transaction = builder.build();

let request = SubmitTransactionRequest {
Expand All @@ -114,27 +119,29 @@ async fn when_i_claim_burn(
}

#[when(
expr = "I claim burn {word} with {word} and {word} and spend it into account {word} on {word} a second time, it \
fails"
expr = "I claim burn {word} with {word}, {word} and {word} and spend it into account {word} on {word} a second \
time, it fails"
)]
async fn when_i_claim_burn_second_time_fails(
world: &mut TariWorld,
commitment_name: String,
proof_name: String,
rangeproof_name: String,
claim_pk_name: String,
account_name: String,
vn_name: String,
) {
assert!(when_i_claim_burn(
when_i_claim_burn(
world,
commitment_name,
proof_name,
rangeproof_name,
claim_pk_name,
account_name,
vn_name,
)
.await
.is_err());
.unwrap_err();
}

#[then(expr = "{word} is on epoch {int} within {int} seconds")]
Expand Down
12 changes: 9 additions & 3 deletions applications/tari_validator_node/tests/steps/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ async fn start_wallet(world: &mut TariWorld, wallet_name: String, bn_name: Strin
}

#[when(
expr = "I burn {int}T on wallet {word} into commitment {word} with proof {word} for {word} and range proof {word}"
expr = "I burn {int}T on wallet {word} into commitment {word} with proof {word} for {word}, range proof {word} \
and claim public key {word}"
)]
async fn when_i_burn_on_wallet(
world: &mut TariWorld,
Expand All @@ -27,13 +28,14 @@ async fn when_i_burn_on_wallet(
proof: String,
account_name: String,
range_proof: String,
claim_public_key_name: String,
) {
let wallet = world
.wallets
.get(&wallet_name)
.unwrap_or_else(|| panic!("Wallet {} not found", wallet_name));

let public_key = world
let (_, public_key) = world
.account_public_keys
.get(&account_name)
.unwrap_or_else(|| panic!("Account {} not found", account_name));
Expand All @@ -44,7 +46,7 @@ async fn when_i_burn_on_wallet(
amount: amount * 1_000_000,
fee_per_gram: 1,
message: "Burn".to_string(),
claim_public_key: public_key.1.to_vec(),
claim_public_key: public_key.to_vec(),
})
.await
.unwrap()
Expand All @@ -63,6 +65,10 @@ async fn when_i_burn_on_wallet(
),
);
world.rangeproofs.insert(range_proof, resp.range_proof);
world.claim_public_keys.insert(
claim_public_key_name,
PublicKey::from_bytes(&resp.reciprocal_claim_public_key).unwrap(),
);
}

#[when(expr = "wallet {word} has at least {int} {word}")]
Expand Down
Loading

0 comments on commit 20e1e64

Please sign in to comment.