@@ -18,11 +18,13 @@ import {
1818 const tokenContract = await Token . deploy ( "Test token" , "TOK1" , minter , burner ) ;
1919 const precision : bigint = await tokenContract . decimals ( ) . then ( d => { if ( d == 0n ) { return 18n ; } else { return d } ; } ) ;
2020
21- const Contract1 = await hre . ethers . getContractFactory ( "BCAServiceManager" ) ;
22- const serviceManager1 = await Contract1 . deploy ( provider1 , tokenContract . getAddress ( ) ) ;
21+ const Manager = await hre . ethers . getContractFactory ( "BCAServiceManager" ) ;
22+ const serviceManager = await Manager . deploy ( tokenContract . getAddress ( ) ) ;
2323
24- const Contract2 = await hre . ethers . getContractFactory ( "BCAServiceManager" ) ;
25- const serviceManager2 = await Contract1 . deploy ( provider2 , tokenContract . getAddress ( ) ) ;
24+ const addrController1 = await ( await serviceManager . connect ( owner ) . newController ( provider1 ) ) . wait ( ) . then ( _ => serviceManager . connect ( owner ) . getControllerAddress ( provider1 ) ) ;
25+ const serviceController1 = await hre . ethers . getContractAt ( "BCAServiceController" , addrController1 )
26+ const addrController2 = await ( await serviceManager . connect ( owner ) . newController ( provider2 ) ) . wait ( ) . then ( _ => serviceManager . connect ( owner ) . getControllerAddress ( provider2 ) ) ;
27+ const serviceController2 = await hre . ethers . getContractAt ( "BCAServiceController" , addrController2 )
2628
2729 // minting some tokens to the users
2830 const one_token = 1n * BigInt ( 10n ** precision ) ;
@@ -34,35 +36,43 @@ import {
3436 const startblocktime : bigint = BigInt ( await time . increase ( 30 ) ) ;
3537
3638 return { token : { tokenContract, one_token, owner, minter, burner, user1, user2 } ,
37- sm1 : { serviceManager1, provider1 } ,
38- sm2 : { serviceManager2, provider2 } } ;
39+ sm : { serviceManager, provider1, provider2 } ,
40+ sc1 : { serviceController1, provider1 } ,
41+ sc2 : { serviceController2, provider2 } } ;
3942 }
4043
4144 describe ( "Deployment" , function ( ) {
42- it ( "Funding contract: should set the right provider " , async function ( ) {
43- const { sm1 } = await loadFixture ( deployContract ) ;
44- expect ( await sm1 . serviceManager1 . providerAddress ( ) ) . to . equal (
45- sm1 . provider1 . address
45+ it ( "Should have already deployed controllers " , async function ( ) {
46+ const { sm } = await loadFixture ( deployContract ) ;
47+ expect ( await sm . serviceManager . countServiceControllers ( ) ) . to . equal (
48+ 2
4649 ) ;
4750 } ) ;
4851
49- it ( "Funding contract: should set the right provider" , async function ( ) {
50- const { sm2 } = await loadFixture ( deployContract ) ;
51- expect ( await sm2 . serviceManager2 . providerAddress ( ) ) . to . equal (
52- sm2 . provider2 . address
52+ it ( "Should set the right provider" , async function ( ) {
53+ const { sc1 } = await loadFixture ( deployContract ) ;
54+ expect ( await sc1 . serviceController1 . providerAddress ( ) ) . to . equal (
55+ sc1 . provider1 . address
56+ ) ;
57+ } ) ;
58+
59+ it ( "Should set the right provider" , async function ( ) {
60+ const { sc2 } = await loadFixture ( deployContract ) ;
61+ expect ( await sc2 . serviceController2 . providerAddress ( ) ) . to . equal (
62+ sc2 . provider2 . address
5363 ) ;
5464 } ) ;
5565 } ) ;
5666
5767 describe ( "Create new services" , function ( ) {
5868 it ( "Should emit ServiceDeployed on new service creation" , async function ( ) {
59- const { sm1 , sm2 } = await loadFixture ( deployContract ) ;
69+ const { sc1 , sc2 } = await loadFixture ( deployContract ) ;
6070
61- await expect ( sm1 . serviceManager1 . connect ( sm1 . provider1 ) . newService ( 3 , 1n * 10n ** 18n ) )
62- . to . emit ( sm1 . serviceManager1 , "ServiceDeployed" )
71+ await expect ( sc1 . serviceController1 . connect ( sc1 . provider1 ) . newService ( 3 , 1n * 10n ** 18n ) )
72+ . to . emit ( sc1 . serviceController1 , "ServiceDeployed" )
6373 . withArgs ( anyValue ) ;
64- await expect ( sm2 . serviceManager2 . connect ( sm2 . provider2 ) . newService ( 99 , 1n * 10n ** 18n / 10n ) )
65- . to . emit ( sm2 . serviceManager2 , "ServiceDeployed" )
74+ await expect ( sc2 . serviceController2 . connect ( sc2 . provider2 ) . newService ( 99 , 1n * 10n ** 18n / 10n ) )
75+ . to . emit ( sc2 . serviceController2 , "ServiceDeployed" )
6676 . withArgs ( anyValue ) ;
6777 } ) ;
6878
0 commit comments