|
|
|
|
@ -118,7 +118,7 @@ impl V03State {
|
|
|
|
|
#[must_use]
|
|
|
|
|
pub fn new_with_genesis_accounts(
|
|
|
|
|
initial_data: &[(AccountId, u128)],
|
|
|
|
|
initial_private_accounts: &[(Nullifier, Commitment)],
|
|
|
|
|
initial_private_accounts: Vec<(Commitment, Nullifier)>,
|
|
|
|
|
) -> Self {
|
|
|
|
|
let authenticated_transfer_program = Program::authenticated_transfer_program();
|
|
|
|
|
let public_state = initial_data
|
|
|
|
|
@ -134,24 +134,18 @@ impl V03State {
|
|
|
|
|
})
|
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
let initial_commitments: Vec<Commitment> = initial_private_accounts
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|(_, c)| c.clone())
|
|
|
|
|
.collect();
|
|
|
|
|
let mut private_state = CommitmentSet::with_capacity(32);
|
|
|
|
|
private_state.extend(&[DUMMY_COMMITMENT]);
|
|
|
|
|
private_state.extend(&initial_commitments);
|
|
|
|
|
|
|
|
|
|
let init_nullifiers: Vec<Nullifier> = initial_private_accounts
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|(n, _)| n.clone())
|
|
|
|
|
.collect();
|
|
|
|
|
let mut commitment_set = CommitmentSet::with_capacity(32);
|
|
|
|
|
commitment_set.extend(&[DUMMY_COMMITMENT]);
|
|
|
|
|
let (commitments, nullifiers): (Vec<Commitment>, Vec<Nullifier>) =
|
|
|
|
|
initial_private_accounts.into_iter().unzip();
|
|
|
|
|
commitment_set.extend(&commitments);
|
|
|
|
|
let mut nullifier_set = NullifierSet::new();
|
|
|
|
|
nullifier_set.extend(init_nullifiers);
|
|
|
|
|
nullifier_set.extend(nullifiers);
|
|
|
|
|
let private_state = (commitment_set, nullifier_set);
|
|
|
|
|
|
|
|
|
|
let mut this = Self {
|
|
|
|
|
public_state,
|
|
|
|
|
private_state: (private_state, nullifier_set),
|
|
|
|
|
private_state,
|
|
|
|
|
programs: HashMap::new(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
@ -528,7 +522,7 @@ pub mod tests {
|
|
|
|
|
this
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&initial_data, &[]);
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&initial_data, vec![]);
|
|
|
|
|
|
|
|
|
|
assert_eq!(state.public_state, expected_public_state);
|
|
|
|
|
assert_eq!(state.programs, expected_builtin_programs);
|
|
|
|
|
@ -548,15 +542,17 @@ pub mod tests {
|
|
|
|
|
let npk1 = keys1.npk();
|
|
|
|
|
let npk2 = keys2.npk();
|
|
|
|
|
|
|
|
|
|
let init_commitment1 = Commitment::new(&npk1, &account);
|
|
|
|
|
let init_commitment2 = Commitment::new(&npk2, &account);
|
|
|
|
|
let init_nullifier1 = Nullifier::for_account_initialization(&npk1);
|
|
|
|
|
let init_nullifier2 = Nullifier::for_account_initialization(&npk2);
|
|
|
|
|
|
|
|
|
|
let initial_private_accounts = vec![
|
|
|
|
|
(init_nullifier1.clone(), Commitment::new(&npk1, &account)),
|
|
|
|
|
(init_nullifier2.clone(), Commitment::new(&npk2, &account)),
|
|
|
|
|
(init_commitment1, init_nullifier1.clone()),
|
|
|
|
|
(init_commitment2, init_nullifier2.clone()),
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&[], &initial_private_accounts);
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&[], initial_private_accounts);
|
|
|
|
|
|
|
|
|
|
assert!(state.private_state.1.contains(&init_nullifier1));
|
|
|
|
|
assert!(state.private_state.1.contains(&init_nullifier2));
|
|
|
|
|
@ -564,7 +560,7 @@ pub mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn insert_program() {
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]);
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]);
|
|
|
|
|
let program_to_insert = Program::simple_balance_transfer();
|
|
|
|
|
let program_id = program_to_insert.id();
|
|
|
|
|
assert!(!state.programs.contains_key(&program_id));
|
|
|
|
|
@ -579,7 +575,7 @@ pub mod tests {
|
|
|
|
|
let key = PrivateKey::try_new([1; 32]).unwrap();
|
|
|
|
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&key));
|
|
|
|
|
let initial_data = [(account_id, 100_u128)];
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&initial_data, &[]);
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&initial_data, vec![]);
|
|
|
|
|
let expected_account = &state.public_state[&account_id];
|
|
|
|
|
|
|
|
|
|
let account = state.get_account_by_id(account_id);
|
|
|
|
|
@ -590,7 +586,7 @@ pub mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn get_account_by_account_id_default_account() {
|
|
|
|
|
let addr2 = AccountId::new([0; 32]);
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&[], &[]);
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&[], vec![]);
|
|
|
|
|
let expected_account = Account::default();
|
|
|
|
|
|
|
|
|
|
let account = state.get_account_by_id(addr2);
|
|
|
|
|
@ -600,7 +596,7 @@ pub mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn builtin_programs_getter() {
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&[], &[]);
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&[], vec![]);
|
|
|
|
|
|
|
|
|
|
let builtin_programs = state.programs();
|
|
|
|
|
|
|
|
|
|
@ -612,7 +608,7 @@ pub mod tests {
|
|
|
|
|
let key = PrivateKey::try_new([1; 32]).unwrap();
|
|
|
|
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&key));
|
|
|
|
|
let initial_data = [(account_id, 100)];
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]);
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, vec![]);
|
|
|
|
|
let from = account_id;
|
|
|
|
|
let to_key = PrivateKey::try_new([2; 32]).unwrap();
|
|
|
|
|
let to = AccountId::from(&PublicKey::new_from_private_key(&to_key));
|
|
|
|
|
@ -633,7 +629,7 @@ pub mod tests {
|
|
|
|
|
let key = PrivateKey::try_new([1; 32]).unwrap();
|
|
|
|
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&key));
|
|
|
|
|
let initial_data = [(account_id, 100)];
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]);
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, vec![]);
|
|
|
|
|
let from = account_id;
|
|
|
|
|
let from_key = key;
|
|
|
|
|
let to_key = PrivateKey::try_new([2; 32]).unwrap();
|
|
|
|
|
@ -658,7 +654,7 @@ pub mod tests {
|
|
|
|
|
let account_id1 = AccountId::from(&PublicKey::new_from_private_key(&key1));
|
|
|
|
|
let account_id2 = AccountId::from(&PublicKey::new_from_private_key(&key2));
|
|
|
|
|
let initial_data = [(account_id1, 100), (account_id2, 200)];
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]);
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, vec![]);
|
|
|
|
|
let from = account_id2;
|
|
|
|
|
let from_key = key2;
|
|
|
|
|
let to = account_id1;
|
|
|
|
|
@ -682,7 +678,7 @@ pub mod tests {
|
|
|
|
|
let key2 = PrivateKey::try_new([2; 32]).unwrap();
|
|
|
|
|
let account_id2 = AccountId::from(&PublicKey::new_from_private_key(&key2));
|
|
|
|
|
let initial_data = [(account_id1, 100)];
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, &[]);
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, vec![]);
|
|
|
|
|
let key3 = PrivateKey::try_new([3; 32]).unwrap();
|
|
|
|
|
let account_id3 = AccountId::from(&PublicKey::new_from_private_key(&key3));
|
|
|
|
|
let balance_to_move = 5;
|
|
|
|
|
@ -721,7 +717,7 @@ pub mod tests {
|
|
|
|
|
fn program_should_fail_if_modifies_nonces() {
|
|
|
|
|
let initial_data = [(AccountId::new([1; 32]), 100)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let account_ids = vec![AccountId::new([1; 32])];
|
|
|
|
|
let program_id = Program::nonce_changer_program().id();
|
|
|
|
|
let message =
|
|
|
|
|
@ -738,7 +734,7 @@ pub mod tests {
|
|
|
|
|
fn program_should_fail_if_output_accounts_exceed_inputs() {
|
|
|
|
|
let initial_data = [(AccountId::new([1; 32]), 100)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let account_ids = vec![AccountId::new([1; 32])];
|
|
|
|
|
let program_id = Program::extra_output_program().id();
|
|
|
|
|
let message =
|
|
|
|
|
@ -755,7 +751,7 @@ pub mod tests {
|
|
|
|
|
fn program_should_fail_with_missing_output_accounts() {
|
|
|
|
|
let initial_data = [(AccountId::new([1; 32]), 100)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let account_ids = vec![AccountId::new([1; 32]), AccountId::new([2; 32])];
|
|
|
|
|
let program_id = Program::missing_output_program().id();
|
|
|
|
|
let message =
|
|
|
|
|
@ -772,7 +768,7 @@ pub mod tests {
|
|
|
|
|
fn program_should_fail_if_modifies_program_owner_with_only_non_default_program_owner() {
|
|
|
|
|
let initial_data = [(AccountId::new([1; 32]), 0)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let account_id = AccountId::new([1; 32]);
|
|
|
|
|
let account = state.get_account_by_id(account_id);
|
|
|
|
|
// Assert the target account only differs from the default account in the program owner
|
|
|
|
|
@ -795,7 +791,7 @@ pub mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn program_should_fail_if_modifies_program_owner_with_only_non_default_balance() {
|
|
|
|
|
let initial_data = [];
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, &[])
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, vec![])
|
|
|
|
|
.with_test_programs()
|
|
|
|
|
.with_non_default_accounts_but_default_program_owners();
|
|
|
|
|
let account_id = AccountId::new([255; 32]);
|
|
|
|
|
@ -819,7 +815,7 @@ pub mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn program_should_fail_if_modifies_program_owner_with_only_non_default_nonce() {
|
|
|
|
|
let initial_data = [];
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, &[])
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, vec![])
|
|
|
|
|
.with_test_programs()
|
|
|
|
|
.with_non_default_accounts_but_default_program_owners();
|
|
|
|
|
let account_id = AccountId::new([254; 32]);
|
|
|
|
|
@ -843,7 +839,7 @@ pub mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn program_should_fail_if_modifies_program_owner_with_only_non_default_data() {
|
|
|
|
|
let initial_data = [];
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, &[])
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, vec![])
|
|
|
|
|
.with_test_programs()
|
|
|
|
|
.with_non_default_accounts_but_default_program_owners();
|
|
|
|
|
let account_id = AccountId::new([253; 32]);
|
|
|
|
|
@ -868,7 +864,7 @@ pub mod tests {
|
|
|
|
|
fn program_should_fail_if_transfers_balance_from_non_owned_account() {
|
|
|
|
|
let initial_data = [(AccountId::new([1; 32]), 100)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let sender_account_id = AccountId::new([1; 32]);
|
|
|
|
|
let receiver_account_id = AccountId::new([2; 32]);
|
|
|
|
|
let balance_to_move: u128 = 1;
|
|
|
|
|
@ -895,7 +891,7 @@ pub mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn program_should_fail_if_modifies_data_of_non_owned_account() {
|
|
|
|
|
let initial_data = [];
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, &[])
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, vec![])
|
|
|
|
|
.with_test_programs()
|
|
|
|
|
.with_non_default_accounts_but_default_program_owners();
|
|
|
|
|
let account_id = AccountId::new([255; 32]);
|
|
|
|
|
@ -921,7 +917,7 @@ pub mod tests {
|
|
|
|
|
fn program_should_fail_if_does_not_preserve_total_balance_by_minting() {
|
|
|
|
|
let initial_data = [];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let account_id = AccountId::new([1; 32]);
|
|
|
|
|
let program_id = Program::minter().id();
|
|
|
|
|
|
|
|
|
|
@ -938,7 +934,7 @@ pub mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn program_should_fail_if_does_not_preserve_total_balance_by_burning() {
|
|
|
|
|
let initial_data = [];
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, &[])
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&initial_data, vec![])
|
|
|
|
|
.with_test_programs()
|
|
|
|
|
.with_account_owned_by_burner_program();
|
|
|
|
|
let program_id = Program::burner().id();
|
|
|
|
|
@ -1130,7 +1126,7 @@ pub mod tests {
|
|
|
|
|
let recipient_keys = test_private_account_keys_1();
|
|
|
|
|
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&[(sender_keys.account_id(), 200)], &[]);
|
|
|
|
|
V03State::new_with_genesis_accounts(&[(sender_keys.account_id(), 200)], vec![]);
|
|
|
|
|
|
|
|
|
|
let balance_to_move = 37;
|
|
|
|
|
|
|
|
|
|
@ -1178,7 +1174,7 @@ pub mod tests {
|
|
|
|
|
};
|
|
|
|
|
let recipient_keys = test_private_account_keys_2();
|
|
|
|
|
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[])
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![])
|
|
|
|
|
.with_private_account(&sender_keys, &sender_private_account);
|
|
|
|
|
|
|
|
|
|
let balance_to_move = 37;
|
|
|
|
|
@ -1247,7 +1243,7 @@ pub mod tests {
|
|
|
|
|
let recipient_initial_balance = 400;
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(
|
|
|
|
|
&[(recipient_keys.account_id(), recipient_initial_balance)],
|
|
|
|
|
&[],
|
|
|
|
|
vec![],
|
|
|
|
|
)
|
|
|
|
|
.with_private_account(&sender_keys, &sender_private_account);
|
|
|
|
|
|
|
|
|
|
@ -2199,7 +2195,7 @@ pub mod tests {
|
|
|
|
|
};
|
|
|
|
|
let recipient_keys = test_private_account_keys_2();
|
|
|
|
|
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[])
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![])
|
|
|
|
|
.with_private_account(&sender_keys, &sender_private_account);
|
|
|
|
|
|
|
|
|
|
let balance_to_move = 37;
|
|
|
|
|
@ -2284,7 +2280,7 @@ pub mod tests {
|
|
|
|
|
let initial_balance = 100;
|
|
|
|
|
let initial_data = [(from, initial_balance)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let to_key = PrivateKey::try_new([2; 32]).unwrap();
|
|
|
|
|
let to = AccountId::from(&PublicKey::new_from_private_key(&to_key));
|
|
|
|
|
let amount: u128 = 37;
|
|
|
|
|
@ -2322,7 +2318,7 @@ pub mod tests {
|
|
|
|
|
let program = Program::authenticated_transfer_program();
|
|
|
|
|
let account_key = PrivateKey::try_new([9; 32]).unwrap();
|
|
|
|
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&account_key));
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]);
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]);
|
|
|
|
|
|
|
|
|
|
assert_eq!(state.get_account_by_id(account_id), Account::default());
|
|
|
|
|
|
|
|
|
|
@ -2343,7 +2339,7 @@ pub mod tests {
|
|
|
|
|
let program = Program::authenticated_transfer_program();
|
|
|
|
|
let account_key = PrivateKey::try_new([10; 32]).unwrap();
|
|
|
|
|
let account_id = AccountId::from(&PublicKey::new_from_private_key(&account_key));
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]);
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]);
|
|
|
|
|
|
|
|
|
|
assert_eq!(state.get_account_by_id(account_id), Account::default());
|
|
|
|
|
|
|
|
|
|
@ -2378,7 +2374,7 @@ pub mod tests {
|
|
|
|
|
let initial_balance = 1000;
|
|
|
|
|
let initial_data = [(from, initial_balance), (to, 0)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let from_key = key;
|
|
|
|
|
let amount: u128 = 37;
|
|
|
|
|
let instruction: (u128, ProgramId, u32, Option<PdaSeed>) = (
|
|
|
|
|
@ -2423,7 +2419,7 @@ pub mod tests {
|
|
|
|
|
let initial_balance = 100;
|
|
|
|
|
let initial_data = [(from, initial_balance), (to, 0)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let from_key = key;
|
|
|
|
|
let amount: u128 = 0;
|
|
|
|
|
let instruction: (u128, ProgramId, u32, Option<PdaSeed>) = (
|
|
|
|
|
@ -2461,7 +2457,7 @@ pub mod tests {
|
|
|
|
|
let initial_balance = 1000;
|
|
|
|
|
let initial_data = [(from, initial_balance), (to, 0)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let amount: u128 = 58;
|
|
|
|
|
let instruction: (u128, ProgramId, u32, Option<PdaSeed>) = (
|
|
|
|
|
amount,
|
|
|
|
|
@ -2507,7 +2503,7 @@ pub mod tests {
|
|
|
|
|
let initial_balance = 100;
|
|
|
|
|
let initial_data = [(from, initial_balance)];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let to_key = PrivateKey::try_new([2; 32]).unwrap();
|
|
|
|
|
let to = AccountId::from(&PublicKey::new_from_private_key(&to_key));
|
|
|
|
|
let amount: u128 = 37;
|
|
|
|
|
@ -2584,7 +2580,7 @@ pub mod tests {
|
|
|
|
|
let sender_init_nullifier = Nullifier::for_account_initialization(&sender_keys.npk());
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(
|
|
|
|
|
&[],
|
|
|
|
|
&[(sender_init_nullifier, sender_commitment.clone())],
|
|
|
|
|
vec![(sender_commitment.clone(), sender_init_nullifier)],
|
|
|
|
|
);
|
|
|
|
|
let sender_pre = AccountWithMetadata::new(sender_private_account, true, &sender_keys.npk());
|
|
|
|
|
let recipient_private_key = PrivateKey::try_new([2; 32]).unwrap();
|
|
|
|
|
@ -2669,9 +2665,9 @@ pub mod tests {
|
|
|
|
|
let to_init_nullifier = Nullifier::for_account_initialization(&to_keys.npk());
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(
|
|
|
|
|
&[],
|
|
|
|
|
&[
|
|
|
|
|
(from_init_nullifier, from_commitment.clone()),
|
|
|
|
|
(to_init_nullifier, to_commitment.clone()),
|
|
|
|
|
vec![
|
|
|
|
|
(from_commitment.clone(), from_init_nullifier),
|
|
|
|
|
(to_commitment.clone(), to_init_nullifier),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
.with_test_programs();
|
|
|
|
|
@ -2779,7 +2775,7 @@ pub mod tests {
|
|
|
|
|
..Account::default()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]);
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]);
|
|
|
|
|
state.add_pinata_token_program(pinata_definition_id);
|
|
|
|
|
|
|
|
|
|
// Set up the token accounts directly (bypassing public transactions which
|
|
|
|
|
@ -2851,7 +2847,7 @@ pub mod tests {
|
|
|
|
|
#[test]
|
|
|
|
|
fn claiming_mechanism_cannot_claim_initialied_accounts() {
|
|
|
|
|
let claimer = Program::claimer();
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs();
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]).with_test_programs();
|
|
|
|
|
let account_id = AccountId::new([2; 32]);
|
|
|
|
|
|
|
|
|
|
// Insert an account with non-default program owner
|
|
|
|
|
@ -2891,7 +2887,7 @@ pub mod tests {
|
|
|
|
|
(sender_id, sender_init_balance),
|
|
|
|
|
(recipient_id, recipient_init_balance),
|
|
|
|
|
],
|
|
|
|
|
&[],
|
|
|
|
|
vec![],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
state.insert_program(Program::modified_transfer_program());
|
|
|
|
|
@ -2941,7 +2937,7 @@ pub mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn private_authorized_uninitialized_account() {
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]);
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]);
|
|
|
|
|
|
|
|
|
|
// Set up keys for the authorized private account
|
|
|
|
|
let private_keys = test_private_account_keys_1();
|
|
|
|
|
@ -2993,7 +2989,7 @@ pub mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn private_unauthorized_uninitialized_account_can_still_be_claimed() {
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs();
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]).with_test_programs();
|
|
|
|
|
|
|
|
|
|
let private_keys = test_private_account_keys_1();
|
|
|
|
|
// This is intentional: claim authorization was introduced to protect public accounts,
|
|
|
|
|
@ -3040,7 +3036,7 @@ pub mod tests {
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn private_account_claimed_then_used_without_init_flag_should_fail() {
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs();
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]).with_test_programs();
|
|
|
|
|
|
|
|
|
|
// Set up keys for the private account
|
|
|
|
|
let private_keys = test_private_account_keys_1();
|
|
|
|
|
@ -3121,7 +3117,7 @@ pub mod tests {
|
|
|
|
|
fn public_changer_claimer_no_data_change_no_claim_succeeds() {
|
|
|
|
|
let initial_data = [];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let account_id = AccountId::new([1; 32]);
|
|
|
|
|
let program_id = Program::changer_claimer().id();
|
|
|
|
|
// Don't change data (None) and don't claim (false)
|
|
|
|
|
@ -3145,7 +3141,7 @@ pub mod tests {
|
|
|
|
|
fn public_changer_claimer_data_change_no_claim_fails() {
|
|
|
|
|
let initial_data = [];
|
|
|
|
|
let mut state =
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let account_id = AccountId::new([1; 32]);
|
|
|
|
|
let program_id = Program::changer_claimer().id();
|
|
|
|
|
// Change data but don't claim (false) - should fail
|
|
|
|
|
@ -3242,7 +3238,7 @@ pub mod tests {
|
|
|
|
|
let recipient_init_nullifier = Nullifier::for_account_initialization(&recipient_keys.npk());
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(
|
|
|
|
|
&[(sender_account.account_id, sender_account.account.balance)],
|
|
|
|
|
&[(recipient_init_nullifier, recipient_commitment.clone())],
|
|
|
|
|
vec![(recipient_commitment.clone(), recipient_init_nullifier)],
|
|
|
|
|
)
|
|
|
|
|
.with_test_programs();
|
|
|
|
|
|
|
|
|
|
@ -3292,7 +3288,7 @@ pub mod tests {
|
|
|
|
|
let validity_window_program = Program::validity_window();
|
|
|
|
|
let account_keys = test_public_account_keys_1();
|
|
|
|
|
let pre = AccountWithMetadata::new(Account::default(), false, account_keys.account_id());
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs();
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]).with_test_programs();
|
|
|
|
|
let tx = {
|
|
|
|
|
let account_ids = vec![pre.account_id];
|
|
|
|
|
let nonces = vec![];
|
|
|
|
|
@ -3344,7 +3340,7 @@ pub mod tests {
|
|
|
|
|
let validity_window_program = Program::validity_window();
|
|
|
|
|
let account_keys = test_public_account_keys_1();
|
|
|
|
|
let pre = AccountWithMetadata::new(Account::default(), false, account_keys.account_id());
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs();
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]).with_test_programs();
|
|
|
|
|
let tx = {
|
|
|
|
|
let account_ids = vec![pre.account_id];
|
|
|
|
|
let nonces = vec![];
|
|
|
|
|
@ -3397,7 +3393,7 @@ pub mod tests {
|
|
|
|
|
let validity_window_program = Program::validity_window();
|
|
|
|
|
let account_keys = test_private_account_keys_1();
|
|
|
|
|
let pre = AccountWithMetadata::new(Account::default(), false, &account_keys.npk());
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs();
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]).with_test_programs();
|
|
|
|
|
let tx = {
|
|
|
|
|
let esk = [3; 32];
|
|
|
|
|
let shared_secret = SharedSecretKey::new(&esk, &account_keys.vpk());
|
|
|
|
|
@ -3466,7 +3462,7 @@ pub mod tests {
|
|
|
|
|
let validity_window_program = Program::validity_window();
|
|
|
|
|
let account_keys = test_private_account_keys_1();
|
|
|
|
|
let pre = AccountWithMetadata::new(Account::default(), false, &account_keys.npk());
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], &[]).with_test_programs();
|
|
|
|
|
let mut state = V03State::new_with_genesis_accounts(&[], vec![]).with_test_programs();
|
|
|
|
|
let tx = {
|
|
|
|
|
let esk = [3; 32];
|
|
|
|
|
let shared_secret = SharedSecretKey::new(&esk, &account_keys.vpk());
|
|
|
|
|
@ -3520,7 +3516,7 @@ pub mod tests {
|
|
|
|
|
let account_id_1 = AccountId::new([1; 32]);
|
|
|
|
|
let account_id_2 = AccountId::new([2; 32]);
|
|
|
|
|
let initial_data = [(account_id_1, 100_u128), (account_id_2, 151_u128)];
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&initial_data, &[]).with_test_programs();
|
|
|
|
|
let state = V03State::new_with_genesis_accounts(&initial_data, vec![]).with_test_programs();
|
|
|
|
|
let bytes = borsh::to_vec(&state).unwrap();
|
|
|
|
|
let state_from_bytes: V03State = borsh::from_slice(&bytes).unwrap();
|
|
|
|
|
assert_eq!(state, state_from_bytes);
|
|
|
|
|
|