コード例 #1
0
    def test_init(self):
        ##
        ## run service
        ##
        checker_service_process = Process(
            target=petition_simple_contract.run_checker_service)
        checker_service_process.start()
        time.sleep(0.1)

        ##
        ## create transaction
        ##
        transaction = petition_simple.init()

        ##
        ## submit transaction
        ##
        response = requests.post('http://127.0.0.1:5000/' +
                                 petition_simple_contract.contract_name +
                                 '/init',
                                 json=transaction_to_solution(transaction))
        self.assertTrue(response.json()['success'])

        ##
        ## stop service
        ##
        checker_service_process.terminate()
        checker_service_process.join()
コード例 #2
0
    def test_add_score(self):
        ##
        ## run service
        ##
        checker_service_process = Process(target=petition_simple_contract.run_checker_service)
        checker_service_process.start()
        time.sleep(0.1)

        ##
        ## create transaction
        ##
        # set up info and options
        UUID = "1234"
        info = "Petition UUID -- Here goes what the petition is about."
        options = ['YES', 'NO']

        # init
        init_transaction = petition_simple.init()
        token = init_transaction['transaction']['outputs'][0]

        # initialise vote (all votes are zero)
        create_petition_transaction = petition_simple.create_petition(
            (token,),
            None,
            None,
            UUID,
            info,
            dumps(options)
        )
        old_petition = create_petition_transaction['transaction']['outputs'][1]

        # add a score
        transaction = petition_simple.add_score(
            (old_petition,),
            None,
            (dumps([1, 0]),)
        )

        ##
        ## submit transaction
        ##
        response = requests.post(
            'http://127.0.0.1:5000/' + petition_simple_contract.contract_name + '/add_score', json=transaction_to_solution(transaction)
        )
        self.assertTrue(response.json()['success'])

        ##
        ## stop service
        ##
        checker_service_process.terminate()
        checker_service_process.join()