Test for pool creation

Also added the `terminusPoolController` view method on the
TerminusFacet.
pull/9/head
Neeraj Kashyap 2021-12-18 12:42:21 -08:00
rodzic aa18d54c6d
commit 2747d63067
5 zmienionych plików z 73 dodań i 6 usunięć

Wyświetl plik

@ -34,6 +34,14 @@ contract TerminusFacet is ERC1155WithTerminusStorage {
return LibTerminus.createPool();
}
function terminusPoolController(uint256 poolID)
external
view
returns (address)
{
return LibTerminus.terminusStorage().poolController[poolID];
}
function mint(
address to,
uint256 poolID,

Wyświetl plik

@ -176,6 +176,10 @@ class TerminusFacet:
self.assert_contract_is_instantiated()
return self.contract.terminusController.call()
def terminus_pool_controller(self, pool_id: int) -> Any:
self.assert_contract_is_instantiated()
return self.contract.terminusPoolController.call(pool_id)
def total_pools(self) -> Any:
self.assert_contract_is_instantiated()
return self.contract.totalPools.call()
@ -356,6 +360,13 @@ def handle_terminus_controller(args: argparse.Namespace) -> None:
print(result)
def handle_terminus_pool_controller(args: argparse.Namespace) -> None:
network.connect(args.network)
contract = TerminusFacet(args.address)
result = contract.terminus_pool_controller(pool_id=args.pool_id)
print(result)
def handle_total_pools(args: argparse.Namespace) -> None:
network.connect(args.network)
contract = TerminusFacet(args.address)
@ -502,6 +513,13 @@ def generate_cli() -> argparse.ArgumentParser:
add_default_arguments(terminus_controller_parser, False)
terminus_controller_parser.set_defaults(func=handle_terminus_controller)
terminus_pool_controller_parser = subcommands.add_parser("terminus-pool-controller")
add_default_arguments(terminus_pool_controller_parser, False)
terminus_pool_controller_parser.add_argument(
"--pool-id", required=True, help="Type: uint256", type=int
)
terminus_pool_controller_parser.set_defaults(func=handle_terminus_pool_controller)
total_pools_parser = subcommands.add_parser("total-pools")
add_default_arguments(total_pools_parser, False)
total_pools_parser.set_defaults(func=handle_total_pools)

Wyświetl plik

@ -5,6 +5,8 @@ from brownie import accounts, network
from .core import facet_cut, gogogo
from .ERC20Facet import ERC20Facet
from .ERC20Initializer import ERC20Initializer
from . import TerminusFacet
from . import TerminusInitializer
class MoonstreamDAOTestCase(unittest.TestCase):
@ -17,7 +19,7 @@ class MoonstreamDAOTestCase(unittest.TestCase):
cls.contracts = gogogo(accounts[0], {"from": accounts[0]})
class MoonstreamDAOFullTestCase(MoonstreamDAOTestCase):
class MoonstreamTokenTestCase(MoonstreamDAOTestCase):
@classmethod
def setUpClass(cls) -> None:
super().setUpClass()
@ -43,6 +45,32 @@ class MoonstreamDAOFullTestCase(MoonstreamDAOTestCase):
cls.erc20_facet = erc20_facet.address
class TerminusTestCase(MoonstreamDAOTestCase):
@classmethod
def setUpClass(cls) -> None:
super().setUpClass()
# Deploy Terminus
initializer = TerminusInitializer.TerminusInitializer(None)
initializer.deploy({"from": accounts[0]})
terminus_facet = TerminusFacet.TerminusFacet(None)
terminus_facet.deploy({"from": accounts[0]})
diamond_address = cls.contracts["Diamond"]
facet_cut(
diamond_address,
"TerminusFacet",
terminus_facet.address,
"add",
{"from": accounts[0]},
initializer.address,
)
cls.terminus_initializer = initializer.address
cls.terminus_facet = terminus_facet.address
class TestCoreDeployment(MoonstreamDAOTestCase):
def test_gogogo(self):
self.assertIn("DiamondCutFacet", self.contracts)

Wyświetl plik

@ -5,7 +5,7 @@ import brownie
from . import ERC20Facet, ERC20Initializer
from .core import ZERO_ADDRESS, facet_cut
from .test_core import MoonstreamDAOTestCase, MoonstreamDAOFullTestCase
from .test_core import MoonstreamDAOTestCase, MoonstreamTokenTestCase
class TestDeployment(MoonstreamDAOTestCase):
@ -118,7 +118,7 @@ class TestRemoveFacet(MoonstreamDAOTestCase):
symbol = diamond_erc20.symbol()
class TestERC20(MoonstreamDAOFullTestCase):
class TestERC20(MoonstreamTokenTestCase):
def test_mint_fails_if_not_controller(self):
diamond_address = self.contracts["Diamond"]
diamond = ERC20Facet.ERC20Facet(diamond_address)

Wyświetl plik

@ -1,11 +1,10 @@
import unittest
from brownie import accounts
import brownie
from . import TerminusFacet, TerminusInitializer
from .core import ZERO_ADDRESS, facet_cut
from .test_core import MoonstreamDAOTestCase, MoonstreamDAOFullTestCase
from .core import facet_cut
from .test_core import MoonstreamDAOTestCase, TerminusTestCase
class TestDeployment(MoonstreamDAOTestCase):
@ -32,5 +31,19 @@ class TestDeployment(MoonstreamDAOTestCase):
self.assertEqual(controller, accounts[0].address)
class TestPoolCreation(TerminusTestCase):
def test_create_pool(self):
diamond_address = self.contracts["Diamond"]
diamond_terminus = TerminusFacet.TerminusFacet(diamond_address)
initial_total_pools = diamond_terminus.total_pools()
diamond_terminus.create_pool({"from": accounts[1]})
final_total_pools = diamond_terminus.total_pools()
self.assertEqual(final_total_pools, initial_total_pools + 1)
pool_controller = diamond_terminus.terminus_pool_controller(final_total_pools)
self.assertEqual(pool_controller, accounts[1].address)
if __name__ == "__main__":
unittest.main()