Esempio n. 1
0
    def setUpClass(cls):
        cls.vnm = None
        try:
            if 'TEST_VALIDATOR_URLS' in os.environ:
                urls = (os.environ['TEST_VALIDATOR_URLS']).split(",")
                cls.url = urls[0]
            else:
                families = ['mktplace.transactions.market_place']
                overrides = {
                    'InitialWaitTime': 1,
                    'TargetWaitTime': 1,
                    "TransactionFamilies": families,
                }
                cls.vnm = get_default_vnm(1, overrides=overrides)
                cls.vnm.do_genesis()
                cls.vnm.launch()
                # the url of the initial validator
                cls.url = cls.vnm.urls()[0] + '/'

            os.environ['CURRENCYHOME'] = os.path.join(
                os.path.dirname(__file__), "all_transactions")

            cls.script_path = os.path.join(os.path.dirname(__file__),
                                           'all_transactions')
            state = mktplace_state.MarketPlaceState(cls.url)
            state.fetch()
        except:
            if cls.vnm is not None:
                cls.vnm.shutdown()
            raise
Esempio n. 2
0
    def test_mktplace_load(self):
        vnm = None
        try:
            print "Launching validator network."
            overrides = {
                "TransactionFamilies": ['mktplace.transactions.market_place'],
            }
            vnm = get_default_vnm(5, overrides=overrides)
            vnm.do_genesis()
            vnm.launch()
            data_dir = vnm.net_config.provider.currency_home
            print "Testing transaction load."
            test_case = MktPlaceLoad(num_traders=5,
                                     iterations=1,
                                     urls=vnm.urls(),
                                     test_dir=data_dir)
            test_case.setup()
            test_case.run()
            test_case.validate()

        finally:
            archive_name = None
            if SAVE_INTEGRATION_TEST_DATA:
                archive_name = "TestMktSmokeResults"
            if vnm is not None:
                vnm.shutdown(archive_name=archive_name)
            else:
                print "No Validator data and logs to preserve."
 def extend_genesis_util(self, overrides):
     print
     vnm = None
     try:
         vnm = get_default_vnm(2, overrides=overrides)
         # Test genesis util
         cfg = vnm.get_configuration(0)
         ledger_type = cfg['LedgerType']
         gblock_file = genesis_info_file_name(cfg['DataDirectory'])
         self.assertFalse(os.path.exists(gblock_file))
         vnm.do_genesis()
         self.assertTrue(os.path.exists(gblock_file))
         genesis_dat = None
         with open(gblock_file, 'r') as f:
             genesis_dat = json.load(f)
         self.assertTrue('GenesisId' in genesis_dat.keys())
         head = genesis_dat['GenesisId']
         # Verify genesis tool efficacy on a minimal network
         vnm.launch()
         # ...verify validator is extending tgt_block
         to = TimeOut(64)
         blk_lists = None
         prog_str = 'testing root extension (expect root: %s)' % head
         with Progress(prog_str) as p:
             print
             while not to.is_timed_out() and blk_lists is None:
                 try:
                     blk_lists = get_blocklists(['http://localhost:8800'])
                     print 'block_lists: %s' % blk_lists
                     if len(blk_lists) < 1 or len(blk_lists[0]) < 2:
                         blk_lists = None
                 except MessageException as e:
                     pass
                 time.sleep(2)
                 p.step()
         self.assertIsNotNone(blk_lists)
         root = blk_lists[0][0]
         self.assertEqual(head, root)
         # ...verify general convergence
         to = TimeOut(32)
         with Progress('testing root convergence') as p:
             print
             while (is_convergent(vnm.urls(), tolerance=1, standard=1) is
                    False and not to.is_timed_out()):
                 time.sleep(2)
                 p.step()
         # ...verify convergence on the genesis block
         blk_lists = get_blocklists(['http://localhost:8800'])
         root = blk_lists[0][0]
         self.assertEqual(head, root)
         print 'network converged on root: %s' % root
     finally:
         if vnm is not None:
             archive_name = 'Test%sGenesisResults' % ledger_type.upper()
             vnm.shutdown(archive_name=archive_name)
