Beispiel #1
0
 def test_compare_nodes(self):
     nodes = 3
     amounts1 = utils.getUserTokenAmounts(host1, db1, login1, pas1)
     amounts2 = utils.getUserTokenAmounts(host2, db2, login2, pas2)
     amounts3 = utils.getUserTokenAmounts(host3, db3, login3, pas3)
     sumAmounts = sum(amount[0] for amount in amounts1)
     self.data1 = utils.login(config1["url"], config1['private_key'], 0)
     maxBlockId1 = funcs.get_max_block_id(config1["url"],
                                          self.data1["jwtToken"])
     self.data2 = utils.login(config2["url"], config1['private_key'], 0)
     maxBlockId2 = funcs.get_max_block_id(config2["url"],
                                          self.data2["jwtToken"])
     self.data3 = utils.login(config3["url"], config1['private_key'], 0)
     maxBlockId3 = funcs.get_max_block_id(config3["url"],
                                          self.data3["jwtToken"])
     maxBlock = max(maxBlockId2, maxBlockId1, maxBlockId3)
     hash1 = utils.get_blockchain_hash(host1, db1, login1, pas1, maxBlock)
     hash2 = utils.get_blockchain_hash(host2, db2, login2, pas2, maxBlock)
     hash3 = utils.get_blockchain_hash(host3, db3, login3, pas3, maxBlock)
     node_position = utils.compare_node_positions(host1, db1, login1, pas1,
                                                  maxBlock, nodes)
     dict1 = dict(amounts=str(amounts1),
                  hash=str(hash1),
                  node_pos=str(node_position))
     dict2 = dict(amounts=str(amounts2), hash=str(hash2), node_pos="True")
     dict3 = dict(amounts=str(amounts3), hash=str(hash3), node_pos="True")
     msg = "Test three nodes is faild. contracts: \n"
     msg += str(amounts1) + str(hash1) + "\n"
     msg += str(amounts2) + str(hash2) + "\n"
     msg += str(amounts3) + str(hash3) + str(node_position) + "\n"
     msg += "Amounts summ: " + str(sumAmounts)
     self.assertDictEqual(dict1, dict2, msg)
     self.assertDictEqual(dict1, dict3, msg)
 def test_block_chain(self):
     fullConfig = config.getNodeConfig()
     nodes = len(fullConfig)
     config1 = fullConfig["1"]
     config2 = fullConfig["2"]
     db1 = config1["dbName"]
     db2 = config2["dbName"]
     login1 = config1["login"]
     login2 = config2["login"]
     pas1 = config1["pass"]
     pas2 = config2["pass"]
     host1 = config1["dbHost"]
     host2 = config2["dbHost"]
     ts_count = 30
     self.data1 = utils.login(config1["url"], config1['private_key'], 0)
     i = 1
     amountsB = utils.getUserTokenAmounts(host1, db1, login1, pas1)
     sumAmountsBefore = sum(amount[0] for amount in amountsB)
     while i < ts_count:
         contName = self.create_contract(
             config1["url"],
             config1['private_key'],
         )
         i = i + 1
         time.sleep(1)
     time.sleep(120)
     count_contracts1 = utils.getCountDBObjects(host1, db1, login1,
                                                pas1)["contracts"]
     count_contracts2 = utils.getCountDBObjects(host2, db2, login2,
                                                pas2)["contracts"]
     amounts1 = utils.getUserTokenAmounts(host1, db1, login1, pas1)
     amounts2 = utils.getUserTokenAmounts(host2, db2, login2, pas2)
     sumAmounts = sum(amount[0] for amount in amounts1)
     maxBlockId1 = funcs.get_max_block_id(config1["url"],
                                          self.data1["jwtToken"])
     self.data2 = utils.login(config2["url"], config1['private_key'], 0)
     maxBlockId2 = funcs.get_max_block_id(config2["url"],
                                          self.data2["jwtToken"])
     maxBlock = max(maxBlockId2, maxBlockId1)
     hash1 = utils.get_blockchain_hash(host1, db1, login1, pas1, maxBlock)
     hash2 = utils.get_blockchain_hash(host2, db2, login2, pas2, maxBlock)
     node_position = utils.compare_node_positions(host1, db1, login1, pas1,
                                                  maxBlock, nodes)
     dict1 = dict(count_contract=count_contracts1,
                  amounts=str(amounts1),
                  summ=str(sumAmounts),
                  hash=str(hash1),
                  node_pos=str(node_position))
     dict2 = dict(count_contract=count_contracts2,
                  amounts=str(amounts2),
                  summ=str(sumAmountsBefore),
                  hash=str(hash2),
                  node_pos="True")
     msg = "Test two_nodes is faild. contracts: \n"
     msg += str(count_contracts1) + str(amounts1) + str(hash1) + str(
         node_position) + "\n"
     msg += str(count_contracts2) + str(amounts1) + str(hash1) + str(
         node_position) + "\n"
     msg += "Amounts summ: " + str(sumAmounts)
     self.assertDictEqual(dict1, dict2, msg)
