コード例 #1
0
    def test_transactions_reg(self):
        client_cli.main(args=["--name", "user",
                              "--script",
                              os.path.join(self.script_path,
                                           "reg_transactions"),
                              "--echo",
                              "--url",
                              self.url])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNotNone(state.n2i("//user", 'Participant'))
        self.assertIsNotNone(state.n2i("//user/user/account",
                                       'Account'))
        self.assertIsNotNone(state.n2i("//user/asset-type/currency",
                                       'AssetType'))
        self.assertIsNotNone(state.n2i("//user/asset-type/good",
                                       'AssetType'))
        self.assertIsNotNone(state.n2i("//user/asset/currency/USD",
                                       'Asset'))
        self.assertIsNotNone(state.n2i("//user/asset/good/paper",
                                       'Asset'))
        self.assertIsNotNone(state.n2i("//user/user/holding/currency/USD",
                                       'Holding'))
        self.assertIsNotNone(state.n2i("//user/user/holding/good/paper",
                                       'Holding'))
        self.assertIsNotNone(state.n2i("//user/user/holding/token",
                                       'Holding'))
        self.assertIsNotNone(state.n2i("//user/user/holding/good/paper",
                                       'Holding'))
        self.assertIsNotNone(state.n2i("//user/user/holding/good/paper",
                                       'Holding'))
コード例 #2
0
 def transactions_exchange(self):
     client_cli.main(args=[
         "--name", "alice", "--script",
         os.path.join(self.script_path, "ex_alice_transactions"), "--echo",
         "--url", self.url
     ])
     state = mktplace_state.MarketPlaceState(self.url)
     state.fetch()
     self.assertEqual(
         state.State[state.n2i("//bob/USD", "Holding")]['count'], 1024)
     self.assertEqual(
         state.State[state.n2i("//bob/batches/choc_chip001",
                               "Holding")]['count'], 12)
     self.assertEqual(
         state.State[state.n2i("//bob/holding/token", "Holding")]['count'],
         1)
     self.assertEqual(
         state.State[state.n2i("//bob/jars/choc_chip", "Holding")]['count'],
         0)
     self.assertEqual(
         state.State[state.n2i("//alice/USD", "Holding")]['count'], 976)
     self.assertEqual(
         state.State[state.n2i("//alice/holding/token",
                               "Holding")]['count'], 1)
     self.assertEqual(
         state.State[state.n2i("//alice/jars/choc_chip",
                               "Holding")]['count'], 12)
コード例 #3
0
    def test_transactions_reg(self):
        client_cli.main(args=[
            "--name", "user", "--script",
            os.path.join(self.script_path, "reg_transactions"), "--echo",
            "--url", self.url
        ])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNotNone(state.n2i("//user", 'Participant'))
        self.assertIsNotNone(state.n2i("//user/user/account", 'Account'))
        self.assertIsNotNone(
            state.n2i("//user/asset-type/currency", 'AssetType'))
        self.assertIsNotNone(state.n2i("//user/asset-type/good", 'AssetType'))
        self.assertIsNotNone(state.n2i("//user/asset/currency/USD", 'Asset'))
        self.assertIsNotNone(state.n2i("//user/asset/good/paper", 'Asset'))
        self.assertIsNotNone(
            state.n2i("//user/user/holding/currency/USD", 'Holding'))
        self.assertIsNotNone(
            state.n2i("//user/user/holding/good/paper", 'Holding'))
        self.assertIsNotNone(state.n2i("//user/user/holding/token", 'Holding'))
        self.assertIsNotNone(
            state.n2i("//user/user/holding/good/paper", 'Holding'))
        self.assertIsNotNone(
            state.n2i("//user/user/holding/good/paper", 'Holding'))
