Esempio n. 1
0
 def test_money_transfer(self):
     balanceNodeOwnerB = utils.get_balance_from_db(conf["1"]["dbHost"],
                                                   conf["1"]["dbName"],
                                                   conf["1"]["login"],
                                                   conf["1"]["pass"],
                                                   conf["2"]["keyID"])
     commisionWallet = utils.get_commission_wallet(conf["1"]["dbHost"],
                                                   conf["1"]["dbName"],
                                                   conf["1"]["login"],
                                                   conf["1"]["pass"], 1)
     balanceCommisionB = utils.get_balance_from_db(conf["1"]["dbHost"],
                                                   conf["1"]["dbName"],
                                                   conf["1"]["login"],
                                                   conf["1"]["pass"],
                                                   commisionWallet)
     tokenRunner, uid = utils.get_uid(conf["2"]["url"])
     signature = sign(keys["key2"], uid)
     pubRunner = get_public_key(keys["key2"])
     balanceRunnerB = utils.get_balance_from_db_by_pub(
         conf["1"]["dbHost"], conf["1"]["dbName"], conf["1"]["login"],
         conf["1"]["pass"], pubRunner)
     dataRunner = utils.login(conf["2"]["url"], keys["key2"], 0)
     tokenRunner = dataRunner["jwtToken"]
     data = {"Recipient": "0005-2070-2000-0006-0200", "Amount": "1000"}
     res = utils.call_contract(conf["2"]["url"], keys["key2"],
                               "MoneyTransfer", data, tokenRunner)
     hash = res["hash"]
     result = utils.txstatus(conf["2"]["url"],
                             conf["2"]["time_wait_tx_in_block"], hash,
                             tokenRunner)
     balanceRunnerMust = balanceRunnerB - 1000
     balanceRunnerB = utils.get_balance_from_db_by_pub(
         conf["1"]["dbHost"], conf["1"]["dbName"], conf["1"]["login"],
         conf["1"]["pass"], pubRunner)
Esempio n. 2
0
def prepare_tx(url, prKey, entity, jvtToken, data):
    heads = {'Authorization': jvtToken}
    resp = requests.post(url + '/prepare/' + entity, data=data, headers=heads)
    result = resp.json()
    print(result)
    signature = sign(prKey, result['forsign'])
    return {
        "time": result['time'],
        "signature": signature,
        "reqID": result['request_id']
    }
Esempio n. 3
0
def prepare_multi_tx(url, prKey, entity, jvtToken, data):
    urlToCont = url + '/prepareMultiple/'
    heads = {'Authorization': jvtToken}
    request = {
        "token_ecosystem": "",
        "max_sum": "",
        "payover": "",
        "signed_by": "",
        "contracts": data
    }
    resp = requests.post(urlToCont,
                         data={"data": json.dumps(request)},
                         headers=heads)
    result = resp.json()
    forsigns = result['forsign']
    signatures = [sign(prKey, forsign) for forsign in forsigns]
    return {
        "time": result['time'],
        "signatures": signatures,
        "reqID": result['request_id']
    }
Esempio n. 4
0
def login(url, prKey, role=0, ecosystem=1):
    token, uid = get_uid(url)
    signature = sign(prKey, "LOGIN" + uid)
    pubkey = get_public_key(prKey)
    fullToken = 'Bearer ' + token
    data = {
        'pubkey': pubkey,
        'signature': signature,
        "role_id": role,
        "ecosystem": ecosystem
    }
    head = {'Authorization': fullToken}
    resp = requests.post(url + '/login', params=data, headers=head)
    res = resp.json()
    print(res)
    result = {}
    result["uid"] = uid
    result["jwtToken"] = 'Bearer ' + res["token"]
    result["pubkey"] = pubkey
    result["address"] = res["address"]
    result["key_id"] = res["key_id"]
    return result
Esempio n. 5
0
if __name__ == "__main__":
    if len(sys.argv) < 6:
        print("Error: Too few parameters")
        exit(1)
    else:
        prKey1 = sys.argv[1]
        host1 = sys.argv[2]
        httpPort1 = sys.argv[3]
        id = sys.argv[4]
        pub = sys.argv[5]
        amount = sys.argv[6]
        baseUrl = "http://" + host1 + ":" + httpPort1 + "/api/v2"
        respUid = requests.get(baseUrl + '/getuid')
        resultGetuid = respUid.json()

        signature = sign(prKey1, "LOGIN" + resultGetuid['uid'])
        print("sign----", signature, "prKey---", prKey1, "data---",
              "LOGIN" + resultGetuid['uid'])

        fullToken = 'Bearer ' + resultGetuid['token']
        respLogin = requests.post(baseUrl + '/login',
                                  params={
                                      'pubkey': get_public_key(prKey1),
                                      'signature': signature
                                  },
                                  headers={'Authorization': fullToken})
        resultLogin = respLogin.json()
        address = resultLogin["address"]
        timeToken = resultLogin["refresh"]
        jvtToken = 'Bearer ' + resultLogin["token"]
