def getNetworkLatestInfo(self) -> NetworkInfo: url = Globals.getHmyNetworkUrl() block_number = 0 try: block_number = blockchain.get_block_number(url) #print(f"Block Number {block_number}") except Exception as ex: HmyBidderLog.error( f'Validator getNetworkLatestInfo get_block_number {ex}') try: response = staking.get_staking_network_info(url) #print(response) if response != None and not 'error' in response: epoch_last_block = int(response['epoch-last-block']) median_raw_stake = float(response['median-raw-stake'] ) / Globals._oneAmountDenominator blocks_to_next_epoch = (epoch_last_block - block_number) network_info = NetworkInfo(epoch_last_block, median_raw_stake, block_number, blocks_to_next_epoch) return network_info else: return None except Exception as ex: HmyBidderLog.error( f'Validator getNetworkLatestInfo get network info {ex}')
def test_get_storage_at_v2(deployed_contract): address = _get_contract_address(deployed_contract["hash"], deployed_contract["from-shard"]) block_number = blockchain.get_block_number(endpoint=endpoints[deployed_contract["from-shard"]]) raw_response = base_request("hmyv2_getStorageAt", params=[address, "0x0", block_number], endpoint=endpoints[deployed_contract["from-shard"]]) response = check_and_unpack_rpc_response(raw_response, expect_error=False) assert isinstance(response, str) and response.startswith("0x") # Must be a hex string
def test_get_code_v2(deployed_contract): address = _get_contract_address(deployed_contract["hash"], deployed_contract["from-shard"]) block_number = blockchain.get_block_number(endpoint=endpoints[deployed_contract["from-shard"]]) raw_response = base_request("hmyv2_getCode", params=[address, block_number], endpoint=endpoints[deployed_contract["from-shard"]]) response = check_and_unpack_rpc_response(raw_response, expect_error=False) assert response == deployed_contract["code"], f"Expected {deployed_contract['code']}, got {response}"
def test_call_v2(deployed_contract): """ TODO: Real smart contract call, currently, it is an error case test. """ address = _get_contract_address(deployed_contract["hash"], deployed_contract["from-shard"]) block_number = blockchain.get_block_number(endpoint=endpoints[deployed_contract["from-shard"]]) raw_response = base_request("hmyv2_call", params=[{"to": address}, block_number], endpoint=endpoints[deployed_contract["from-shard"]]) assert is_valid_json_rpc(raw_response), f"Invalid JSON response: {raw_response}" try: response = check_and_unpack_rpc_response(raw_response, expect_error=False) assert isinstance(response, str) and response.startswith("0x") # Must be a hex string except Exception as e: pytest.skip("RPC format being reworked, fix when finished")
def test_errors(): with pytest.raises(exceptions.RPCError): blockchain.chain_id(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_node_metadata(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_peer_info(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.protocol_version(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_shard(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_staking_epoch(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_prestaking_epoch(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_sharding_structure(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_leader_address(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.is_last_block(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.epoch_last_block(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_circulating_supply(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_total_supply(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_number(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_current_epoch(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_last_cross_links(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_gas_price(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_num_peers(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_version(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_latest_header(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_header_by_number(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_latest_chain_headers(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_by_number(0, endpoint=fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_by_hash('', endpoint=fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_transaction_count_by_number(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_transaction_count_by_hash('', fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_staking_transaction_count_by_number(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_staking_transaction_count_by_hash('', fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_blocks(0, 1, endpoint=fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_signers(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_block_signers_keys(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.is_block_signer(0, '', fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_signed_blocks('', fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_validators(1, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.get_validator_keys(0, fake_shard) with pytest.raises(exceptions.RPCError): blockchain.in_sync(fake_shard) with pytest.raises(exceptions.RPCError): blockchain.beacon_in_sync(fake_shard)
local_test_address = 'one1zksj3evekayy90xt4psrz8h6j2v3hla4qwz4ur' test_validator_address = 'one18tvf56zqjkjnak686lwutcp5mqfnvee35xjnhc' genesis_block_number = 0 test_block_number = 1 #get local test key from keystore keys = [ item.split(".")[0] for item in os.listdir( "/root/go/src/github.com/harmony-one/harmony/.hmy/keystore") ] for key in keys: balance = account.get_balance(key) print("There are %d one in %s" % (balance, key)) #current block number cur_block_num = blockchain.get_block_number() #get balance at certain block account.get_balance_by_block(keys[-1], cur_block_num) #get balance on all shards account.get_balance_on_all_shards(keys[-1]) #restore keys[-1] from keystore by cli cli.single_call( "hmy keys import-ks /root/go/src/github.com/harmony-one/harmony/.hmy/keystore/%s.key" % key) balance_before = account.get_balance(keys[-1]) #send 2 one from keys[-1] to local_test_address cli.single_call(