def test_shield_with_different_memo_size(self, contract_path, client): contract_name = "sapling_memo_size_different" implicit_account = "bootstrap1" contract_address = client.originate( contract_name=contract_name, amount=0, sender=implicit_account, contract=contract_path, args=["--init", "{ }", "--burn-cap", "3.0"], ).contract utils.bake(client, bake_for=implicit_account) client.sapling_gen_key(key_name='alice') client.sapling_use_key_for_contract('alice', contract_name, memo_size=16) address = client.sapling_gen_address(key_name='alice').address # Key was registered with a memo_size of 16, it should fail with assert_run_failure(r"Memo sizes of two sapling states"): client.sapling_shield( amount=TX_AMOUNT, src=implicit_account, dest=address, contract=contract_address, args=["--burn-cap", "3.0"], )
def test_bake_to_catch_up(self, sandbox, session, legacy_stores): # pylint: disable=unused-argument for _ in range(BATCH): utils.bake(sandbox.client(1)) session['head_level'] = sandbox.client(1).get_head()['header']['level'] for i in GROUP: assert utils.check_level(sandbox.client(i), session['head_level'])
def test_all_nodes_run_proto_b(self, sandbox: Sandbox): # we let a PROTO_A baker bake the last blocks of PROTO_A # sandbox.add_baker( # 0, [f"bootstrap{i}" for i in range(1, 6)], proto=PROTO_A_DAEMON # ) # for i in range(1,NUM_NODES): # sandbox.add_baker( # i, [f"bootstrap{i}"], proto=PROTO_B_DAEMON # ) clients = sandbox.all_clients() client = clients[0] utils.bake(client, bake_for="bootstrap2") all_have_proto_b = False while not all_have_proto_b: try: utils.bake(client, bake_for="bootstrap2") except subprocess.CalledProcessError: # A fatal error is raised when we do not have enough endorsing # power. # This is typical of a simple bake for call in Tenderbake # Therefore this means we actually have migrated to Tenderbake # Let's use a baking call that is sure to pass tenderbake(client) # either succeeds out of the loop or fails due to the timeout header client_protocols = [client.get_protocol() for c in clients] all_have_proto_b = all(p == PROTO_B for p in client_protocols) time.sleep(POLLING_TIME)
def test_change_keys_and_threshold(self, msig, client: Client): """Test changing the keys and threshold with `set threshold of multisig` command.""" current_storage = client.get_storage(msig['handle']) current_counter = parse_msig_storage( storage=current_storage)['counter'] current_balance = client.get_balance(msig['handle']) keys = msig['keys'] new_keys = [keys[0], keys[2]] sig0 = client.msig_sign_setting_threshold(msig['handle'], keys[0], 2, new_keys) to_sign = client.msig_prepare_setting_threshold( msig['handle'], 2, new_keys, ['--bytes-only']) sig2 = client.sign_bytes_of_string(to_sign, msig['keys'][2]) client.msig_set_threshold(msig['handle'], 2, new_keys, 'bootstrap1', [sig0, sig2]) utils.bake(client) new_storage = client.get_storage(msig['handle']) expected_counter = 1 + current_counter expected_storage = build_msig_storage( client=client, counter=expected_counter, threshold=2, keys=[keys[0], keys[2]], ) assert_msig_storage_eq(client, new_storage, expected_storage) new_balance = client.get_balance(msig['handle']) assert new_balance == current_balance
def test_deploy_multisig(self, msig, client: Client): """Test that: - the script originated by the "deploy multisig" command, - the generic_multisig.tz script found in the mini_scenarios directory, and - the script printed by the "show multisig script" are the same.""" keys = msig['keys'] # The command cannot originate the legacy contract so there is # nothing to test in the legacy case. if msig['version'] == 'generic': client.deploy_msig( 'dummy_msig', 100, 'bootstrap1', 2, keys, ['--burn-cap', '100', '--force'], ) utils.bake(client) expected_hash = ( 'exprub9UzpxmhedNQnsv1J1DazWGJnj1dLhtG1fxkUoWSdFLBGLqJ4\n') assert expected_hash in client.run( ['show', 'supported', 'multisig', 'hashes']) assert client.get_script_hash(msig['handle']) == expected_hash assert client.get_script_hash('dummy_msig') == expected_hash assert (client.hash_script( client.run(['show', 'multisig', 'script'])) == expected_hash) assert client.get_balance('dummy_msig') == 100
def test_import_rolling_snapshot_node2(self, sandbox, session): sandbox.add_node(2, snapshot=session['snapshot_rolling'], node_config=NODE_CONFIG) client = sandbox.client(2) utils.synchronize([sandbox.client(1), client], max_diff=0) utils.bake(client, BAKER)
def test_originate_contract_noop(self, client: Client): contract = path.join(CONTRACT_PATH, 'opcodes', 'noop.tz') client.remember('noop', contract) client.typecheck(contract) client.originate('noop', 1000, 'bootstrap1', contract, ['--burn-cap', '0.295']) utils.bake(client)
def test_call(self, client: Client, session: dict): contract = session['contract'] bootstrap3 = '"tz1faswCTDciRzE4oJ9jn2Vm2dvjeyA9fUzU"' transfer = client.call('bootstrap2', contract, ['--arg', bootstrap3]) utils.bake(client, 'bootstrap5') assert utils.check_block_contains_operations(client, [transfer.operation_hash])
def test_operation_size_originate_munch_contract(self, client: Client): contract = path.join(CONTRACT_PATH, 'opcodes', 'munch.tz') client.remember('munch', contract) client.typecheck(contract) client.originate('munch', 1000, 'bootstrap1', contract, ['--burn-cap', '0.295']) utils.bake(client)
def sandbox(request, sandbox: Sandbox, contract_name, session: dict): """Adds two nodes to sandbox. Using the first node, originates the identity contract `id.tz` with the name contract_name and makes it address available under session['originated_accounts']. """ sandbox.add_node(1, params=constants.NODE_PARAMS, mode=request.param) sandbox.add_node(2, params=constants.NODE_PARAMS, mode=request.param) client = sandbox.client(1) parameters = protocol.get_parameters() parameters['consensus_threshold'] = 0 protocol.activate(sandbox.client(1), activate_in_the_past=True, parameters=parameters) utils.bake(client) time.sleep(2) # Deploy a contract contract = os.path.join(contract_paths.CONTRACT_PATH, 'attic', 'id.tz') args = ['--init', "\"tezos\"", '--burn-cap', '10.0'] origination = client.originate(contract_name, 10.0, "bootstrap1", contract, args) session['originated_accounts'] = [origination.contract] utils.bake(client) assert utils.check_block_contains_operations(client, [origination.operation_hash]) return sandbox
def test_shielded_transfer_using_non_sapling_transfer_method( self, client, contract_name, session, transparent_signer, baker, tmpdir): transaction_filename = f'{tmpdir}/sapling_transaction_2.bin' client.sapling_forge_transaction( amount=10.0, src='bob', dest=session['bob_address_1'], contract=contract_name, file=transaction_filename, args=[], ) with open(transaction_filename, "r") as file_descriptor: content = re.sub(r'\s+', ' ', file_descriptor.read()) client.transfer( 0, giver=transparent_signer, receiver=contract_name, args=[ "--arg", '{Pair %s None }' % content, "--burn-cap", "3.0", ], ) utils.bake(client, bake_for=baker)
def test_ticket_split(self, client): def ticket(target_addr, param, utxo_amount): param = ('(Pair (Pair "' + target_addr + '" ' + str(param) + ') ' + str(utxo_amount) + ')') client.transfer( 100, 'bootstrap1', 'ticketer', ['-arg', param, '--burn-cap', '10'], ) init_with_transfer( client, path.join(OPCODES_CONTRACT_PATH, 'ticketer-2.tz'), 'Unit', 100, 'bootstrap1', 'ticketer', ) init_with_transfer( client, path.join(OPCODES_CONTRACT_PATH, 'ticket_split.tz'), 'Unit', 100, 'bootstrap1', 'splitter', ) bake(client) splitter_addr = client.get_contract_address('splitter') ticket(splitter_addr, 42, 3) with assert_run_failure(r'script reached FAILWITH instruction'): # Wrong Split Amount ticket(splitter_addr, 42, 4) bake(client)
def test_split_bytes(self, client_regtest_scrubbed: ClientRegression): client = client_regtest_scrubbed init_with_transfer( client, path.join(OPCODES_CONTRACT_PATH, 'split_bytes.tz'), '{}', 1000, 'bootstrap1', ) client.transfer( 0, 'bootstrap1', 'split_bytes', ['-arg', '0xaabbcc', '--burn-cap', '10'], ) bake(client) assert_storage_contains(client, 'split_bytes', '{ 0xaa ; 0xbb ; 0xcc }') client.transfer( 0, 'bootstrap1', 'split_bytes', ['-arg', '0xddeeff', '--burn-cap', '10'], ) bake(client) assert_storage_contains(client, 'split_bytes', '{ 0xaa ; 0xbb ; 0xcc ; 0xdd ; 0xee ; 0xff }')
def test_ticket_user_forge(self, client): bake(client) init_with_transfer( client, path.join(OPCODES_CONTRACT_PATH, 'ticket_store-2.tz'), 'None', 100, 'bootstrap1', 'storer', ) # Create parameter by hand with a ticket type but no ticket in it client.transfer(100, 'bootstrap1', 'storer', ['-arg', 'None', '--burn-cap', '10']) with assert_run_failure(r'Unexpected forged value'): # Create parameter by hand with a ticket in it client.transfer( 100, 'bootstrap1', 'storer', ['-arg', 'Some 1', '--burn-cap', '10'], ) with assert_run_failure(r'Unexpected forged value'): # Create storage by hand with a ticket in it init_with_transfer( client, path.join(OPCODES_CONTRACT_PATH, 'ticket_bad.tz'), '1', 100, 'bootstrap1', 'ticket_bad', )
def test_sender(self, client_regtest_scrubbed: ClientRegression): client = client_regtest_scrubbed client.set_regtest(None) init_store = IDENTITIES['bootstrap4']['identity'] init_with_transfer( client, path.join(OPCODES_CONTRACT_PATH, 'sender.tz'), f'"{init_store}"', 1000, 'bootstrap1', ) # direct transfer to the contract client.transfer(0, 'bootstrap2', 'sender', ['--burn-cap', '10']) bake(client) sender_addr = IDENTITIES['bootstrap2']['identity'] assert_storage_contains(client, 'sender', f'"{sender_addr}"') # indirect transfer to the contract through proxy contract_addr = client.get_contract_address('sender') proxy_addr = client.get_contract_address('proxy') client.transfer( 0, 'bootstrap2', 'proxy', ['--burn-cap', '10', '--arg', f'"{contract_addr}"'], ) bake(client) assert_storage_contains(client, 'sender', f'"{proxy_addr}"')
def test_split_string(self, client_regtest_scrubbed: ClientRegression): client = client_regtest_scrubbed init_with_transfer( client, path.join(OPCODES_CONTRACT_PATH, 'split_string.tz'), '{}', 1000, 'bootstrap1', ) client.transfer( 0, 'bootstrap1', 'split_string', ['-arg', '"abc"', '--burn-cap', '10'], ) bake(client) assert_storage_contains(client, 'split_string', '{ "a" ; "b" ; "c" }') client.transfer( 0, 'bootstrap1', 'split_string', ['-arg', '"def"', '--burn-cap', '10'], ) bake(client) assert_storage_contains(client, 'split_string', '{ "a" ; "b" ; "c" ; "d" ; "e" ; "f" }')
def test_bake_last_block_of_proposal_period(self, client: Client): utils.bake(client) period_info = client.get_current_period() metadata = client.get_metadata() meta_level = metadata["level"] level_info = metadata["level_info"] meta_period_info = metadata["voting_period_info"] expected_commitment = meta_level["expected_commitment"] deprecated_period_kind = metadata["voting_period_kind"] period_index = metadata["level"]["voting_period"] period_position = metadata["level"]["voting_period_position"] level = client.get_current_level() # check if metadata has the same value as the level and voting period, # see inline comment in alpha apply.ml. This is tested here because the # level of metadata and current level use the compatibility encoding # that contains the voting period information assert meta_level == level assert level["level"] == level_info["level"] assert level["level_position"] == level_info["level_position"] assert level["cycle"] == level_info["cycle"] assert level["cycle_position"] == level_info["cycle_position"] assert expected_commitment == level_info["expected_commitment"] assert period_index == period_info["voting_period"]["index"] assert deprecated_period_kind == "exploration" assert period_position == period_info["position"] assert level["level_position"] == 7 assert period_info["voting_period"]["index"] == 1 assert period_info["voting_period"]["kind"] == "proposal" assert period_info["voting_period"]["start_position"] == 4 assert period_info["position"] == 3 assert period_info["remaining"] == 0 assert meta_period_info == period_info
def test_level(self, client_regtest_scrubbed): client = client_regtest_scrubbed init_with_transfer( client, path.join(OPCODES_CONTRACT_PATH, 'level.tz'), '9999999', 100, 'bootstrap1', ) bake(client) client.transfer(500, "bootstrap1", 'level', ['-arg', 'Unit', '--burn-cap', '10']) bake(client) level = client.get_level() slevel = str(level) assert_storage_contains(client, 'level', slevel) bake(client) bake(client) # checks the storage hasn't changed even though the current level has assert_storage_contains(client, 'level', slevel) # Run again to check the storage gets updated client.transfer(500, "bootstrap1", 'level', ['-arg', 'Unit', '--burn-cap', '10']) bake(client) assert_storage_contains(client, 'level', str(level + 3))
def test_bake_batch_1(self, sandbox, session): for _ in range(BATCH_1): utils.bake(sandbox.client(0)) sandbox.client(0).endorse('bootstrap2') session['head_hash'] = sandbox.client(0).get_head()['hash'] session['head_level'] = sandbox.client(0).get_head()['header']['level'] session['snapshot_level'] = session['head_level']
def test_bake_first_block_of_new_proposal_period(self, client: Client): utils.bake(client) # Because of the current hack in proposal here we make sure we get the # correct value level = client.get_current_level() period_info = client.get_current_period() metadata = client.get_metadata() level_info = metadata["level_info"] meta_period_info = metadata["voting_period_info"] expected_commitment = level["expected_commitment"] assert level["level"] == level_info["level"] assert level["level_position"] == level_info["level_position"] assert level["cycle"] == level_info["cycle"] assert level["cycle_position"] == level_info["cycle_position"] assert expected_commitment == level_info["expected_commitment"] assert level["level_position"] == 11 assert period_info["voting_period"]["index"] == 2 assert period_info["voting_period"]["kind"] == "exploration" assert period_info["voting_period"]["start_position"] == 8 assert period_info["position"] == 3 assert period_info["remaining"] == 0 assert meta_period_info == period_info utils.bake(client) period_info = client.get_current_period() level = client.get_current_level() assert level["level_position"] == 12 assert period_info["voting_period"]["index"] == 3 assert period_info["voting_period"]["kind"] == "proposal" assert period_info["voting_period"]["start_position"] == 12 assert period_info["position"] == 0 assert period_info["remaining"] == 3 assert client.get_listings() != '[]' # strange behavior here, RPC returns 'null' on stderr assert client.get_current_proposal() is None assert client.get_ballot_list() == []
def test_multiple_transfers(self, client: Client, payer: str, source: str): """Test a multiple transfers to implicit accounts, with implicit accounts or a manager contract as source as per parametrization. """ balance_source = client.get_mutez_balance(source) balance_bootstrap1 = client.get_mutez_balance('bootstrap1') balance_bootstrap3 = client.get_mutez_balance('bootstrap3') amount_1 = 10.1 amount_mutez_1 = utils.mutez_of_tez(amount_1) amount_3 = 11.01 amount_mutez_3 = utils.mutez_of_tez(amount_3) json_obj = [ {"destination": "bootstrap1", "amount": str(amount_1)}, {"destination": "bootstrap3", "amount": str(amount_3)}, ] json_ops = json.dumps(json_obj, separators=(',', ':')) client.run(client.cmd_batch(source, json_ops)) utils.bake(client, 'bootstrap5') new_balance_source = client.get_mutez_balance(source) new_balance_bootstrap1 = client.get_mutez_balance('bootstrap1') new_balance_bootstrap3 = client.get_mutez_balance('bootstrap3') if payer == source: fee_first_transfer = 403 fee_second_transfer = 307 source_fee_mutez = fee_first_transfer + fee_second_transfer else: source_fee_mutez = 0 assert ( balance_source - amount_mutez_1 - amount_mutez_3 - source_fee_mutez == new_balance_source ) assert balance_bootstrap1 + amount_mutez_1 == new_balance_bootstrap1 assert balance_bootstrap3 + amount_mutez_3 == new_balance_bootstrap3
def test_transfer_json_to_entrypoint_with_args( self, big_map_entrypoints: str, client: Client, payer: str, source: str ): """Test the multiple transfers command with a single transfer to a contract's entrypoint, with implicit accounts or a manager contract as source as per parametrization. """ balance_source = client.get_mutez_balance(source) balance_payer = client.get_mutez_balance(payer) fee = 0.0123 fee_mutez = utils.mutez_of_tez(fee) json_obj = [ { "destination": big_map_entrypoints, "amount": "0", "fee": str(fee), "gas-limit": "65942", "storage-limit": "1024", "arg": '"Hello"', "entrypoint": "mem_right", } ] json_ops = json.dumps(json_obj, separators=(',', ':')) client.run(client.cmd_batch(source, json_ops)) utils.bake(client, 'bootstrap5') new_balance_source = client.get_mutez_balance(source) new_balance_payer = client.get_mutez_balance(payer) if payer != source: assert balance_source == new_balance_source assert balance_payer - fee_mutez == new_balance_payer
def test_bake_batch_2(self, sandbox, session): for _ in range(BATCH_2): utils.bake(sandbox.client(0)) sandbox.client(0).endorse('bootstrap2') session['head_hash'] = sandbox.client(0).get_head()['hash'] session['head_level'] = sandbox.client(0).get_head()['header']['level'] for i in GROUP2: assert utils.check_level(sandbox.client(i), session['head_level'])
def test_endorse_node_0(self, sandbox: Sandbox, session: dict): """bootstrap1 builds an endorsement for block A""" client = sandbox.client(0) client.run(["endorse", "for", 'bootstrap3', '--force']) mempool = client.get_mempool() endorsement = mempool['applied'][0] session['endorsement1'] = endorsement utils.bake(client, bake_for='bootstrap2')
def test_transfer_bar_foo(self, client: Client, session): client.transfer( 1000, session['keys'][1], session['keys'][0], ['--fee', '0', '--force-low-fee'], ) utils.bake(client)
def test_delegate_simulation(self, client: Client): """ Tests that --simulation does not ask for the key password. """ client.gen_key("delegate") client.transfer(100, "bootstrap1", "delegate", ["--burn-cap", "1.0"]) bake(client, bake_for="bootstrap1") client.register_delegate("delegate") bake(client, bake_for="bootstrap1") client.set_delegate("encrypted_account", "delegate", ["--simulation"])
def test_bake_one_block(self, client: Client): utils.bake(client) period_info = client.get_current_period() assert period_info["voting_period"]["index"] == 1 assert period_info["voting_period"]["kind"] == "proposal" assert period_info["voting_period"]["start_position"] == 4 assert period_info["position"] == 1 assert period_info["remaining"] == 2
def test_bake_node0_level_b(self, sandbox: Sandbox, session: dict): for _ in range(BATCH_2 - BATCH_1): utils.bake(sandbox.client(0)) session['head_hash'] = sandbox.client(0).get_head()['hash'] session['head_level'] = sandbox.client(0).get_head()['header']['level'] assert utils.check_level(sandbox.client(0), session['head_level']) assert utils.check_level(sandbox.client(1), session['head_level']) assert utils.check_level(sandbox.client(2), session['head_level'])
def test_endorse_node_0(self, sandbox: Sandbox, session: dict): """bootstrap1 builds an endorsement for block A""" client = sandbox.client(0) client.endorse('bootstrap1') mempool = client.get_mempool() endorsement = mempool['applied'][0] session['endorsement1'] = endorsement utils.bake(client)
def test_last_block_of_proposal_period(self, client: Client): # last block of voting period 0 utils.bake(client) period_info = client.get_current_period() assert period_info["voting_period"]["index"] == 0 assert period_info["voting_period"]["kind"] == "proposal" assert period_info["voting_period"]["start_position"] == 0 assert period_info["position"] == 3 assert period_info["remaining"] == 0