Esempio n. 6
0
 def test_deactive_contract_with_err(self):
     if funcs.is_contract_activated(conf["2"]["url"], "CostContract",
                                    self.token) == True:
         self.deactivateContract()
     walletId = funcs.get_activated_wallet(conf["2"]["url"], "CostContract",
                                           self.token)
     balanceContractOwnerB = utils.get_balance_from_db(
         conf["1"]["dbHost"], conf["1"]["dbName"], conf["1"]["login"],
         conf["1"]["pass"], walletId)
     balanceNodeOwnerB = utils.get_balance_from_db(conf["1"]["dbHost"],
                                                   conf["1"]["dbName"],
                                                   conf["1"]["login"],
                                                   conf["1"]["pass"],
                                                   conf["2"]["keyID"])
     commisionWallet = utils.get_commission_wallet(conf["1"]["dbHost"],
                                                   conf["1"]["dbName"],
                                                   conf["1"]["login"],
                                                   conf["1"]["pass"], 1)
     balanceCommisionB = utils.get_balance_from_db(conf["1"]["dbHost"],
                                                   conf["1"]["dbName"],
                                                   conf["1"]["login"],
                                                   conf["1"]["pass"],
                                                   commisionWallet)
     commission = utils.get_system_parameter(conf["1"]["dbHost"],
                                             conf["1"]["dbName"],
                                             conf["1"]["login"],
                                             conf["1"]["pass"],
                                             "commission_size")
     tokenRunner, uid = utils.get_uid(conf["2"]["url"])
     signature = sign(keys["key2"], uid)
     pubRunner = get_public_key(keys["key2"])
     balanceRunnerB = utils.get_balance_from_db_by_pub(
         conf["1"]["dbHost"], conf["1"]["dbName"], conf["1"]["login"],
         conf["1"]["pass"], pubRunner)
     dataRunner = utils.login(conf["2"]["url"], keys["key2"], 0)
     tokenRunner = dataRunner["jwtToken"]
     res = utils.call_contract(conf["2"]["url"], keys["key2"],
                               "CostContract", {"State": 0}, tokenRunner)
     time.sleep(10)
     hash = res["hash"]
     result = utils.txstatus(conf["2"]["url"],
                             conf["2"]["time_wait_tx_in_block"], hash,
                             tokenRunner)
     balanceContractOwnerA = utils.get_balance_from_db(
         conf["1"]["dbHost"], conf["1"]["dbName"], conf["1"]["login"],
         conf["1"]["pass"], walletId)
     balanceNodeOwnerA = utils.get_balance_from_db(conf["1"]["dbHost"],
                                                   conf["1"]["dbName"],
                                                   conf["1"]["login"],
                                                   conf["1"]["pass"],
                                                   conf["2"]["keyID"])
     balanceCommisionA = utils.get_balance_from_db(conf["1"]["dbHost"],
                                                   conf["1"]["dbName"],
                                                   conf["1"]["login"],
                                                   conf["1"]["pass"],
                                                   commisionWallet)
     balanceRunnerA = utils.get_balance_from_db_by_pub(
         conf["1"]["dbHost"], conf["1"]["dbName"], conf["1"]["login"],
         conf["1"]["pass"], pubRunner)
     dictValid = dict(balanceContractOwner=balanceContractOwnerA,
                      balanceNodeOwner=balanceNodeOwnerA,
                      balanceCommision=balanceCommisionA,
                      balanceRunner=balanceRunnerA)
     dictExpect = dict(balanceContractOwner=balanceContractOwnerB,
                       balanceNodeOwner=balanceNodeOwnerB,
                       balanceCommision=balanceCommisionB,
                       balanceRunner=balanceRunnerB)
     msg = "balanceContractOwnerA:" + str(balanceContractOwnerA) + "\n" +\
     "balanceContractOwnerE:" + str(balanceContractOwnerB) + "\n" +\
     "balanceNodeOwnerA:" + str(balanceNodeOwnerA) + "\n" +\
     "balanceNodeOwnerE:" + str(balanceNodeOwnerB) + "\n" +\
     "balanceCommisionA:" + str(balanceCommisionA) + "\n" +\
     "balanceCommisionE:" + str(balanceCommisionB) + "\n" +\
     "balanceRunnerA:" + str(balanceRunnerA) + "\n" +\
     "balanceRunnerE:" + str(balanceRunnerB) + "\n"
     self.assertDictEqual(dictValid, dictExpect, msg)
