def test_reset_approval(self, token_client, token_wallet_client): # Start with some spending money from the token wallet assert token_client.balance_of(token_client.address) == 0 token_wallet_client.transfer(token_client.address, 12345 * 2) assert token_client.balance_of(token_client.address) == 24690 # Approve a client to spend up to 12345 approved_address = token_client.w3.eth.accounts[1] token_client.approve(approved_address, 12345) assert token_client.allowance(token_client.address, approved_address) == 12345 # Client spends some money, allowance goes down client = DeviseToken(private_key=TEST_KEYS[1]) client.transfer_from(token_client.address, client.address, 12340) assert token_client.allowance(token_client.address, approved_address) == 5 # client has insufficient allowance with raises(AssertionError): client.transfer_from(token_client.address, client.address, 10) # reset client allowance token_client.approve(approved_address, 12345) assert token_client.allowance(token_client.address, approved_address) == 12345 client.transfer_from(token_client.address, client.address, 100) assert token_client.allowance(token_client.address, approved_address) == 12245
def token_client(): """Devise Client fixture created using an account's private key""" client = DeviseToken(private_key=TEST_KEYS[0]) net_id = client.w3.version.network if net_id == "1": raise RuntimeError("Cowardly refusing to run tests against MainNet!!") return client
def test_transfer_from(self, token_wallet_client, token_client): # Start with some spending money from the token wallet assert token_client.balance_of(token_client.address) == 0 token_wallet_client.transfer(token_client.address, 12345) assert token_client.balance_of(token_client.address) == 12345 approved_address = token_client.w3.eth.accounts[1] token_client.approve(approved_address, 12345) approved_client = DeviseToken(private_key=TEST_KEYS[1]) approved_client.transfer_from(token_client.address, approved_address, 12345) assert token_client.balance_of(approved_address) == 12345 assert token_client.allowance(token_client.address, approved_address) == 0 # Reached allowance, should fail with raises(Exception): approved_client.transfer_from(token_client.address, approved_address, 1)