diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index 607934590b3dbbe3eb7ba3c746b74c9c044c11de..f6ab93b5f6068a07638ca39189a7ff248448ddf2 100644 --- a/tests_python/tests_014/test_contract.py +++ b/tests_python/tests_014/test_contract.py @@ -1604,193 +1604,6 @@ code {{ assert run_script_res.storage == expected_storage -@pytest.mark.contract -class TestComparables: - def test_comparable_unit(self, client): - client.typecheck_data('{}', '(set unit)') - client.typecheck_data('{Unit}', '(set unit)') - - def test_comparable_options(self, client): - client.typecheck_data('{}', '(set (option nat))') - client.typecheck_data('{None; Some 1; Some 2}', '(set (option int))') - utils.assert_typecheck_data_failure( - client, '{Some "foo"; Some "bar"}', '(set (option string))' - ) - utils.assert_typecheck_data_failure( - client, '{Some Unit; None}', '(set (option unit))' - ) - - def test_comparable_unions(self, client): - client.typecheck_data('{}', '(set (or unit bool))') - client.typecheck_data( - '{Left 3; Left 4; Right "bar"; Right "foo"}', - '(set (or nat string))', - ) - utils.assert_typecheck_data_failure( - client, '{Left 2; Left 1}', '(set (or mutez unit))' - ) - utils.assert_typecheck_data_failure( - client, '{Right True; Right False}', '(set (or unit bool))' - ) - utils.assert_typecheck_data_failure( - client, '{Right 0; Left 1}', '(set (or nat nat))' - ) - - def test_comparable_pair(self, client: Client): - # tests that comb pairs are comparable and that the order is the - # expected one - client.typecheck_data('{}', '(set (pair nat string))') - client.typecheck_data('{Pair 0 "foo"}', '(set (pair nat string))') - client.typecheck_data( - '{Pair 0 "foo"; Pair 1 "bar"}', '(set (pair nat string))' - ) - client.typecheck_data( - '{Pair 0 "bar"; Pair 0 "foo"; \ - Pair 1 "bar"; Pair 1 "foo"}', - '(set (pair nat string))', - ) - client.typecheck_data('{}', '(set (pair nat (pair string bytes)))') - - client.typecheck_data('{}', '(map (pair nat string) unit)') - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit}', '(map (pair nat string) unit)' - ) - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit}', - '(map (pair nat string) unit)', - ) - client.typecheck_data( - '{Elt (Pair 0 "bar") Unit; \ - Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit; \ - Elt (Pair 1 "foo") Unit}', - '(map (pair nat string) unit)', - ) - client.typecheck_data('{}', '(map (pair nat (pair string bytes)) unit)') - - client.typecheck_data('{}', '(big_map (pair nat string) unit)') - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit}', '(big_map (pair nat string) unit)' - ) - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit}', - '(big_map (pair nat string) unit)', - ) - client.typecheck_data( - '{Elt (Pair 0 "bar") Unit; \ - Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit; \ - Elt (Pair 1 "foo") Unit}', - '(big_map (pair nat string) unit)', - ) - client.typecheck_data( - '{}', '(big_map (pair nat (pair string bytes)) unit)' - ) - client.typecheck_data('{}', '(set (pair (pair nat nat) nat))') - client.typecheck_data( - '{}', - '(set (pair (pair int nat) \ - (pair bool bytes)))', - ) - - def test_order_of_pairs(self, client: Client): - # tests that badly-ordered set literals are rejected - utils.assert_typecheck_data_failure( - client, '{Pair 0 "foo"; Pair 0 "bar"}', '(set (pair nat string))' - ) - utils.assert_typecheck_data_failure( - client, '{Pair 1 "bar"; Pair 0 "foo"}', '(set (pair nat string))' - ) - - def test_comparable_chain_id(self, client): - client.typecheck_data('{}', '(set chain_id)') - chain1 = client.rpc('get', 'chains/main/chain_id') - chain2 = 'NetXZVhNXbDTx5M' - utils.assert_typecheck_data_failure( - client, - '{"' + f'{chain1}' + '"; "' + f'{chain2}' + '"}', - '(set chain_id)', - ) - client.typecheck_data( - '{"' + f'{chain2}' + '"; "' + f'{chain1}' + '"}', '(set chain_id)' - ) - - def test_comparable_signature(self, client): - client.typecheck_data('{}', '(set signature)') - packed = client.pack('Unit', 'unit') - sig1 = client.sign_bytes_of_string(packed, "bootstrap1") - sig2 = client.sign_bytes_of_string(packed, "bootstrap2") - utils.assert_typecheck_data_failure( - client, - '{"' + f'{sig1}' + '"; "' + f'{sig2}' + '"}', - '(set signature)', - ) - client.typecheck_data( - '{"' + f'{sig2}' + '"; "' + f'{sig1}' + '"}', '(set signature)' - ) - - def test_comparable_key(self, client): - pubkey1 = IDENTITIES['bootstrap1']['public'] - pubkey2 = IDENTITIES['bootstrap2']['public'] - client.typecheck_data('{}', '(set key)') - utils.assert_typecheck_data_failure( - client, - '{"' + f'{pubkey1}' + '"; "' + f'{pubkey2}' + '"}', - '(set key)', - ) - client.typecheck_data( - '{"' + f'{pubkey2}' + '"; "' + f'{pubkey1}' + '"}', '(set key)' - ) - - def test_comparable_key_different_schemes(self, client): - client.gen_key('sk1', ['--sig', 'ed25519']) - key1 = client.show_address('sk1').public_key - - client.gen_key('sk2', ['--sig', 'secp256k1']) - key2 = client.show_address('sk2').public_key - - client.gen_key('sk3', ['--sig', 'p256']) - key3 = client.show_address('sk3').public_key - - # Three public keys of the three different signature schemes, ordered - client.typecheck_data( - '{"' + key1 + '"; "' + key2 + '"; "' + key3 + '"}', '(set key)' - ) - - # Test all orderings that do not respect the comparable order - utils.assert_typecheck_data_failure( - client, - '{"' + key1 + '"; "' + key3 + '"; "' + key2 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key2 + '"; "' + key1 + '"; "' + key3 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key2 + '"; "' + key3 + '"; "' + key1 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key3 + '"; "' + key1 + '"; "' + key2 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key3 + '"; "' + key2 + '"; "' + key1 + '"}', - '(set key)', - ) - - BAD_ANNOT_TEST = ''' parameter bytes; storage (option (lambda unit unit)); diff --git a/tests_python/tests_015/test_contract.py b/tests_python/tests_015/test_contract.py index 607934590b3dbbe3eb7ba3c746b74c9c044c11de..f6ab93b5f6068a07638ca39189a7ff248448ddf2 100644 --- a/tests_python/tests_015/test_contract.py +++ b/tests_python/tests_015/test_contract.py @@ -1604,193 +1604,6 @@ code {{ assert run_script_res.storage == expected_storage -@pytest.mark.contract -class TestComparables: - def test_comparable_unit(self, client): - client.typecheck_data('{}', '(set unit)') - client.typecheck_data('{Unit}', '(set unit)') - - def test_comparable_options(self, client): - client.typecheck_data('{}', '(set (option nat))') - client.typecheck_data('{None; Some 1; Some 2}', '(set (option int))') - utils.assert_typecheck_data_failure( - client, '{Some "foo"; Some "bar"}', '(set (option string))' - ) - utils.assert_typecheck_data_failure( - client, '{Some Unit; None}', '(set (option unit))' - ) - - def test_comparable_unions(self, client): - client.typecheck_data('{}', '(set (or unit bool))') - client.typecheck_data( - '{Left 3; Left 4; Right "bar"; Right "foo"}', - '(set (or nat string))', - ) - utils.assert_typecheck_data_failure( - client, '{Left 2; Left 1}', '(set (or mutez unit))' - ) - utils.assert_typecheck_data_failure( - client, '{Right True; Right False}', '(set (or unit bool))' - ) - utils.assert_typecheck_data_failure( - client, '{Right 0; Left 1}', '(set (or nat nat))' - ) - - def test_comparable_pair(self, client: Client): - # tests that comb pairs are comparable and that the order is the - # expected one - client.typecheck_data('{}', '(set (pair nat string))') - client.typecheck_data('{Pair 0 "foo"}', '(set (pair nat string))') - client.typecheck_data( - '{Pair 0 "foo"; Pair 1 "bar"}', '(set (pair nat string))' - ) - client.typecheck_data( - '{Pair 0 "bar"; Pair 0 "foo"; \ - Pair 1 "bar"; Pair 1 "foo"}', - '(set (pair nat string))', - ) - client.typecheck_data('{}', '(set (pair nat (pair string bytes)))') - - client.typecheck_data('{}', '(map (pair nat string) unit)') - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit}', '(map (pair nat string) unit)' - ) - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit}', - '(map (pair nat string) unit)', - ) - client.typecheck_data( - '{Elt (Pair 0 "bar") Unit; \ - Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit; \ - Elt (Pair 1 "foo") Unit}', - '(map (pair nat string) unit)', - ) - client.typecheck_data('{}', '(map (pair nat (pair string bytes)) unit)') - - client.typecheck_data('{}', '(big_map (pair nat string) unit)') - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit}', '(big_map (pair nat string) unit)' - ) - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit}', - '(big_map (pair nat string) unit)', - ) - client.typecheck_data( - '{Elt (Pair 0 "bar") Unit; \ - Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit; \ - Elt (Pair 1 "foo") Unit}', - '(big_map (pair nat string) unit)', - ) - client.typecheck_data( - '{}', '(big_map (pair nat (pair string bytes)) unit)' - ) - client.typecheck_data('{}', '(set (pair (pair nat nat) nat))') - client.typecheck_data( - '{}', - '(set (pair (pair int nat) \ - (pair bool bytes)))', - ) - - def test_order_of_pairs(self, client: Client): - # tests that badly-ordered set literals are rejected - utils.assert_typecheck_data_failure( - client, '{Pair 0 "foo"; Pair 0 "bar"}', '(set (pair nat string))' - ) - utils.assert_typecheck_data_failure( - client, '{Pair 1 "bar"; Pair 0 "foo"}', '(set (pair nat string))' - ) - - def test_comparable_chain_id(self, client): - client.typecheck_data('{}', '(set chain_id)') - chain1 = client.rpc('get', 'chains/main/chain_id') - chain2 = 'NetXZVhNXbDTx5M' - utils.assert_typecheck_data_failure( - client, - '{"' + f'{chain1}' + '"; "' + f'{chain2}' + '"}', - '(set chain_id)', - ) - client.typecheck_data( - '{"' + f'{chain2}' + '"; "' + f'{chain1}' + '"}', '(set chain_id)' - ) - - def test_comparable_signature(self, client): - client.typecheck_data('{}', '(set signature)') - packed = client.pack('Unit', 'unit') - sig1 = client.sign_bytes_of_string(packed, "bootstrap1") - sig2 = client.sign_bytes_of_string(packed, "bootstrap2") - utils.assert_typecheck_data_failure( - client, - '{"' + f'{sig1}' + '"; "' + f'{sig2}' + '"}', - '(set signature)', - ) - client.typecheck_data( - '{"' + f'{sig2}' + '"; "' + f'{sig1}' + '"}', '(set signature)' - ) - - def test_comparable_key(self, client): - pubkey1 = IDENTITIES['bootstrap1']['public'] - pubkey2 = IDENTITIES['bootstrap2']['public'] - client.typecheck_data('{}', '(set key)') - utils.assert_typecheck_data_failure( - client, - '{"' + f'{pubkey1}' + '"; "' + f'{pubkey2}' + '"}', - '(set key)', - ) - client.typecheck_data( - '{"' + f'{pubkey2}' + '"; "' + f'{pubkey1}' + '"}', '(set key)' - ) - - def test_comparable_key_different_schemes(self, client): - client.gen_key('sk1', ['--sig', 'ed25519']) - key1 = client.show_address('sk1').public_key - - client.gen_key('sk2', ['--sig', 'secp256k1']) - key2 = client.show_address('sk2').public_key - - client.gen_key('sk3', ['--sig', 'p256']) - key3 = client.show_address('sk3').public_key - - # Three public keys of the three different signature schemes, ordered - client.typecheck_data( - '{"' + key1 + '"; "' + key2 + '"; "' + key3 + '"}', '(set key)' - ) - - # Test all orderings that do not respect the comparable order - utils.assert_typecheck_data_failure( - client, - '{"' + key1 + '"; "' + key3 + '"; "' + key2 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key2 + '"; "' + key1 + '"; "' + key3 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key2 + '"; "' + key3 + '"; "' + key1 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key3 + '"; "' + key1 + '"; "' + key2 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key3 + '"; "' + key2 + '"; "' + key1 + '"}', - '(set key)', - ) - - BAD_ANNOT_TEST = ''' parameter bytes; storage (option (lambda unit unit)); diff --git a/tests_python/tests_alpha/test_contract.py b/tests_python/tests_alpha/test_contract.py index 607934590b3dbbe3eb7ba3c746b74c9c044c11de..f6ab93b5f6068a07638ca39189a7ff248448ddf2 100644 --- a/tests_python/tests_alpha/test_contract.py +++ b/tests_python/tests_alpha/test_contract.py @@ -1604,193 +1604,6 @@ code {{ assert run_script_res.storage == expected_storage -@pytest.mark.contract -class TestComparables: - def test_comparable_unit(self, client): - client.typecheck_data('{}', '(set unit)') - client.typecheck_data('{Unit}', '(set unit)') - - def test_comparable_options(self, client): - client.typecheck_data('{}', '(set (option nat))') - client.typecheck_data('{None; Some 1; Some 2}', '(set (option int))') - utils.assert_typecheck_data_failure( - client, '{Some "foo"; Some "bar"}', '(set (option string))' - ) - utils.assert_typecheck_data_failure( - client, '{Some Unit; None}', '(set (option unit))' - ) - - def test_comparable_unions(self, client): - client.typecheck_data('{}', '(set (or unit bool))') - client.typecheck_data( - '{Left 3; Left 4; Right "bar"; Right "foo"}', - '(set (or nat string))', - ) - utils.assert_typecheck_data_failure( - client, '{Left 2; Left 1}', '(set (or mutez unit))' - ) - utils.assert_typecheck_data_failure( - client, '{Right True; Right False}', '(set (or unit bool))' - ) - utils.assert_typecheck_data_failure( - client, '{Right 0; Left 1}', '(set (or nat nat))' - ) - - def test_comparable_pair(self, client: Client): - # tests that comb pairs are comparable and that the order is the - # expected one - client.typecheck_data('{}', '(set (pair nat string))') - client.typecheck_data('{Pair 0 "foo"}', '(set (pair nat string))') - client.typecheck_data( - '{Pair 0 "foo"; Pair 1 "bar"}', '(set (pair nat string))' - ) - client.typecheck_data( - '{Pair 0 "bar"; Pair 0 "foo"; \ - Pair 1 "bar"; Pair 1 "foo"}', - '(set (pair nat string))', - ) - client.typecheck_data('{}', '(set (pair nat (pair string bytes)))') - - client.typecheck_data('{}', '(map (pair nat string) unit)') - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit}', '(map (pair nat string) unit)' - ) - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit}', - '(map (pair nat string) unit)', - ) - client.typecheck_data( - '{Elt (Pair 0 "bar") Unit; \ - Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit; \ - Elt (Pair 1 "foo") Unit}', - '(map (pair nat string) unit)', - ) - client.typecheck_data('{}', '(map (pair nat (pair string bytes)) unit)') - - client.typecheck_data('{}', '(big_map (pair nat string) unit)') - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit}', '(big_map (pair nat string) unit)' - ) - client.typecheck_data( - '{Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit}', - '(big_map (pair nat string) unit)', - ) - client.typecheck_data( - '{Elt (Pair 0 "bar") Unit; \ - Elt (Pair 0 "foo") Unit; \ - Elt (Pair 1 "bar") Unit; \ - Elt (Pair 1 "foo") Unit}', - '(big_map (pair nat string) unit)', - ) - client.typecheck_data( - '{}', '(big_map (pair nat (pair string bytes)) unit)' - ) - client.typecheck_data('{}', '(set (pair (pair nat nat) nat))') - client.typecheck_data( - '{}', - '(set (pair (pair int nat) \ - (pair bool bytes)))', - ) - - def test_order_of_pairs(self, client: Client): - # tests that badly-ordered set literals are rejected - utils.assert_typecheck_data_failure( - client, '{Pair 0 "foo"; Pair 0 "bar"}', '(set (pair nat string))' - ) - utils.assert_typecheck_data_failure( - client, '{Pair 1 "bar"; Pair 0 "foo"}', '(set (pair nat string))' - ) - - def test_comparable_chain_id(self, client): - client.typecheck_data('{}', '(set chain_id)') - chain1 = client.rpc('get', 'chains/main/chain_id') - chain2 = 'NetXZVhNXbDTx5M' - utils.assert_typecheck_data_failure( - client, - '{"' + f'{chain1}' + '"; "' + f'{chain2}' + '"}', - '(set chain_id)', - ) - client.typecheck_data( - '{"' + f'{chain2}' + '"; "' + f'{chain1}' + '"}', '(set chain_id)' - ) - - def test_comparable_signature(self, client): - client.typecheck_data('{}', '(set signature)') - packed = client.pack('Unit', 'unit') - sig1 = client.sign_bytes_of_string(packed, "bootstrap1") - sig2 = client.sign_bytes_of_string(packed, "bootstrap2") - utils.assert_typecheck_data_failure( - client, - '{"' + f'{sig1}' + '"; "' + f'{sig2}' + '"}', - '(set signature)', - ) - client.typecheck_data( - '{"' + f'{sig2}' + '"; "' + f'{sig1}' + '"}', '(set signature)' - ) - - def test_comparable_key(self, client): - pubkey1 = IDENTITIES['bootstrap1']['public'] - pubkey2 = IDENTITIES['bootstrap2']['public'] - client.typecheck_data('{}', '(set key)') - utils.assert_typecheck_data_failure( - client, - '{"' + f'{pubkey1}' + '"; "' + f'{pubkey2}' + '"}', - '(set key)', - ) - client.typecheck_data( - '{"' + f'{pubkey2}' + '"; "' + f'{pubkey1}' + '"}', '(set key)' - ) - - def test_comparable_key_different_schemes(self, client): - client.gen_key('sk1', ['--sig', 'ed25519']) - key1 = client.show_address('sk1').public_key - - client.gen_key('sk2', ['--sig', 'secp256k1']) - key2 = client.show_address('sk2').public_key - - client.gen_key('sk3', ['--sig', 'p256']) - key3 = client.show_address('sk3').public_key - - # Three public keys of the three different signature schemes, ordered - client.typecheck_data( - '{"' + key1 + '"; "' + key2 + '"; "' + key3 + '"}', '(set key)' - ) - - # Test all orderings that do not respect the comparable order - utils.assert_typecheck_data_failure( - client, - '{"' + key1 + '"; "' + key3 + '"; "' + key2 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key2 + '"; "' + key1 + '"; "' + key3 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key2 + '"; "' + key3 + '"; "' + key1 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key3 + '"; "' + key1 + '"; "' + key2 + '"}', - '(set key)', - ) - - utils.assert_typecheck_data_failure( - client, - '{"' + key3 + '"; "' + key2 + '"; "' + key1 + '"}', - '(set key)', - ) - - BAD_ANNOT_TEST = ''' parameter bytes; storage (option (lambda unit unit)); diff --git a/tezt/lib_tezos/client.ml b/tezt/lib_tezos/client.ml index 331174539feadcaf9e2dfede742385c403fadb66..e8e73e0989d74d20bde21a36e795023d26b58856 100644 --- a/tezt/lib_tezos/client.ml +++ b/tezt/lib_tezos/client.ml @@ -731,7 +731,7 @@ let propose_for ?endpoint ?(minimal_timestamp = true) ?protocol ?key ?force let id = ref 0 -let spawn_gen_keys ?alias client = +let spawn_gen_keys ?alias ?sig_alg client = let alias = match alias with | None -> @@ -739,10 +739,12 @@ let spawn_gen_keys ?alias client = sf "tezt_%d" !id | Some alias -> alias in - (spawn_command client ["gen"; "keys"; alias], alias) + ( spawn_command client @@ ["gen"; "keys"; alias] + @ optional_arg "sig" Fun.id sig_alg, + alias ) -let gen_keys ?alias client = - let p, alias = spawn_gen_keys ?alias client in +let gen_keys ?alias ?sig_alg client = + let p, alias = spawn_gen_keys ?alias ?sig_alg client in let* () = Process.check p in return alias @@ -776,8 +778,8 @@ let list_known_addresses client = in return addresses -let gen_and_show_keys ?alias client = - let* alias = gen_keys ?alias client in +let gen_and_show_keys ?alias ?sig_alg client = + let* alias = gen_keys ?alias ?sig_alg client in show_address ~alias client let spawn_bls_gen_keys ?hooks ?(force = false) ?alias client = @@ -1493,6 +1495,20 @@ let spawn_normalize_script ?mode ~script client = let normalize_script ?mode ~script client = spawn_normalize_script ?mode ~script client |> Process.check_and_read_stdout +let spawn_typecheck_data ~data ~typ ?gas ?(legacy = false) client = + let gas_cmd = + Option.map Int.to_string gas |> Option.map (fun g -> ["--gas"; g]) + in + let cmd = + ["typecheck"; "data"; data; "against"; "type"; typ] + @ Option.value ~default:[] gas_cmd + @ if legacy then ["--legacy"] else [] + in + spawn_command client cmd + +let typecheck_data ~data ~typ ?gas ?(legacy = false) client = + spawn_typecheck_data ~data ~typ ?gas ~legacy client |> Process.check + let spawn_typecheck_script ~script ?(details = false) ?(emacs = false) ?(no_print_source = false) ?gas ?(legacy = false) client = let gas_cmd = diff --git a/tezt/lib_tezos/client.mli b/tezt/lib_tezos/client.mli index 2bffa6a64e65df6352edc730aa59851721605fb0..f027e19f441c770f9c61929bee3f6be3beea52bf 100644 --- a/tezt/lib_tezos/client.mli +++ b/tezt/lib_tezos/client.mli @@ -597,11 +597,12 @@ val spawn_list_known_addresses : t -> Process.t (** Run [octez-client gen keys] and return the key alias. The default value for [alias] is a fresh alias of the form [tezt_]. *) -val gen_keys : ?alias:string -> t -> string Lwt.t +val gen_keys : ?alias:string -> ?sig_alg:string -> t -> string Lwt.t (** A helper to run [octez-client gen keys] followed by [octez-client show address] to get the generated key. *) -val gen_and_show_keys : ?alias:string -> t -> Account.key Lwt.t +val gen_and_show_keys : + ?alias:string -> ?sig_alg:string -> t -> Account.key Lwt.t (** Run [octez-client bls gen keys ]. *) val bls_gen_keys : @@ -1199,6 +1200,14 @@ val normalize_script : val spawn_normalize_script : ?mode:normalize_mode -> script:string -> t -> Process.t +(** Run [octez-client typecheck data ..]*) +val typecheck_data : + data:string -> typ:string -> ?gas:int -> ?legacy:bool -> t -> unit Lwt.t + +(** Same as [typecheck_data], but do not wait for the process to exit. *) +val spawn_typecheck_data : + data:string -> typ:string -> ?gas:int -> ?legacy:bool -> t -> Process.t + (** Run [octez-client typecheck script ..]*) val typecheck_script : script:string -> diff --git a/tezt/tests/comparable_datatype.ml b/tezt/tests/comparable_datatype.ml new file mode 100644 index 0000000000000000000000000000000000000000..23f580d5c1f178ecf1eb3a429e191927d3ddb05c --- /dev/null +++ b/tezt/tests/comparable_datatype.ml @@ -0,0 +1,329 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2020 Nomadic Labs *) +(* Copyright (c) 2022 Marigold *) +(* *) +(* Permission is hereby granted, free of charge, to any person obtaining a *) +(* copy of this software and associated documentation files (the "Software"),*) +(* to deal in the Software without restriction, including without limitation *) +(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *) +(* and/or sell copies of the Software, and to permit persons to whom the *) +(* Software is furnished to do so, subject to the following conditions: *) +(* *) +(* The above copyright notice and this permission notice shall be included *) +(* in all copies or substantial portions of the Software. *) +(* *) +(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*) +(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *) +(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *) +(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*) +(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *) +(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *) +(* DEALINGS IN THE SOFTWARE. *) +(* *) +(*****************************************************************************) + +(* Testing + ------- + Components: Michelson + Invocation: dune exec tezt/tests/main.exe -- --file comparable_datatype.ml + Subject: Tests for comparable data type +*) + +let test_comparable_unit client () = + let* () = Client.typecheck_data ~data:"{}" ~typ:"(set unit)" client in + let* () = Client.typecheck_data ~data:"{Unit}" ~typ:"(set unit)" client in + unit + +let assert_typecheck_data_failure client ~data ~typ = + let expected_msg = rex "ill-typed data" in + let process = Client.spawn_typecheck_data ~data ~typ client in + Process.check_error ~msg:expected_msg process + +let test_comparable_options client () = + let* () = Client.typecheck_data ~data:"{}" ~typ:"(set (option nat))" client in + let* () = + Client.typecheck_data + ~data:"{None; Some 1; Some 2}" + ~typ:"(set (option int))" + client + in + let* () = + assert_typecheck_data_failure + client + ~data:"{Some \"foo\"; Some \"bar\"}" + ~typ:"(set (option string))" + in + let* () = + assert_typecheck_data_failure + ~data:"{Some Unit; None}" + ~typ:"(set (option unit))" + client + in + unit + +let test_comparable_unions client () = + let* () = + Client.typecheck_data ~data:"{}" ~typ:"(set (or unit bool))" client + in + let* () = + Client.typecheck_data + ~data:"{Left 3; Left 4; Right \"bar\"; Right \"foo\"}" + ~typ:"(set (or nat string))" + client + in + let* () = + assert_typecheck_data_failure + client + ~data:"{Left 2; Left 1}" + ~typ:"(set (or mutez unit))" + in + let* () = + assert_typecheck_data_failure + client + ~data:"{Right True; Right False}" + ~typ:"(set (or unit bool))" + in + let* () = + assert_typecheck_data_failure + client + ~data:"{Right 0; Left 1}" + ~typ:"(set (or nat nat))" + in + unit + +(* Tests that badly-ordered set literals are rejected *) +let test_comparable_pair client () = + let* () = + Client.typecheck_data ~data:"{}" ~typ:"(set (pair nat string))" client + in + let* () = + Client.typecheck_data + ~data:"{Pair 0 \"foo\"}" + ~typ:"(set (pair nat string))" + client + in + let* () = + Client.typecheck_data + ~data:"{Pair 0 \"foo\"; Pair 1 \"bar\"}" + ~typ:"(set (pair nat string))" + client + in + let* () = + Client.typecheck_data + ~data:"{Pair 0 \"bar\"; Pair 0 \"foo\"; Pair 1 \"bar\"; Pair 1 \"foo\"}" + ~typ:"(set (pair nat string))" + client + in + let* () = + Client.typecheck_data + ~data:"{}" + ~typ:"(set (pair nat (pair string bytes)))" + client + in + let* () = + Client.typecheck_data ~data:"{}" ~typ:"(map (pair nat string) unit)" client + in + let* () = + Client.typecheck_data + ~data:"{Elt (Pair 0 \"foo\") Unit}" + ~typ:"(map (pair nat string) unit)" + client + in + let* () = + Client.typecheck_data + ~data:"{Elt (Pair 0 \"foo\") Unit; Elt (Pair 1 \"bar\") Unit}" + ~typ:"(map (pair nat string) unit)" + client + in + let* () = + Client.typecheck_data + ~data: + "{Elt (Pair 0 \"bar\") Unit; Elt (Pair 0 \"foo\") Unit; Elt (Pair 1 \ + \"bar\") Unit; Elt (Pair 1 \"foo\") Unit}" + ~typ:"(map (pair nat string) unit)" + client + in + let* () = + Client.typecheck_data + ~data:"{}" + ~typ:"(map (pair nat (pair string bytes)) unit)" + client + in + let* () = + Client.typecheck_data + ~data:"{}" + ~typ:"(big_map (pair nat string) unit)" + client + in + let* () = + Client.typecheck_data + ~data:"{Elt (Pair 0 \"foo\") Unit}" + ~typ:"(big_map (pair nat string) unit)" + client + in + let* () = + Client.typecheck_data + ~data:"{Elt (Pair 0 \"foo\") Unit; Elt (Pair 1 \"bar\") Unit}" + ~typ:"(big_map (pair nat string) unit)" + client + in + let* () = + Client.typecheck_data + ~data: + "{Elt (Pair 0 \"bar\") Unit; Elt (Pair 0 \"foo\") Unit; Elt (Pair 1 \ + \"bar\") Unit; Elt (Pair 1 \"foo\") Unit}" + ~typ:"(big_map (pair nat string) unit)" + client + in + let* () = + Client.typecheck_data + ~data:"{}" + ~typ:"(big_map (pair nat (pair string bytes)) unit)" + client + in + let* () = + Client.typecheck_data + ~data:"{}" + ~typ:"(set (pair (pair nat nat) nat))" + client + in + let* () = + Client.typecheck_data + ~data:"{}" + ~typ:"(set (pair (pair int nat) (pair bool bytes)))" + client + in + unit + +let test_order_of_pairs client () = + let* () = + assert_typecheck_data_failure + ~data:"{Pair 0 \"foo\"; Pair 0 \"bar\"}" + ~typ:"(set (pair nat string))" + client + in + let* () = + assert_typecheck_data_failure + ~data:"{Pair 1 \"bar\"; Pair 0 \"foo\"}" + ~typ:"(set (pair nat string))" + client + in + unit + +let test_comparable_chain_id client () = + let* () = Client.typecheck_data ~data:"{}" ~typ:"(set chain_id)" client in + let* chain1 = RPC.Client.call client @@ RPC.get_chain_chain_id () in + let chain2 = "NetXZVhNXbDTx5M" in + let data = sf {|{"%s" ; "%s"}|} chain1 chain2 in + let* () = assert_typecheck_data_failure ~data ~typ:"(set chain_id)" client in + let data = sf {|{"%s" ; "%s"}|} chain2 chain1 in + let* () = Client.typecheck_data client ~data ~typ:"(set chain_id)" in + unit + +let test_comparable_signature client () = + let* () = Client.typecheck_data ~data:"{}" ~typ:"(set signature)" client in + let* hash_data_output = Client.hash_data ~data:"Unit" ~typ:"unit" client in + let packed_data = List.assoc "Raw packed data" hash_data_output in + let* sign1 = + Client.sign_bytes ~signer:"bootstrap1" ~data:packed_data client + in + let* sign2 = + Client.sign_bytes ~signer:"bootstrap2" ~data:packed_data client + in + let data = sf {|{"%s" ; "%s"}|} sign1 sign2 in + let* () = assert_typecheck_data_failure ~data ~typ:"(set signature)" client in + let data = sf {|{"%s" ; "%s"}|} sign2 sign1 in + let* () = Client.typecheck_data ~data ~typ:"(set signature)" client in + unit + +let test_comparable_key client () = + let* () = Client.typecheck_data ~data:"{}" ~typ:"(set key)" client in + let pubkey1 = Constant.bootstrap1.public_key in + let pubkey2 = Constant.bootstrap2.public_key in + let data = sf {|{"%s" ; "%s"}|} pubkey1 pubkey2 in + let* () = assert_typecheck_data_failure ~data ~typ:"(set key)" client in + let data = sf {|{"%s" ; "%s"}|} pubkey2 pubkey1 in + let* () = Client.typecheck_data ~data ~typ:"(set key)" client in + unit + +let test_comparable_key_different_schemes client () = + let* sk1 = Client.gen_and_show_keys ~alias:"sk1" ~sig_alg:"ed25519" client in + let* sk2 = + Client.gen_and_show_keys ~alias:"sk2" ~sig_alg:"secp256k1" client + in + let* sk3 = Client.gen_and_show_keys ~alias:"sk3" ~sig_alg:"p256" client in + let data = + sf + {|{"%s" ; "%s"; "%s"}|} + sk1.Account.public_key + sk2.Account.public_key + sk3.Account.public_key + in + let* () = Client.typecheck_data ~data ~typ:"(set key)" client in + let data = + sf + {|{"%s" ; "%s"; "%s"}|} + sk1.Account.public_key + sk3.Account.public_key + sk2.Account.public_key + in + let* () = assert_typecheck_data_failure ~data ~typ:"(set key)" client in + let data = + sf + {|{"%s" ; "%s"; "%s"}|} + sk2.Account.public_key + sk1.Account.public_key + sk3.Account.public_key + in + let* () = assert_typecheck_data_failure ~data ~typ:"(set key)" client in + let data = + sf + {|{"%s" ; "%s"; "%s"}|} + sk2.Account.public_key + sk3.Account.public_key + sk1.Account.public_key + in + let* () = assert_typecheck_data_failure ~data ~typ:"(set key)" client in + let data = + sf + {|{"%s" ; "%s"; "%s"}|} + sk3.Account.public_key + sk1.Account.public_key + sk2.Account.public_key + in + let* () = assert_typecheck_data_failure ~data ~typ:"(set key)" client in + let data = + sf + {|{"%s" ; "%s"; "%s"}|} + sk3.Account.public_key + sk2.Account.public_key + sk1.Account.public_key + in + let* () = assert_typecheck_data_failure ~data ~typ:"(set key)" client in + unit + +let register ~protocols = + List.iter + (fun (title, test_function) -> + Protocol.register_test + ~__FILE__ + ~title + ~tags:["client"; "michelson"] + (fun protocol -> + let* client = Client.init_mockup ~protocol () in + test_function client ()) + protocols) + [ + ("Run `comparable_unit`", test_comparable_unit); + ("Run `comparable_options`", test_comparable_options); + ("Run `comparable_unions`", test_comparable_unions); + ("Run `comparable_pair`", test_comparable_pair); + ("Run `order_of_pairs`", test_order_of_pairs); + ("Run `comparable_chain_id`", test_comparable_chain_id); + ("Run `comparable_signature`", test_comparable_signature); + ("Run `comparable_key`", test_comparable_key); + ( "Run `comparable_key_different_schemes`", + test_comparable_key_different_schemes ); + ] diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index d80b6ba8aad578632e2854f083a4710c59d0c57c..0cd26c130186e936b52ed69a3da43964362829d5 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -105,6 +105,7 @@ let register_protocol_tests_that_use_supports_correctly () = Client_commands.register ~protocols ; Client_config.register ~protocols ; Client_run_view.register ~protocols ; + Comparable_datatype.register ~protocols ; Contract_hash_fun.register ~protocols ; Contract_hash_with_origination.register ~protocols ; Create_contract.register ~protocols ;