-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[INDY-1029] Change timeout for getting cathup replies (#499)
* [INDY-1029] Change timeout for getting cathup replies Signed-off-by: Andrew Nikitin <[email protected]> * [indy-1029] Add scripts for generating and adding transactions to domain ledger for test purpose Signed-off-by: Andrew Nikitin <[email protected]> * [INDY-1029] Add new timeout var into config Signed-off-by: Andrew Nikitin <[email protected]> * [INDY-1029] Fix static validation Signed-off-by: Andrew Nikitin <[email protected]> * [INDY-1029] Change evaluating pool catchup timeout for tests Signed-off-by: Andrew Nikitin <[email protected]> * [INDY-1029] Make timeout depended from node count (for test logic) Signed-off-by: Andrew Nikitin <[email protected]> * [INDY-1029] Erase dublicate sdk_reqToTxn function Signed-off-by: Andrew Nikitin <[email protected]>
- Loading branch information
1 parent
6d7a942
commit d49cb4b
Showing
7 changed files
with
202 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import os | ||
import sys | ||
import json | ||
import argparse | ||
|
||
from stp_core.types import HA | ||
from indy_common.config_util import getConfig | ||
from plenum.server.node import Node | ||
from indy_common.config_helper import NodeConfigHelper | ||
|
||
config = getConfig() | ||
|
||
|
||
def get_ha_cliha_node_name(path_to_env): | ||
node_name_key = 'NODE_NAME' | ||
node_port_key = 'NODE_PORT' | ||
node_clien_port_key = 'NODE_CLIENT_PORT' | ||
node_name = '' | ||
node_port = '' | ||
node_clieint_port = '' | ||
with open(path_to_env) as fenv: | ||
for line in fenv.readlines(): | ||
print(line) | ||
if line.find(node_name_key) != -1: | ||
node_name = line.split('=')[1].strip() | ||
elif line.find(node_port_key) != -1: | ||
node_port = int(line.split('=')[1].strip()) | ||
elif line.find(node_clien_port_key) != -1: | ||
node_clieint_port = int(line.split('=')[1].strip()) | ||
return node_name, node_port, node_clieint_port | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('infpath', help="Path to previous generated txns", type=str, default='/tmp/generated_txns') | ||
parser.add_argument('--env_file', help='Path to environment file with node name and ports', default='/etc/indy/indy.env') | ||
args = parser.parse_args() | ||
path_to_txns = os.path.realpath(args.infpath) | ||
path_to_env = os.path.realpath(args.env_file) | ||
|
||
if not os.path.exists(path_to_txns): | ||
print("Path to txns file does not exist") | ||
sys.exit(1) | ||
|
||
if not os.path.exists(path_to_env): | ||
print("Path to env file does not exist") | ||
sys.exit(1) | ||
|
||
nname, nport, ncliport = get_ha_cliha_node_name(path_to_env) | ||
ha = HA("0.0.0.0", nport) | ||
cliha = HA("0.0.0.0", ncliport) | ||
config_helper = NodeConfigHelper(nname, config) | ||
|
||
node = Node(nname, nodeRegistry=None, | ||
ha=ha, | ||
cliha=cliha, | ||
config_helper=config_helper, | ||
config=config) | ||
i = 0 | ||
with open(path_to_txns) as txns: | ||
for txn in txns: | ||
node.domainLedger.add(json.loads(txn)) | ||
i += 1 | ||
if not i % 1000: | ||
print("added {} txns".format(i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#! /usr/bin/env python3 | ||
|
||
import os | ||
import json | ||
import time | ||
from contextlib import ExitStack | ||
import argparse | ||
import random | ||
from typing import Sequence | ||
from plenum.common.request import Request | ||
from plenum.common.constants import CURRENT_PROTOCOL_VERSION | ||
from plenum.common.util import randomString | ||
from plenum.common.config_util import getConfig | ||
from plenum.common.txn_util import sdk_reqToTxn | ||
from indy.ledger import sign_request | ||
from indy import signus, wallet | ||
from stp_core.loop.looper import Looper | ||
|
||
config = getConfig() | ||
|
||
|
||
async def get_wallet_and_pool(): | ||
pool_name = 'pool' + randomString(3) | ||
wallet_name = 'wallet' + randomString(10) | ||
their_wallet_name = 'their_wallet' + randomString(10) | ||
seed_trustee1 = "000000000000000000000000Trustee1" | ||
|
||
await wallet.create_wallet(pool_name, wallet_name, None, None, None) | ||
my_wallet_handle = await wallet.open_wallet(wallet_name, None, None) | ||
|
||
await wallet.create_wallet(pool_name, their_wallet_name, None, None, None) | ||
their_wallet_handle = await wallet.open_wallet(their_wallet_name, None, None) | ||
|
||
await signus.create_and_store_my_did(my_wallet_handle, "{}") | ||
|
||
(their_did, their_verkey) = await signus.create_and_store_my_did(their_wallet_handle, | ||
json.dumps({"seed": seed_trustee1})) | ||
|
||
await signus.store_their_did(my_wallet_handle, json.dumps({'did': their_did, 'verkey': their_verkey})) | ||
|
||
return their_wallet_handle, their_did | ||
|
||
|
||
def randomOperation(): | ||
return { | ||
"type": "buy", | ||
"amount": random.randint(10, 100000) | ||
} | ||
|
||
|
||
def random_requests(count): | ||
return [randomOperation() for _ in range(count)] | ||
|
||
|
||
def sdk_gen_request(operation, protocol_version=CURRENT_PROTOCOL_VERSION, identifier=None): | ||
return Request(operation=operation, reqId=random.randint(10, 100000), | ||
protocolVersion=protocol_version, identifier=identifier) | ||
|
||
|
||
def sdk_random_request_objects(count, protocol_version, identifier=None): | ||
ops = random_requests(count) | ||
return [sdk_gen_request(op, protocol_version=protocol_version, identifier=identifier) for op in ops] | ||
|
||
|
||
def sdk_sign_request_objects(looper, sdk_wallet, reqs: Sequence): | ||
wallet_h, did = sdk_wallet | ||
reqs_str = [json.dumps(req.as_dict) for req in reqs] | ||
resp = [looper.loop.run_until_complete(sign_request(wallet_h, did, req)) for req in reqs_str] | ||
return resp | ||
|
||
|
||
def sdk_signed_random_requests(looper, sdk_wallet, count): | ||
_, did = sdk_wallet | ||
reqs_obj = sdk_random_request_objects(count, identifier=did, protocol_version=CURRENT_PROTOCOL_VERSION) | ||
return sdk_sign_request_objects(looper, sdk_wallet, reqs_obj) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('count', help="Count of generated txns", type=int) | ||
parser.add_argument('outfpath', help="Path to save generated txns", type=str, default='/tmp/generated_txns') | ||
args = parser.parse_args() | ||
path_to_save = os.path.realpath(args.outfpath) | ||
|
||
with ExitStack() as exit_stack: | ||
with Looper() as looper: | ||
sdk_wallet, did = looper.loop.run_until_complete(get_wallet_and_pool()) | ||
with open(path_to_save, 'w') as outpath: | ||
for _ in range(args.count): | ||
req = sdk_signed_random_requests(looper, (sdk_wallet, did), 1)[0] | ||
txn = sdk_reqToTxn(req, int(time.time())) | ||
outpath.write(json.dumps(txn)) | ||
outpath.write(os.linesep) | ||
looper.stopall() |