コード例 #4
0
    def test_scenario_b(self):

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(state.n2i("//BANK-trader"))
        self.assertIsNotNone(state.n2i("//BANK-trader/USD"))
        self.assertIsNotNone(state.n2i("//BANK-trader/paper"))
        self.assertIsNotNone(state.n2i("//BANK-dealer"))
        self.assertIsNotNone(state.n2i("//BANK-dealer/USD"))
        self.assertIsNotNone(state.n2i("//BANK-dealer/paper"))

        self.assertIn("count", state.State[state.n2i("//BANK-trader/USD")])
        self.assertIn("count", state.State[state.n2i("//BANK-trader/paper")])
        self.assertIn("count", state.State[state.n2i("//BANK-dealer/USD")])
        self.assertIn("count", state.State[state.n2i("//BANK-dealer/paper")])

        trader_usd = state.State[state.n2i("//BANK-trader/USD")]["count"]
        trader_paper = state.State[state.n2i("//BANK-trader/paper")]["count"]
        dealer_usd = state.State[state.n2i("//BANK-dealer/USD")]["count"]
        dealer_paper = state.State[state.n2i("//BANK-dealer/paper")]["count"]

        client_cli.main(
            args=["--name", "BANK-trader",
                  "--script",
                  os.path.join(self.scenarios_path,
                               "scenario_b_1_trader"),
                  "--echo",
                  "--url",
                  self.url
                  ])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(state.n2i("//BANK-trader/offer-b"))

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

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertEquals(state.State[state.n2i("//BANK-trader/USD")]["count"],
                          trader_usd - 99388)
        self.assertEquals(state.State[state.n2i("//BANK-dealer/USD")]["count"],
                          dealer_usd + 99388)
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/paper")]["count"],
            trader_paper + 1)
        self.assertEquals(
            state.State[state.n2i("//BANK-dealer/paper")]["count"],
            dealer_paper - 1)
コード例 #5
0
 def test_transactions_exchange(self):
     client_cli.main(args=["--name", "user",
                           "--script",
                           os.path.join(self.script_path,
                                        "ex_transactions"),
                           "--echo",
                           "--url",
                           self.url])
コード例 #6
0
    def test_scenario_b(self):

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(state.n2i("//BANK-trader"))
        self.assertIsNotNone(state.n2i("//BANK-trader/USD"))
        self.assertIsNotNone(state.n2i("//BANK-trader/paper"))
        self.assertIsNotNone(state.n2i("//BANK-dealer"))
        self.assertIsNotNone(state.n2i("//BANK-dealer/USD"))
        self.assertIsNotNone(state.n2i("//BANK-dealer/paper"))

        self.assertIn("count", state.State[state.n2i("//BANK-trader/USD")])
        self.assertIn("count", state.State[state.n2i("//BANK-trader/paper")])
        self.assertIn("count", state.State[state.n2i("//BANK-dealer/USD")])
        self.assertIn("count", state.State[state.n2i("//BANK-dealer/paper")])

        trader_usd = state.State[state.n2i("//BANK-trader/USD")]["count"]
        trader_paper = state.State[state.n2i("//BANK-trader/paper")]["count"]
        dealer_usd = state.State[state.n2i("//BANK-dealer/USD")]["count"]
        dealer_paper = state.State[state.n2i("//BANK-dealer/paper")]["count"]

        client_cli.main(
            args=["--name", "BANK-trader",
                  "--script",
                  os.path.join(self.scenarios_path,
                               "scenario_b_1_trader"),
                  "--echo",
                  "--url",
                  self.url])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(state.n2i("//BANK-trader/offer-b"))

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

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertEquals(state.State[state.n2i("//BANK-trader/USD")]["count"],
                          trader_usd - 99388)
        self.assertEquals(state.State[state.n2i("//BANK-dealer/USD")]["count"],
                          dealer_usd + 99388)
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/paper")]["count"],
            trader_paper + 1)
        self.assertEquals(
            state.State[state.n2i("//BANK-dealer/paper")]["count"],
            dealer_paper - 1)
