def test_buy_tokens_ledger_mock(self, ledger_mock): """Tests that we can buy Devise tokens with Ledger nano s HD wallet""" test_client_account = "0xA1C2684B68A98c9636FC22F3B4E4332eF35A2408" ledger = DeviseClient(account=test_client_account, auth_type='ledger') old_tokens_balance = ledger.dvz_balance ether_amount = .5 vrs = ( 28, 2182719146884808318922065288388701482638595064358707342427872633327257261733, 46015294558581125017244029788985539581305398667308472361832920130849890183038) ledger_mock().sign.return_value = vrs ledger_mock().get_account_index.return_value = 0 ledger.w3.eth.estimateGas = MagicMock(return_value=400000) ledger.w3.eth.generateGasPrice = MagicMock(return_value=100000000000) ledger.buy_eth_worth_of_tokens(ether_amount) assert ledger_mock().get_account_index.call_count == 1 ledger_mock().get_account_index.assert_has_calls([call(test_client_account)]) assert ledger_mock().sign.call_count == 1 ledger_mock().sign.assert_has_calls([call( b"\xea\x80\x85\x17Hv\xe8\x00\x83\x07\xa1 \x94\t\x87\xee'By\xc6pu5\xfa\xee\x0e!5\x85\x7f<2\x91\x88\x06\xf0[Y\xd3\xb2\x00\x00\x80", account_index=0)]) currentRate = ledger._token_sale_contract.functions.getCurrentRate().call() new_tokens_balance = ledger.dvz_balance tokens_purchased = ether_amount * currentRate assert new_tokens_balance == old_tokens_balance + tokens_purchased
def test_get_all_bidders(self, client, master_node): """Tests that we can get all the bids in the price auction""" # Add leptons lepton_hash = hashlib.sha1('hello world 1'.encode('utf8')).hexdigest() master_node.add_lepton(lepton_hash, None, 1.5123456789123456789) # client 1 buys and provisions tokens client.buy_eth_worth_of_tokens(2) client.provision(16000) assert client.get_all_bidders() == [] # client 1 leases the blockchain lease_prc = 1000 client.lease_all(lease_prc, 1) assert client.get_all_bidders() == [ {'address': '0xA1C2684B68A98c9636FC22F3B4E4332eF35A2408', 'limit_price': lease_prc, 'requested_seats': 1}] assert client.get_all_bidders(active=True) == [ {'address': '0xA1C2684B68A98c9636FC22F3B4E4332eF35A2408', 'limit_price': lease_prc, 'requested_seats': 1}] # Add another bidder leases the blockchain client2 = DeviseClient(private_key=TEST_KEYS[2]) client2.buy_eth_worth_of_tokens(2) client2.provision(16000) client2.lease_all(lease_prc + 1, 1) assert client.get_all_bidders(active=True) == [ {'address': client.w3.eth.accounts[2], 'limit_price': lease_prc + 1, 'requested_seats': 1}, {'address': '0xA1C2684B68A98c9636FC22F3B4E4332eF35A2408', 'limit_price': lease_prc, 'requested_seats': 1}] # client 2 escrow balances drops below bid price, no longer active client2.withdraw(client2.dvz_balance_escrow) assert client.get_all_bidders(active=True) == [ {'address': '0xA1C2684B68A98c9636FC22F3B4E4332eF35A2408', 'limit_price': lease_prc, 'requested_seats': 1}]
def test_buy_tokens_keyfile_with_password(self): """Tests that we can buy Devise tokens with ethers using a local encrypted key store file""" key_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'key_file.json') client_local_keyfile = DeviseClient(key_file=key_path, password='******') old_tokens_balance = client_local_keyfile.dvz_balance ether_amount = .5 client_local_keyfile.buy_eth_worth_of_tokens(ether_amount) currentRate = client_local_keyfile._token_sale_contract.functions.getCurrentRate().call() new_tokens_balance = client_local_keyfile.dvz_balance tokens_purchased = ether_amount * currentRate assert new_tokens_balance == old_tokens_balance + tokens_purchased