Esempio n. 1
0
    def test_local_validation_errors(self):
        client = IntegerKeyClient(self.urls[0],
                                  keystring=generate_private_key(),
                                  disable_client_validation=True)

        with self.assertRaises(InvalidTransactionError):
            client.inc("bob", 1)
Esempio n. 2
0
    def setup(self, urls, numkeys):
        self.localState = {}
        self.transactions = []
        self.clients = []
        self.state = IntegerKeyState(urls[0])

        with Progress("Creating clients") as p:
            for u in urls:
                key = generate_private_key()
                self.clients.append(IntegerKeyClient(u, keystring=key))
                p.step()

        print "Checking for pre-existing state"
        self.state.fetch()
        keys = self.state.State.keys()

        for k, v in self.state.State.iteritems():
            self.localState[k] = v

        with Progress("Populating initial key values") as p:
            txncount = 0
            starttime = time.clock()
            for n in range(1, numkeys + 1):
                n = str(n)
                if n not in keys:
                    c = self._get_client()
                    v = random.randint(5, 1000)
                    self.localState[n] = v
                    txnid = c.set(n, v)
                    if txnid is None:
                        raise Exception("Failed to set {} to {}".format(n, v))
                    self.transactions.append(txnid)
                    txncount += 1
            self.txnrate(starttime, txncount)
        self._wait_for_transaction_commits()
    def test_initial_connectivity_n_minus_1(self):
        try:
            self.vnm.validator_config['LedgerURL'] = "**none**"
            validator = self.vnm.launch_node(genesis=True)
            validators = [validator]
            with Progress("Launching validator network") as p:
                self.vnm.validator_config['LedgerURL'] = validator.url
                node_identifiers = [validator.Address]
                for i in range(1, 5):
                    self.vnm.validator_config['InitialConnectivity'] = i
                    v = self.vnm.launch_node(genesis=False, daemon=False)
                    validators.append(v)
                    node_identifiers.append(v.Address)
                    p.step()
            self.vnm.wait_for_registration(validators, validator)
            validator_urls = self.vnm.urls()
            clients = [SawtoothClient(base_url=u) for u in validator_urls]
            integer_key_clients = [
                IntegerKeyClient(baseurl=u, keystring=generate_private_key())
                for u in validator_urls
            ]

            for int_key_client in integer_key_clients:
                int_key_client.set(key=str(1), value=20)

            self._verify_equality_of_block_lists(clients)
            self._verify_orderly_transactions(clients, node_identifiers)
        finally:
            self.vnm.shutdown()
            self.vnm.create_result_archive(
                'TestOrderlyInitialConnectivity.tar.gz')
    def test_adding_node_with_nodelist(self):
        try:
            validators = self.vnm.launch_network(5)
            validator_urls = self.vnm.urls()
            endpoint_client = EndpointRegistryClient(validator_urls[0])
            nodes = []
            for epl in endpoint_client.get_endpoint_list():
                node = {}
                node['Host'] = epl['Host']
                node['Port'] = epl['Port']
                node['Identifier'] = epl['NodeIdentifier']
                node['NodeName'] = epl['Name']
                nodes.append(node)
            peers = [nodes[0]['NodeName'], nodes[2]['NodeName'], 'validator-x']
            self.vnm.validator_config['Nodes'] = nodes
            self.vnm.validator_config['Peers'] = peers
            v = self.vnm.launch_node()
            validator_urls.append(v.url)

            self.vnm.wait_for_registration([v], validators[0])
            ledger_web_clients = [
                LedgerWebClient(url=u) for u in validator_urls
            ]
            integer_key_clients = [
                IntegerKeyClient(baseurl=u, keystring=generate_private_key())
                for u in validator_urls
            ]

            for int_key_client in integer_key_clients:
                int_key_client.set(key=str(1), value=20)
            self._verify_equality_of_block_lists(ledger_web_clients)

        finally:
            self.vnm.shutdown()
            self.vnm.create_result_archive('TestNodeList.tar.gz')
    def on_validator_discovered(self, url):
        # We need a key file for the client, but as soon as the client is
        # created, we don't need it any more.  Then create a new client and
        # add it to our cadre of clients to use

        keystring = signing.encode_privkey(signing.generate_privkey(), 'wif')
        with self._lock:
            self._clients.append(
                IntegerKeyClient(baseurl=url, keystring=keystring))
    def test_join_after_delay_start(self):
        delayed_validator = None
        validator_urls = []
        try:
            self.vnm.launch_network(5)
            validator_urls = self.vnm.urls()

            delayed_validator = self.vnm.launch_node(delay=True)
            time.sleep(5)

            command_url = delayed_validator.url + '/command'
            request = urllib2.Request(
                url=command_url, headers={'Content-Type': 'application/json'})
            response = urllib2.urlopen(request, data='{"action": "start"}')
            response.close()
            self.assertEqual(response.code, 200,
                             "Successful post to delayed validator")

            validator_urls.append(delayed_validator.url)
            ledger_web_clients = [
                LedgerWebClient(url=u) for u in validator_urls
            ]

            with Progress("Waiting for registration of 1 validator") as p:
                url = validator_urls[0]
                to = TimeOut(60)
                while not delayed_validator.is_registered(url):
                    if to():
                        raise ExitError(
                            "{} delayed validator failed to register "
                            "within {}S.".format(1, to.WaitTime))
                    p.step()
                    time.sleep(1)
                    try:
                        delayed_validator.check_error()
                    except ValidatorManagerException as vme:
                        delayed_validator.dump_log()
                        delayed_validator.dump_stderr()
                        raise ExitError(str(vme))
            integer_key_clients = [
                IntegerKeyClient(baseurl=u, keystring=generate_private_key())
                for u in validator_urls
            ]

            for int_key_client in integer_key_clients:
                int_key_client.set(key=str(1), value=20)

            self._verify_equality_of_block_lists(ledger_web_clients)

        finally:
            self.vnm.shutdown()
            if delayed_validator is not None and \
                    validator_urls is not [] and \
                    delayed_validator.url not in validator_urls:
                delayed_validator.shutdown()
            self.vnm.create_result_archive("TestDelayedStart.tar.gz")
    def on_validator_discovered(self, url):
        # We need a key file for the client, but as soon as the client is
        # created, we don't need it any more.  Then create a new client and
        # add it to our cadre of clients to use

        keystring = pybitcointools.encode_privkey(
            pybitcointools.random_key(), 'wif')
        self._clients.append(IntegerKeyClient(
            baseurl=url,
            keystring=keystring))