コード例 #7
0
    def test_scenario_a(self):

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(state.n2i("//BANK-trader", 'Participant'))
        self.assertIsNotNone(state.n2i("//BANK-trader/USD", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-trader/paper", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-agent", 'Participant'))
        self.assertIsNotNone(state.n2i("//BANK-agent/USD", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-agent/paper", 'Holding'))
        self.assertEquals(state.State[state.n2i("//BANK-trader/USD",
                                                'Holding')]["count"], 1000000)
        self.assertEquals(state.State[state.n2i("//BANK-agent/USD",
                                                'Holding')]["count"], 1000000)
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/paper",
                                  'Holding')]["count"], 10)
        self.assertEquals(
            state.State[state.n2i("//BANK-agent/paper",
                                  'Holding')]["count"], 10)

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

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNotNone(state.n2i("//BANK-trader/offer-a",
                                       'ExchangeOffer'))

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

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertEquals(state.State[state.n2i("//BANK-trader/USD",
                                                'Holding')]["count"], 900612)
        self.assertEquals(state.State[state.n2i("//BANK-agent/USD",
                                                'Holding')]["count"], 1099388)
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/paper",
                                  'Holding')]["count"], 11)
        self.assertEquals(
            state.State[state.n2i("//BANK-agent/paper",
                                  "Holding")]["count"], 9)
コード例 #8
0
    def test_scenario_a(self):

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(state.n2i("//BANK-trader", 'Participant'))
        self.assertIsNotNone(state.n2i("//BANK-trader/USD", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-trader/paper", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-agent", 'Participant'))
        self.assertIsNotNone(state.n2i("//BANK-agent/USD", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-agent/paper", 'Holding'))
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/USD", 'Holding')]["count"],
            1000000)
        self.assertEquals(
            state.State[state.n2i("//BANK-agent/USD", 'Holding')]["count"],
            1000000)
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/paper", 'Holding')]["count"],
            10)
        self.assertEquals(
            state.State[state.n2i("//BANK-agent/paper", 'Holding')]["count"],
            10)

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

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNotNone(
            state.n2i("//BANK-trader/offer-a", 'ExchangeOffer'))

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

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/USD", 'Holding')]["count"],
            900612)
        self.assertEquals(
            state.State[state.n2i("//BANK-agent/USD", 'Holding')]["count"],
            1099388)
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/paper", 'Holding')]["count"],
            11)
        self.assertEquals(
            state.State[state.n2i("//BANK-agent/paper", "Holding")]["count"],
            9)
コード例 #9
0
    def transactions_unr(self):
        client_cli.main(args=[
            "--name", "alice", "--script",
            os.path.join(self.script_path, "unr_alice_transactions"), "--echo",
            "--url", self.url
        ])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNone(state.n2i("//alice", 'Participant'))
        self.assertIsNone(state.n2i("//alice/jars/choc_chip", "Holding"))
        self.assertIsNone(state.n2i("//alice/USD", "Holding"))
        self.assertIsNone(state.n2i("//alice/holding/token", "Holding"))
        self.assertIsNone(state.n2i("//alice/account", "Account"))
コード例 #10
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:
                vnm_config = defaultValidatorConfig.copy()
                if 'mktplace.transactions.market_place' not in \
                        vnm_config['TransactionFamilies']:
                    vnm_config['TransactionFamilies'].append(
                        'mktplace.transactions.market_place')
                cls.vnm = ValidatorNetworkManager(http_port=9500,
                                                  udp_port=9600,
                                                  cfg=vnm_config)
                cls.vnm.launch_network(5)
                # 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
