Esempio n. 1
0
 def test_transfer(self):
     f = faucets.random()
     contract = deploy(contracts['Coin'], faucet = f)
     pk = fresh.private_key()
     v = random.randint(0, 1000)
     contract.functions.transfer(address(pk), v).transact({ 'from': f })
     b = contract.functions.balanceOf(address(pk)).call()
     self.assertEqual(b, v)
    def test_reject_incorrect_private_key(self):
        v = random.randint(1, 1000000000)
        faucets.ether(self.fwd.address, v)
        beneficiary = fresh.address()

        # check the initial balances
        self.assertEqual(w3.eth.getBalance(self.fwd.address), v)
        self.assertEqual(w3.eth.getBalance(beneficiary), 0)

        # try calling the contract with an incorrect private key
        with self.assertRaises(ValueError):
            self.fwd(
                target=beneficiary,
                value=v,
            ).sign(fresh.private_key()).transact(faucets.random())

        # check the final balances
        self.assertEqual(w3.eth.getBalance(self.fwd.address), v)
        self.assertEqual(w3.eth.getBalance(beneficiary), 0)
 def setUp(self):
     self.pk = fresh.private_key()
     self.fwd = self.deploy(address(self.pk))
Esempio n. 4
0
 def test_fresh_address_has_no_tokens(self):
     contract = deploy(contracts['Coin'])
     pk = fresh.private_key()
     b = contract.functions.balanceOf(address(pk)).call()
     self.assertEqual(b, 0)
Esempio n. 5
0
 def test_fresh_private_key_with_balance(self):
     w = w3.toWei(random.randint(1, 1000), 'gwei')
     pk = fresh.private_key(balance = w)
     b = w3.eth.getBalance(address(pk))
     self.assertEqual(b, w)
Esempio n. 6
0
 def test_fresh_private_key(self):
     pk = fresh.private_key()
     b = w3.eth.getBalance(address(pk))
     self.assertEqual(b, 0)