Esempio n. 4
0
    def setUpClass(cls):
        cls.vnm = None
        try:
            if 'TEST_VALIDATOR_URLS' in os.environ:
                urls = (os.environ['TEST_VALIDATOR_URLS']).split(",")
                cls.url = urls[0]
            else:
                families = ['mktplace.transactions.market_place']
                overrides = {
                    "TransactionFamilies": families,
                }
                cls.vnm = get_default_vnm(5, overrides=overrides)
                cls.vnm.do_genesis()
                cls.vnm.launch()
                # the url of the initial validator
                cls.url = cls.vnm.urls()[0] + '/'

            os.environ['CURRENCYHOME'] = os.path.join(
                os.path.dirname(__file__), "cp_scenarios")

            cls.scenarios_path = os.path.join(os.path.dirname(__file__),
                                              'cp_scenarios')
            client_cli.main(args=[
                "--name", "mkt", "--script",
                os.path.join(cls.scenarios_path, "scenario_setup_1_mkt"),
                "--echo", "--url", cls.url
            ])

            client_cli.main(args=[
                "--name", "BANK-trader", "--script",
                os.path.join(os.path.dirname(__file__), "cp_scenarios",
                             "scenario_setup_2_trader"), "--echo", "--url",
                cls.url
            ])

            client_cli.main(args=[
                "--name", "BANK-agent", "--script",
                os.path.join(cls.scenarios_path, "scenario_setup_3_agent"),
                "--echo", "--url", cls.url
            ])

            client_cli.main(args=[
                "--name", "BANK-dealer", "--script",
                os.path.join(cls.scenarios_path, "scenario_setup_4_dealer"),
                "--echo", "--url", cls.url
            ])

            state = mktplace_state.MarketPlaceState(cls.url)
            state.fetch()
        except:
            if cls.vnm is not None:
                cls.vnm.shutdown()
            raise
Esempio n. 5
0
 def test_intkey_load_ext(self):
     vnm = None
     try:
         print "Launching validator network."
         vnm = get_default_vnm(5)
         vnm.do_genesis()
         vnm.launch()
         print "Testing transaction load."
         test = IntKeyLoadTest()
         test.setup(vnm.urls(), 10)
         test.run(1)
         test.run_with_missing_dep(1)
         test.validate()
     finally:
         if vnm is not None:
             vnm.shutdown(archive_name="TestIntegrationResults_0")
Esempio n. 6
0
    def test_validator_shutdown_ext(self):
        vnm = None
        print
        try:
            vnm = get_default_vnm(5)
            vnm.do_genesis()
            vnm.launch()

            keys = 10
            rounds = 2
            txn_intv = 0

            print "Testing transaction load."
            test = IntKeyLoadTest()
            urls = vnm.urls()
            self.assertEqual(5, len(urls))
            test.setup(vnm.urls(), keys)
            test.validate()
            test.run(keys, rounds, txn_intv)

            test.setup(urls, keys)
            test.validate()
            test.run(keys, rounds, txn_intv)

            print "test validator shutdown w/ SIGINT"
            vnm.deactivate_node(2, sig='SIGINT', timeout=8, force=False)

            print "sending more txns after SIGINT"
            urls = vnm.urls()
            self.assertEqual(4, len(urls))
            test.setup(urls, keys)
            test.validate()
            test.run(keys, rounds, txn_intv)

            print "test validator shutdown w/ SIGINT"
            vnm.deactivate_node(4, sig='SIGTERM', timeout=8, force=False)

            print "sending more txns after SIGTERM"
            urls = vnm.urls()
            self.assertEqual(3, len(urls))
            test.setup(urls, keys)
            test.validate()
            test.run(keys, rounds, txn_intv)

        finally:
            vnm.shutdown(archive_name='TestValidatorShutdown')
Esempio n. 7
0
def setUpModule():
    # setUpModule will be the first thing ran. This allows us to start up the
    # validators that we will use for all the following tests in the test suite
    print "Starting Validators for DevModeTestSuite"
    cfg = {}
    cfg['LedgerType'] = 'dev_mode'
    cfg['LocalValidation'] = True
    cfg['BlockWaitTime'] = 0
    global dev_vnm
    dev_vnm = None
    try:
        # Start up validators using SimController
        dev_vnm = get_default_vnm(1, overrides=cfg)
        dev_vnm.do_genesis()
        dev_vnm.launch()
    except Exception as e:
        print "Something went wrong during setUp. {}".format(e)
Esempio n. 8
0
    def test_missing_dependencies(self):
        vnm = None
        try:
            print "Launching validator network."
            vnm = get_default_vnm(5)
            vnm.do_genesis()
            vnm.launch()

            print "Testing limit of missing dependencies."
            test = IntKeyLoadTest()
            test.setup(vnm.urls(), 10)
            test.run(1)
            test.run_with_limit_txn_dependencies(1)
            test.validate()
        finally:
            if vnm is not None:
                vnm.shutdown(archive_name="TestIntegrationResults_1")
Esempio n. 9
0
 def setUpClass(cls):
     cls.vnm = None
     try:
         if 'TEST_VALIDATOR_URL' in os.environ:
             cls.url = os.environ['TEST_VALIDATOR_URL']
         else:
             overrides = {
                 "TransactionFamilies": ['sawtooth_xo'],
             }
             cls.vnm = get_default_vnm(5, overrides=overrides)
             cls.vnm.do_genesis()
             cls.vnm.launch()
             # the url of the initial validator
             cls.url = cls.vnm.urls()[0] + '/'
     except:
         if cls.vnm is not None:
             cls.vnm.shutdown()
             cls.vnm = None
         raise
Esempio n. 10
0
def main():
    vnm = None
    error_occurred = False
    try:
        opts = configure(sys.argv[1:])
    except Exception as e:
        print >> sys.stderr, str(e)
        sys.exit(1)

    try:
        vnm = get_default_vnm(opts['count'],
                              txnvalidator=opts['validator'],
                              overrides=opts['validator_config'],
                              log_config=opts['log_config_dict'],
                              data_dir=opts['data_dir'],
                              block_chain_archive=opts['load_blockchain'],
                              http_port=int(opts['http_port']),
                              udp_port=int(opts['port']),
                              host=opts['host'],
                              endpoint_host=opts['endpoint'])
        vnm.do_genesis()
        vnm.staged_launch()
        run_stats(vnm.urls()[0])
    except KeyboardInterrupt:
        print "\nExiting"
    except ExitError as e:
        # this is an expected error/exit, don't print stack trace -
        # the code raising this exception is expected to have printed the error
        # details
        error_occurred = True
        print "\nFailed!\nExiting: {}".format(e)
    except:
        error_occurred = True
        traceback.print_exc()
        print "\nFailed!\nExiting: {}".format(sys.exc_info()[0])

    finally:
        archive_name = None
        if opts['save_blockchain']:
            archive_name = opts['save_blockchain']
        if vnm is not None:
            vnm.shutdown(archive_name=archive_name)
