def test_01_start(self): print("\n-----", sys._getframe().f_code.co_name, "-----") key_exchange_manager.KeyExchangeManager.KEY_EXCHANGE_INVOKE_MAX_BACKOFF = 1 key_exchange_manager.KeyExchangeManager.KEY_EXCHANGE_RETRY_INTERVAL = 3 key_exchange_manager.KeyExchangeManager.KEY_REFRESH_INTERVAL = 15 key_exchange_manager.KeyExchangeManager.KEY_OBSOLETE_TIMER = 4 TopologyManagerBase.NEIGHBOR_LIST_REFRESH_INTERVAL = 15 dummycore = DummyCore() keyconfig = { 'use': True, 'directory': ".bbc1-domainkeys", 'obsolete_timeout': 3, } global networkings, nodes, conf for i, nw in enumerate(networkings): if os.path.exists(".bbc1-%d"%i): shutil.rmtree(".bbc1-%d"%i) config = bbc_config.BBcConfig(directory=".bbc1-%d"%i) conf = config.get_config() conf["domain_key"].update(keyconfig) networkings[i] = bbc_network.BBcNetwork(core=dummycore, config=config, p2p_port=6641+i, loglevel=LOGLEVEL) networkings[i].create_domain(domain_id=domain_id) nodes[i] = networkings[i].domains[domain_id]['neighbor'].my_node_id assert nodes[i] is not None assert networkings[i].ip_address != '' print("IPv4: %s, IPv6 %s, port: %d" % (networkings[i].ip_address, networkings[i].ip6_address, networkings[i].port))
def test_01_start(self): print("\n-----", sys._getframe().f_code.co_name, "-----") TopologyManagerBase.NEIGHBOR_LIST_REFRESH_INTERVAL = 15 dummycore = DummyCore() global networkings, nodes, conf for i, nw in enumerate(networkings): if os.path.exists(".bbc1-%d" % i): shutil.rmtree(".bbc1-%d" % i) config = bbc_config.BBcConfig(directory=".bbc1-%d" % i) networkings[i] = bbc_network.BBcNetwork(core=dummycore, config=config, p2p_port=6641 + i, loglevel=LOGLEVEL) networkings[i].create_domain(domain_id=domain_id) nodes[i] = networkings[i].domains[domain_id]['neighbor'].my_node_id assert nodes[i] is not None assert networkings[i].ip_address != '' print("IPv4: %s, IPv6 %s, port: %d" % (networkings[i].ip_address, networkings[i].ip6_address, networkings[i].port))
def test_01_start(self): print("\n-----", sys._getframe().f_code.co_name, "-----") global dummy_cores, networkings, nodes user_message_routing.UserMessageRouting.REFRESH_FORWARDING_LIST_INTERVAL = 10 # for testing for i, nw in enumerate(networkings): if os.path.exists(".bbc1-%d" % i): shutil.rmtree(".bbc1-%d" % i) dummy_cores[i] = DummyCore(9000 + i) config = bbc_config.BBcConfig(directory=".bbc1-%d" % i) networkings[i] = bbc_network.BBcNetwork(core=dummy_cores[i], config=config, p2p_port=6641 + i, loglevel=LOGLEVEL) dummy_cores[i].networking = networkings[i] networkings[i].create_domain(domain_id=domain_id) user_routings[i] = networkings[i].domains[domain_id]['user'] nodes[i] = networkings[i].domains[domain_id]['neighbor'].my_node_id assert nodes[i] is not None assert networkings[i].ip_address != '' print("IPv4: %s, IPv6 %s, port: %d" % (networkings[i].ip_address, networkings[i].ip6_address, networkings[i].port))
def test_01_start(self): print("-----", sys._getframe().f_code.co_name, "-----") dummycore = DummyCore() from bbc1.core import simple_cluster simple_cluster.FORWARD_CACHE_SIZE = 5 global networkings, nodes, conf for i, nw in enumerate(networkings): config = bbc_config.BBcConfig(directory=".bbc1-%d" % i) networkings[i] = bbc_network.BBcNetwork(core=dummycore, config=config, p2p_port=6641 + i, loglevel=LOGLEVEL) networkings[i].create_domain(network_module="simple_cluster", domain_id=domain_id) nodes[i] = networkings[i].domains[domain_id].node_id assert nodes[i] is not None assert networkings[i].ip_address != '' print("IPv4: %s, IPv6 %s, port: %d" % (networkings[i].ip_address, networkings[i].ip6_address, networkings[i].port)) for i in range(core_nodes): networkings[i].register_user_id(domain_id, asset_group_id, users[i])
def test_ledger_subsystem(default_config): setup.setup_run(default_config) prevdir = os.getcwd() dir = os.path.dirname(os.path.realpath(__file__)) os.chdir(dir) os.chdir('../bbc1/core/ethereum') conf = default_config.get_config() print(conf) eth = bbc_ethereum.BBcEthereum(conf['ethereum']['account'], conf['ethereum']['passphrase'], conf['ethereum']['contract_address']) os.chdir('..') networking = bbc_network.BBcNetwork(core=DummyCore(), config=conf, p2p_port=6641) networking.create_domain(domain_id=domain_id1) ls = ledger_subsystem.LedgerSubsystem(conf, networking=networking, domain_id=domain_id1, enabled=True) for i in range(150): ls.register_transaction(hashlib.sha256(i.to_bytes(4, 'big')).digest()) time.sleep(0.1) time.sleep(30) i = 300 j = ls.verify_transaction(hashlib.sha256(i.to_bytes(4, 'big')).digest()) assert not j['result'] for i in range(150): digest = hashlib.sha256(i.to_bytes(4, 'big')).digest() j = ls.verify_transaction(digest) assert j['result'] assert eth.verify(digest, j['subtree']) > 0 # -- test in another domain networking.create_domain(domain_id=domain_id2) ls = ledger_subsystem.LedgerSubsystem(conf, networking=networking, domain_id=domain_id2, enabled=True) i = 100 j = ls.verify_transaction(hashlib.sha256(i.to_bytes(4, 'big')).digest()) assert not j['result'] i = 99 digest = hashlib.sha256(i.to_bytes(4, 'big')).digest() ls.register_transaction(digest) time.sleep(31) j = ls.verify_transaction(digest) assert j['result'] assert eth.verify(digest, j['subtree']) > 0 setup.setup_stop(default_config)
def test_ledger_subsystem(default_config): bbc_ethereum.setup_run(default_config) prevdir = os.getcwd() os.chdir(bbc1.__path__[0] + '/core/ethereum') conf = default_config.get_config() eth = bbc_ethereum.BBcEthereum(conf['ethereum']['account'], conf['ethereum']['passphrase'], conf['ethereum']['contract_address']) os.chdir('..') networking = bbc_network.BBcNetwork(core=DummyCore(), config=default_config, p2p_port=6641) networking.create_domain(domain_id=domain_id1) ls = ledger_subsystem.LedgerSubsystem(default_config, networking=networking, domain_id=domain_id1, enabled=True) for i in range(150): ls.register_transaction(hashlib.sha256(i.to_bytes(4, 'big')).digest()) print("\n30-second interval for trigger Merkle tree creation.") for i in range(6, 0, -1): print("continuing to sleep. countdown", i) time.sleep(5) i = 300 j = ls.verify_transaction(hashlib.sha256(i.to_bytes(4, 'big')).digest()) assert not j['result'] for i in range(150): digest = hashlib.sha256(i.to_bytes(4, 'big')).digest() j = ls.verify_transaction(digest) assert j['result'] assert eth.verify(digest, j['subtree']) > 0 # -- test in another domain networking.create_domain(domain_id=domain_id2) ls = ledger_subsystem.LedgerSubsystem(default_config, networking=networking, domain_id=domain_id2, enabled=True) i = 100 j = ls.verify_transaction(hashlib.sha256(i.to_bytes(4, 'big')).digest()) assert not j['result'] i = 99 digest = hashlib.sha256(i.to_bytes(4, 'big')).digest() ls.register_transaction(digest) print("31-second interval for trigger Merkle tree creation.") time.sleep(1) for i in range(6, 0, -1): print("continuing to sleep. countdown", i) time.sleep(5) j = ls.verify_transaction(digest) assert j['result'] assert eth.verify(digest, j['subtree']) > 0 os.chdir(prevdir) bbc_ethereum.setup_stop(default_config)