Beispiel #3
0
 def test_max_block_user_tx(self):
     max_block_user_tx = utils.get_system_parameter(conf["1"]["dbHost"],
                                                    conf["1"]["dbName"],
                                                    conf["1"]["login"],
                                                    conf["1"]["pass"],
                                                    "max_block_user_tx")
     self.update_sys_param("max_block_user_tx", "1")
     time.sleep(30)
     i = 1
     while i < 10:
         name = "cont" + utils.generate_random_name()
         code = "contract " + name + contract["limits"]["code"]
         data = {
             "Wallet": "",
             "Value": code,
             "ApplicationId": 1,
             "Conditions": "true"
         }
         utils.call_contract(conf["2"]["url"], conf["1"]['private_key'],
                             "NewContract", data, token)
         i = i + 1
     time.sleep(5)
     maxBlock = funcs.get_max_block_id(conf["2"]["url"], token)
     print("maxBlock = ", maxBlock)
     isOneOrTwo = utils.isCountTxInBlock(conf["2"]["dbHost"],
                                         conf["2"]["dbName"],
                                         conf["2"]["login"],
                                         conf["2"]["pass"], maxBlock, 1)
     self.update_sys_param("max_block_user_tx ", str(max_block_user_tx))
     time.sleep(30)
     self.assertTrue(isOneOrTwo,
                     "One of block contains more than 2 transaction")
Beispiel #4
0
 def test_rollback1(self):
     # Install apps
     self.impApp("admin", url, prKey, token)
     self.impApp("system_parameters", url, prKey, token)
     print("Start rollback test")
     self.addNotification()
     self.addBinary()
     tableName = self.addUserTable()
     self.insertToUserTable(tableName)
     # Save to file block id for rollback
     rollbackBlockId = funcs.get_max_block_id(url, token)
     file = os.path.join(os.getcwd(), "blockId.txt")
     with open(file, 'w') as f:
         f.write(str(rollbackBlockId))
     # Save to file user table name
     tableNameWithPrefix = "1_" + tableName
     file = os.path.join(os.getcwd(), "userTableName.txt")
     with open(file, 'w') as f:
         f.write(tableNameWithPrefix)
     # Save to file user table state
     dbUserTableInfo = utils.getUserTableState(host, db, login, pas,
                                               tableNameWithPrefix)
     file = os.path.join(os.getcwd(), "dbUserTableState.json")
     with open(file, 'w') as fconf:
         json.dump(dbUserTableInfo, fconf)
     # Save to file all tables state
     dbInformation = utils.getCountDBObjects(host, db, login, pas)
     file = os.path.join(os.getcwd(), "dbState.json")
     with open(file, 'w') as fconf:
         json.dump(dbInformation, fconf)
     self.updateUserTable(tableName)
     self.money_transfer()
     contract, code = self.create_contract("")
     self.edit_contract(contract, code)
     self.activate_contract(contract)
     self.deactivate_contract(contract)
     param = self.new_parameter()
     self.edit_parameter(param)
     menu = self.new_menu()
     self.edit_menu()
     self.append_memu()
     self.new_page()
     self.edit_page()
     self.append_page()
     self.new_block()
     self.edit_block()
     table = self.new_table()
     self.edit_table(table)
     column = self.new_column(table)
     self.edit_column(table, column)
     lang = self.new_lang()
     langs = funcs.call_get_api(url + "/list/languages", {}, token)
     self.edit_lang(langs["count"], lang)
     sign = self.new_sign()
     self.edit_sign(sign)
     self.impApp("basic", url, prKey, token)
     time.sleep(20)
Beispiel #5
0
 def get_load_time(self, url, token, maxBlock):
     maxTime = 12000
     sec = 1
     while sec < maxTime:
         maxBlockId1 = funcs.get_max_block_id(url, token)
         if maxBlockId1 == maxBlock:
             print("Time: ", sec)
             return {"time": sec, "blocks": maxBlockId1}
         else:
             sec = sec + 1
     return {"time": 12001, "blocks": maxBlockId1}
Beispiel #6
0
 def test_compare_blocks(self):
     conf = config.getNodeConfig()
     time.sleep(30)
     data2 = utils.login(conf['2']['url'], conf['1']['private_key'], 0)
     maxBlockId2 = funcs.get_max_block_id(conf["2"]["url"],
                                          data2["jwtToken"])
     data1 = utils.login(conf['1']['url'], conf['1']['private_key'], 0)
     res = self.get_load_time(conf["1"]["url"], data1["jwtToken"],
                              maxBlockId2)
     msg = "All " + str(maxBlockId2) +\
      " blocks doesn't load in time. Last loaded block is " + str(res['blocks'])
     self.assertLess(res['time'], 12000, msg)