示例#1
0
def get_test_accounts_from_args(argv):
    node_account_id = argv[1]
    pk = argv[2]
    sk = argv[3]
    rpc_nodes = argv[4].split(',')
    num_nodes = int(argv[5])
    max_tps = float(argv[6])
    logger.info(f'rpc_nodes: {rpc_nodes}')

    node_account_key = key.Key(node_account_id, pk, sk)
    test_account_keys = [
        key.Key(mocknet.load_testing_account_id(node_account_id, i), pk, sk)
        for i in range(mocknet.NUM_ACCOUNTS)
    ]

    base_block_hash = mocknet_helpers.get_latest_block_hash()

    rpc_infos = [(rpc_addr, mocknet_helpers.RPC_PORT) for rpc_addr in rpc_nodes]
    node_account = account.Account(node_account_key,
                                   mocknet_helpers.get_nonce_for_pk(
                                       node_account_key.account_id,
                                       node_account_key.pk),
                                   base_block_hash,
                                   rpc_infos=rpc_infos)
    accounts = [
        account.Account(key,
                        mocknet_helpers.get_nonce_for_pk(
                            key.account_id, key.pk),
                        base_block_hash,
                        rpc_infos=rpc_infos) for key in test_account_keys
    ]
    max_tps_per_node = max_tps / num_nodes
    return node_account, accounts, max_tps_per_node
示例#2
0
def send_random_transactions(node_account, test_accounts, max_tps_per_node):
    logger.info("===========================================")
    logger.info("New iteration of 'send_random_transactions'")
    base_block_hash = mocknet_helpers.get_latest_block_hash()
    pmap(
        lambda index_and_account: random_transaction(index_and_account[1],
                                                     index_and_account[0],
                                                     node_account,
                                                     max_tps_per_node,
                                                     base_block_hash=
                                                     base_block_hash),
        enumerate(test_accounts))
示例#3
0
def get_test_accounts_from_args(argv):
    assert len(argv) == 7
    node_account_id = argv[1]
    pk = argv[2]
    sk = argv[3]
    assert argv[4]
    rpc_nodes = argv[4].split(',')
    logger.info(f'rpc_nodes: {rpc_nodes}')
    max_tps = float(argv[5])
    need_deploy = (argv[6] == 'deploy')

    logger.info(f'need_deploy: {need_deploy}')

    rpc_infos = [(rpc_addr, mocknet_helpers.RPC_PORT) for rpc_addr in rpc_nodes]

    node_account_key = key_mod.Key(node_account_id, pk, sk)
    test_account_keys = [
        key_mod.Key(load_testing_account_id(node_account_id, i), pk, sk)
        for i in range(NUM_ACCOUNTS)
    ]

    base_block_hash = mocknet_helpers.get_latest_block_hash()
    node_account = account_mod.Account(node_account_key,
                                       mocknet_helpers.get_nonce_for_pk(
                                           node_account_key.account_id,
                                           node_account_key.pk),
                                       base_block_hash,
                                       rpc_infos=rpc_infos)

    if need_deploy:
        init_ft(node_account)

    accounts = []
    for key in test_account_keys:
        account = account_mod.Account(key,
                                      mocknet_helpers.get_nonce_for_pk(
                                          key.account_id, key.pk),
                                      base_block_hash,
                                      rpc_infos=rpc_infos)
        accounts.append(account)
        if need_deploy:
            logger.info(f'Deploying contract for account {key.account_id}')
            tx_res = account.send_deploy_contract_tx('betanet_state.wasm')
            logger.info(f'Deploying result: {tx_res}')
            init_ft_account(node_account, account)
            logger.info(
                f'Account {key.account_id} balance after initialization: {account.get_amount_yoctonear()}'
            )
            mocknet_helpers.wait_at_least_one_block()

    return node_account, accounts, max_tps
示例#4
0
文件: endtoend.py 项目: near/nearcore
def do_ping(account, rpc_server):
    account_id = account.key.account_id
    base_block_hash = mocknet_helpers.get_latest_block_hash(addr=rpc_server[0],
                                                            port=rpc_server[1])
    balance = mocknet_helpers.retry_and_ignore_errors(
        lambda: mocknet_helpers.get_amount_yoctonear(
            account_id, addr=rpc_server[0], port=rpc_server[1]))
    if balance is not None:
        balance_gauge.labels(account=account_id).set(balance)
    logger.info(f'Sending 0 tokens from {account_id} to itself')
    tx_res = mocknet_helpers.retry_and_ignore_errors(
        lambda: account.send_transfer_tx(
            account_id, transfer_amount=0, base_block_hash=base_block_hash))
    logger.info(
        f'Sending 0 tokens from {account_id} to itself, tx result: {tx_res}')
