Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
158 changes: 158 additions & 0 deletions src/lib/transaction_snark/test/account_timing/account_timing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1643,4 +1643,162 @@ let%test_module "account timing check" =
check_zkapp_failure
Transaction_status.Failure
.Update_not_permitted_timing_existing_account result ) )

let%test_unit "zkApp command, change untimed account to timed" =
Async.Thread_safe.block_on_async_exn (fun () ->
let ledger_init_state =
List.map keypairs ~f:(fun keypair ->
let balance = Currency.Amount.of_int 100_000_000_000_000 in
let nonce = Mina_numbers.Account_nonce.zero in
(keypair, balance, nonce, Account_timing.Untimed) )
|> Array.of_list
in
let sender_keypair = List.hd_exn keypairs in
let zkapp_keypair = List.nth_exn keypairs 1 in
let (update_timing_spec : Transaction_snark.For_tests.Spec.t) =
{ sender = (sender_keypair, Account.Nonce.zero)
; fee = Currency.Fee.of_int 1_000_000
; fee_payer = None
; receivers = []
; amount = Currency.Amount.zero
; zkapp_account_keypairs = [ zkapp_keypair ]
; memo =
Signed_command_memo.create_from_string_exn "zkApp update timing"
; new_zkapp_account = false
; snapp_update =
(let timing =
Zkapp_basic.Set_or_keep.Set
( { initial_minimum_balance =
Currency.Balance.of_int 1_000_000_000
; cliff_time = Mina_numbers.Global_slot.of_int 10
; cliff_amount = Currency.Amount.of_int 1_000_000_000
; vesting_period = Mina_numbers.Global_slot.of_int 10
; vesting_increment =
Currency.Amount.of_int 1_000_000_000
}
: Party.Update.Timing_info.value )
in
{ Party.Update.dummy with timing } )
; current_auth = Permissions.Auth_required.Signature
; call_data = Snark_params.Tick.Field.zero
; events = []
; sequence_events = []
; protocol_state_precondition = None
; account_precondition = None
}
in
let open Async.Deferred.Let_syntax in
let%map update_timing_parties =
Transaction_snark.For_tests.update_states ~constraint_constants
update_timing_spec
in
let gen =
Quickcheck.Generator.return
(ledger_init_state, update_timing_parties)
in
Quickcheck.test
~seed:
(`Deterministic
"zkapp command, change untimed account to timed account" )
~sexp_of:[%sexp_of: Mina_ledger.Ledger.init_state * Parties.t]
~trials:1 gen ~f:(fun (ledger_init_state, update_timing_parties) ->
Mina_ledger.Ledger.with_ephemeral_ledger
~depth:constraint_constants.ledger_depth ~f:(fun ledger ->
Mina_ledger.Ledger.apply_initial_ledger_state ledger
ledger_init_state ;
let state_view =
Transaction_snark_tests.Util.genesis_state_view
in
match
Mina_ledger.Ledger.apply_parties_unchecked ~state_view
~constraint_constants ledger update_timing_parties
with
| Ok _ ->
()
| Error e ->
failwith (Error.to_string_hum e) ) ) )

let%test_unit "zkApp command, invalid update for timed account" =
Async.Thread_safe.block_on_async_exn (fun () ->
let ledger_init_state =
List.mapi keypairs ~f:(fun i keypair ->
let balance = Currency.Amount.of_int 100_000_000_000_000 in
let nonce = Mina_numbers.Account_nonce.zero in
( keypair
, balance
, nonce
, if i = 1 then
Account_timing.Timed
{ initial_minimum_balance =
Currency.Balance.of_int 10_000_000_000
; cliff_time = Mina_numbers.Global_slot.of_int 10_000
; cliff_amount = Currency.Amount.zero
; vesting_period = Mina_numbers.Global_slot.of_int 1
; vesting_increment = Currency.Amount.of_int 100_000
}
else Account_timing.Untimed ) )
|> Array.of_list
in
let sender_keypair = List.hd_exn keypairs in
let zkapp_keypair = List.nth_exn keypairs 1 in
let (update_timing_spec : Transaction_snark.For_tests.Spec.t) =
{ sender = (sender_keypair, Account.Nonce.zero)
; fee = Currency.Fee.of_int 1_000_000
; fee_payer = None
; receivers = []
; amount = Currency.Amount.zero
; zkapp_account_keypairs = [ zkapp_keypair ]
; memo =
Signed_command_memo.create_from_string_exn "zkApp update timing"
; new_zkapp_account = false
; snapp_update =
(let timing =
Zkapp_basic.Set_or_keep.Set
( { initial_minimum_balance =
Currency.Balance.of_int 1_000_000_000
; cliff_time = Mina_numbers.Global_slot.of_int 10
; cliff_amount = Currency.Amount.of_int 1_000_000_000
; vesting_period = Mina_numbers.Global_slot.of_int 10
; vesting_increment =
Currency.Amount.of_int 1_000_000_000
}
: Party.Update.Timing_info.value )
in
{ Party.Update.dummy with timing } )
; current_auth = Permissions.Auth_required.Signature
; call_data = Snark_params.Tick.Field.zero
; events = []
; sequence_events = []
; protocol_state_precondition = None
; account_precondition = None
}
in
let open Async.Deferred.Let_syntax in
let%map update_timing_parties =
Transaction_snark.For_tests.update_states ~constraint_constants
update_timing_spec
in
let gen =
Quickcheck.Generator.return
(ledger_init_state, update_timing_parties)
in
Quickcheck.test
~seed:
(`Deterministic "zkapp command, invalid update for timed account")
~sexp_of:[%sexp_of: Mina_ledger.Ledger.init_state * Parties.t]
~trials:1 gen ~f:(fun (ledger_init_state, update_timing_parties) ->
Mina_ledger.Ledger.with_ephemeral_ledger
~depth:constraint_constants.ledger_depth ~f:(fun ledger ->
Mina_ledger.Ledger.apply_initial_ledger_state ledger
ledger_init_state ;
let state_view =
Transaction_snark_tests.Util.genesis_state_view
in
let result =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call apply_zkapp_commands_at_slot instead (for all tests you added)? It applies both in snark and out of snark

Mina_ledger.Ledger.apply_parties_unchecked ~state_view
~constraint_constants ledger update_timing_parties
in
check_zkapp_failure
Transaction_status.Failure
.Update_not_permitted_timing_existing_account result ) ) )
end )