コード例 #11
0
    def transactions_unr(self):
        client_cli.main(args=["--name", "alice",
                              "--script",
                              os.path.join(self.script_path,
                                           "unr_alice_transactions"),
                              "--echo",
                              "--url",
                              self.url])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNone(state.n2i("//alice", 'Participant'))
        self.assertIsNone(state.n2i("//alice/jars/choc_chip",
                                    "Holding"))
        self.assertIsNone(state.n2i("//alice/USD",
                                    "Holding"))
        self.assertIsNone(state.n2i("//alice/holding/token",
                                    "Holding"))
        self.assertIsNone(state.n2i("//alice/account", "Account"))
コード例 #12
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
コード例 #13
0
 def test_transactions_unr_dangling_ref(self):
     import sys
     from StringIO import StringIO
     saved_stdout = sys.stdout
     try:
         out = StringIO()
         sys.stdout = out
         client_cli.main(args=[
             "--name", "user", "--script",
             os.path.join(self.script_path, "unr_transactions"), "--echo",
             "--url", self.url
         ])
         output = out.getvalue().strip()
         self.assertFalse(
             output.find("An error occurred processing "
                         "unr --name /user/liability/currency/USD") == -1)
         self.assertFalse(
             output.find("An error occurred processing "
                         "unr --name /user/holding/currency/USD") == -1)
         self.assertFalse(
             output.find("An error occurred processing "
                         "unr --name /user/holding/token") == -1)
         self.assertFalse(
             output.find("An error occurred processing "
                         "unr --name /asset/currency/USD") == -1)
         self.assertFalse(
             output.find("An error occurred processing "
                         "unr --name /asset/good/paper") == -1)
         self.assertFalse(
             output.find("An error occurred processing "
                         "unr --name /asset-type/currency") == -1)
         self.assertFalse(
             output.find("An error occurred processing "
                         "unr --name /asset-type/good") == -1)
         self.assertFalse(
             output.find("An error occurred processing "
                         "unr --name /user/account") == -1)
         self.assertFalse(
             output.find("An error occurred processing "
                         "unr --name //user") == -1)
     finally:
         sys.stdout = saved_stdout
コード例 #14
0
 def test_transactions_unr_dangling_ref(self):
     import sys
     from StringIO import StringIO
     saved_stdout = sys.stdout
     try:
         out = StringIO()
         sys.stdout = out
         client_cli.main(args=["--name", "user",
                               "--script",
                               os.path.join(self.script_path,
                                            "unr_transactions"),
                               "--echo",
                               "--url",
                               self.url])
         output = out.getvalue().strip()
         self.assertFalse(output.find("An error occurred processing "
                          "unr --name /user/liability/currency/USD")
                          == -1)
         self.assertFalse(output.find("An error occurred processing "
                          "unr --name /user/holding/currency/USD")
                          == -1)
         self.assertFalse(output.find("An error occurred processing "
                          "unr --name /user/holding/token")
                          == -1)
         self.assertFalse(output.find("An error occurred processing "
                          "unr --name /asset/currency/USD")
                          == -1)
         self.assertFalse(output.find("An error occurred processing "
                          "unr --name /asset/good/paper")
                          == -1)
         self.assertFalse(output.find("An error occurred processing "
                          "unr --name /asset-type/currency")
                          == -1)
         self.assertFalse(output.find("An error occurred processing "
                          "unr --name /asset-type/good")
                          == -1)
         self.assertFalse(output.find("An error occurred processing "
                                      "unr --name /user/account") == -1)
         self.assertFalse(output.find("An error occurred processing "
                                      "unr --name //user") == -1)
     finally:
         sys.stdout = saved_stdout