示例#5
0
def send_resigned_transactions(tx_path, home_dir):
    with open(os.path.join(home_dir, 'node0/', 'node_key.json'), 'r') as fin:
        key_pair_json = json.load(fin)
    key_pair = Key(key_pair_json['account_id'], key_pair_json['public_key'],
                   key_pair_json['secret_key'])
    base_block_hash = mocknet_helpers.get_latest_block_hash(addr=LOCALHOST)
    my_account = Account(key_pair,
                         init_nonce=0,
                         base_block_hash=base_block_hash,
                         rpc_infos=[(LOCALHOST, "3030")])

    schema = dict(tx_schema + crypto_schema + bridge_schema)
    with open(tx_path) as fin:
        txs = json.load(fin, object_pairs_hook=OrderedDict)
    for original_signed_tx in txs:
        tx = convert_json_rust_instance_to_py_object(
            original_signed_tx['transaction'], Transaction)
        if hasattr(tx, 'blockHash'):
            tx.blockHash = base_block_hash
        if hasattr(tx, 'actions'):
            try:
                tx.actions = [
                    convert_json_action_to_py_action(action_dict)
                    for action_dict in tx.actions
                ]
            except ValueError:
                continue
        tx.publicKey = PublicKey()
        tx.publicKey.keyType = 0
        tx.publicKey.data = key_pair.decoded_pk()
        msg = BinarySerializer(schema).serialize(tx)
        hash_ = hashlib.sha256(msg).digest()
        signature = Signature()
        signature.keyType = 0
        signature.data = key_pair.sign_bytes(hash_)
        resigned_tx = SignedTransaction()
        resigned_tx.transaction = tx
        resigned_tx.signature = signature
        resigned_tx.hash = hash_
        my_account.send_tx(BinarySerializer(schema).serialize(resigned_tx))
示例#6
0
文件: loadtest.py 项目: near/nearcore
                        type=str,
                        default='storage',
                        help="""# Contract types:
    #  - storage - tries to do maximum amount of reads & writes (increments a large vector)
    #  - compute - tries to do maximum amount of compute (infinite loop)
    #  - write - tries to write a lot of data to the contract state.""")
    args = parser.parse_args()

    accounts = [args.account_ids.split(",")] if args.account_ids else [
        f"shard{i}" for i in range(args.num_accounts)
    ]

    validator_key = key.Key.from_json_file(
        join(args.home, args.sender_key_file))

    base_block_hash = mocknet_helpers.get_latest_block_hash(addr=args.host)
    nonce = mocknet_helpers.get_nonce_for_key(validator_key, addr=args.host)

    my_account = account.Account(validator_key,
                                 init_nonce=nonce,
                                 base_block_hash=base_block_hash,
                                 rpc_infos=[(args.host, "3030")])

    # First - 'reset' the counters in the contract.
    for y in accounts:
        my_account.send_call_contract_raw_tx(
            contract_id=y,
            method_name="reset_increment_many",
            args=f'{{"how_many": 400}}'.encode("utf-8"),
            deposit=0)