Esempio n. 8
0
    def setup(self, urls, numkeys):
        self.localState = {}
        self.transactions = []
        self.last_key_txn = {}
        self.clients = []
        self.state = IntegerKeyState(urls[0])

        with Progress("Creating clients") as p:
            for u in urls:
                try:
                    key = generate_private_key()
                    self.clients.append(IntegerKeyClient(u, keystring=key))
                    p.step()
                except MessageException:
                    logger.warn("Unable to connect to Url: %s ", u)
            if len(self.clients) == 0:
                return

        # add check for if a state already exists
        with Progress("Checking for pre-existing state") as p:
            self.state.fetch()
            for k, v in self.state.State.iteritems():
                self.localState[k] = v
                p.step()

        keys = self.state.State.keys()

        with Progress("Populating initial key values") as p:
            txncount = 0
            starttime = time.time()
            for n in range(1, numkeys + 1):
                n = str(n)
                if n not in keys:
                    c = self._get_client()
                    v = random.randint(5, 1000)
                    self.localState[n] = v
                    txnid = c.set(n, v)
                    if txnid is None:
                        raise Exception("Failed to set {} to {}".format(n, v))
                    self.transactions.append(txnid)
                    txncount += 1
                    self.last_key_txn[n] = txnid
                    p.step()
            print
            self.txnrate(starttime, txncount, "submitted")
        self._wait_for_transaction_commits()
        self.txnrate(starttime, txncount, "committed")
Esempio n. 9
0
    def setup(self, urls):
        self.global_store = {}
        self.running_url_list = urls
        self.global_keys = []
        self.transactions = []
        self.lastKeyTxn = {}
        self.clients = []
        self.state = IntegerKeyState(urls[0])

        with Progress("Creating clients") as p:
            print "Creating clients"
            for u in self.running_url_list:
                try:
                    key = generate_private_key()
                    self.clients.append(IntegerKeyClient(u, keystring=key))
                    p.step()
                except MessageException:
                    print "Unable to connect to Url: {}".format(u)
    def test_basic_startup(self):
        try:

            self.vnm.launch_network(count=self.number_of_daemons,
                                    others_daemon=True)

            validator_urls = self.vnm.urls()
            # IntegerKeyClient is only needed to send one more transaction
            # so n-1=number of EndpointRegistryTransactions
            integer_key_clients = [
                IntegerKeyClient(baseurl=u, keystring=generate_private_key())
                for u in validator_urls
            ]
            clients = [SawtoothClient(base_url=u) for u in validator_urls]
            for int_key_client in integer_key_clients:
                int_key_client.set(key=str(1), value=20)
            self._verify_equality_of_block_lists(clients)

        finally:
            self.vnm.shutdown()
            self.vnm.create_result_archive('TestDaemonStartup.tar.gz')
