def test_cap(self): price_per_token = 1000 token_value = 5 cap = token_value * 2 eth = EthTools("http://localhost:5000") eth.init_fixtures("/var/lib/takewing/tests/fixtures.json") #Tokens base_token = eth.filter(name="BaseToken").contract tether = eth.filter(name="Tether").contract #Accounts deployer = eth.filter(role="Deployer").accounts[0].address tester = eth.filter(role="Tester").accounts[0].address eth.filter(role="Tester").unlock() base_token.instance.mint(deployer, 100, transact={'from': deployer}) tether.instance.mint(tester, 100000, transact={'from': deployer}) #Crowdsale capped_crowdsale = eth.filter(name="CappedCrowdsale").contract base_token.instance.transfer(capped_crowdsale.address,100, transact={'from': deployer}) self.assertEqual(base_token.instance.balanceOf(tester), 0) self.assertEqual(tether.instance.balanceOf(deployer), 0) #Invest tether.instance.approve(capped_crowdsale.address,price_per_token * token_value, transact={'from': tester}) capped_crowdsale.instance.invest(price_per_token * token_value,tether.address, transact={'from': tester}) with self.assertRaises(ValueError): tether.instance.approve(capped_crowdsale.address,price_per_token * token_value * 2, transact={'from': tester}) capped_crowdsale.instance.invest(price_per_token * token_value * 2,tether.address, transact={'from': tester}) tether.instance.approve(capped_crowdsale.address,price_per_token * token_value, transact={'from':tester}) capped_crowdsale.instance.invest(price_per_token * token_value,tether.address, transact={'from': tester}) with self.assertRaises(ValueError): tether.instance.approve(capped_crowdsale.address,price_per_token * token_value, transact={'from': tester}) capped_crowdsale.instance.invest(price_per_token * token_value,tether.address, transact={'from': tester}) self.assertEqual(base_token.instance.balanceOf(tester), token_value * 2) self.assertEqual(tether.instance.balanceOf(deployer), price_per_token * token_value * 2)
def test_invest(self): price_per_token = 1000 token_value = 2 eth = EthTools("http://localhost:5000") eth.init_fixtures("/var/lib/takewing/tests/fixtures.json") #Tokens base_token = eth.filter(name="BaseToken").contract tether = eth.filter(name="Tether").contract #Accounts deployer = eth.filter(role="Deployer").accounts[0].address tester = eth.filter(role="Tester").accounts[0].address eth.filter(role="Tester").unlock() #Crowdsale crowdsale = eth.filter(name="Crowdsale").contract base_token.instance.transfer(crowdsale.address, 100, transact={'from': deployer}) self.assertEqual(base_token.instance.balanceOf(tester), 0) self.assertEqual(tether.instance.balanceOf(deployer), 0) tether.instance.approve(crowdsale.address, token_value * price_per_token, transact={'from': tester}) crowdsale.instance.invest(token_value * price_per_token, tether.address, transact={'from': tester}) self.assertEqual(base_token.instance.balanceOf(tester), token_value) self.assertEqual(tether.instance.balanceOf(deployer), token_value * price_per_token)
def test_on_pause(self): price_per_token = 1000 token_value = 2 eth = EthTools("http://localhost:5000") eth.init_fixtures("/var/lib/takewing/tests/fixtures.json") #Tokens base_token = eth.filter(name="BaseToken").contract tether = eth.filter(name="Tether").contract #Accounts deployer = eth.filter(role="Deployer").accounts[0].address tester = eth.filter(role="Tester").accounts[0].address eth.filter(role="Tester").unlock() base_token.instance.mint(deployer, 100, transact={'from': deployer}) tether.instance.mint(tester, 100000, transact={'from': deployer}) #Crowdsale pausable_crowdsale = eth.filter(name="PausableCrowdsale").contract base_token.instance.transfer(pausable_crowdsale.address,100, transact={'from': deployer}) pausable_crowdsale.instance.pause(transact={'from':deployer}) #Pause with self.assertRaises(ValueError): tether.instance.approve(pausable_crowdsale.address,token_value*price_per_token, transact={'from': tester}) pausable_crowdsale.instance.invest(token_value*price_per_token,tether.address, transact={'from': tester})
def test_user_not_in_list(self): price_per_token = 1000 token_value = 5 eth = EthTools("http://localhost:5000") eth.init_fixtures("/var/lib/takewing/tests/fixtures.json") #Tokens base_token = eth.filter(name="BaseToken").contract tether = eth.filter(name="Tether").contract #Accounts deployer = eth.filter(role="Deployer").accounts[0].address tester = eth.filter(role="Tester").accounts[0].address eth.filter(role="Tester").unlock() #Whitelist whitelist_crowdsale = eth.filter(name="WhitelistedCrowdsale").contract base_token.instance.transfer(whitelist_crowdsale.address,100, transact={'from': deployer}) with self.assertRaises(ValueError): tether.instance.approve(whitelist_crowdsale.address,price_per_token*token_value, transact={'from': tester}) whitelist_crowdsale.instance.invest(price_per_token*token_value,tether.address, transact={'from': tester})