def get_test_accounts_from_args(argv):
    node_account_id = argv[1]
    pk = argv[2]
    sk = argv[3]
    assert argv[4]
    rpc_nodes = argv[4].split(',')
    logger.info(f'rpc_nodes: {rpc_nodes}')
    num_nodes = int(argv[5])
    max_tps = float(argv[6])
    leader_account_id = sys.argv[7]
    upk = sys.argv[8]
    usk = sys.argv[9]

    node_account_key = key.Key(node_account_id, pk, sk)
    test_account_keys = [
        key.Key(mocknet.load_testing_account_id(node_account_id, i), pk, sk)
        for i in range(mocknet.NUM_ACCOUNTS)
    ]

    base_block_hash = mocknet_helpers.get_latest_block_hash()

    rpc_infos = [(rpc_addr, mocknet_helpers.RPC_PORT) for rpc_addr in rpc_nodes]
    node_account = account.Account(node_account_key,
                                   mocknet_helpers.get_nonce_for_pk(
                                       node_account_key.account_id,
                                       node_account_key.pk),
                                   base_block_hash,
                                   rpc_infos=rpc_infos)
    accounts = [
        account.Account(key,
                        mocknet_helpers.get_nonce_for_pk(
                            key.account_id, key.pk),
                        base_block_hash,
                        rpc_infos=rpc_infos) for key in test_account_keys
    ]
    max_tps_per_node = max_tps / num_nodes

    special_account_keys = [
        key.Key(mocknet.SKYWARD_ACCOUNT, upk, usk),
        key.Key(mocknet.TOKEN1_ACCOUNT, upk, usk),
        key.Key(mocknet.TOKEN2_ACCOUNT, upk, usk),
        key.Key(mocknet.ACCOUNT1_ACCOUNT, upk, usk),
        key.Key(mocknet.TOKEN2_OWNER_ACCOUNT, upk, usk),
    ]
    global special_accounts
    special_accounts = [
        account.Account(key,
                        mocknet_helpers.get_nonce_for_pk(
                            key.account_id, key.pk),
                        base_block_hash,
                        rpc_infos=rpc_infos) for key in special_account_keys
    ]

    start_time = time.monotonic()
    if node_account_id == leader_account_id:
        initialize_skyward_contract(node_account_id, pk, sk)
        elapsed = time.monotonic() - start_time
        if elapsed < SKYWARD_INIT_TIME:
            logger.info(f'Leader sleeps for {SKYWARD_INIT_TIME-elapsed}sec')
            time.sleep(SKYWARD_INIT_TIME - elapsed)
    else:
        logger.info(f'Non-leader sleeps for {SKYWARD_INIT_TIME}sec')
        time.sleep(SKYWARD_INIT_TIME)

    return node_account, accounts, max_tps_per_node
示例#8
0
    parser.add_argument('--num_accounts', type=int, default=5)
    parser.add_argument('--contract_dir',
                        type=str,
                        default='pytest/tests/loadtest/contract')
    args = parser.parse_args()

    print("Compiling contract")
    subprocess.check_call(args=[
        "cargo", "build", "--target", "wasm32-unknown-unknown", "--release"
    ],
                          cwd=args.contract_dir)

    for i in range(args.num_accounts):
        account_name = f"shard{i}"

        shard_key = key.Key.from_json_file(join(args.home,
                                                f"shard{i}_key.json"))

        base_block_hash = mocknet_helpers.get_latest_block_hash()
        nonce = mocknet_helpers.get_nonce_for_key(shard_key)

        shard_account = account.Account(shard_key,
                                        init_nonce=nonce,
                                        base_block_hash=base_block_hash,
                                        rpc_infos=[("localhost", "3030")])

        shard_account.send_deploy_contract_tx(
            join(
                args.contract_dir,
                "target/wasm32-unknown-unknown/release/loadtest_contract.wasm"))
示例#9
0
文件: endtoend.py 项目: near/nearcore
    args = parser.parse_args()

    assert args.ips
    ips = args.ips.split(',')
    assert args.accounts
    account_ids = args.accounts.split(',')
    assert len(account_ids) == len(
        ips), 'List of test accounts must match the list of node IP addresses'
    interval_sec = args.interval_sec
    assert interval_sec > 1, 'Need at least 1 second between pings'
    port = args.port
    pk, sk = args.public_key, args.private_key
    rpc_server = (args.rpc_server_addr, args.rpc_server_port)

    keys = [key_mod.Key(account_id, pk, sk) for account_id in account_ids]
    base_block_hash = mocknet_helpers.get_latest_block_hash(addr=rpc_server[0],
                                                            port=rpc_server[1])
    accounts = []
    for ip, key in zip(ips, keys):
        nonce = mocknet_helpers.get_nonce_for_pk(key.account_id,
                                                 key.pk,
                                                 addr=rpc_server[0],
                                                 port=rpc_server[1])
        accounts.append(
            account_mod.Account(key,
                                nonce,
                                base_block_hash,
                                rpc_infos=[(ip, port)]))

    prometheus_client.start_http_server(args.metrics_port)

    with ThreadPoolExecutor() as executor: