def main(): tumbler.contract._populate_empty_checkers() print "operation\t\tmean (ms)\t\tsd (ms)\t\truns" # == init =============== init_tx = tumbler.init() # == create_tumbler =============== # gen run(RUNS, '[g] create_tumbler', tumbler.create_tumbler, (token, ), None, None, aggr_vk) # check run_checker(RUNS, '[c] create_tumbler', tumbler.contract.checkers['create_tumbler'], transaction_to_solution(create_tx)) # == redeem =============== # gen run(RUNS, '[g] redeem', tumbler.redeem, (old_list, ), None, (dumps(addr), ), sigma, aggr_vk, ID) # check run_checker(RUNS, '[c] redeem', tumbler.contract.checkers['redeem'], transaction_to_solution(redeem_tx))
def test_commit(self): with auction_contract.test_service(): ## create transaction # init init_transaction = auction.init() token = init_transaction['transaction']['outputs'][0] # create auction auction_transaction = auction.create( (token, ), None, None, aggr_vk, t_commit, t_reveal, uid, v0, ov0) auction_object = auction_transaction['transaction']['outputs'][1] ## commit transaction = auction.commit( (auction_object, ), None, None, bidders[0][0], # seq bidders[0][1], # v bidders[0][2] # sigma ) ## submit transaction response = requests.post('http://127.0.0.1:5000/' + auction_contract.contract_name + '/commit', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success'])
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'])
def test(self): ## ## run service ## checker_service_process = Process( target=increment_twice_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## init ## transaction = increment_twice.init() ## ## increment ## zero = transaction['transaction']['outputs'][0] transaction = increment_twice.increment(('1', ), None, [zero]) print transaction ## ## submit transaction ## response = requests.post('http://127.0.0.1:5000/' + increment_twice_contract.contract_name + '/increment', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_request(self): with coconut_contract.test_service(): ## create transactions # init init_transaction = coconut_chainspace.init() token = init_transaction['transaction']['outputs'][0] # create instance create_transaction = coconut_chainspace.create( (token, ), None, None, q, t, n, callback, aggr_vk, ) instance = create_transaction['transaction']['outputs'][1] # request transaction = coconut_chainspace.request( (instance, ), None, None, public_m, private_m, gamma) ## submit transaction response = requests.post('http://127.0.0.1:5000/' + coconut_contract.contract_name + '/request', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success'])
def test_create_account(self): ## run service checker_service_process = Process( target=cscoin_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## create transaction # init init_transaction = cscoin.init()['transaction'] token = init_transaction['outputs'][0] # create bank account transaction = cscoin.create_account((token, ), None, None, alice_pub, None) ## submit transaction response = requests.post('http://127.0.0.1:5000/' + cscoin_contract.contract_name + '/create_account', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## stop service checker_service_process.terminate() checker_service_process.join()
def test_init(self): ## ## run service ## checker_service_process = Process( target=sensor_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## transaction_dict = sensor.init() ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:5000/' + sensor_contract.contract_name + '/init', json=transaction_to_solution(transaction_dict)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_create_petition(self): ## run service checker_service_process = Process( target=petition_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## create transaction # init init_transaction = petition.init() token = init_transaction['transaction']['outputs'][0] # initialise petition transaction = petition.create_petition( (token, ), None, None, UUID, options, priv_owner, pub_owner, vvk) ## 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']) ## stop service checker_service_process.terminate() checker_service_process.join()
def test_create(self): with coconut_contract.test_service(): ## create transaction # init init_transaction = coconut.init() token = init_transaction['transaction']['outputs'][0] # create instance transaction = coconut.create( (token,), None, None, q, t, n, callback, vvk, sig ) ## submit transaction response = requests.post( 'http://127.0.0.1:5000/' + coconut_contract.contract_name + '/create', json=transaction_to_solution(transaction) ) self.assertTrue(response.json()['success'])
def test_submit_bid(self): ## ## run service ## checker_service_process = Process( target=energy_bidding_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## # generate crypto params G = setup()[0] (provider_priv, provider_pub) = key_gen(setup()) # init init_transaction = energy_bidding.init() token = init_transaction['transaction']['outputs'][0] # create meter create_meter_transaction = energy_bidding.create_meter( (token, ), None, None, pack(provider_pub), 'Some info about the meter.', dumps([5, 3, 5, 3, 5]), # the tariffs dumps(764) # billing period ) token = create_meter_transaction['transaction']['outputs'][0] meter = create_meter_transaction['transaction']['outputs'][1] # Submit bid transaction = energy_bidding.submit_bid((token, ), (meter, ), (dumps({ 'type': 'EBBuy', 'energy': 10, 'price': 50 }), ), pack(provider_priv)) token = bid_transaction['transaction']['outputs'][0] bid = bid_transaction['transaction']['outputs'][1] print transaction ## ## submit transaction ## response = requests.post('http://127.0.0.1:5000/' + energy_bidding_contract.contract_name + '/submit_bid', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_add_many_reading(self): ## ## run service ## checker_service_process = Process( target=smart_meter_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## # generate crypto params G = setup()[0] (provider_priv, provider_pub) = key_gen(setup()) # set init values tariffs = [5, 3, 5, 3, 5] readings = [10, 20, 30, 10, 50] openings = [G.order().random() for _ in tariffs] billing_period = 764 # init init_transaction = smart_meter.init() token = init_transaction['transaction']['outputs'][0] # create meter create_meter_transaction = smart_meter.create_meter( (token, ), None, None, pack(provider_pub), 'Some info about the meter.', dumps(tariffs), dumps(billing_period)) meter = create_meter_transaction['transaction']['outputs'][1] # add a readings transaction = {} input_obj = meter for i in range(0, len(tariffs)): transaction = smart_meter.add_reading((input_obj, ), None, None, pack(provider_priv), dumps(readings[i]), pack(openings[i])) input_obj = transaction['transaction']['outputs'][0] ## ## submit transaction ## response = requests.post('http://127.0.0.1:5000/' + smart_meter_contract.contract_name + '/add_reading', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_add_reading(self): ## ## run service ## checker_service_process = Process( target=smart_meter_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## # generate crypto params G = setup()[0] (provider_priv, provider_pub) = key_gen(setup()) # init init_transaction = smart_meter.init() token = init_transaction['transaction']['outputs'][0] # create meter create_meter_transaction = smart_meter.create_meter( (token, ), None, None, pack(provider_pub), 'Some info about the meter.', dumps([5, 3, 5, 3, 5]), # the tariffs dumps(764) # billing period ) meter = create_meter_transaction['transaction']['outputs'][1] # add a reading transaction = smart_meter.add_reading( (meter, ), None, None, pack(provider_priv), dumps(10), # the new reading pack(G.order().random()) # the opening value ) print transaction ## ## submit transaction ## response = requests.post('http://127.0.0.1:5000/' + smart_meter_contract.contract_name + '/add_reading', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_many_auth_transfer(self): ## ## run service ## checker_service_process = Process( target=bank_authenticated_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## # create alice's and bob public key num_transfers = 7 transfer_amount = 1 params = setup() (alice_priv, alice_pub) = key_gen(params) (bob_priv, bob_pub) = key_gen(params) # init init_transaction = bank_authenticated.init()['transaction'] token = init_transaction['outputs'][0] # create alice's account create_alice_account_transaction = bank_authenticated.create_account( (token, ), None, None, pack(alice_pub))['transaction'] token = create_alice_account_transaction['outputs'][0] alice_account = create_alice_account_transaction['outputs'][1] # create bob's account create_bob_account_transaction = bank_authenticated.create_account( (token, ), None, None, pack(bob_pub))['transaction'] bob_account = create_bob_account_transaction['outputs'][1] # pack transaction transaction = {} input_obj = [alice_account, bob_account] for i in range(0, num_transfers): transaction_dict = bank_authenticated.auth_transfer( input_obj, None, [dumps(transfer_amount)], pack(alice_priv)) input_obj = transaction_dict['transaction']['outputs'] ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:5000/' + bank_authenticated_contract.contract_name + '/auth_transfer', json=transaction_to_solution(transaction_dict)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_tally(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] ## submit transaction response = requests.post('http://127.0.0.1:5000/' + petition_contract.contract_name + '/tally', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success'])
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'])
def test_redeem(self): ## run service checker_service_process = Process( target=tumbler_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## create transaction # init init_transaction = tumbler.init() token = init_transaction['transaction']['outputs'][0] # initialise petition create_transaction = tumbler.create_tumbler((token, ), None, None, vvk, auth_sig) old_list = create_transaction['transaction']['outputs'][1] # some crypto # ------------------------------------ hasher = sha256() hasher.update(dumps(ID).encode('utf8')) hasher.update(dumps(merchant_addr).encode('utf8')) m = Bn.from_binary(hasher.digest()) (priv, pub) = elgamal_keygen(bp_params) (cm, c, proof_s) = prepare_blind_sign(bp_params, m, pub) enc_sigs = [ blind_sign(bp_params, ski, cm, c, pub, proof_s) for ski in sk ] (h, enc_epsilon) = zip(*enc_sigs) sigs = [(h[0], elgamal_dec(bp_params, priv, enc)) for enc in enc_epsilon] sig = aggregate_th_sign(bp_params, sigs) sig = randomize(bp_params, sig) # reveal ID and merchant addr #print(verify(bp_params, vvk, m, sig)) # ------------------------------------ # add signature to th petition transaction = tumbler.redeem( (old_list, ), None, (dumps(ID), dumps(merchant_addr)), sig, vvk, ) ## submit transaction response = requests.post('http://127.0.0.1:5000/' + tumbler_contract.contract_name + '/redeem', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## stop service checker_service_process.terminate() checker_service_process.join()
def test_init(): with hello_contract.test_service(): ## create transaction transaction = hello.init() ## submit transaction response = requests.post('http://127.0.0.1:5000/' + hello_contract.contract_name + '/init', json=transaction_to_solution(transaction)) assert response.json()['success']
def test_withdraw(self): with auction_contract.test_service(): ## create transaction # init init_transaction = auction.init() token = init_transaction['transaction']['outputs'][0] # create auction auction_transaction = auction.create( (token, ), None, None, aggr_vk, t_commit, t_reveal, uid, v0, ov0) auction_object = auction_transaction['transaction']['outputs'][1] ## commit for i in range(len(bidders)): commit_transaction = auction.commit( (auction_object, ), None, None, bidders[i][0], # seq bidders[i][1], # v bidders[i][2] # sigma ) auction_object = commit_transaction['transaction']['outputs'][ 0] ## reveal for i in range(len(bidders)): reveal_transaction = auction.reveal( (auction_object, ), None, (dumps(bidders[i][1]), ), # v bidders[i][0], # seq bidders[i][2] # sigma ) auction_object = reveal_transaction['transaction']['outputs'][ 0] ## withdraw transaction = auction.withdraw( (auction_object, ), None, (dumps(bidders[1][1]), pack(addr)), bidders[1][0], # seq bidders[1][2] # sigma ) ## submit transaction response = requests.post('http://127.0.0.1:5000/' + auction_contract.contract_name + '/withdraw', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success'])
def main(): coconut_chainspace.contract._populate_empty_checkers() print("operation\t\tmean (ms)\t\tsd (ms)\t\truns") # == create =============== # gen run(RUNS, '[g] create', coconut_chainspace.create, (token, ), None, None, q, t, n, callback, aggr_vk) # check run_checker(RUNS, '[c] create', coconut_chainspace.contract.checkers['create'], transaction_to_solution(create_tx)) # == request =============== # gen run(RUNS, '[g] request', coconut_chainspace.request, (instance, ), None, None, public_m, private_m, gamma) # check run_checker(RUNS, '[c] request', coconut_chainspace.contract.checkers['request'], transaction_to_solution(request_tx)) # == issue =============== # gen run(RUNS, '[g] issue', coconut_chainspace.issue, (coco_request, ), None, (0, ), sk[0]) # check run_checker(RUNS, '[c] issue', coconut_chainspace.contract.checkers['issue'], transaction_to_solution(issue_tx)) # == verify =============== # gen run(RUNS, '[g] verify', coconut_chainspace.verify, None, (instance, ), (dumps(public_m), ), sigma, private_m) # check run_checker(RUNS, '[c] verify', coconut_chainspace.contract.checkers['verify'], transaction_to_solution(verify_tx))
def main(): petition.contract._populate_empty_checkers() print("operation\t\tmean (ms)\t\tsd (ms)\t\truns") # == create_petition =============== # gen run(RUNS, '[g] create_petition', petition.create_petition, (token, ), None, None, UUID, options, sk_owners[0], aggr_pk_owner, t_owners, n_owners, aggr_vk) # check run_checker(RUNS, '[c] create_petition', petition.contract.checkers['create_petition'], transaction_to_solution(create_petition_tx)) # == sign =============== # gen run(RUNS, '[g] sign', petition.sign, (old_petition, old_list), None, None, d, sigma, aggr_vk, 1) # check run_checker(RUNS, '[c] sign', petition.contract.checkers['sign'], transaction_to_solution(sign_tx)) # == tally =============== # gen run(RUNS, '[g] tally', petition.tally, (old_petition, ), None, None, sk_owners[0], 0, t_owners) # check run_checker(RUNS, '[c] tally', petition.contract.checkers['tally'], transaction_to_solution(tally_tx)) # == read =============== # gen run(RUNS, '[g] read', petition.read, None, (old_petition, ), None) # check run_checker(RUNS, '[c] read', petition.contract.checkers['read'], transaction_to_solution(read_tx))
def test_issue(self): with coconut_contract.test_service(): ## create transactions # init init_transaction = coconut_chainspace.init() token = init_transaction['transaction']['outputs'][0] # create instance create_transaction = coconut_chainspace.create( (token, ), None, None, q, t, n, callback, aggr_vk, ) instance = create_transaction['transaction']['outputs'][1] # request request_transaction = coconut_chainspace.request( (instance, ), None, None, public_m, private_m, gamma) old_request = request_transaction['transaction']['outputs'][1] # issue a credential transaction = coconut_chainspace.issue((old_request, ), None, (0, ), sk[0]) old_request = transaction['transaction']['outputs'][0] ## submit transaction response = requests.post('http://127.0.0.1:5000/' + coconut_contract.contract_name + '/issue', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) # issue the other credential for i in range(1, n): transaction = coconut_chainspace.issue((old_request, ), None, (i, ), sk[i]) old_request = transaction['transaction']['outputs'][0] # some crypto - to show that this actually works # ------------------------------------ packed_sigs_tilde = loads(old_request)['sigs'] sigs_tilde = [unpack(x) for x in packed_sigs_tilde] sigs = [ unblind(params, sigma_tilde, d) for sigma_tilde in sigs_tilde ] aggr_sigma = agg_cred(params, sigs) Theta = prove_cred(params, aggr_vk, aggr_sigma, private_m) print("\n\n=================== VERIFICATION ===================\n") print(verify_cred(params, aggr_vk, Theta, public_m=public_m)) print("\n====================================================\n\n")
def test_sign(self): ## run service checker_service_process = Process( target=petition_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## 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, priv_owner, pub_owner, vvk) old_petition = create_petition_transaction['transaction']['outputs'][1] old_list = create_petition_transaction['transaction']['outputs'][2] # some crypto # ------------------------------------ (priv_signer, pub_signer) = elgamal_keygen(bp_params) m = priv_signer (cm, c, proof_s) = prepare_blind_sign(bp_params, m, pub_signer) enc_sigs = [ blind_sign(bp_params, ski, cm, c, pub_signer, proof_s) for ski in sk ] (h, enc_epsilon) = zip(*enc_sigs) sigs = [(h[0], elgamal_dec(bp_params, priv_signer, enc)) for enc in enc_epsilon] sig = aggregate_th_sign(bp_params, sigs) sig = randomize(bp_params, sig) (kappa, nu, proof_v) = show_coconut_petition(bp_params, vvk, m, UUID) #print(coconut_petition_verify(bp_params, vvk, kappa, sig, proof_v, UUID, nu)) # ------------------------------------ # add signature to th petition start = time.time() transaction = petition.sign((old_petition, old_list), None, (dumps([1, 0]), ), priv_signer, sig, vvk) end = time.time() print((end - start) * 1000) ## 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']) ## stop service checker_service_process.terminate() checker_service_process.join()
def test_hello(): with hello_contract.test_service(): init_transaction = hello.init() token = init_transaction['transaction']['outputs'][0] # create instance transaction = hello.hello((token, ), None, None) ## submit transaction response = requests.post('http://127.0.0.1:5000/' + hello_contract.contract_name + '/hello', json=transaction_to_solution(transaction)) assert response.json()['success']
def test_read_data(self): ## ## run service ## checker_service_process = Process( target=sensor_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## # init init_transaction = sensor_contract.init()['transaction'] token = init_transaction['outputs'][0] # create sensor create_sensor_transaction = sensor_contract.create_sensor( (token, ), None, None, ) sensor = create_sensor_transaction['transaction']['outputs'][1] # pack transaction add_data_transaction = sensor_contract.add_data( (sensor, ), None, [dumps([1, 2, 3])], ) # read data new_sensor = add_data_transaction['transaction']['outputs'][0] read_transaction = sensor_contract.read(None, (new_sensor, ), None) print(read_transaction['transaction']['returns']) ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:5000/' + sensor_contract.contract_name + '/read', json=transaction_to_solution(read_transaction)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_create_meter(self): ## ## run service ## checker_service_process = Process( target=energy_bidding_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## # create provider's public key (_, provider_pub) = key_gen(setup()) # init init_transaction = energy_bidding.init() token = init_transaction['transaction']['outputs'][0] # create meter transaction = energy_bidding.create_meter( (token, ), None, None, pack(provider_pub), 'Some info about the meter.', # some info about the meter dumps([5, 3, 5, 3, 5]), # the tariffs dumps(764) # the billing period ) print transaction ## ## submit transaction ## response = requests.post('http://127.0.0.1:5000/' + energy_bidding_contract.contract_name + '/create_meter', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()
def test_redeem(self): with tumbler_contract.test_service(): ## create transaction # init init_transaction = tumbler.init() token = init_transaction['transaction']['outputs'][0] # initialise petition create_transaction = tumbler.create_tumbler( (token,), None, None, aggr_vk ) old_list = create_transaction['transaction']['outputs'][1] # some crypto # ------------------------------------ ID = 10 # sequence number embedded in the credentials addr = 100 # merchant address (d, gamma) = elgamal_keygen(bp_params) private_m = [ID, addr] 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 = tumbler.redeem( (old_list,), None, (dumps(addr),), sigma, aggr_vk, ID ) ## submit transaction response = requests.post( 'http://127.0.0.1:5000/' + tumbler_contract.contract_name + '/redeem', json=transaction_to_solution(transaction) ) self.assertTrue(response.json()['success'])
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 = "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()
def test_create_tumbler(self): with tumbler_contract.test_service(): ## create transaction # init init_transaction = tumbler.init() token = init_transaction['transaction']['outputs'][0] # initialise petition transaction = tumbler.create_tumbler( (token,), None, None, aggr_vk, ) ## submit transaction response = requests.post( 'http://127.0.0.1:5000/' + tumbler_contract.contract_name + '/create_tumbler', json=transaction_to_solution(transaction) ) self.assertTrue(response.json()['success'])
def test_transfer(self): ## run service checker_service_process = Process( target=cscoin_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## create transaction # init init_transaction = cscoin.init() token = init_transaction['transaction']['outputs'][0] # create Alice's bank account create_transaction = cscoin.create_account((token, ), None, None, alice_pub, None) alice_account = create_transaction['transaction']['outputs'][1] # create Bob's bank account create_transaction = cscoin.create_account((token, ), None, None, bob_pub, callback) bob_account = create_transaction['transaction']['outputs'][1] # make transfer transaction = cscoin.transfer((alice_account, bob_account), None, (dumps(1), ), alice_priv) ## submit transaction response = requests.post('http://127.0.0.1:5000/' + cscoin_contract.contract_name + '/transfer', json=transaction_to_solution(transaction)) self.assertTrue(response.json()['success']) print("\n\n===================== ACCOUNTS =====================\n") print('No callback') print('Alice\'s balance: ' + str(loads(transaction['transaction']['outputs'][0])['balance'])) print('Bob\'s balance: ' + str(loads(transaction['transaction']['outputs'][1])['balance'])) print("\n====================================================\n\n") ## stop service checker_service_process.terminate() checker_service_process.join()
def test_create_sensor(self): ## ## run service ## checker_service_process = Process( target=sensor_contract.run_checker_service) checker_service_process.start() time.sleep(0.1) ## ## create transaction ## # init init_transaction = sensor.init()['transaction'] token = init_transaction['outputs'][0] # create bank account transaction_dict = sensor.create_sensor( (token, ), None, None, ) print(transaction_dict) ## ## submit transaction ## response = requests.post( 'http://127.0.0.1:5000/' + sensor_contract.contract_name + '/create_sensor', json=transaction_to_solution(transaction_dict)) self.assertTrue(response.json()['success']) ## ## stop service ## checker_service_process.terminate() checker_service_process.join()