@@ -23,6 +23,7 @@ const {
23
23
shouldBehaveLikeNotDelayedAdminOperation,
24
24
shouldBehaveLikeRoleAdminOperation,
25
25
shouldBehaveLikeAManagedRestrictedOperation,
26
+ shouldBehaveLikeASelfRestrictedOperation,
26
27
} = require ( './AccessManager.behavior' ) ;
27
28
28
29
const {
@@ -48,7 +49,7 @@ async function fixture() {
48
49
roles . SOME . members = [ member ] ;
49
50
roles . PUBLIC . members = [ admin , roleAdmin , roleGuardian , member , user , other ] ;
50
51
51
- const manager = await ethers . deployContract ( '$AccessManager ' , [ admin ] ) ;
52
+ const manager = await ethers . deployContract ( '$AccessManagerMock ' , [ admin ] ) ;
52
53
const target = await ethers . deployContract ( '$AccessManagedTarget' , [ manager ] ) ;
53
54
54
55
for ( const { id : roleId , admin, guardian, members } of Object . values ( roles ) ) {
@@ -1105,10 +1106,18 @@ describe('AccessManager', function () {
1105
1106
expect ( await this . manager . isTargetClosed ( this . target ) ) . to . be . false ;
1106
1107
} ) ;
1107
1108
1108
- it ( 'reverts if closing the manager' , async function ( ) {
1109
- await expect ( this . manager . connect ( this . admin ) . setTargetClosed ( this . manager , true ) )
1110
- . to . be . revertedWithCustomError ( this . manager , 'AccessManagerLockedAccount' )
1111
- . withArgs ( this . manager ) ;
1109
+ describe ( 'when the target is the manager' , async function ( ) {
1110
+ it ( 'closes and opens the manager' , async function ( ) {
1111
+ await expect ( this . manager . connect ( this . admin ) . setTargetClosed ( this . manager , true ) )
1112
+ . to . emit ( this . manager , 'TargetClosed' )
1113
+ . withArgs ( this . manager , true ) ;
1114
+ expect ( await this . manager . isTargetClosed ( this . manager ) ) . to . be . true ;
1115
+
1116
+ await expect ( this . manager . connect ( this . admin ) . setTargetClosed ( this . manager , false ) )
1117
+ . to . emit ( this . manager , 'TargetClosed' )
1118
+ . withArgs ( this . manager , false ) ;
1119
+ expect ( await this . manager . isTargetClosed ( this . manager ) ) . to . be . false ;
1120
+ } ) ;
1112
1121
} ) ;
1113
1122
} ) ;
1114
1123
@@ -1670,18 +1679,74 @@ describe('AccessManager', function () {
1670
1679
} ) ;
1671
1680
} ) ;
1672
1681
1682
+ describe ( 'access managed self operations' , function ( ) {
1683
+ describe ( 'when calling a restricted target function' , function ( ) {
1684
+ const method = 'fnRestricted()' ;
1685
+
1686
+ beforeEach ( 'set required role' , async function ( ) {
1687
+ this . role = { id : 785913n } ;
1688
+ await this . manager . $_setTargetFunctionRole (
1689
+ this . manager ,
1690
+ this . manager [ method ] . getFragment ( ) . selector ,
1691
+ this . role . id ,
1692
+ ) ;
1693
+ } ) ;
1694
+
1695
+ describe ( 'restrictions' , function ( ) {
1696
+ beforeEach ( 'set method and args' , function ( ) {
1697
+ this . caller = this . user ;
1698
+ this . calldata = this . manager . interface . encodeFunctionData ( method , [ ] ) ;
1699
+ } ) ;
1700
+
1701
+ shouldBehaveLikeASelfRestrictedOperation ( ) ;
1702
+ } ) ;
1703
+
1704
+ it ( 'succeeds called by a role member' , async function ( ) {
1705
+ await this . manager . $_grantRole ( this . role . id , this . user , 0 , 0 ) ;
1706
+
1707
+ await expect ( this . manager . connect ( this . user ) [ method ] ( ) )
1708
+ . to . emit ( this . manager , 'CalledRestricted' )
1709
+ . withArgs ( this . user ) ;
1710
+ } ) ;
1711
+ } ) ;
1712
+
1713
+ describe ( 'when calling a non-restricted target function' , function ( ) {
1714
+ const method = 'fnUnrestricted()' ;
1715
+
1716
+ beforeEach ( 'set required role' , async function ( ) {
1717
+ this . role = { id : 879435n } ;
1718
+ await this . manager . $_setTargetFunctionRole (
1719
+ this . manager ,
1720
+ this . manager [ method ] . getFragment ( ) . selector ,
1721
+ this . role . id ,
1722
+ ) ;
1723
+ } ) ;
1724
+
1725
+ it ( 'succeeds called by anyone' , async function ( ) {
1726
+ await expect ( this . manager . connect ( this . user ) [ method ] ( ) )
1727
+ . to . emit ( this . manager , 'CalledUnrestricted' )
1728
+ . withArgs ( this . user ) ;
1729
+ } ) ;
1730
+ } ) ;
1731
+ } ) ;
1732
+
1673
1733
describe ( 'access managed target operations' , function ( ) {
1674
1734
describe ( 'when calling a restricted target function' , function ( ) {
1675
- beforeEach ( 'set required role' , function ( ) {
1676
- this . method = this . target . fnRestricted . getFragment ( ) ;
1735
+ const method = 'fnRestricted()' ;
1736
+
1737
+ beforeEach ( 'set required role' , async function ( ) {
1677
1738
this . role = { id : 3597243n } ;
1678
- this . manager . $_setTargetFunctionRole ( this . target , this . method . selector , this . role . id ) ;
1739
+ await this . manager . $_setTargetFunctionRole (
1740
+ this . target ,
1741
+ this . target [ method ] . getFragment ( ) . selector ,
1742
+ this . role . id ,
1743
+ ) ;
1679
1744
} ) ;
1680
1745
1681
1746
describe ( 'restrictions' , function ( ) {
1682
1747
beforeEach ( 'set method and args' , function ( ) {
1683
- this . calldata = this . target . interface . encodeFunctionData ( this . method , [ ] ) ;
1684
1748
this . caller = this . user ;
1749
+ this . calldata = this . target . interface . encodeFunctionData ( method , [ ] ) ;
1685
1750
} ) ;
1686
1751
1687
1752
shouldBehaveLikeAManagedRestrictedOperation ( ) ;
@@ -1690,11 +1755,7 @@ describe('AccessManager', function () {
1690
1755
it ( 'succeeds called by a role member' , async function ( ) {
1691
1756
await this . manager . $_grantRole ( this . role . id , this . user , 0 , 0 ) ;
1692
1757
1693
- await expect (
1694
- this . target . connect ( this . user ) [ this . method . selector ] ( {
1695
- data : this . calldata ,
1696
- } ) ,
1697
- )
1758
+ await expect ( this . target . connect ( this . user ) [ method ] ( ) )
1698
1759
. to . emit ( this . target , 'CalledRestricted' )
1699
1760
. withArgs ( this . user ) ;
1700
1761
} ) ;
@@ -1713,11 +1774,7 @@ describe('AccessManager', function () {
1713
1774
} ) ;
1714
1775
1715
1776
it ( 'succeeds called by anyone' , async function ( ) {
1716
- await expect (
1717
- this . target . connect ( this . user ) [ method ] ( {
1718
- data : this . calldata ,
1719
- } ) ,
1720
- )
1777
+ await expect ( this . target . connect ( this . user ) [ method ] ( ) )
1721
1778
. to . emit ( this . target , 'CalledUnrestricted' )
1722
1779
. withArgs ( this . user ) ;
1723
1780
} ) ;
0 commit comments