diff --git a/tests_python/tests_014/test_contract.py b/tests_python/tests_014/test_contract.py index c9790e30e47e2c237595c2257d5733fec8208da9..6c2664cbe32b4e0516b266726cbf74e5b11f8a7e 100644 --- a/tests_python/tests_014/test_contract.py +++ b/tests_python/tests_014/test_contract.py @@ -1108,41 +1108,6 @@ class TestNonRegression: class TestMiniScenarios: """Test mini scenarios""" - # replay.tz related tests - def test_replay_originate(self, client: Client, session: dict): - path = os.path.join(CONTRACT_PATH, 'mini_scenarios', 'replay.tz') - originate(client, session, path, 'Unit', 0) - - def test_replay_transfer_fail(self, client: Client): - with utils.assert_run_failure("Internal operation replay attempt"): - client.transfer(10, "bootstrap1", "replay", []) - - # create_contract.tz related tests - def test_create_contract_originate(self, client: Client, session: dict): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'create_contract.tz' - ) - originate(client, session, path, 'Unit', 1000) - - def test_create_contract_balance(self, client: Client): - assert client.get_balance('create_contract') == 1000 - - def test_create_contract_perform_creation(self, client: Client): - transfer_result = client.transfer( - 0, - "bootstrap1", - "create_contract", - ['-arg', 'None', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - pattern = r"New contract (\w*) originated" - match = re.search(pattern, transfer_result.client_output) - assert match is not None - kt_1 = match.groups()[0] - assert client.get_storage(kt_1) == '"abcdefg"' - assert client.get_balance(kt_1) == 100 - assert client.get_balance('create_contract') == 900 - # Originates a contract that when called, creates a contract with a # rootname annotation. Such annotations comes in two flavors, thus the # parameterization. Then calls the first contract and verifies the @@ -1182,207 +1147,6 @@ class TestMiniScenarios: 'with type unit' ) - # default_account.tz related tests - def test_default_account_originate(self, client: Client, session: dict): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'default_account.tz' - ) - originate(client, session, path, 'Unit', 1000) - - def test_default_account_transfer_then_bake(self, client: Client): - tz1 = IDENTITIES['bootstrap4']['identity'] - client.transfer( - 0, - "bootstrap1", - "default_account", - ['-arg', f'"{tz1}"', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - account = 'tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5' - client.transfer( - 0, - "bootstrap1", - "default_account", - ['-arg', f'"{account}"', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - assert client.get_balance(account) == 100 - - # Test bytes, SHA252, CHECK_SIGNATURE - def test_reveal_signed_preimage_originate( - self, client: Client, session: dict - ): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'reveal_signed_preimage.tz' - ) - byt = ( - '0x9995c2ef7bcc7ae3bd15bdd9b02' - + 'dc6e877c27b26732340d641a4cbc6524813bb' - ) - sign = 'p2pk66uq221795tFxT7jfNmXtBMdjMf6RAaxRTwv1dbuSHbH6yfqGwz' - storage = f'(Pair {byt} "{sign}")' - originate(client, session, path, storage, 1000) - - def test_wrong_preimage(self, client: Client): - byt = ( - '0x050100000027566f756c657a2d766f75732' - + '0636f75636865722061766563206d6f692c20636520736f6972' - ) - sign = ( - 'p2sigvgDSBnN1bUsfwyMvqpJA1cFhE5s5oi7SetJ' - + 'VQ6LJsbFrU2idPvnvwJhf5v9DhM9ZTX1euS9DgWozVw6BTHiK9VcQVpAU8' - ) - arg = f'(Pair {byt} "{sign}")' - - # We check failure of ASSERT_CMPEQ in the script. - with utils.assert_run_failure("At line 8 characters 9 to 21"): - client.transfer( - 0, - "bootstrap1", - "reveal_signed_preimage", - ['-arg', arg, '--burn-cap', '10'], - ) - - def test_wrong_signature(self, client: Client): - byt = ( - '0x050100000027566f756c657a2d766f757320636' - + 'f75636865722061766563206d6f692c20636520736f6972203f' - ) - sign = ( - 'p2sigvgDSBnN1bUsfwyMvqpJA1cFhE5s5oi7SetJVQ6' - + 'LJsbFrU2idPvnvwJhf5v9DhM9ZTX1euS9DgWozVw6BTHiK9VcQVpAU8' - ) - arg = f'(Pair {byt} "{sign}")' - - # We check failure of CHECK_SIGNATURE ; ASSERT in the script. - with utils.assert_run_failure("At line 15 characters 9 to 15"): - client.transfer( - 0, - "bootstrap1", - "reveal_signed_preimage", - ['-arg', arg, '--burn-cap', '10'], - ) - - def test_good_preimage_and_signature(self, client: Client): - byt = ( - '0x050100000027566f756c657a2d766f757320636f7563' - + '6865722061766563206d6f692c20636520736f6972203f' - ) - sign = ( - 'p2sigsceCzcDw2AeYDzUonj4JT341WC9Px4wdhHBxbZcG1F' - + 'hfqFVuG7f2fGCzrEHSAZgrsrQWpxduDPk9qZRgrpzwJnSHC3gZJ' - ) - arg = f'(Pair {byt} "{sign}")' - client.transfer( - 0, - "bootstrap1", - "reveal_signed_preimage", - ['-arg', arg, '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - - # Test vote_for_delegate - def test_vote_for_delegate_originate(self, client: Client, session: dict): - b_3 = IDENTITIES['bootstrap3']['identity'] - b_4 = IDENTITIES['bootstrap4']['identity'] - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'vote_for_delegate.tz' - ) - storage = f'''(Pair (Pair "{b_3}" None) (Pair "{b_4}" None))''' - originate(client, session, path, storage, 1000) - assert client.get_delegate('vote_for_delegate').delegate is None - - def test_vote_for_delegate_wrong_identity1(self, client: Client): - # We check failure of CHECK_SIGNATURE ; ASSERT in the script. - with utils.assert_run_failure("At line 14 characters 9 to 12"): - client.transfer( - 0, - "bootstrap1", - "vote_for_delegate", - ['-arg', 'None', '--burn-cap', '10'], - ) - - def test_vote_for_delegate_wrong_identity2(self, client: Client): - # We check failure of CHECK_SIGNATURE ; ASSERT in the script. - with utils.assert_run_failure("At line 14 characters 9 to 12"): - client.transfer( - 0, - "bootstrap2", - "vote_for_delegate", - ['-arg', 'None', '--burn-cap', '10'], - ) - - def test_vote_for_delegate_b3_vote_for_b5(self, client: Client): - b_5 = IDENTITIES['bootstrap5']['identity'] - client.transfer( - 0, - "bootstrap3", - "vote_for_delegate", - ['-arg', f'(Some "{b_5}")', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - storage = client.get_storage('vote_for_delegate') - assert re.search(b_5, storage) - - def test_vote_for_delegate_still_no_delegate1(self, client: Client): - assert client.get_delegate('vote_for_delegate').delegate is None - - def test_vote_for_delegate_b4_vote_for_b2(self, client: Client): - b_2 = IDENTITIES['bootstrap2']['identity'] - client.transfer( - 0, - "bootstrap4", - "vote_for_delegate", - ['-arg', f'(Some "{b_2}")', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - storage = client.get_storage('vote_for_delegate') - assert re.search(b_2, storage) - - def test_vote_for_delegate_still_no_delegate2(self, client: Client): - assert client.get_delegate('vote_for_delegate').delegate is None - - def test_vote_for_delegate_b4_vote_for_b5(self, client: Client): - b_5 = IDENTITIES['bootstrap5']['identity'] - client.transfer( - 0, - "bootstrap4", - "vote_for_delegate", - ['-arg', f'(Some "{b_5}")', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - storage = client.get_storage('vote_for_delegate') - assert re.search(b_5, storage) - - def test_vote_for_delegate_has_delegate(self, client: Client): - b_5 = IDENTITIES['bootstrap5']['identity'] - result = client.get_delegate('vote_for_delegate') - assert result.delegate == b_5 - - def test_multiple_entrypoints_counter(self, session: dict, client: Client): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'multiple_entrypoints_counter.tz' - ) - - storage = 'None' - - # originate contract - originate(client, session, path, storage, 0) - utils.bake(client, bake_for='bootstrap5') - - # call contract: creates the internal contract and calls it. - client.transfer( - 0, - 'bootstrap1', - 'multiple_entrypoints_counter', - ['--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - assert client.get_storage('multiple_entrypoints_counter') == 'None', ( - "The storage of the multiple_entrypoints_counter contract" - " should be None" - ) - # Test CONTRACT with/without entrypoint annotation on literal address # parameters with/without entrypoint annotation def test_originate_simple_entrypoints(self, session: dict, client: Client): diff --git a/tests_python/tests_015/test_contract.py b/tests_python/tests_015/test_contract.py index c9790e30e47e2c237595c2257d5733fec8208da9..6c2664cbe32b4e0516b266726cbf74e5b11f8a7e 100644 --- a/tests_python/tests_015/test_contract.py +++ b/tests_python/tests_015/test_contract.py @@ -1108,41 +1108,6 @@ class TestNonRegression: class TestMiniScenarios: """Test mini scenarios""" - # replay.tz related tests - def test_replay_originate(self, client: Client, session: dict): - path = os.path.join(CONTRACT_PATH, 'mini_scenarios', 'replay.tz') - originate(client, session, path, 'Unit', 0) - - def test_replay_transfer_fail(self, client: Client): - with utils.assert_run_failure("Internal operation replay attempt"): - client.transfer(10, "bootstrap1", "replay", []) - - # create_contract.tz related tests - def test_create_contract_originate(self, client: Client, session: dict): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'create_contract.tz' - ) - originate(client, session, path, 'Unit', 1000) - - def test_create_contract_balance(self, client: Client): - assert client.get_balance('create_contract') == 1000 - - def test_create_contract_perform_creation(self, client: Client): - transfer_result = client.transfer( - 0, - "bootstrap1", - "create_contract", - ['-arg', 'None', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - pattern = r"New contract (\w*) originated" - match = re.search(pattern, transfer_result.client_output) - assert match is not None - kt_1 = match.groups()[0] - assert client.get_storage(kt_1) == '"abcdefg"' - assert client.get_balance(kt_1) == 100 - assert client.get_balance('create_contract') == 900 - # Originates a contract that when called, creates a contract with a # rootname annotation. Such annotations comes in two flavors, thus the # parameterization. Then calls the first contract and verifies the @@ -1182,207 +1147,6 @@ class TestMiniScenarios: 'with type unit' ) - # default_account.tz related tests - def test_default_account_originate(self, client: Client, session: dict): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'default_account.tz' - ) - originate(client, session, path, 'Unit', 1000) - - def test_default_account_transfer_then_bake(self, client: Client): - tz1 = IDENTITIES['bootstrap4']['identity'] - client.transfer( - 0, - "bootstrap1", - "default_account", - ['-arg', f'"{tz1}"', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - account = 'tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5' - client.transfer( - 0, - "bootstrap1", - "default_account", - ['-arg', f'"{account}"', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - assert client.get_balance(account) == 100 - - # Test bytes, SHA252, CHECK_SIGNATURE - def test_reveal_signed_preimage_originate( - self, client: Client, session: dict - ): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'reveal_signed_preimage.tz' - ) - byt = ( - '0x9995c2ef7bcc7ae3bd15bdd9b02' - + 'dc6e877c27b26732340d641a4cbc6524813bb' - ) - sign = 'p2pk66uq221795tFxT7jfNmXtBMdjMf6RAaxRTwv1dbuSHbH6yfqGwz' - storage = f'(Pair {byt} "{sign}")' - originate(client, session, path, storage, 1000) - - def test_wrong_preimage(self, client: Client): - byt = ( - '0x050100000027566f756c657a2d766f75732' - + '0636f75636865722061766563206d6f692c20636520736f6972' - ) - sign = ( - 'p2sigvgDSBnN1bUsfwyMvqpJA1cFhE5s5oi7SetJ' - + 'VQ6LJsbFrU2idPvnvwJhf5v9DhM9ZTX1euS9DgWozVw6BTHiK9VcQVpAU8' - ) - arg = f'(Pair {byt} "{sign}")' - - # We check failure of ASSERT_CMPEQ in the script. - with utils.assert_run_failure("At line 8 characters 9 to 21"): - client.transfer( - 0, - "bootstrap1", - "reveal_signed_preimage", - ['-arg', arg, '--burn-cap', '10'], - ) - - def test_wrong_signature(self, client: Client): - byt = ( - '0x050100000027566f756c657a2d766f757320636' - + 'f75636865722061766563206d6f692c20636520736f6972203f' - ) - sign = ( - 'p2sigvgDSBnN1bUsfwyMvqpJA1cFhE5s5oi7SetJVQ6' - + 'LJsbFrU2idPvnvwJhf5v9DhM9ZTX1euS9DgWozVw6BTHiK9VcQVpAU8' - ) - arg = f'(Pair {byt} "{sign}")' - - # We check failure of CHECK_SIGNATURE ; ASSERT in the script. - with utils.assert_run_failure("At line 15 characters 9 to 15"): - client.transfer( - 0, - "bootstrap1", - "reveal_signed_preimage", - ['-arg', arg, '--burn-cap', '10'], - ) - - def test_good_preimage_and_signature(self, client: Client): - byt = ( - '0x050100000027566f756c657a2d766f757320636f7563' - + '6865722061766563206d6f692c20636520736f6972203f' - ) - sign = ( - 'p2sigsceCzcDw2AeYDzUonj4JT341WC9Px4wdhHBxbZcG1F' - + 'hfqFVuG7f2fGCzrEHSAZgrsrQWpxduDPk9qZRgrpzwJnSHC3gZJ' - ) - arg = f'(Pair {byt} "{sign}")' - client.transfer( - 0, - "bootstrap1", - "reveal_signed_preimage", - ['-arg', arg, '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - - # Test vote_for_delegate - def test_vote_for_delegate_originate(self, client: Client, session: dict): - b_3 = IDENTITIES['bootstrap3']['identity'] - b_4 = IDENTITIES['bootstrap4']['identity'] - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'vote_for_delegate.tz' - ) - storage = f'''(Pair (Pair "{b_3}" None) (Pair "{b_4}" None))''' - originate(client, session, path, storage, 1000) - assert client.get_delegate('vote_for_delegate').delegate is None - - def test_vote_for_delegate_wrong_identity1(self, client: Client): - # We check failure of CHECK_SIGNATURE ; ASSERT in the script. - with utils.assert_run_failure("At line 14 characters 9 to 12"): - client.transfer( - 0, - "bootstrap1", - "vote_for_delegate", - ['-arg', 'None', '--burn-cap', '10'], - ) - - def test_vote_for_delegate_wrong_identity2(self, client: Client): - # We check failure of CHECK_SIGNATURE ; ASSERT in the script. - with utils.assert_run_failure("At line 14 characters 9 to 12"): - client.transfer( - 0, - "bootstrap2", - "vote_for_delegate", - ['-arg', 'None', '--burn-cap', '10'], - ) - - def test_vote_for_delegate_b3_vote_for_b5(self, client: Client): - b_5 = IDENTITIES['bootstrap5']['identity'] - client.transfer( - 0, - "bootstrap3", - "vote_for_delegate", - ['-arg', f'(Some "{b_5}")', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - storage = client.get_storage('vote_for_delegate') - assert re.search(b_5, storage) - - def test_vote_for_delegate_still_no_delegate1(self, client: Client): - assert client.get_delegate('vote_for_delegate').delegate is None - - def test_vote_for_delegate_b4_vote_for_b2(self, client: Client): - b_2 = IDENTITIES['bootstrap2']['identity'] - client.transfer( - 0, - "bootstrap4", - "vote_for_delegate", - ['-arg', f'(Some "{b_2}")', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - storage = client.get_storage('vote_for_delegate') - assert re.search(b_2, storage) - - def test_vote_for_delegate_still_no_delegate2(self, client: Client): - assert client.get_delegate('vote_for_delegate').delegate is None - - def test_vote_for_delegate_b4_vote_for_b5(self, client: Client): - b_5 = IDENTITIES['bootstrap5']['identity'] - client.transfer( - 0, - "bootstrap4", - "vote_for_delegate", - ['-arg', f'(Some "{b_5}")', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - storage = client.get_storage('vote_for_delegate') - assert re.search(b_5, storage) - - def test_vote_for_delegate_has_delegate(self, client: Client): - b_5 = IDENTITIES['bootstrap5']['identity'] - result = client.get_delegate('vote_for_delegate') - assert result.delegate == b_5 - - def test_multiple_entrypoints_counter(self, session: dict, client: Client): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'multiple_entrypoints_counter.tz' - ) - - storage = 'None' - - # originate contract - originate(client, session, path, storage, 0) - utils.bake(client, bake_for='bootstrap5') - - # call contract: creates the internal contract and calls it. - client.transfer( - 0, - 'bootstrap1', - 'multiple_entrypoints_counter', - ['--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - assert client.get_storage('multiple_entrypoints_counter') == 'None', ( - "The storage of the multiple_entrypoints_counter contract" - " should be None" - ) - # Test CONTRACT with/without entrypoint annotation on literal address # parameters with/without entrypoint annotation def test_originate_simple_entrypoints(self, session: dict, client: Client): diff --git a/tests_python/tests_alpha/test_contract.py b/tests_python/tests_alpha/test_contract.py index c9790e30e47e2c237595c2257d5733fec8208da9..6c2664cbe32b4e0516b266726cbf74e5b11f8a7e 100644 --- a/tests_python/tests_alpha/test_contract.py +++ b/tests_python/tests_alpha/test_contract.py @@ -1108,41 +1108,6 @@ class TestNonRegression: class TestMiniScenarios: """Test mini scenarios""" - # replay.tz related tests - def test_replay_originate(self, client: Client, session: dict): - path = os.path.join(CONTRACT_PATH, 'mini_scenarios', 'replay.tz') - originate(client, session, path, 'Unit', 0) - - def test_replay_transfer_fail(self, client: Client): - with utils.assert_run_failure("Internal operation replay attempt"): - client.transfer(10, "bootstrap1", "replay", []) - - # create_contract.tz related tests - def test_create_contract_originate(self, client: Client, session: dict): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'create_contract.tz' - ) - originate(client, session, path, 'Unit', 1000) - - def test_create_contract_balance(self, client: Client): - assert client.get_balance('create_contract') == 1000 - - def test_create_contract_perform_creation(self, client: Client): - transfer_result = client.transfer( - 0, - "bootstrap1", - "create_contract", - ['-arg', 'None', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - pattern = r"New contract (\w*) originated" - match = re.search(pattern, transfer_result.client_output) - assert match is not None - kt_1 = match.groups()[0] - assert client.get_storage(kt_1) == '"abcdefg"' - assert client.get_balance(kt_1) == 100 - assert client.get_balance('create_contract') == 900 - # Originates a contract that when called, creates a contract with a # rootname annotation. Such annotations comes in two flavors, thus the # parameterization. Then calls the first contract and verifies the @@ -1182,207 +1147,6 @@ class TestMiniScenarios: 'with type unit' ) - # default_account.tz related tests - def test_default_account_originate(self, client: Client, session: dict): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'default_account.tz' - ) - originate(client, session, path, 'Unit', 1000) - - def test_default_account_transfer_then_bake(self, client: Client): - tz1 = IDENTITIES['bootstrap4']['identity'] - client.transfer( - 0, - "bootstrap1", - "default_account", - ['-arg', f'"{tz1}"', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - account = 'tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5' - client.transfer( - 0, - "bootstrap1", - "default_account", - ['-arg', f'"{account}"', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - assert client.get_balance(account) == 100 - - # Test bytes, SHA252, CHECK_SIGNATURE - def test_reveal_signed_preimage_originate( - self, client: Client, session: dict - ): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'reveal_signed_preimage.tz' - ) - byt = ( - '0x9995c2ef7bcc7ae3bd15bdd9b02' - + 'dc6e877c27b26732340d641a4cbc6524813bb' - ) - sign = 'p2pk66uq221795tFxT7jfNmXtBMdjMf6RAaxRTwv1dbuSHbH6yfqGwz' - storage = f'(Pair {byt} "{sign}")' - originate(client, session, path, storage, 1000) - - def test_wrong_preimage(self, client: Client): - byt = ( - '0x050100000027566f756c657a2d766f75732' - + '0636f75636865722061766563206d6f692c20636520736f6972' - ) - sign = ( - 'p2sigvgDSBnN1bUsfwyMvqpJA1cFhE5s5oi7SetJ' - + 'VQ6LJsbFrU2idPvnvwJhf5v9DhM9ZTX1euS9DgWozVw6BTHiK9VcQVpAU8' - ) - arg = f'(Pair {byt} "{sign}")' - - # We check failure of ASSERT_CMPEQ in the script. - with utils.assert_run_failure("At line 8 characters 9 to 21"): - client.transfer( - 0, - "bootstrap1", - "reveal_signed_preimage", - ['-arg', arg, '--burn-cap', '10'], - ) - - def test_wrong_signature(self, client: Client): - byt = ( - '0x050100000027566f756c657a2d766f757320636' - + 'f75636865722061766563206d6f692c20636520736f6972203f' - ) - sign = ( - 'p2sigvgDSBnN1bUsfwyMvqpJA1cFhE5s5oi7SetJVQ6' - + 'LJsbFrU2idPvnvwJhf5v9DhM9ZTX1euS9DgWozVw6BTHiK9VcQVpAU8' - ) - arg = f'(Pair {byt} "{sign}")' - - # We check failure of CHECK_SIGNATURE ; ASSERT in the script. - with utils.assert_run_failure("At line 15 characters 9 to 15"): - client.transfer( - 0, - "bootstrap1", - "reveal_signed_preimage", - ['-arg', arg, '--burn-cap', '10'], - ) - - def test_good_preimage_and_signature(self, client: Client): - byt = ( - '0x050100000027566f756c657a2d766f757320636f7563' - + '6865722061766563206d6f692c20636520736f6972203f' - ) - sign = ( - 'p2sigsceCzcDw2AeYDzUonj4JT341WC9Px4wdhHBxbZcG1F' - + 'hfqFVuG7f2fGCzrEHSAZgrsrQWpxduDPk9qZRgrpzwJnSHC3gZJ' - ) - arg = f'(Pair {byt} "{sign}")' - client.transfer( - 0, - "bootstrap1", - "reveal_signed_preimage", - ['-arg', arg, '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - - # Test vote_for_delegate - def test_vote_for_delegate_originate(self, client: Client, session: dict): - b_3 = IDENTITIES['bootstrap3']['identity'] - b_4 = IDENTITIES['bootstrap4']['identity'] - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'vote_for_delegate.tz' - ) - storage = f'''(Pair (Pair "{b_3}" None) (Pair "{b_4}" None))''' - originate(client, session, path, storage, 1000) - assert client.get_delegate('vote_for_delegate').delegate is None - - def test_vote_for_delegate_wrong_identity1(self, client: Client): - # We check failure of CHECK_SIGNATURE ; ASSERT in the script. - with utils.assert_run_failure("At line 14 characters 9 to 12"): - client.transfer( - 0, - "bootstrap1", - "vote_for_delegate", - ['-arg', 'None', '--burn-cap', '10'], - ) - - def test_vote_for_delegate_wrong_identity2(self, client: Client): - # We check failure of CHECK_SIGNATURE ; ASSERT in the script. - with utils.assert_run_failure("At line 14 characters 9 to 12"): - client.transfer( - 0, - "bootstrap2", - "vote_for_delegate", - ['-arg', 'None', '--burn-cap', '10'], - ) - - def test_vote_for_delegate_b3_vote_for_b5(self, client: Client): - b_5 = IDENTITIES['bootstrap5']['identity'] - client.transfer( - 0, - "bootstrap3", - "vote_for_delegate", - ['-arg', f'(Some "{b_5}")', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - storage = client.get_storage('vote_for_delegate') - assert re.search(b_5, storage) - - def test_vote_for_delegate_still_no_delegate1(self, client: Client): - assert client.get_delegate('vote_for_delegate').delegate is None - - def test_vote_for_delegate_b4_vote_for_b2(self, client: Client): - b_2 = IDENTITIES['bootstrap2']['identity'] - client.transfer( - 0, - "bootstrap4", - "vote_for_delegate", - ['-arg', f'(Some "{b_2}")', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - storage = client.get_storage('vote_for_delegate') - assert re.search(b_2, storage) - - def test_vote_for_delegate_still_no_delegate2(self, client: Client): - assert client.get_delegate('vote_for_delegate').delegate is None - - def test_vote_for_delegate_b4_vote_for_b5(self, client: Client): - b_5 = IDENTITIES['bootstrap5']['identity'] - client.transfer( - 0, - "bootstrap4", - "vote_for_delegate", - ['-arg', f'(Some "{b_5}")', '--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - storage = client.get_storage('vote_for_delegate') - assert re.search(b_5, storage) - - def test_vote_for_delegate_has_delegate(self, client: Client): - b_5 = IDENTITIES['bootstrap5']['identity'] - result = client.get_delegate('vote_for_delegate') - assert result.delegate == b_5 - - def test_multiple_entrypoints_counter(self, session: dict, client: Client): - path = os.path.join( - CONTRACT_PATH, 'mini_scenarios', 'multiple_entrypoints_counter.tz' - ) - - storage = 'None' - - # originate contract - originate(client, session, path, storage, 0) - utils.bake(client, bake_for='bootstrap5') - - # call contract: creates the internal contract and calls it. - client.transfer( - 0, - 'bootstrap1', - 'multiple_entrypoints_counter', - ['--burn-cap', '10'], - ) - utils.bake(client, bake_for='bootstrap5') - assert client.get_storage('multiple_entrypoints_counter') == 'None', ( - "The storage of the multiple_entrypoints_counter contract" - " should be None" - ) - # Test CONTRACT with/without entrypoint annotation on literal address # parameters with/without entrypoint annotation def test_originate_simple_entrypoints(self, session: dict, client: Client): diff --git a/tezt/tests/contract_mini_scenarios.ml b/tezt/tests/contract_mini_scenarios.ml new file mode 100644 index 0000000000000000000000000000000000000000..22a8c6b94c595ff43848a331340617394fca89b1 --- /dev/null +++ b/tezt/tests/contract_mini_scenarios.ml @@ -0,0 +1,461 @@ +(*****************************************************************************) +(* *) +(* Open Source License *) +(* Copyright (c) 2021 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 + ------- + Component: Michelson + Invocation: dune exec tezt/tests/main.exe -- --file contract_mini_scenarios.ml + Subject: Test mini scenarios +*) + +let contract_path protocol kind contract = + sf + "tests_python/contracts_%s/%s/%s" + (match protocol with + | Protocol.Alpha -> "alpha" + | _ -> sf "%03d" @@ Protocol.number protocol) + kind + contract + +let test_replay client ~protocol = + Log.info "Replay 'originate'" ; + let* contract = + let prg = contract_path protocol "mini_scenarios" "replay.tz" in + Client.originate_contract + ~alias:"replay" + ~amount:Tez.zero + ~src:Constant.bootstrap1.alias + ~prg + ~init:"Unit" + ~burn_cap:Tez.one + client + in + Log.info "Replay transfer fail" ; + let* () = + Client.spawn_transfer + ~amount:(Tez.of_int 10) + ~giver:"bootstrap1" + ~receiver:contract + ~arg:"Unit" + client + |> Process.check_error ~msg:(rex "Internal operation replay attempt") + in + unit + +let check_balance ~__LOC__ ~account client ~amount = + let* contract_balance = Client.get_balance_for ~account client in + Check.(contract_balance = Tez.of_int amount) + Tez.typ + ~__LOC__ + ~error_msg:"Expected balance %R, got %L" ; + unit + +let test_create_contract_balance client ~contract = + check_balance ~__LOC__ ~account:contract ~amount:1000 client + +let check_contract_storage ~__LOC__ client contract ~expected = + let* storage = Client.contract_storage contract client in + Check.( + (String.trim storage = expected) + string + ~__LOC__ + ~error_msg:"Expected storage %R, got %L") ; + unit + +let extract_new_contract client_output = + match client_output =~* rex "New contract ?(KT1\\w{33})" with + | None -> + Test.fail + "Cannot extract new contract from client_output: %s" + client_output + | Some c -> return c + +let test_create_contract client ~protocol = + Log.info "Create contract 'originate'" ; + let* create_contract = + let prg = contract_path protocol "mini_scenarios" "create_contract.tz" in + Client.originate_contract + ~alias:"create_contract" + ~amount:(Tez.of_int 1000) + ~src:Constant.bootstrap1.alias + ~prg + ~init:"Unit" + ~burn_cap:Tez.one + client + in + let* () = test_create_contract_balance client ~contract:create_contract in + Log.info "Test create contract perform creation" ; + let* () = + let process = + Client.spawn_transfer + ~burn_cap:(Tez.of_int 10) + ~amount:Tez.zero + ~giver:"bootstrap1" + ~receiver:create_contract + ~arg:"None" + client + in + let* client_output = Process.check_and_read_stdout process in + let* kt_1 = extract_new_contract client_output in + let* () = + check_contract_storage ~__LOC__ client kt_1 ~expected:"\"abcdefg\"" + in + let* () = check_balance ~__LOC__ ~account:kt_1 client ~amount:100 in + let* () = + check_balance ~__LOC__ ~account:create_contract client ~amount:900 + in + unit + in + unit + +let test_default_account client ~protocol = + Log.info "Default account 'originate'" ; + let* default_account = + let prg = contract_path protocol "mini_scenarios" "default_account.tz" in + Client.originate_contract + ~alias:"default_contract" + ~amount:(Tez.of_int 1000) + ~src:"bootstrap1" + ~prg + ~init:"Unit" + ~burn_cap:Tez.one + client + in + Log.info "Test default account transfer" ; + let* () = + let tz1 = Constant.bootstrap4.Account.public_key_hash in + let arg = sf "\"%s\"" tz1 in + let* () = + Client.transfer + ~burn_cap:(Tez.of_int 10) + ~amount:Tez.zero + ~giver:"bootstrap1" + ~receiver:default_account + ~arg + client + in + let account = "tz1SuakBpFdG9b4twyfrSMqZzruxhpMeSrE5" in + let arg = sf "\"%s\"" account in + let* () = + Client.transfer + ~burn_cap:(Tez.of_int 10) + ~amount:Tez.zero + ~giver:"bootstrap1" + ~receiver:default_account + ~arg + client + in + unit + in + unit + +let test_preimage_and_signature client ~protocol = + Log.info "Reveal signed preimage 'originate'" ; + let* reveal_signed_preimage = + let prg = + contract_path protocol "mini_scenarios" "reveal_signed_preimage.tz" + in + let byt = + "0x9995c2ef7bcc7ae3bd15bdd9b02dc6e877c27b26732340d641a4cbc6524813bb" + in + let sign = "p2pk66uq221795tFxT7jfNmXtBMdjMf6RAaxRTwv1dbuSHbH6yfqGwz" in + let init = sf "Pair %s \"%s\"" byt sign in + Client.originate_contract + ~alias:"default_contract" + ~amount:(Tez.of_int 1000) + ~src:"bootstrap1" + ~prg + ~init + ~burn_cap:Tez.one + client + in + Log.info "Test wrong preimage" ; + let* () = + let byte = + "0x050100000027566f756c657a2d766f757320636f75636865722061766563206d6f692c20636520736f6972" + in + let sign = + "p2sigvgDSBnN1bUsfwyMvqpJA1cFhE5s5oi7SetJVQ6LJsbFrU2idPvnvwJhf5v9DhM9ZTX1euS9DgWozVw6BTHiK9VcQVpAU8" + in + let arg = sf "Pair %s \"%s\"" byte sign in + Client.spawn_transfer + ~amount:Tez.zero + ~giver:"bootstrap1" + ~receiver:reveal_signed_preimage + ~arg + ~burn_cap:(Tez.of_int 10) + client + |> Process.check_error ~msg:(rex "At line 8 characters 9 to 21") + in + Log.info "Test wrong signature" ; + let* () = + let byte = + "0x050100000027566f756c657a2d766f757320636f75636865722061766563206d6f692c20636520736f6972203f" + in + let sign = + "p2sigvgDSBnN1bUsfwyMvqpJA1cFhE5s5oi7SetJVQ6LJsbFrU2idPvnvwJhf5v9DhM9ZTX1euS9DgWozVw6BTHiK9VcQVpAU8" + in + let arg = sf "Pair %s \"%s\"" byte sign in + Client.spawn_transfer + ~amount:Tez.zero + ~giver:"bootstrap1" + ~receiver:reveal_signed_preimage + ~arg + ~burn_cap:(Tez.of_int 10) + client + |> Process.check_error ~msg:(rex "At line 15 characters 9 to 15") + in + Log.info "Test good preimage and signature" ; + let* () = + let byte = + "0x050100000027566f756c657a2d766f757320636f75636865722061766563206d6f692c20636520736f6972203f" + in + let sign = + "p2sigsceCzcDw2AeYDzUonj4JT341WC9Px4wdhHBxbZcG1FhfqFVuG7f2fGCzrEHSAZgrsrQWpxduDPk9qZRgrpzwJnSHC3gZJ" + in + let arg = sf "Pair %s \"%s\"" byte sign in + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"bootstrap1" + ~receiver:reveal_signed_preimage + ~arg + ~burn_cap:(Tez.of_int 10) + client + in + unit + in + unit + +(* Test vote_for_delegate *) +let test_vote_for_delegate client ~protocol = + Log.info "vote for delegate 'originate" ; + let* vote_for_delegate = + let prg = contract_path protocol "mini_scenarios" "vote_for_delegate.tz" in + let b_3 = Constant.bootstrap3.Account.public_key_hash in + let b_4 = Constant.bootstrap4.Account.public_key_hash in + let init = sf {|(Pair (Pair "%s" None) (Pair "%s" None))|} b_3 b_4 in + Client.originate_contract + ~alias:"vote_for_delegate" + ~amount:(Tez.of_int 1000) + ~src:"bootstrap1" + ~prg + ~init + ~burn_cap:Tez.one + client + in + let* delegate_opt = Client.get_delegate ~src:vote_for_delegate client in + let () = + Check.((delegate_opt = None) (option string)) + ~error_msg:"expected delegate %R, got %L" + in + Log.info "Test vote for delegate wrong identity1" ; + let* () = + Client.spawn_transfer + ~amount:Tez.zero + ~giver:"bootstrap1" + ~receiver:vote_for_delegate + ~arg:"None" + ~burn_cap:(Tez.of_int 10) + client + |> Process.check_error ~msg:(rex "At line 14 characters 9 to 12") + in + Log.info "Test vote for delegate wrong identity2" ; + let* () = + Client.spawn_transfer + ~amount:Tez.zero + ~giver:"bootstrap2" + ~receiver:vote_for_delegate + ~arg:"None" + ~burn_cap:(Tez.of_int 10) + client + |> Process.check_error ~msg:(rex "At line 14 characters 9 to 12") + in + Log.info "Test vote for delegate b3 vote for b5" ; + let* () = + let b_5 = Constant.bootstrap5.Account.public_key_hash in + let arg = sf {|(Some "%s")|} b_5 in + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"bootstrap3" + ~receiver:vote_for_delegate + ~arg + ~burn_cap:(Tez.of_int 10) + client + in + let b_3 = Constant.bootstrap3.Account.public_key_hash in + let b_4 = Constant.bootstrap4.Account.public_key_hash in + let expected = + sf + "Pair (Pair \"%s\"\n (Some \"%s\"))\n \"%s\"\n None" + b_3 + b_5 + b_4 + in + let* () = + check_contract_storage ~__LOC__ client vote_for_delegate ~expected + in + unit + in + Log.info "Test vote for delegate still no delegate1" ; + let* () = + let* delegate_opt = Client.get_delegate ~src:vote_for_delegate client in + let () = + Check.((delegate_opt = None) (option string)) + ~error_msg:"expected delegate %R, got %L" + in + unit + in + Log.info "Test vote for delegate b4 vote for b2" ; + let* () = + let b_2 = Constant.bootstrap2.Account.public_key_hash in + let arg = sf {|(Some "%s")|} b_2 in + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"bootstrap4" + ~receiver:vote_for_delegate + ~arg + ~burn_cap:(Tez.of_int 10) + client + in + let b_3 = Constant.bootstrap3.Account.public_key_hash in + let b_4 = Constant.bootstrap4.Account.public_key_hash in + let b_5 = Constant.bootstrap5.Account.public_key_hash in + let expected = + sf + "Pair (Pair \"%s\"\n\ + \ (Some \"%s\"))\n\ + \ \"%s\"\n\ + \ (Some \"%s\")" + b_3 + b_5 + b_4 + b_2 + in + let* () = + check_contract_storage ~__LOC__ client vote_for_delegate ~expected + in + unit + in + Log.info "Test vote for delegate still no delegate2" ; + let* () = + let* delegate_opt = Client.get_delegate ~src:vote_for_delegate client in + let () = + Check.((delegate_opt = None) (option string)) + ~error_msg:"expected delegate %R, got %L" + in + unit + in + Log.info "Test vote for delegate b4 vote for b5" ; + let* () = + let b_5 = Constant.bootstrap5.Account.public_key_hash in + let arg = sf {|(Some "%s")|} b_5 in + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"bootstrap4" + ~receiver:vote_for_delegate + ~arg + ~burn_cap:(Tez.of_int 10) + client + in + let b_3 = Constant.bootstrap3.Account.public_key_hash in + let b_4 = Constant.bootstrap4.Account.public_key_hash in + let expected = + sf + "Pair (Pair \"%s\"\n\ + \ (Some \"%s\"))\n\ + \ \"%s\"\n\ + \ (Some \"%s\")" + b_3 + b_5 + b_4 + b_5 + in + let* () = + check_contract_storage ~__LOC__ client vote_for_delegate ~expected + in + unit + in + Log.info "Test vote for delegate has delegate" ; + let* () = + let b_5 = Constant.bootstrap5.Account.public_key_hash in + let* delegate_opt = Client.get_delegate ~src:vote_for_delegate client in + let () = + Check.((delegate_opt = Some b_5) (option string)) + ~error_msg:"expected delegate %R, got %L" + in + unit + in + unit + +let test_multiple_entrypoints_counter client ~protocol = + let prg = + contract_path protocol "mini_scenarios" "multiple_entrypoints_counter.tz" + in + let* contract = + Client.originate_contract + ~alias:"multiple_entrypoints_counter" + ~amount:Tez.zero + ~src:"bootstrap5" + ~prg + ~init:"None" + ~burn_cap:Tez.one + client + in + (* call contract: creates the internal contract and calls it. *) + let* () = + Client.transfer + ~amount:Tez.zero + ~giver:"bootstrap1" + ~receiver:contract + ~burn_cap:(Tez.of_int 10) + client + in + let* () = check_contract_storage ~__LOC__ client contract ~expected:"None" in + unit + +let register ~protocols = + List.iter + (fun (title, test_function) -> + Protocol.register_test + ~__FILE__ + ~title + ~tags:["client"; "michelson"; "mini_scenarios"] + (fun protocol -> + let* client = Client.init_mockup ~protocol () in + test_function client ~protocol) + protocols) + [ + ("test create contract balance", test_create_contract); + ("test replay", test_replay); + ("test default account originate and transfer", test_default_account); + ("test preimage and signature", test_preimage_and_signature); + ("test vote for delegate", test_vote_for_delegate); + ("test multiple entrypoints counter", test_multiple_entrypoints_counter); + ] diff --git a/tezt/tests/main.ml b/tezt/tests/main.ml index 93b401f920c58b0e0af7c5f34d807a1213064075..6ee17c22c8016e869714287821a9c7a9443127f8 100644 --- a/tezt/tests/main.ml +++ b/tezt/tests/main.ml @@ -109,6 +109,7 @@ let register_protocol_tests_that_use_supports_correctly () = Contract_hash_fun.register ~protocols ; Contract_hash_with_origination.register ~protocols ; Contract_opcodes.register ~protocols ; + Contract_mini_scenarios.register ~protocols ; Create_contract.register ~protocols ; Deposits_limit.register ~protocols ; Double_bake.register ~protocols ;