コード例 #15
0
 def transactions_exchange(self):
     client_cli.main(args=["--name", "alice",
                           "--script",
                           os.path.join(self.script_path,
                                        "ex_alice_transactions"),
                           "--echo",
                           "--url",
                           self.url])
     state = mktplace_state.MarketPlaceState(self.url)
     state.fetch()
     self.assertEqual(
         state.State[state.n2i(
             "//bob/USD", "Holding")]['count'], 1024)
     self.assertEqual(
         state.State[state.n2i(
             "//bob/batches/choc_chip001", "Holding")]['count'], 12)
     self.assertEqual(
         state.State[state.n2i(
             "//bob/holding/token", "Holding")]['count'], 1)
     self.assertEqual(
         state.State[state.n2i(
             "//bob/jars/choc_chip",
             "Holding"
         )]['count'], 0)
     self.assertEqual(
         state.State[state.n2i(
             "//alice/USD",
             "Holding"
         )]['count'],
         976)
     self.assertEqual(
         state.State[state.n2i(
             "//alice/holding/token",
             "Holding"
         )]['count'],
         1)
     self.assertEqual(
         state.State[state.n2i(
             "//alice/jars/choc_chip",
             "Holding"
         )]['count'],
         12)
コード例 #16
0
    def test_transactions_unr(self):
        client_cli.main(args=[
            "--name", "user", "--script",
            os.path.join(self.script_path, "unr_transactions"), "--echo",
            "--url", self.url
        ])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNone(state.n2i("//user"))
        self.assertIsNone(state.n2i("//user/user/account"))
        self.assertIsNone(state.n2i("//user/asset-type/currency"))
        self.assertIsNone(state.n2i("//user/asset-type/good"))
        self.assertIsNone(state.n2i("//user/asset/currency/USD"))
        self.assertIsNone(state.n2i("//user/asset/good/paper"))
        self.assertIsNone(state.n2i("//user/user/holding/currency/USD"))
        self.assertIsNone(state.n2i("//user/user/holding/good/paper"))
        self.assertIsNone(state.n2i("//user/user/holding/token"))
        self.assertIsNone(state.n2i("//user/user/holding/good/paper"))
        self.assertIsNone(state.n2i("//user/user/holding/good/paper"))
コード例 #17
0
    def transactions_reg(self):
        client_cli.main(args=[
            '--name', 'mkt', '--script',
            os.path.join(self.script_path, 'reg_mkt_transactions'), '--echo',
            '--url', self.url
        ])

        client_cli.main(args=[
            "--name", "alice", "--script",
            os.path.join(self.script_path, "reg_alice_transactions"), "--echo",
            "--url", self.url
        ])

        client_cli.main(args=[
            "--name", "bob", "--script",
            os.path.join(self.script_path, "reg_bob_transactions"), "--echo",
            "--url", self.url
        ])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNotNone(state.n2i("//alice", 'Participant'))
        self.assertIsNotNone(state.n2i("//mkt", 'Participant'))
        self.assertIsNotNone(state.n2i("//bob", 'Participant'))
        self.assertIsNotNone(state.n2i("//alice/account", 'Account'))
        self.assertIsNotNone(
            state.n2i("//mkt/asset-type/currency", 'AssetType'))
        self.assertIsNotNone(state.n2i("//mkt/asset-type/cookie", 'AssetType'))
        self.assertIsNotNone(state.n2i("//mkt/asset/currency/USD", 'Asset'))

        self.assertIsNotNone(state.n2i("//alice/USD", 'Holding'))
        self.assertIsNotNone(state.n2i("//alice/jars/choc_chip", 'Holding'))
        self.assertIsNotNone(state.n2i("//alice/holding/token", 'Holding'))
        self.assertIsNotNone(state.n2i("//bob/USD", "Holding"))
        self.assertIsNotNone(state.n2i("//bob/jars/choc_chip", "Holding"))
