kopia lustrzana https://github.com/bugout-dev/dao
tests for erc20
rodzic
0d8e00931b
commit
873fd3c30d
|
@ -1,4 +1,7 @@
|
|||
import unittest
|
||||
|
||||
from brownie import accounts
|
||||
import brownie
|
||||
|
||||
from . import ERC20Facet, ERC20Initializer
|
||||
from .core import ZERO_ADDRESS, facet_cut
|
||||
|
@ -147,6 +150,24 @@ class TestERC20(MoonstreamDAOFullTestCase):
|
|||
self.assertEqual(final_sender_balance, initial_sender_balance - 500)
|
||||
self.assertEqual(final_receiver_balance, initial_receiver_balance + 500)
|
||||
|
||||
def test_transfer_insufficient_balance(self):
|
||||
diamond_address = self.contracts["Diamond"]
|
||||
diamond = ERC20Facet.ERC20Facet(diamond_address)
|
||||
|
||||
initial_sender_balance = diamond.balance_of(accounts[1].address)
|
||||
initial_receiver_balance = diamond.balance_of(accounts[2].address)
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
diamond.transfer(
|
||||
accounts[2].address, initial_sender_balance + 1, {"from": accounts[1]}
|
||||
)
|
||||
|
||||
final_sender_balance = diamond.balance_of(accounts[1].address)
|
||||
final_receiver_balance = diamond.balance_of(accounts[2].address)
|
||||
|
||||
self.assertEqual(final_sender_balance, initial_sender_balance)
|
||||
self.assertEqual(final_receiver_balance, initial_receiver_balance)
|
||||
|
||||
def test_transfer_from_with_approval(self):
|
||||
diamond_address = self.contracts["Diamond"]
|
||||
diamond = ERC20Facet.ERC20Facet(diamond_address)
|
||||
|
@ -166,3 +187,105 @@ class TestERC20(MoonstreamDAOFullTestCase):
|
|||
|
||||
self.assertEqual(final_sender_balance, initial_sender_balance - 500)
|
||||
self.assertEqual(final_receiver_balance, initial_receiver_balance + 500)
|
||||
|
||||
def test_transfer_with_approval_insufficient_balance(self):
|
||||
diamond_address = self.contracts["Diamond"]
|
||||
diamond = ERC20Facet.ERC20Facet(diamond_address)
|
||||
|
||||
initial_sender_balance = diamond.balance_of(accounts[1].address)
|
||||
initial_receiver_balance = diamond.balance_of(accounts[2].address)
|
||||
|
||||
diamond.approve(
|
||||
accounts[2].address, initial_sender_balance + 1, {"from": accounts[1]}
|
||||
)
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
diamond.transfer_from(
|
||||
accounts[1].address,
|
||||
accounts[2].address,
|
||||
initial_sender_balance + 1,
|
||||
{"from": accounts[2]},
|
||||
)
|
||||
|
||||
final_sender_balance = diamond.balance_of(accounts[1].address)
|
||||
final_receiver_balance = diamond.balance_of(accounts[2].address)
|
||||
|
||||
self.assertEqual(final_sender_balance, initial_sender_balance)
|
||||
self.assertEqual(final_receiver_balance, initial_receiver_balance)
|
||||
|
||||
def test_transfer_from_with_approval_insufficient_allowance_sufficient_balance(
|
||||
self,
|
||||
):
|
||||
diamond_address = self.contracts["Diamond"]
|
||||
diamond = ERC20Facet.ERC20Facet(diamond_address)
|
||||
|
||||
diamond.mint(accounts[1].address, 1000, {"from": accounts[0]})
|
||||
diamond.approve(accounts[2].address, 500, {"from": accounts[1]})
|
||||
|
||||
initial_sender_balance = diamond.balance_of(accounts[1].address)
|
||||
initial_receiver_balance = diamond.balance_of(accounts[2].address)
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
diamond.transfer_from(
|
||||
accounts[1].address,
|
||||
accounts[2].address,
|
||||
501,
|
||||
{"from": accounts[2]},
|
||||
)
|
||||
|
||||
final_sender_balance = diamond.balance_of(accounts[1].address)
|
||||
final_receiver_balance = diamond.balance_of(accounts[2].address)
|
||||
|
||||
self.assertEqual(final_sender_balance, initial_sender_balance)
|
||||
self.assertEqual(final_receiver_balance, initial_receiver_balance)
|
||||
|
||||
def test_not_burnable(self):
|
||||
diamond_address = self.contracts["Diamond"]
|
||||
diamond = ERC20Facet.ERC20Facet(diamond_address)
|
||||
|
||||
diamond.mint(accounts[1].address, 1000, {"from": accounts[0]})
|
||||
|
||||
with self.assertRaises(Exception):
|
||||
diamond.transfer(brownie.ZERO_ADDRESS, 500, {"from": accounts[1]})
|
||||
|
||||
def test_approve_and_allowance(self):
|
||||
diamond_address = self.contracts["Diamond"]
|
||||
diamond = ERC20Facet.ERC20Facet(diamond_address)
|
||||
|
||||
diamond.approve(accounts[2].address, 500, {"from": accounts[1]})
|
||||
allowance = diamond.allowance(accounts[1].address, accounts[2].address)
|
||||
self.assertEqual(allowance, 500)
|
||||
|
||||
def test_increase_allowance(self):
|
||||
diamond_address = self.contracts["Diamond"]
|
||||
diamond = ERC20Facet.ERC20Facet(diamond_address)
|
||||
|
||||
initial_allowance = diamond.allowance(accounts[1].address, accounts[2].address)
|
||||
|
||||
diamond.increase_allowance(accounts[2].address, 500, {"from": accounts[1]})
|
||||
final_allowance = diamond.allowance(accounts[1].address, accounts[2].address)
|
||||
self.assertEqual(final_allowance, initial_allowance + 500)
|
||||
|
||||
def test_decrease_allowance(self):
|
||||
diamond_address = self.contracts["Diamond"]
|
||||
diamond = ERC20Facet.ERC20Facet(diamond_address)
|
||||
|
||||
initial_allowance = diamond.allowance(accounts[1].address, accounts[2].address)
|
||||
|
||||
diamond.decrease_allowance(accounts[2].address, 500, {"from": accounts[1]})
|
||||
final_allowance = diamond.allowance(accounts[1].address, accounts[2].address)
|
||||
self.assertEqual(final_allowance, initial_allowance - 500)
|
||||
|
||||
def test_mint_total_supply(self):
|
||||
diamond_address = self.contracts["Diamond"]
|
||||
diamond = ERC20Facet.ERC20Facet(diamond_address)
|
||||
|
||||
initial_total_supply = diamond.total_supply()
|
||||
diamond.mint(accounts[1].address, 1000, {"from": accounts[0]})
|
||||
|
||||
final_total_supply = diamond.total_supply()
|
||||
self.assertEqual(final_total_supply, initial_total_supply + 1000)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
|
Ładowanie…
Reference in New Issue