Пример #1
0
    def test_create_petition(self):
        with petition_contract.test_service():
            ## create transaction
            # init
            init_transaction = petition.init()
            token = init_transaction['transaction']['outputs'][0]

            # initialise petition
            transaction = petition.create_petition(
                (token,),
                None,
                None,
                UUID,
                options,
                sk_owners[0],
                aggr_pk_owner,
                t_owners,
                n_owners,
                aggr_vk
            )

            ## submit transaction
            response = requests.post(
                'http://127.0.0.1:5000/' + petition_contract.contract_name 
                + '/create_petition', json=transaction_to_solution(transaction)
            )
            self.assertTrue(response.json()['success'])
Пример #2
0
    def test_init(self):
        with petition_contract.test_service():
            ## create transaction
            transaction = petition.init()

            ## submit transaction
            response = requests.post(
                'http://127.0.0.1:5000/' + petition_contract.contract_name 
                + '/init', json=transaction_to_solution(transaction)
            )
            self.assertTrue(response.json()['success'])
Пример #3
0
    def test_sign(self):
        with petition_contract.test_service():
            # create transaction
            # init
            init_transaction = petition.init()
            token = init_transaction['transaction']['outputs'][0]

            # initialise petition
            create_petition_transaction = petition.create_petition(
                (token,),
                None,
                None,
                UUID,
                options,
                sk_owners[0],
                aggr_pk_owner,
                t_owners,
                n_owners,
                aggr_vk
            )
            old_petition = create_petition_transaction['transaction']['outputs'][1]
            old_list = create_petition_transaction['transaction']['outputs'][2]

            # some crypto to get the credentials
            # ------------------------------------
            (d, gamma) = elgamal_keygen(bp_params)
            private_m = [d]
            Lambda = prepare_blind_sign(bp_params, gamma, private_m)
            sigs_tilde = [blind_sign(bp_params, ski, gamma, Lambda) for ski in sk]
            sigs = [unblind(bp_params, sigma_tilde, d) for sigma_tilde in sigs_tilde]
            sigma = agg_cred(bp_params, sigs)
            # ------------------------------------

            # add signature to th petition
            transaction = petition.sign(
                (old_petition, old_list),
                None,
                None,
                d,
                sigma,
                aggr_vk,
                1
            )

            ## submit transaction
            response = requests.post(
                'http://127.0.0.1:5000/' + petition_contract.contract_name 
                + '/sign', json=transaction_to_solution(transaction)
            )
            self.assertTrue(response.json()['success'])
Пример #4
0
    def test_read(self):
        with petition_contract.test_service():
            # create transaction
            # init
            init_transaction = petition.init()
            token = init_transaction['transaction']['outputs'][0]

            # initialise petition
            create_petition_transaction = petition.create_petition(
                (token,),
                None,
                None,
                UUID,
                options,
                sk_owners[0],
                aggr_pk_owner,
                t_owners,
                n_owners,
                aggr_vk
            )
            old_petition = create_petition_transaction['transaction']['outputs'][1]
            old_list = create_petition_transaction['transaction']['outputs'][2]

            # add signature to the petition
            for i in range(3):
                # some crypto to get the credentials
                # ------------------------------------
                (d, gamma) = elgamal_keygen(bp_params)
                private_m = [d]
                Lambda = prepare_blind_sign(bp_params, gamma, private_m)
                sigs_tilde = [blind_sign(bp_params, ski, gamma, Lambda) for ski in sk]
                sigs = [unblind(bp_params, sigma_tilde, d) for sigma_tilde in sigs_tilde]
                sigma = agg_cred(bp_params, sigs)
                # ------------------------------------

                sign_transaction = petition.sign(
                    (old_petition, old_list),
                    None,
                    None,
                    d,
                    sigma,
                    aggr_vk,
                    1 # vote
                )
                old_petition = sign_transaction['transaction']['outputs'][0]
                old_list = sign_transaction['transaction']['outputs'][1]

            # tally
            for i in range(t_owners):
                transaction = petition.tally(
                    (old_petition,),
                    None,
                    None,
                    sk_owners[i],
                    i,
                    t_owners
                )
                old_petition = transaction['transaction']['outputs'][0]


            # read
            transaction = petition.read(
                None,
                (old_petition,),
                None
            )

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

            print("\n\n==================== OUTCOME ====================\n")
            print('OUTCOME: ', loads(transaction['transaction']['returns'][0]))
            print("\n===================================================\n\n")