ConsenSysMesh / singulardtv-contracts

19 stars 16 forks source link

Exceptions should be asserted #52

Closed ethers closed 8 years ago

ethers commented 8 years ago

Exceptions should be asserted. For example, if fund does not have throw an exception, the except clause isn't run.

https://github.com/ConsenSys/singulardtv-contracts/blob/master/tests/test_successful_funding.py#L105-L109

       # Backer 1 starts funding, but doesn't send enough money to buy a share, transaction fails.
        try:
            self.crowdfunding_contract.fund(value=ETH_VALUE_PER_SHARE - 1, sender=keys[BACKER_1])
        except TransactionFailed:
            self.assertEqual(self.token_contract.balanceOf(accounts[BACKER_1]), 0)

The test should assert that fund does always throw an exception for the test case above. The syntax might be something like:

with pytest.raises(exceptions.InvalidTransaction):
  self.crowdfunding_contract.fund(value=ETH_VALUE_PER_SHARE - 1, sender=keys[BACKER_1])
Georgi87 commented 8 years ago

Added (unittest assertion) in 7e6f2a786aca359fa2a172f799587ab06b2a236d