コード例 #18
0
    def test_transactions_unr(self):
        client_cli.main(args=["--name", "user",
                              "--script",
                              os.path.join(self.script_path,
                                           "unr_transactions"),
                              "--echo",
                              "--url",
                              self.url])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNone(state.n2i("//user"))
        self.assertIsNone(state.n2i("//user/user/account"))
        self.assertIsNone(state.n2i("//user/asset-type/currency"))
        self.assertIsNone(state.n2i("//user/asset-type/good"))
        self.assertIsNone(state.n2i("//user/asset/currency/USD"))
        self.assertIsNone(state.n2i("//user/asset/good/paper"))
        self.assertIsNone(state.n2i("//user/user/holding/currency/USD"))
        self.assertIsNone(state.n2i("//user/user/holding/good/paper"))
        self.assertIsNone(state.n2i("//user/user/holding/token"))
        self.assertIsNone(state.n2i("//user/user/holding/good/paper"))
        self.assertIsNone(state.n2i("//user/user/holding/good/paper"))
コード例 #19
0
    def setUpClass(cls):
        cls.vnm = None
        try:
            cls.url = "http://localhost:8800"

            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
コード例 #20
0
    def transactions_reg(self):
        client_cli.main(args=['--name', 'mkt',
                              '--script',
                              os.path.join(self.script_path,
                                           'reg_mkt_transactions'),
                              '--echo', '--url',
                              self.url])

        client_cli.main(args=["--name", "alice",
                              "--script",
                              os.path.join(self.script_path,
                                           "reg_alice_transactions"),
                              "--echo",
                              "--url",
                              self.url])

        client_cli.main(args=["--name", "bob",
                              "--script",
                              os.path.join(self.script_path,
                                           "reg_bob_transactions"),
                              "--echo",
                              "--url",
                              self.url])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertIsNotNone(state.n2i("//alice", 'Participant'))
        self.assertIsNotNone(state.n2i("//mkt", 'Participant'))
        self.assertIsNotNone(state.n2i("//bob", 'Participant'))
        self.assertIsNotNone(state.n2i("//alice/account",
                                       'Account'))
        self.assertIsNotNone(state.n2i("//mkt/asset-type/currency",
                                       'AssetType'))
        self.assertIsNotNone(state.n2i("//mkt/asset-type/cookie",
                                       'AssetType'))
        self.assertIsNotNone(state.n2i("//mkt/asset/currency/USD",
                                       'Asset'))

        self.assertIsNotNone(state.n2i("//alice/USD",
                                       'Holding'))
        self.assertIsNotNone(state.n2i("//alice/jars/choc_chip",
                                       'Holding'))
        self.assertIsNotNone(state.n2i("//alice/holding/token",
                                       'Holding'))
        self.assertIsNotNone(state.n2i("//bob/USD", "Holding"))
        self.assertIsNotNone(state.n2i("//bob/jars/choc_chip", "Holding"))
コード例 #21
0
    def test_scenario_d(self):

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(state.n2i("//BANK-trader", 'Participant'))
        self.assertIsNotNone(state.n2i("//BANK-trader/USD", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-trader/paper", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-agent", 'Participant'))
        self.assertIsNotNone(state.n2i("//BANK-agent/USD", "Holding"))
        self.assertIsNotNone(state.n2i("//BANK-agent/paper", 'Holding'))

        self.assertIn("count", state.State[state.n2i("//BANK-trader/USD",
                                                     'Holding')])
        self.assertIn("count", state.State[state.n2i("//BANK-trader/paper",
                                                     "Holding")])
        self.assertIn("count", state.State[state.n2i("//BANK-agent/USD",
                                                     'Holding')])
        self.assertIn("count", state.State[state.n2i("//BANK-agent/paper",
                                                     "Holding")])

        trader_usd = state.State[state.n2i("//BANK-trader/USD",
                                           'Holding')]["count"]
        trader_paper = state.State[state.n2i("//BANK-trader/paper",
                                             'Holding')]["count"]
        agent_usd = state.State[state.n2i("//BANK-agent/USD",
                                          'Holding')]["count"]
        agent_paper = state.State[state.n2i("//BANK-agent/paper",
                                            'Holding')]["count"]

        client_cli.main(args=[
            "--name", "BANK-trader", "--script",
            os.path.join(self.scenarios_path, "scenario_d_1_trader"), "--echo",
            "--url", self.url
        ])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(
            state.n2i("//BANK-trader/offer-d", 'ExchangeOffer'))

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

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/USD", 'Holding')]["count"],
            trader_usd + 100000)
        self.assertEquals(
            state.State[state.n2i("//BANK-agent/USD", 'Holding')]["count"],
            agent_usd - 100000)
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/paper", 'Holding')]["count"],
            trader_paper - 1)
        self.assertEquals(
            state.State[state.n2i("//BANK-agent/paper", "Holding")]["count"],
            agent_paper + 1)