Esempio n. 11
0
    def setup(self, urls, numKeys):
        self.localState = {}
        self.transactions = []
        self.clients = []
        self.state = IntegerKeyState(urls[0])

        with Progress("Creating clients") as p:
            for u in urls:
                key = generate_private_key()
                self.clients.append(IntegerKeyClient(u, keystring=key))
                p.step()

        with Progress("Creating initial key values") as p:
            for n in range(1, numKeys + 1):
                n = str(n)
                c = self._get_client()
                v = random.randint(5, 1000)
                self.localState[n] = v
                txnid = c.set(n, v)
                if txnid is None:
                    raise Exception("Failed to set {} to {}".format(n, v))
                self.transactions.append(txnid)

        self._wait_for_transaction_commits()
Esempio n. 12
0
 def test_two_clique(self):
     # this topology forms 2 exclusive cliques when n2 is severed
     vulnerable_mat = [
         [1, 1, 0, 0, 0],
         [1, 1, 1, 0, 0],
         [0, 1, 1, 1, 0],
         [0, 0, 1, 1, 1],
         [0, 0, 0, 1, 1],
     ]
     two_clique_mat = copy.deepcopy(vulnerable_mat)
     two_clique_mat[2][2] = 0
     n = len(vulnerable_mat)
     top = SimController(n)
     print
     try:
         print 'phase 0: build vulnerably connected 5-net:'
         from txnintegration.netconfig import NetworkConfigProvider
         net_cfg = NetworkConfig(gen_dfl_cfg_poet0(),
                                 n,
                                 provider=NetworkConfigProvider())
         net_cfg.set_nodes(vulnerable_mat)
         net_cfg.set_peers(vulnerable_mat)
         net_cfg.set_blacklist()
         vnm = ValidatorCollectionController(net_cfg)
         top.initialize(net_cfg, vnm, NopEdgeController(net_cfg))
         print 'phase 1: launch vulnerably connected 5-net:'
         top.do_genesis(probe_seconds=0)
         top.launch(probe_seconds=0)
         print 'phase 2: validate state across 5-net:'
         sit_rep(top.urls(), verbosity=2)
         print 'phase 3: morph 5-net into two exclusive 2-net cliques:'
         top.update(node_mat=two_clique_mat, probe_seconds=0, reg_seconds=0)
         print 'providing time for convergence (likely partial)...'
         time.sleep(32)
         sit_rep(top.urls())
         print 'phase 4: generate chain-ext A on clique {0, 1}:'
         url = top.urls()[0]
         print 'sending transactions to %s...' % (url)
         ikcA = IntegerKeyClient(baseurl=url, keystring=gen_pk())
         self._do_work(ikcA, 5, 2)
         print 'providing time for partial convergence...'
         time.sleep(8)
         sit_rep(top.urls())
         print 'phase 5: generate chain-ext B on clique {3, 4}, |B| = 2|A|:'
         url = top.urls()[-1]
         print 'sending transactions to %s...' % (url)
         ikcB = IntegerKeyClient(baseurl=url, keystring=gen_pk())
         self._do_work(ikcB, 1, 4)
         print 'providing time for partial convergence...'
         time.sleep(8)
         sit_rep(top.urls())
         print 'TEST 1: asserting network is forked'
         self.assertEquals(False, is_convergent(top.urls(), standard=3))
         print 'phase 6: reconnect 5-net:'
         print 'rezzing validator-2 with InitialConnectivity = |Peers|...'
         cfg = top.get_configuration(2)
         cfg['InitialConnectivity'] = 2
         top.set_configuration(2, cfg)
         top.update(node_mat=vulnerable_mat, probe_seconds=0, reg_seconds=0)
         print 'phase 7: validate state across 5-net:'
         print 'providing time for global convergence...'
         time.sleep(64)
         sit_rep(top.urls())
         print 'TEST 2: asserting network is convergent'
         self.assertEquals(True, is_convergent(top.urls(), standard=4))
     except Exception as e:
         print 'Exception encountered: %s' % (e.message)
         traceback.print_exc()
         sit_rep(top.urls())
         raise
     finally:
         top.shutdown(archive_name="TestPartitionRecoveryResults")
 def _generate_invalid_transactions(self, url):
     client = IntegerKeyClient(url,
                               keystring=generate_private_key(),
                               disable_client_validation=True)
     with self.assertRaises(InvalidTransactionError):
         client.inc("bob", 1)
 def _generate_invalid_transactions(self, url):
     client = IntegerKeyClient(url,
                               keystring=generate_private_key(),
                               disable_client_validation=True)
     with self.assertRaises(InvalidTransactionError):
         client.inc("bob", 1)