Esempio n. 11
0
    def test_validator_shutdown_restart_ext(self):
        vnm = None
        print
        try:
            vnm = get_default_vnm(5)
            vnm.do_genesis()
            vnm.launch()

            keys = 10
            rounds = 2
            txn_intv = 0

            print "Testing transaction load."
            test = IntKeyLoadTest()
            urls = vnm.urls()
            self.assertEqual(5, len(urls))
            test.setup(vnm.urls(), keys)
            test.run(keys, rounds, txn_intv)
            test.validate()

            print "test validator shutdown w/ SIGINT"
            vnm.deactivate_node(2, sig='SIGINT', timeout=8, force=False)
            print 'check state of validators:'
            sit_rep(vnm.urls(), verbosity=2)

            print "sending more txns after SIGINT"
            urls = vnm.urls()
            self.assertEqual(4, len(urls))
            test.setup(urls, keys)
            test.run(keys, rounds, txn_intv)
            test.validate()

            print("relaunching removed_validator", 2)
            vnm.activate_node(2)
            print 'check state of validators:'
            sit_rep(vnm.urls(), verbosity=2)
            if is_convergent(vnm.urls(), tolerance=2, standard=5) is True:
                print "all validators are on the same chain"
            else:
                print "all validators are not on the same chain"

            print "sending more txns after relaunching validator 2"
            urls = vnm.urls()
            self.assertEqual(5, len(urls))
            test.setup(urls, keys)
            test.run(keys, rounds, txn_intv)
            test.validate()

            print "test validator shutdown w/ SIGTERM"
            vnm.deactivate_node(4, sig='SIGTERM', timeout=8, force=False)
            print 'check state of validators:'
            sit_rep(vnm.urls(), verbosity=2)

            print "sending more txns after SIGTERM"
            urls = vnm.urls()
            self.assertEqual(4, len(urls))
            test.setup(urls, keys)
            test.run(keys, rounds, txn_intv)
            test.validate()

            print("relaunching removed_validator", 4)
            vnm.activate_node(4)
            print 'check state of validators:'
            sit_rep(vnm.urls(), verbosity=2)
            if is_convergent(vnm.urls(), tolerance=2, standard=5) is True:
                print "all validators are on the same chain"
            else:
                print "all validators are not on the same chain"

            print "sending more txns after relaunching validator 4"
            urls = vnm.urls()
            self.assertEqual(5, len(urls))
            test.setup(urls, keys)
            test.run(keys, rounds, txn_intv)
            test.validate()

        finally:
            vnm.shutdown(archive_name='TestValidatorShutdown')
    def test_validator_shutdown_restart_restore_ext(self):
        print
        try:
            print "launching a validator network of 5"
            vnm = get_default_vnm(5)
            vnm.do_genesis()
            vnm.launch()

            keys = 10
            rounds = 2
            txn_intv = 0
            timeout = 5

            print "Testing transaction load."
            test = IntKeyLoadTest()
            urls = vnm.urls()
            self.assertEqual(5, len(urls))
            test.setup(vnm.urls(), keys)
            test.run(keys, rounds, txn_intv)
            test.validate()

            to = TimeOut(timeout)
            convergent = False
            with Progress("Checking for validators convergence") as p:
                while convergent is False or not to.is_timed_out():
                    time.sleep(timeout)
                    p.step()
                    convergent = is_convergent(vnm.urls(),
                                               tolerance=2,
                                               standard=5)
            self.assertTrue(convergent, "All validators are "
                            "not on the same chain.")
            print "all validators are on the same chain"
            sit_rep(vnm.urls(), verbosity=1)
            report_before_shutdown = sit_rep(vnm.urls(), verbosity=1)
            validator_report = report_before_shutdown[2]
            valid_dict_value = validator_report['Status']
            validator_blocks_shutdown = valid_dict_value['Blocks']
            print "validator_blocks", validator_blocks_shutdown

            print "turn off entire validator network"
            vnm.update(node_mat=numpy.zeros(shape=(5, 5)), timeout=8)
            # set InitialConnectivity of individual
            # node to zero before relaunching
            cfg = vnm.get_configuration(2)
            cfg['InitialConnectivity'] = 0
            vnm.set_configuration(2, cfg)
            print "relaunch validator 2"
            vnm.activate_node(2)
            report_after_relaunch = sit_rep(vnm.urls(), verbosity=1)
            validator_report = report_after_relaunch[0]
            valid_dict_value = validator_report['Status']
            validator_blocks_relaunch = valid_dict_value['Blocks']
            print "validator_blocks_relaunch", validator_blocks_relaunch

            # the length of post-shutdown validator blocks might be bigger
            # than the length of pre-shutdown validator blocks
            for i in range(0, len(validator_blocks_shutdown)):
                self.assertEqual(
                    validator_blocks_relaunch[i], validator_blocks_shutdown[i],
                    "mismatch in post-shutdown validator blocks. "
                    "Validator didn't restore fr local db")
                break
                print "relaunched validator restored from local database"

        finally:
            if vnm is not None:
                # Validator network shutting down
                vnm.shutdown(archive_name='TestValidatorShutdownRestore')
    def test_validator_shutdown_sigkill_restart_ext(self):
        print
        try:
            print "launching a validator network of 5"
            vnm = get_default_vnm(5)
            vnm.do_genesis()
            vnm.launch()

            keys = 10
            rounds = 2
            txn_intv = 0
            timeout = 5

            print "Testing transaction load."
            test = IntKeyLoadTest()
            urls = vnm.urls()
            self.assertEqual(5, len(urls))
            test.setup(vnm.urls(), keys)
            test.run(keys, rounds, txn_intv)
            test.validate()

            to = TimeOut(timeout)
            convergent = False
            with Progress("Checking for validators convergence") as p:
                while convergent is False or not to.is_timed_out():
                    time.sleep(timeout)
                    p.step()
                    convergent = is_convergent(vnm.urls(),
                                               tolerance=2,
                                               standard=5)
            self.assertTrue(convergent, "All validators are "
                                        "not on the same chain.")
            print "all validators are on the same chain"
            sit_rep(vnm.urls(), verbosity=1)
            report_before_shutdown = sit_rep(vnm.urls(), verbosity=1)
            validator_report = report_before_shutdown[4]
            valid_dict_value = validator_report['Status']
            validator_blocks_shutdown = valid_dict_value['Blocks']
            print "validator_blocks", validator_blocks_shutdown

            print "shutdown validator 4 w/ SIGKILL"
            vnm.deactivate_node(4, sig='SIGKILL', timeout=8)
            print 'check state of validators:'
            sit_rep(vnm.urls(), verbosity=2)

            print "sending more txns after SIGKILL"
            urls = vnm.urls()
            self.assertEqual(4, len(urls))
            test.setup(urls, keys)
            test.run(keys, rounds, txn_intv)
            test.validate()

            print "turn off entire validator network"
            for i in range(0, 4):
                vnm.deactivate_node(i, sig='SIGINT', timeout=8, force=False)
            print 'check state of validators after graceful shutdown:'
            sit_rep(vnm.urls(), verbosity=2)

            # set InitialConnectivity of individual
            # node to zero before relaunching
            cfg = vnm.get_configuration(4)
            cfg['InitialConnectivity'] = 0
            vnm.set_configuration(4, cfg)
            print "relaunch validator 4"
            vnm.activate_node(4)
            report_after_relaunch = sit_rep(vnm.urls(), verbosity=1)
            validator_report = report_after_relaunch[0]
            valid_dict_value = validator_report['Status']
            validator_blocks_relaunch = valid_dict_value['Blocks']
            print "validator_blocks_relaunch", validator_blocks_relaunch

            if len(validator_blocks_relaunch) == \
                    len(validator_blocks_shutdown):
                if validator_blocks_shutdown == validator_blocks_relaunch:
                    print "relaunched validator restored from local db"
            else:
                for i in range(0, len(validator_blocks_shutdown)):
                    self.assertEqual(validator_blocks_relaunch[i],
                                     validator_blocks_shutdown[i],
                                     "relaunched validator didn't"
                                     " restore fr local db")
                    break
                print "relaunched validator restored from local database"

        finally:
            if vnm is not None:
                # shutting down validator network
                vnm.shutdown(archive_name='TestValidatorShutdownRestore')