def test_get_shard_block_by_hash(make_devnet, tmpdir): port = make_devnet(tmpdir) latest_block = CliHelpers(port).get_latest_shard_block() hash_ = latest_block['hash'] command = "get_shard_block_by_hash {}".format(hash_) out = CliHelpers(port).run_command(command) assert latest_block == json.loads(out)
def test_set_get_values( make_devnet, tmpdir, get_incrementing_number, hello_wasm_path, ): port = make_devnet(tmpdir) buster = get_incrementing_number() contract_name = "test_contract_{}".format(buster) contract, _ = CliHelpers(port).deploy_contract(contract_name, hello_wasm_path) contract_name = contract['account_id'] value = 'test' args = {'value': value} command = "schedule_function_call {} setValue --args '{}'" \ .format(contract_name, json.dumps(args)) CliHelpers(port).run_command(command) @retry(stop_max_attempt_number=5, wait_fixed=1000) def _wait_for_state_change(): command_ = "call_view_function {} getValue --args {{}}" \ .format(contract_name) out = CliHelpers(port).run_command(command_) data = json.loads(out) assert data == value _wait_for_state_change()
def test_send_money(make_devnet, tmpdir): port = make_devnet(tmpdir) receiver = 'send_money_test.near' CliHelpers(port).create_account(receiver) command = "send_money --receiver {} --amount 1".format(receiver) CliHelpers(port).run_command(command) @retry(stop_max_attempt_number=5, wait_fixed=1000) def _wait_for_balance_change(): account = CliHelpers(port).view_account(receiver) assert account['amount'] == 11 _wait_for_balance_change()
def test_view_state( make_devnet, tmpdir, get_incrementing_number, hello_wasm_path, ): port = make_devnet(tmpdir) buster = get_incrementing_number() contract_name = "test_contract_{}".format(buster) contract, _ = CliHelpers(port).deploy_contract(contract_name, hello_wasm_path) contract_name = contract['account_id'] command = "view_state {}".format(contract_name) out = CliHelpers(port).run_command(command) data = json.loads(out) assert data['values'] == {}
def test_deploy_contract( make_devnet, tmpdir, get_incrementing_number, hello_wasm_path, ): port = make_devnet(tmpdir) buster = get_incrementing_number() contract_name = "test_contract_{}".format(buster) CliHelpers(port).deploy_contract(contract_name, hello_wasm_path)
def test_import_block_pagination(make_devnet, tmpdir): port = make_devnet(tmpdir) api = _make_debugger_api(port) for i in range(0, 1): account_id = "test_account.{}".format(i) CliHelpers(port).create_account(account_id) api.import_beacon_blocks() response = api.list_beacon_blocks() assert len(response.data) == 3
def test_deploy_contract_transaction(make_devnet, tmpdir, tmp_path): port = make_devnet(tmpdir) api = _make_debugger_api(port) contract_name = 'deploy_contract_test' wasm_file = tmp_path / 'dummy.wasm' wasm_file.write_bytes(bytearray([])) wasm_path = str(wasm_file.resolve()) _, transaction_hash = CliHelpers(port).deploy_contract( contract_name, wasm_path, ) @retry(stop_max_attempt_number=5, wait_fixed=1000) def _wait_for_transaction(): api.import_beacon_blocks() transaction = api.get_transaction_info(transaction_hash) assert transaction is not None return transaction _wait_for_transaction()
def _wait_for_balance_change(): account = CliHelpers(port).view_account(receiver) assert account['amount'] == 11
def test_create_account(make_devnet, tmpdir): port = make_devnet(tmpdir) account_id = 'eve.near' CliHelpers(port).create_account(account_id)
def test_view_account(make_devnet, tmpdir): port = make_devnet(tmpdir) CliHelpers(port).view_account()
def test_view_latest_shard_block(make_devnet, tmpdir): port = make_devnet(tmpdir) CliHelpers(port).get_latest_shard_block()
def test_swap_key(make_devnet, tmpdir): port = make_devnet(tmpdir) public_key = NearLib().keystore.create_key_pair('alice.near') command = "swap_key {} {}".format(public_key, public_key) CliHelpers(port).run_command(command)
def _wait_for_state_change(): command_ = "call_view_function {} getValue --args {{}}" \ .format(contract_name) out = CliHelpers(port).run_command(command_) data = json.loads(out) assert data == value