def test_Web3Wallet(): private_key_str = '0x9c75ed156c45b5a365bde30dc8871e9c6d2b5dc08a7b47572e0354afb859cb15' wallet1 = web3wallet.Web3Wallet(private_key=private_key_str) wallet2 = web3wallet.Web3Wallet(private_key=private_key_str) assert wallet1.address == wallet2.address assert wallet1.private_key == wallet2.private_key assert wallet1.account.private_key == wallet2.account.private_key
def testSendEth(): _web3 = web3util.get_web3() network = web3util.get_network() #wallet1 should have got ETH from ganache startup (see deploy.py) private_key1 = web3util.confFileValue(network, 'TEST_PRIVATE_KEY1') wallet1 = web3wallet.Web3Wallet(private_key1) orig_bal1_base = wallet1.ETH_base() print("orig bal1 = %s" % web3util.fromBase18(orig_bal1_base)) assert orig_bal1_base > web3util.toBase18(1.0) #wallet2 should have 0 ETH wallet2 = web3wallet.randomWeb3Wallet() orig_bal2_base = wallet2.ETH_base() print("orig bal2 = %s" % web3util.fromBase18(orig_bal2_base)) assert orig_bal2_base == 0 #wallet1 gives wallet2 1.0 ETH sent_base = web3util.toBase18(1.0) wallet1.sendEth(wallet2.address, sent_base) new_bal1_base = wallet1.ETH_base() new_bal2_base = wallet2.ETH_base() print("new bal1 = %s" % web3util.fromBase18(new_bal1_base)) print("new bal2 = %s" % web3util.fromBase18(new_bal2_base)) assert new_bal2_base == sent_base assert (orig_bal1_base - sent_base*1.1) < new_bal1_base < (orig_bal1_base - sent_base)
def test_ETHbalance1(): _web3 = web3util.get_web3() network = web3util.get_network() private_key = web3util.confFileValue(network, 'TEST_PRIVATE_KEY1') wallet = web3wallet.Web3Wallet(private_key) assert wallet.ETH_base() > 1.0 #should have got ETH from ganache startup assert wallet.ETH_base() == _web3.eth.getBalance(wallet.address)
def __init__(self, symbol: str): #A random wallet won't have ETH for gas fees. So, use # 'TEST_PRIVATE_KEY1' which got funds in ganache startup (see deploy.py) network = web3util.get_network() key1 = web3util.confFileValue(network, 'TEST_PRIVATE_KEY1') self._web3_wallet = web3wallet.Web3Wallet(key1) factory = dtfactory.DTFactory() token_address = factory.createToken('', symbol, symbol, constants.HUGEINT, self._web3_wallet) self._token = datatoken.Datatoken(token_address)
def __init__(self, USD: float = 0.0, OCEAN: float = 0.0, private_key=None): if private_key is None: self._web3wallet = web3wallet.randomWeb3Wallet() else: self._web3wallet = web3wallet.Web3Wallet(private_key) #Give the new wallet ETH to pay gas fees (but don't track otherwise) self._web3wallet.fundFromAbove(toBase18(0.01)) #magic number #USD self._USD = USD #lump in ETH too #OCEAN globaltokens.mintOCEAN(address=self._web3wallet.address, value_base=toBase18(OCEAN)) self._cached_OCEAN_base: typing.Union[int, None] = None #for speed #amount self._total_USD_in: float = USD self._total_OCEAN_in: float = OCEAN