Esempio n. 7
0
 def test_deactive_contract(self):
     if funcs.is_contract_activated(conf["2"]["url"], "CostContract",
                                    self.token) == True:
         self.deactivateContract()
     walletId = funcs.get_activated_wallet(conf["2"]["url"], "CostContract",
                                           self.token)
     sumsBefore = utils.getUserTokenAmounts(conf["1"]["dbHost"],
                                            conf["1"]["dbName"],
                                            conf["1"]["login"],
                                            conf["1"]["pass"])
     summBefore = sum(summ[0] for summ in sumsBefore)
     bNodeBalance = self.getNodeBalances()
     tokenRunner, uid = utils.get_uid(conf["2"]["url"])
     signature = sign(keys["key2"], uid)
     pubRunner = get_public_key(keys["key2"])
     balanceRunnerB = utils.get_balance_from_db_by_pub(
         conf["1"]["dbHost"], conf["1"]["dbName"], conf["1"]["login"],
         conf["1"]["pass"], pubRunner)
     dataRunner = utils.login(conf["2"]["url"], keys["key2"], 0)
     tokenRunner = dataRunner["jwtToken"]
     res = utils.call_contract(conf["2"]["url"], keys["key2"],
                               "CostContract", {"State": 1}, tokenRunner)
     result = utils.txstatus(conf["2"]["url"],
                             conf["2"]["time_wait_tx_in_block"],
                             res["hash"], tokenRunner)
     time.sleep(10)
     node = utils.get_block_gen_node(conf["1"]["dbHost"],
                                     conf["1"]["dbName"],
                                     conf["1"]["login"], conf["1"]["pass"],
                                     result["blockid"])
     sumsAfter = utils.getUserTokenAmounts(conf["1"]["dbHost"],
                                           conf["1"]["dbName"],
                                           conf["1"]["login"],
                                           conf["1"]["pass"])
     summAfter = sum(summ[0] for summ in sumsAfter)
     aNodeBalance = self.getNodeBalances()
     nodeCommission = 141620000000000000
     platformaCommission = 4380000000000000
     commission = nodeCommission + platformaCommission
     balanceRunnerA = utils.get_balance_from_db_by_pub(
         conf["1"]["dbHost"], conf["1"]["dbName"], conf["1"]["login"],
         conf["1"]["pass"], pubRunner)
     balanceContractOwnerA = utils.get_balance_from_db(
         conf["1"]["dbHost"], conf["1"]["dbName"], conf["1"]["login"],
         conf["1"]["pass"], walletId)
     inHistory = self.isCommissionsInHistory(nodeCommission,
                                             dataRunner["key_id"],
                                             platformaCommission, node)
     if node == 0:
         dictValid = dict(balanceRunner=balanceRunnerA,
                          platformBalance=aNodeBalance[0],
                          summ=summBefore,
                          history=inHistory)
         dictExpect = dict(balanceRunner=balanceRunnerB - commission,
                           platformBalance=bNodeBalance[0] + commission,
                           summ=summAfter,
                           history=True)
     else:
         dictValid = dict(balanceRunner=balanceRunnerA,
                          platformBalance=aNodeBalance[0],
                          nodeBalance=aNodeBalance[node],
                          summ=summBefore,
                          history=inHistory)
         dictExpect = dict(balanceRunner=balanceRunnerB - commission,
                           platformBalance=bNodeBalance[0] +
                           platformaCommission,
                           nodeBalance=bNodeBalance[node] + nodeCommission,
                           summ=summAfter,
                           history=True)
     self.assertDictEqual(dictValid, dictExpect,
                          "Error in comissions run deactivated contract")
Esempio n. 8
0
    parser = argparse.ArgumentParser()

    parser.add_argument('-privKey', required=True)
    parser.add_argument('-name', required=True)
    parser.add_argument('-value', required=True)

    parser.add_argument('-httpHost', default='127.0.0.1')
    parser.add_argument('-httpPort', default='7079')

    args = parser.parse_args()

    baseUrl = "http://" + args.httpHost + ":" + args.httpPort + "/api/v2"
    respUid = requests.get(baseUrl + '/getuid')
    resultGetuid = respUid.json()

    signature = sign(args.privKey, "LOGIN" + resultGetuid['uid'])
    print("signature------------", signature)

    fullToken = 'Bearer ' + resultGetuid['token']
    respLogin = requests.post(baseUrl + '/login',
                              params={
                                  'pubkey': get_public_key(args.privKey),
                                  'signature': signature
                              },
                              headers={'Authorization': fullToken})
    resultLogin = respLogin.json()
    address = resultLogin["address"]
    timeToken = resultLogin["refresh"]
    jvtToken = 'Bearer ' + resultLogin["token"]

    print(args.name)