コード例 #22
0
    def test_scenario_d(self):

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(state.n2i("//BANK-trader", 'Participant'))
        self.assertIsNotNone(state.n2i("//BANK-trader/USD", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-trader/paper", 'Holding'))
        self.assertIsNotNone(state.n2i("//BANK-agent", 'Participant'))
        self.assertIsNotNone(state.n2i("//BANK-agent/USD", "Holding"))
        self.assertIsNotNone(state.n2i("//BANK-agent/paper", 'Holding'))

        self.assertIn("count", state.State[state.n2i("//BANK-trader/USD",
                                                     'Holding')])
        self.assertIn("count", state.State[state.n2i("//BANK-trader/paper",
                                                     "Holding")])
        self.assertIn("count", state.State[state.n2i("//BANK-agent/USD",
                                                     'Holding')])
        self.assertIn("count", state.State[state.n2i("//BANK-agent/paper",
                                                     "Holding")])

        trader_usd = state.State[state.n2i("//BANK-trader/USD",
                                           'Holding')]["count"]
        trader_paper = state.State[state.n2i("//BANK-trader/paper",
                                             'Holding')]["count"]
        agent_usd = state.State[state.n2i("//BANK-agent/USD",
                                          'Holding')]["count"]
        agent_paper = state.State[state.n2i("//BANK-agent/paper",
                                            'Holding')]["count"]

        client_cli.main(
            args=["--name", "BANK-trader",
                  "--script",
                  os.path.join(self.scenarios_path,
                               "scenario_d_1_trader"),
                  "--echo",
                  "--url",
                  self.url])

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()

        self.assertIsNotNone(state.n2i("//BANK-trader/offer-d",
                                       'ExchangeOffer'))

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

        state = mktplace_state.MarketPlaceState(self.url)
        state.fetch()
        self.assertEquals(state.State[state.n2i("//BANK-trader/USD",
                                                'Holding')]["count"],
                          trader_usd + 100000)
        self.assertEquals(state.State[state.n2i("//BANK-agent/USD",
                                                'Holding')]["count"],
                          agent_usd - 100000)
        self.assertEquals(
            state.State[state.n2i("//BANK-trader/paper", 'Holding')]["count"],
            trader_paper - 1)
        self.assertEquals(
            state.State[state.n2i("//BANK-agent/paper", "Holding")]["count"],
            agent_paper + 1)
コード例 #23
0
 def test_transactions_exchange(self):
     client_cli.main(args=[
         "--name", "user", "--script",
         os.path.join(self.script_path, "ex_transactions"), "--echo",
         "--url", self.url
     ])
コード例 #24
0
    def setUpClass(cls):
        cls.vnm = None
        try:
            if 'TEST_VALIDATOR_URL' in os.environ:
                cls.url = os.environ['TEST_VALIDATOR_URL']
            else:
                vnm_config = defaultValidatorConfig.copy()
                if 'mktplace.transactions.market_place' not in \
                        vnm_config['TransactionFamilies']:
                    vnm_config['TransactionFamilies'].append(
                        'mktplace.transactions.market_place')
                vnm_config['LogLevel'] = 'DEBUG'
                cls.vnm = ValidatorNetworkManager(
                    httpPort=9500, udpPort=9600, cfg=vnm_config)
                cls.vnm.launch_network(5)
                # 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