Beispiel #1
0
 def NewContract(self):
     code, name = utils.generate_name_and_code("")
     data = {"Value": code, "ApplicationId": 1, "Conditions": "true"}
     sign = utils.prepare_tx(url, prKey, "NewContract", token, data)
     dataContract = {"time": sign['time'], "signature": sign["signature"]}
     self.client.post("/contract/" + sign["reqID"],
                      dataContract,
                      headers={"Authorization": token},
                      name="NewContract")
 def create_contract(self, url, prKey):
     code, name = utils.generate_name_and_code("")
     data = {
         'Wallet': '',
         'Value': code,
         "ApplicationId": 1,
         'Conditions': "ContractConditions(`MainCondition`)"
     }
     resp = utils.call_contract(url, prKey, "NewContract", data,
                                self.data1["jwtToken"])
     return name
Beispiel #3
0
 def create_contract(self, data):
     code, name = utils.generate_name_and_code("")
     dataC = {}
     if data == "":
         dataC = {
             "Wallet": '',
             "ApplicationId": 1,
             "Value": code,
             "Conditions": "ContractConditions(\"MainCondition\")"
         }
     else:
         dataC = data
     res = self.call("NewContract", dataC)
     return name, code
Beispiel #4
0
 def updateUserTable(self, tableName):
     # create contarct, wich updated record in created table
     body = """
     {
     data {}
     conditions {}
     action {
         DBUpdate("%s", 1, {MyName: "update", ver_on_null: "update"})
         }
     }
     """ % tableName
     code, name = utils.generate_name_and_code(body)
     data = {"Value": code, "ApplicationId": 1, "Conditions": "true"}
     res = self.call("NewContract", data)
     # call contarct, wich added record in created table
     res = self.call(name, data)
Beispiel #5
0
 def addNotification(self):
     # create contract, wich added record in notifications table
     body = """
     {
     data {}
     conditions {}
     action {
         DBInsert("notifications", {"recipient->member_id": "-8399130570195839739",
                                     "notification->type": 1,
                                     "notification->header": "Message header",
                                     "notification->body": "Message body"}) 
         }
     }
     """
     code, name = utils.generate_name_and_code(body)
     data = {
         "Wallet": '',
         "ApplicationId": 1,
         "Value": code,
         "Conditions": "ContractConditions(\"MainCondition\")"
     }
     res = self.call("NewContract", data)
     self.assertGreater(int(res["blockid"]), 0,
                        "BlockId is not generated: " + str(res))
     # change permission for notifications table
     dataEdit = {}
     dataEdit["Name"] = "notifications"
     dataEdit["InsertPerm"] = "true"
     dataEdit["UpdatePerm"] = "true"
     dataEdit["ReadPerm"] = "true"
     dataEdit["NewColumnPerm"] = "true"
     res = self.call("EditTable", dataEdit)
     # call contract, wich added record in notification table
     res = self.call(name, "")
     # change permission for notifications table back
     dataEdit = {}
     dataEdit["Name"] = "notifications"
     dataEdit[
         "InsertPerm"] = "ContractAccess(\"Notifications_Single_Send_map\",\"Notifications_Roles_Send_map\")"
     dataEdit["UpdatePerm"] = "ContractConditions(\"MainCondition\")"
     dataEdit["ReadPerm"] = "ContractConditions(\"MainCondition\")"
     dataEdit["NewColumnPerm"] = "ContractConditions(\"MainCondition\")"
     res = self.call("EditTable", dataEdit)
Beispiel #6
0
 def test_get_avatar_without_login(self):
     # add file in binaries
     name = "file_" + utils.generate_random_name()
     path = os.path.join(os.getcwd(), "fixtures", "image2.jpg")
     with open(path, 'rb') as f:
         file = f.read()
     files = {'Data': file}
     data = {"Name": name, "ApplicationId": 1, "DataMimeType": "image/jpeg"}
     resp = utils.call_contract_with_files(url, prKey, "UploadBinary", data,
                                           files, token)
     res = self.assertTxInBlock(resp, token)
     self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
     # find last added file
     asserts = ["count"]
     res = self.check_get_api("/list/binaries", "", asserts)
     lastRec = res["count"]
     # find founder ID
     asserts = ["list"]
     res = self.check_get_api("/list/members", "", asserts)
     # iterating response elements
     i = 0
     founderID = ""
     while i < len(res['list']):
         if res['list'][i]['member_name'] == "founder":
             founderID = res['list'][i]['id']
         i += 1
     # change column permissions
     data = {
         "TableName": "members",
         "Name": "image_id",
         "UpdatePerm": "true",
         "ReadPerm": "true"
     }
     res = self.call("EditColumn", data)
     self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
     # update members table
     code = """
            {
                data{}
                conditions{}
                action{
                    DBUpdate("members", %s, {image_id: "%s"})
                }
            }
            """ % (founderID, lastRec)
     code, name = utils.generate_name_and_code(code)
     data = {"Value": code, "ApplicationId": 1, "Conditions": "true"}
     res = self.call("NewContract", data)
     self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
     data = {}
     resp = utils.call_contract(url, prKey, name, data, token)
     res = self.assertTxInBlock(resp, token)
     self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
     # rollback changes column permissions
     data = {
         "TableName": "members",
         "Name": "image_id",
         "UpdatePerm": "ContractAccess(\"Profile_Edit\")",
         "ReadPerm": "true"
     }
     res = self.call("EditColumn", data)
     self.assertGreater(int(res), 0, "BlockId is not generated: " + res)
     # test
     ecosystemID = "1"
     avaURL = url + "/avatar/" + ecosystemID + "/" + founderID
     resp = requests.get(avaURL)
     msg = "Content-Length is different!"
     self.assertIn("71926", str(resp.headers["Content-Length"]), msg)