How to use get_account method in localstack

Best Python code snippet using localstack_python

test_unit.py

Source:test_unit.py Github

copy

Full Screen

...10 return deployCTKtoken("Company")11#Fund accouts12def test_FundMe():13 if network.show_active() == "development":14 accounts[0].transfer(get_account("JH"), "5 ether")15 accounts[1].transfer(get_account("RH"), "5 ether")16 accounts[2].transfer(get_account("AA"), "5 ether")17 accounts[3].transfer(get_account("VR"), "5 ether")18 else:19 pytest.skip("only for local testing")20# Checks state of smart contract on deployment21def test_DeploymentState(sc):22 errors = []23 24 if not sc.vaultContract() == defaultOperators[0]:25 errors.append("vaultContract was not set correctly on deployment")26 if not sc.administrator() == defaultOperators[1]:27 errors.append("administrator was not set correctly on deployment")28 if not sc.defaultOperators() == defaultOperators:29 errors.append("defaultOperators were not set correctly on deployment")30 if not sc.totalSupply() == initial_supply:31 errors.append("total supply was not set correctly on deployment")32 if not sc.balanceOf(sc.vaultContract()) == initial_supply:33 errors.append("initial supply was not set correctly on deployment")34 if sc.paused():35 errors.append("paused flag should be false on deployment")36 if sc.whitelistEnabled():37 errors.append("whitelistEnabled flag should be false on deployment")38 # assert no error message has been registered39 assert not errors40# Mint tokens to Vault41def test_MintTokens(sc):42 tokens_to_add = Web3.toWei(1000, "ether")43 if network.show_active() == "development":44 with brownie.reverts("Money printer for the Fed goes brrrr, but not for you. You are not an operator."):45 mintTokensToVault(tokens_to_add,"AA", sc)46 mintTokensToVault(tokens_to_add,"RH", sc)47 assert sc.balanceOf(sc.vaultContract()) == initial_supply + tokens_to_add, "tokens were not minted to the vault correctly"48 mintTokensToVault(tokens_to_add,"JH", sc)49 assert sc.balanceOf(sc.vaultContract()) == initial_supply + 2 * tokens_to_add, "tokens were not minted to the vault correctly"50 assert sc.totalSupply() == initial_supply + 2 * tokens_to_add, "Incorrect total supply"51# Send tokens to individual wallets52def test_vaultContractSendIndividual(sc):53 amount_to_send = Web3.toWei(1000, "ether")54 if network.show_active() == "development":55 with brownie.reverts("Sneaky, but not smart. Only the admin or vault can perform this action!"):56 sendTokensToIndividualAddress(get_account("RH"), amount_to_send, "AA", sc) 57 58 sendTokensToIndividualAddress(get_account("AA"), amount_to_send, "RH", sc)59 assert sc.balanceOf(sc.vaultContract()) == sc.totalSupply() - amount_to_send, "Incorrect balance of vaultContract"60 assert sc.balanceOf(get_account("AA")) == amount_to_send, "Incorrect balance of recipient"61 62 sendTokensToIndividualAddress(get_account("AA"), amount_to_send, "JH", sc)63 assert sc.balanceOf(sc.vaultContract()) == sc.totalSupply() - 2 * amount_to_send, "Incorrect balance of vaultContract"64 assert sc.balanceOf(get_account("AA")) == 2 * amount_to_send, "Incorrect balance of recipient"65# Send tokens to multiple addresses66def test_vaultContractSendMultiple(sc):67 if network.show_active() == "development":68 with brownie.reverts("Sneaky, but not smart. Only the admin or vault can perform this action!"):69 sendTokensToMultipleAddresses([get_account("RH"), get_account("JH")], brownie.convert.to_uint(sc.totalSupply()/4), "AA", sc)70 71 with brownie.reverts("Insufficient tokens"):72 sendTokensToMultipleAddresses([get_account("RH"), get_account("AA")], brownie.convert.to_uint(sc.totalSupply()/2) + 1, "JH", sc)73 sendTokensToMultipleAddresses([get_account("RH"), get_account("AA")], brownie.convert.to_uint(sc.totalSupply()/4), "RH", sc)74 assert sc.balanceOf(sc.vaultContract()) == brownie.convert.to_uint(sc.totalSupply()/2)75 assert sc.balanceOf(get_account("RH")) == brownie.convert.to_uint(sc.totalSupply()/4)76 assert sc.balanceOf(get_account("AA")) == brownie.convert.to_uint(sc.totalSupply()/4)77 sendTokensToMultipleAddresses([get_account("RH"), get_account("AA")], brownie.convert.to_uint(sc.totalSupply()/4), "JH", sc)78 assert sc.balanceOf(sc.vaultContract()) == 079 assert sc.balanceOf(get_account("RH")) == brownie.convert.to_uint(sc.totalSupply()/2)80 assert sc.balanceOf(get_account("AA")) == brownie.convert.to_uint(sc.totalSupply()/2)81# Request Payout82def test_RequestPayout(sc):83 amount_to_send = Web3.toWei(1000, "ether")84 sendTokensToIndividualAddress(get_account("AA"), amount_to_send, "JH", sc)85 requestPayout_tx = requestPayout(amount_to_send, "", "AA", sc)86 assert requestPayout_tx.events["Payout"]["from"] == get_account("AA")87 assert requestPayout_tx.events["Payout"]["amount"] == amount_to_send88# Operator Send89def test_OperatorSend(sc):90 amount_to_send = Web3.toWei(1000, "ether")91 sendTokensToIndividualAddress(get_account("AA"), amount_to_send, "JH", sc)92 if network.show_active() == "development":93 with brownie.reverts("You are not the boss of me. You are not the boss of anyone. Only an operator can move funds."):94 operatorSend(get_account("AA"), sc.vaultContract(), amount_to_send, "AA", sc)95 96 with brownie.reverts("Watch yourself! An operator can only send tokens to the vaultContract."):97 operatorSend(get_account("AA"), get_account("RH"), amount_to_send, "RH", sc)98 operatorSend_tx = operatorSend(get_account("AA"), sc.vaultContract(), amount_to_send, "RH", sc)99 assert sc.balanceOf(sc.vaultContract()) == sc.totalSupply(), "Incorrect balance of vaultContract"100 assert sc.balanceOf(get_account("AA")) == 0, "Incorrect balance of holder"101 assert operatorSend_tx.events["Payout"]["from"] == get_account("AA")102 assert operatorSend_tx.events["Payout"]["amount"] == amount_to_send103# Operator Burn104def test_OperatorBurn(sc):105 amount_to_burn = Web3.toWei(1000, "ether")106 if network.show_active() == "development":107 with brownie.reverts("M.C. Hammer: Duh da ra-duh duh-da duh-da, Cant Touch This. You are not an operator."):108 operatorBurn(sc.vaultContract(), amount_to_burn, "AA", sc)109 110 with brownie.reverts("Trying to be mean? An operator can only burn tokens in the vaultContract."):111 operatorBurn(get_account("AA"), amount_to_burn, "RH", sc)112 operatorBurn(sc.vaultContract(), amount_to_burn, "RH", sc)113 assert sc.balanceOf(sc.vaultContract()) == initial_supply - amount_to_burn, "Incorrect balance of vaultContract"114 assert sc.totalSupply() == initial_supply - amount_to_burn, "Incorrect total supply"115# Pause contract116def test_PauseContract(sc):117 amount_to_send = Web3.toWei(1000, "ether")118 if network.show_active() == "development":119 with brownie.reverts("You are missing a promotion to the board of directors. Only the admin can perform this action!"):120 pauseContract("JH", sc)121 with brownie.reverts("You are missing a promotion to the board of directors. Only the admin can perform this action!"):122 pauseContract("AA", sc)123 pauseContract("RH", sc)124 assert sc.paused(), "pause flag should be true"125 if network.show_active() == "development":126 with brownie.reverts("Pausable: paused"):127 sendTokensToIndividualAddress(get_account("AA"), amount_to_send, "JH", sc)128 129 with brownie.reverts("Pausable: paused"):130 sendTokensToMultipleAddresses([get_account("AA")], amount_to_send, "JH", sc)131 with brownie.reverts("Pausable: paused"):132 send(get_account("AA"), amount_to_send, "JH", sc)133 with brownie.reverts("Pausable: paused"):134 transfer(get_account("AA"), amount_to_send, "JH", sc)135 136 with brownie.reverts("Pausable: paused"):137 mintTokensToVault(amount_to_send, "JH", sc)138 with brownie.reverts("Pausable: paused"):139 operatorBurn(sc.vaultContract(), amount_to_send, "JH", sc)140 with brownie.reverts("Pausable: paused"):141 operatorSend(get_account("AA"), sc.vaultContract(), amount_to_send, "JH", sc)142 143 with brownie.reverts("Pausable: paused"):144 requestPayout(amount_to_send, "", "AA", sc)145 with brownie.reverts("You are missing a promotion to the board of directors. Only the admin can perform this action!"):146 unpauseContract("JH", sc)147 with brownie.reverts("You are missing a promotion to the board of directors. Only the admin can perform this action!"):148 unpauseContract("AA", sc)149 unpauseContract("RH", sc)150 assert not sc.paused(), "paused flag should be false"151 sendTokensToIndividualAddress(get_account("AA"), amount_to_send, "JH", sc)152 assert sc.balanceOf(sc.vaultContract()) == sc.totalSupply() - amount_to_send, "Incorrect balance of vaultContract"153 assert sc.balanceOf(get_account("AA")) == amount_to_send, "Incorrect balance of recipient"154# Whitelist tests155def test_Whitelist(sc):156 amount_to_send = Web3.toWei(1000, "ether")157 sendTokensToIndividualAddress(get_account("AA"), amount_to_send, "JH", sc)158 159 if network.show_active() == "development":160 with brownie.reverts("Nice try, but user transfers are not enabled."):161 send(get_account("RH"), amount_to_send, "AA", sc)162 with brownie.reverts("Nice try, but user transfers are not enabled."):163 transfer(get_account("RH"), amount_to_send, "AA", sc)164 165 with brownie.reverts("You are missing a promotion to the board of directors. Only the admin can perform this action!"):166 activateWhitelist("AA", sc)167 168 activateWhitelist("RH", sc)169 assert sc.whitelistEnabled(), "whitelistEnabled flag should be true"170 if network.show_active() == "development":171 with brownie.reverts("Oops, the recipient is not a whitelisted address."):172 send(get_account("RH"), amount_to_send/2, "AA", sc)173 with brownie.reverts("Oops, the recipient is not a whitelisted address."):174 transfer(get_account("RH"), amount_to_send/2, "AA", sc)175 176 with brownie.reverts("Gotta ask the host before you add +1s. You are not an operator."):177 whitelistUsers([get_account("RH"), get_account("AA")], "AA", sc)178 whitelistUsers([get_account("RH"), get_account("AA")], "RH", sc)179 assert sc.isWhitelistedAddress(get_account("RH"))180 assert sc.isWhitelistedAddress(get_account("AA"))181 send(get_account("RH"), amount_to_send/2, "AA", sc)182 transfer(get_account("RH"), amount_to_send/2, "AA", sc)183 assert sc.balanceOf(get_account("AA")) == 0, "Incorrect balance of holder 1"184 assert sc.balanceOf(get_account("RH")) == amount_to_send, "Incorrect balance of holder 2"185 if network.show_active() == "development":186 with brownie.reverts("Do you not like them? Host your own party if you want to kick them out. You are not an operator."):187 removeFromWhitelist([get_account("RH"), get_account("AA")], "AA", sc)188 189 removeFromWhitelist_tx = removeFromWhitelist([get_account("AA")], "RH", sc)190 assert sc.isWhitelistedAddress(get_account("RH"))191 assert not sc.isWhitelistedAddress(get_account("AA"))192 assert len(removeFromWhitelist_tx.events) == 0193 if network.show_active() == "development":194 with brownie.reverts("Oops, the recipient is not a whitelisted address."):195 send(get_account("AA"), amount_to_send/2, "RH", sc)196 with brownie.reverts("Oops, the recipient is not a whitelisted address."):197 transfer(get_account("AA"), amount_to_send/2, "RH", sc)198 assert sc.balanceOf(get_account("RH")) == amount_to_send, "Incorrect balance of holder"199 removeFromWhitelist_tx = removeFromWhitelist([get_account("RH")], "RH", sc)200 assert sc.balanceOf(get_account("RH")) == 0, "Incorrect balance of holder"201 assert sc.balanceOf(sc.vaultContract()) == initial_supply, "Incorrect balance of vaultContract"202 assert removeFromWhitelist_tx.events["Payout"]["from"] == get_account("RH")203 assert removeFromWhitelist_tx.events["Payout"]["amount"] == amount_to_send204 if network.show_active() == "development":205 with brownie.reverts("You are missing a promotion to the board of directors. Only the admin can perform this action!"):206 deactivateWhitelist("AA", sc)207 with brownie.reverts("You are missing a promotion to the board of directors. Only the admin can perform this action!"):208 deactivateWhitelist("JH", sc)209 210 deactivateWhitelist("RH", sc)211 assert not sc.whitelistEnabled(), "whitelistEnabled flag should be false"212 if network.show_active() == "development":213 with brownie.reverts("Nice try, but user transfers are not enabled."):214 send(get_account("AA"), amount_to_send, "RH", sc)215 216 with brownie.reverts("Nice try, but user transfers are not enabled."):217 transfer(get_account("AA"), amount_to_send, "RH", sc)218 219# defaultOperators220def test_DefaultOperators(sc):221 assert not sc.isOperatorFor(get_account("AA"), get_account("AA"))222 if network.show_active() == "development":223 with brownie.reverts("With great power comes great responsibility. You have neither. Only the admin or vault can do this!"):224 authorizeOperator(get_account("AA"), "AA", sc)225 authorizeOperator(get_account("AA"), "RH", sc)226 assert sc.isOperatorFor(get_account("AA"), get_account("AA"))227 if network.show_active() == "development":228 with brownie.reverts("Tut, tut. You cannot take powers you do not even have yourself. Only the admin or vault can do this!"):229 revokeOperator(get_account("AA"), "AA", sc)230 revokeOperator(get_account("AA"), "RH", sc)231 assert not sc.isOperatorFor(get_account("AA"), get_account("AA"))232 revokeOperator(get_account("RH"), "JH", sc)233 assert not sc.isOperatorFor(get_account("RH"), get_account("AA"))234 authorizeOperator(get_account("RH"), "JH", sc)235 assert sc.isOperatorFor(get_account("RH"), get_account("AA"))236# change Adminsitrator237def test_ChangeAdminstrator(sc):238 assert sc.administrator() == get_account("RH")239 if network.show_active() == "development":240 with brownie.reverts("Getting power hungry? Only the vault contract can perform this action!"):241 setAdmin(get_account("AA"), "AA", sc)242 with brownie.reverts("Getting power hungry? Only the vault contract can perform this action!"):243 setAdmin(get_account("AA"), "RH", sc)244 setAdmin(get_account("AA"), "JH", sc)245 assert sc.administrator() == get_account("AA")246# change vault247def test_ChangeVault(sc):248 assert sc.vaultContract() == get_account("JH")249 if network.show_active() == "development":250 with brownie.reverts("Getting power hungry? Only the vault contract can perform this action!"):251 setVault(get_account("AA"), "AA", sc)252 with brownie.reverts("Getting power hungry? Only the vault contract can perform this action!"):253 setVault(get_account("AA"), "RH", sc)254 setVault(get_account("AA"), "JH", sc)255 assert sc.vaultContract() == get_account("AA")256 257def main():258 test_DeploymentState(sc)259 test_MintTokens(sc)260 test_vaultContractSendIndividual(sc)261 test_vaultContractSendMultiple(sc)262 test_RequestPayout(sc)263 test_OperatorSend(sc)264 test_OperatorBurn(sc)265 test_PauseContract(sc)266 test_Whitelist(sc)267 test_DefaultOperators(sc)268 test_ChangeAdminstrator(sc)269 test_ChangeVault(sc)...

