Ejemplo n.º 1
0
    def call_signed_contract(self, signed_tx, pre=True, node_index=None):
        sendrawtxtask = Task(Config.BASEAPI_PATH +
                             "/rpc/sendrawtransaction.json")
        if pre:
            sendrawtxtask.request()["params"] = [signed_tx, 1]
        else:
            sendrawtxtask.request()["params"] = [signed_tx]

        if node_index != None:
            sendrawtxtask.data()["NODE_INDEX"] = node_index

        (result,
         response) = TaskRunner.run_single_task(sendrawtxtask, True, False)

        sendrawtxtask.data()["RESPONSE"] = response

        if not response is None and ("result" in response and "Result"
                                     in response["result"]) and not isinstance(
                                         response["result"]["Result"], list):
            response["result"]["Result String"] = HexToByte(
                response["result"]["Result"]).decode('iso-8859-1')

        logger.print("[ CALL CONTRACT ] " +
                     json.dumps(sendrawtxtask.data(), indent=4))

        return (result, response)
Ejemplo n.º 2
0
    def test_1(self):
        logger.open("TestNode.log", "TestNode")
        result = False
        try:
            node_i = 7
            task = Task("tasks/transfer.json")
            nodeaddress = Config.NODES[node_i]["address"]
            task.data()["NODE_INDEX"] = node_i
            task.data()["REQUEST"]["Params"]["params"][1]["value"][0][
                "value"] = script_hash_bl_reserver(
                    base58_to_address(nodeaddress))
            task.data()["REQUEST"]["Params"]["params"][1]["value"][1][
                "value"] = script_hash_bl_reserver(
                    base58_to_address(nodeaddress))
            task.data(
            )["REQUEST"]["Params"]["params"][1]["value"][2]["value"] = "1000"
            (result, response) = call_contract(task, twice=True)
            if not result:
                raise Error("call contract error")

            result = pause(
                "please check you next step, then put '1' or '0' in you command window.\n '1' is ok, '0' is not ok"
            )
            result = int(result)
        except Exception as e:
            print(e)
            print(e.msg)
        logger.close(result)
Ejemplo n.º 3
0
def getMaxBlockChangeView():
    getbalance = Task("../utils/baseapi/rpc/getstorage.json")
    contract_address = "0200000000000000000000000000000000000000"
    key = "79626674436f6e666967"
    getbalance.data()["REQUEST"]["params"] = [contract_address, key]
    (result, response) = run_single_task(getbalance, True, False)
    return int(response["result"]["ont"])
Ejemplo n.º 4
0
 def test_main(self):
     logger.open("TestConsensus1.log", "TestConsensus1")
     try:
         #step 1
         txHash = ""
         task1 = Task("../utils/api/requests/rpc/getblock.json")
         (result, response) = run_single_task(task1)
         print(response["result"]["Hash"])
         #step 2
         txHash = response["result"]["Hash"]
         task2 = Task("../utils/api/requests/rpc/getblock.json")
         task2.data()["REQUEST"]["params"][0] = txHash
         (result, response) = run_single_task(task2)
         if not result:
             raise Error("send transaction error")
     except Exception as e:
         print(e.msg)
     logger.close(result)
Ejemplo n.º 5
0
    def test_main(self):
        logger.open("TestConsensus1.log", "TestConsensus1")
        try:
            #step 1 put
            task1 = Task("tasks/invoke_put.json")
            (result, response) = call_contract(task1)
            if not result:
                raise Error("error")

            #step 2 确认区块生成并包含该交易
            txHash = response["result"]["Hash"]
            task2 = Task("../utils/baseapi/rpc/getblock.json")
            task2.data()["REQUEST"]["params"][0] = txHash
            (result, response) = run_single_task(task2)
            if not result:
                raise Error("send transaction error")
        except Exception as e:
            print(e.msg)
        logger.close(result)
Ejemplo n.º 6
0
def getbalance_ont(wallet_address):
    getbalance = Task("../utils/baseapi/rpc/getbalance.json")
    getbalance.data()["REQUEST"]["params"] = [wallet_address]
    (result, response) = run_single_task(getbalance, True, False)
    return int(response["result"]["ont"])
Ejemplo n.º 7
0
 def getblockcount(self, node_index=None):
     task = Task(Config.BASEAPI_PATH + "/rpc/getblockcount.json")
     if node_index != None:
         task.data()["NODE_INDEX"] = node_index
     return run_single_task(task)