Full Screen

Full Screen

test_sktl.py

Source:test_sktl.py Github

copy

Full Screen

...26 3000, # 227 7000, # 428 13000, # 529 ]30 self.token = SKTL.deploy({"from": get_account(0)})31 for i in range(1, len(self.init_acc_tokens)):32 self.token.transfer(get_account(i), self.init_acc_tokens[i] * DECIMALS)33 self.donation_pool_acc = 934 self.token.transfer(35 get_account(self.donation_pool_acc), self.init_donation_pool * DECIMALS36 ) # this is the donation pool37 def test_init_wallets(self):38 self.assertEqual(39 self.token.balanceOf(get_account(0)),40 (self.init_token - self.init_donation_pool - sum(self.init_acc_tokens))41 * DECIMALS,42 "original account balance failed after init transfer",43 )44 for i in range(1, len(self.init_acc_tokens)):45 self.assertEqual(46 self.token.balanceOf(get_account(i)),47 self.init_acc_tokens[i] * DECIMALS,48 f"original account[{i}] balance failed after init transfer",49 )50 self.assertEqual(51 self.token.balanceOf(get_account(self.donation_pool_acc)),52 self.init_donation_pool * DECIMALS,53 "original donation pool balance failed after init transfer",54 )55 def test_init_reward_tokens(self):56 # check the rewardToken57 total_reward_token = self.token.totalRewardToken()58 half_token = int(total_reward_token / 2)59 self.assertEqual(60 int(61 self.token.rewardTokenBalance(get_account(self.donation_pool_acc))62 / DECIMALS63 ),64 int(half_token / DECIMALS),65 "Donation pool doesn't have half rewardToken",66 )67 for i in range(1, len(self.init_acc_tokens)):68 self.assertEqual(69 int(self.token.rewardTokenBalance(get_account(i))),70 int(71 ((self.init_acc_tokens[i] * total_reward_token) // self.init_token)72 ),73 msg=f"account[{i}] rewardbalance doesn't match",74 )75 def test_simple_rewards(self):76 rewards = 1000077 self.token.increaseReward(rewards * DECIMALS)78 # owner should not have any rewardBalance79 self.assertEqual(80 self.token.rewardBalance(get_account(0)),81 0,82 )83 # owner has all the rewards so far84 self.assertEqual(85 self.token.balanceOf(get_account(0)),86 (87 self.init_token88 - self.init_donation_pool89 - sum(self.init_acc_tokens)90 + rewards91 )92 * DECIMALS,93 )94 for i in range(1, len(self.init_acc_tokens)):95 self.assertIntAlmostEqual(96 self.token.rewardBalance(get_account(i)),97 int((rewards * self.init_acc_tokens[i] * DECIMALS) // self.init_token),98 f"account[{i}] reward balance doesn't match",99 )100 def test_second_rewards(self):101 rewards = [4000, 8000]102 for i in range(len(rewards)):103 self.token.increaseReward(rewards[i] * DECIMALS)104 self.assertEqual(105 self.token.rewardBalance(get_account(0)),106 0,107 )108 # owner has all the rewards so far109 self.assertEqual(110 self.token.balanceOf(get_account(0)),111 (112 self.init_token113 - self.init_donation_pool114 - sum(self.init_acc_tokens)115 + sum(rewards)116 )117 * DECIMALS,118 )119 for i in range(1, len(self.init_acc_tokens)):120 self.assertIntAlmostEqual(121 self.token.rewardBalance(get_account(i)),122 int(123 (sum(rewards) * self.init_acc_tokens[i] * DECIMALS)124 / self.init_token125 ),126 f"account[{i}] reward balance doesn't match after multiple rewards",127 )128 def test_transfer_after_rewards(self):129 # test reward, then transfer, then reward130 rewards = 1000131 transfer = 301.0000001132 self.token.increaseReward(rewards * DECIMALS)133 self.token.transfer(134 get_account(3), transfer * DECIMALS, {"from": get_account(2)}135 )136 # make sure the rewardBalance is Zero137 self.assertEqual(self.token.rewardBalance(get_account(2)), 0)138 self.assertEqual(self.token.rewardBalance(get_account(3)), 0)139 balance2 = (140 self.init_acc_tokens[2] * (1 + rewards / self.init_token)141 ) - transfer142 balance3 = (143 self.init_acc_tokens[3] * (1 + rewards / self.init_token)144 ) + transfer145 self.assertIntAlmostEqual(146 self.token.balanceOf(get_account(2)),147 balance2 * DECIMALS,148 )149 self.assertIntAlmostEqual(150 self.token.balanceOf(get_account(3)),151 balance3 * DECIMALS,152 )153 def test_should_fail(self):154 # make sure only owner can reward155 with brownie.reverts():156 self.token.increaseReward(1000 * DECIMALS, {"from": get_account(2)})157 # transfer more than it owns158 with brownie.reverts():159 self.token.transfer(160 get_account(1),161 self.init_acc_tokens[2] * 2 * DECIMALS,162 {"from": get_account(2)},163 )164 def test_set_owner(self):165 rewards = [1000, 2000]166 self.token.increaseReward(rewards[0] * DECIMALS, {"from": get_account(0)})167 with brownie.reverts():168 self.token.transferOwnership(get_account(2), {"from": get_account(1)})169 # make sure new owner can't hold tokens170 with brownie.reverts():171 self.token.transferOwnership(get_account(4), {"from": get_account(0)})172 self.token.transferOwnership(get_account(8), {"from": get_account(0)})173 # make old owner can't reward174 with brownie.reverts():175 self.token.increaseReward(rewards[0] * DECIMALS, {"from": get_account(0)})176 # new owner can reward177 self.token.increaseReward(rewards[1] * DECIMALS, {"from": get_account(8)})178 scaled_reward_token = (179 sum(rewards) * DECIMALS * self.init_acc_tokens[1] / self.init_token180 )181 self.assertEqual(182 self.token.rewardBalance(get_account(1)),183 scaled_reward_token,184 )185 self.token.withdraw({"from": get_account(1)})186 self.assertEqual(187 self.token.balanceOf(get_account(1)),188 self.init_acc_tokens[1] * DECIMALS + scaled_reward_token,189 )190 def test_transfer_from_using_allowance(self):191 transfer = 300192 # not allowed yet193 with brownie.reverts():194 self.token.transferFrom(195 get_account(1),196 get_account(3),197 1000 * DECIMALS,198 {"from": get_account(0)},199 )200 self.token.approve(201 get_account(3), transfer * DECIMALS, {"from": get_account(1)}202 )203 # not allow over transferFrom204 with brownie.reverts():205 self.token.transferFrom(206 get_account(1),207 get_account(3),208 (transfer + 1) * DECIMALS,209 {"from": get_account(3)},210 )211 self.token.transferFrom(212 get_account(1),213 get_account(4),214 transfer * DECIMALS,215 {"from": get_account(3)},216 )217 balance1 = self.init_acc_tokens[1] - transfer218 self.assertEqual(219 self.token.balanceOf(get_account(1)),220 balance1 * DECIMALS,221 )222 balance4 = self.init_acc_tokens[4] + transfer223 self.assertEqual(224 self.token.balanceOf(get_account(4)),225 balance4 * DECIMALS,226 )227 self.assertEqual(self.token.rewardBalance(get_account(1)), 0)228 self.assertEqual(self.token.rewardBalance(get_account(4)), 0)229 # make sure the simple reward works230 reward = 1000231 self.token.increaseReward(reward * DECIMALS)232 self.assertEqual(233 self.token.rewardBalance(get_account(0)),234 0,235 )236 self.assertIntAlmostEqual(237 self.token.rewardBalance(get_account(1)),238 reward * DECIMALS * balance1 / self.init_token,239 )240 self.assertIntAlmostEqual(241 self.token.rewardBalance(get_account(4)),242 reward * DECIMALS * balance4 / self.init_token,243 )244 self.assertIntAlmostEqual(245 self.token.rewardBalance(get_account(3)),246 reward * DECIMALS * self.init_acc_tokens[3] / self.init_token,247 )248 def test_transfer_balance_plus_reward(self):249 rewards = 3000250 self.token.increaseReward(rewards * DECIMALS)251 self.assertEqual(252 self.token.balanceOf(get_account(1)),253 self.init_acc_tokens[1] * DECIMALS,254 )255 scaled_reward_balance1 = (256 rewards * DECIMALS * self.init_acc_tokens[1] / self.init_token257 )258 self.assertEqual(259 self.token.rewardBalance(get_account(1)),260 scaled_reward_balance1,261 )262 total_transfer = self.init_acc_tokens[1] * DECIMALS + scaled_reward_balance1263 self.token.transfer(264 get_account(3), total_transfer, {"from": get_account(1)}265 ) # transfer balance + reward266 self.assertEqual(267 self.token.balanceOf(get_account(1)),268 0,269 )270 self.assertEqual(271 self.token.rewardBalance(get_account(1)),272 0,273 )274 scaled_reward_balance3 = (275 rewards * DECIMALS * self.init_acc_tokens[3] / self.init_token276 )277 self.assertEqual(278 self.token.balanceOf(get_account(3)),279 self.init_acc_tokens[3] * DECIMALS280 + total_transfer281 + scaled_reward_balance3,282 )283 self.assertEqual(284 self.token.rewardBalance(get_account(3)),285 0,286 )287 def test_transferfrom_balance_plus_reward(self):288 rewards = 3000289 self.token.increaseReward(rewards * DECIMALS)290 self.assertEqual(291 self.token.balanceOf(get_account(1)),292 self.init_acc_tokens[1] * DECIMALS,293 )294 scaled_reward_balance1 = (295 rewards * DECIMALS * self.init_acc_tokens[1] / self.init_token296 )297 self.assertEqual(298 self.token.rewardBalance(get_account(1)),299 scaled_reward_balance1,300 )301 total_transfer = self.init_acc_tokens[1] * DECIMALS + scaled_reward_balance1302 self.token.approve(get_account(4), total_transfer, {"from": get_account(1)})303 # transfer balance + reward304 self.token.transferFrom(305 get_account(1), get_account(3), total_transfer, {"from": get_account(4)}306 )307 self.assertEqual(308 self.token.balanceOf(get_account(1)),309 0,310 )311 self.assertEqual(312 self.token.rewardBalance(get_account(1)),313 0,314 )315 scaled_reward_balance3 = (316 rewards * DECIMALS * self.init_acc_tokens[3] / self.init_token317 )318 self.assertEqual(319 self.token.balanceOf(get_account(3)),320 self.init_acc_tokens[3] * DECIMALS321 + total_transfer322 + scaled_reward_balance3,323 )324 self.assertEqual(325 self.token.rewardBalance(get_account(3)),326 0,327 )328 def test_max_supply(self):329 three_mm = 300 * 10 ** 6330 self.token.increaseReward((three_mm - self.init_token) * DECIMALS)331 with brownie.reverts():332 self.token.increaseReward(1)333 def test_pause(self):334 # non-owner can't pause335 with brownie.reverts():336 self.token.pause({"from": get_account(1)})337 # not in pause state, can't unpause338 with brownie.reverts():339 self.token.unpause({"from": get_account(0)})340 self.token.pause({"from": get_account(0)})341 # paused, can't transfer342 with brownie.reverts():343 self.token.transfer(344 get_account(5), 1000 * DECIMALS, {"from": get_account(0)}345 )346 # can't pause twice347 with brownie.reverts():348 self.token.pause({"from": get_account(0)})349 # non-owner can't unpause350 with brownie.reverts():351 self.token.unpause({"from": get_account(1)})352 self.token.unpause({"from": get_account(0)})353 self.test_transfer_after_rewards() # transfer test normal354 def test_transfer_same_account(self):355 """356 support transfer same account357 no ill effect on the reward, except the reward will be withdrawn358 """359 rewards = 3000360 self.token.increaseReward(rewards * DECIMALS)361 self.assertEqual(362 self.token.balanceOf(get_account(3)),363 self.init_acc_tokens[3] * DECIMALS,364 )365 self.token.transfer(get_account(3), 1 * DECIMALS, {"from": get_account(3)})366 scaled_reward_balance3 = (367 rewards * DECIMALS * self.init_acc_tokens[3] / self.init_token368 )369 self.assertEqual(370 self.token.balanceOf(get_account(3)),371 self.init_acc_tokens[3] * DECIMALS + scaled_reward_balance3,...

Full Screen

Full Screen

test_lottery_unit.py

Source:test_lottery_unit.py Github

copy

Full Screen

...14 assert expected_entrance_fee == entrance_fee15def test_cant_enter_unless_started():16 if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:17 pytest.skip('Not in local environments!')18 account = get_account()19 lottery = deploy_lottery()20 with pytest.raises(exceptions.VirtualMachineError):21 lottery.enter({'from': account, 'value': lottery.getEntranceFee()})22def test_can_start_and_enter():23 if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:24 pytest.skip('Not in local environments!')25 # Arrange26 account = get_account()27 lottery = deploy_lottery()28 lottery.start({'from': account})29 # Act30 lottery.enter({'from': account, 'value': lottery.getEntranceFee()})31 # Assert32 lottery.players(0) == account33def test_can_end_lottery():34 if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:35 pytest.skip('Not in local environments!')36 # Arrange37 account = get_account()38 lottery = deploy_lottery()39 lottery.start({'from': account})40 lottery.enter({'from': account, 'value': lottery.getEntranceFee()})41 # Act42 fund_with_link(lottery.address)43 lottery.end({'from': account})44 # Assert45 assert lottery.lotteryState() == 246def test_can_choose_winner_correctly():47 if network.show_active() not in LOCAL_BLOCKCHAIN_ENVIRONMENTS:48 pytest.skip('Not in local environments!')49 # Arrange50 account = get_account()51 lottery = deploy_lottery()52 lottery.start({'from': account})53 lottery.enter({'from': get_account(index=1), 'value': lottery.getEntranceFee()})54 lottery.enter({'from': get_account(index=2), 'value': lottery.getEntranceFee()})55 lottery.enter({'from': get_account(index=3), 'value': lottery.getEntranceFee()})56 winner_starting_balance = get_account(index=1).balance()57 winner_expected_total_balance = winner_starting_balance + lottery.balance()58 MOCK_RANDOM_NUMBER = 77759 # Act 60 fund_with_link(lottery.address)61 tx = lottery.end({'from': account})62 request_id = tx.events['RequestedRandomness']['requestId']63 get_contract('vrf_cordinator').callBackWithRandomness(request_id, MOCK_RANDOM_NUMBER, lottery)64 # Assert65 assert lottery.recentWinner() == get_account(index=1)66 assert lottery.balance() == 0...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful