@@ -83,14 +83,16 @@ describe('ERC7984Wrapper', function () {
8383 } ) ;
8484
8585 it ( 'max amount works' , async function ( ) {
86- const maxAmount = ( 2n ** 64n - 1n ) / 10n ** 6n ;
87- await this . token . $_mint ( this . holder . address , ethers . parseUnits ( maxAmount . toString ( ) , 18 ) ) ;
88- const amountToWrap = ethers . parseUnits ( maxAmount . toString ( ) , 18 ) ;
86+ await this . token . $_mint ( this . holder . address , ethers . MaxUint256 / 2n ) ; // mint a lot of tokens
87+
88+ const rate = await this . wrapper . rate ( ) ;
89+ const maxConfidentialSupply = await this . wrapper . maxTotalSupply ( ) ;
90+ const maxUnderlyingSupply = maxConfidentialSupply * rate ;
8991
9092 if ( viaCallback ) {
91- await this . token . connect ( this . holder ) . transferAndCall ( this . wrapper , amountToWrap ) ;
93+ await this . token . connect ( this . holder ) . transferAndCall ( this . wrapper , maxUnderlyingSupply ) ;
9294 } else {
93- await this . wrapper . connect ( this . holder ) . wrap ( this . holder . address , amountToWrap ) ;
95+ await this . wrapper . connect ( this . holder ) . wrap ( this . holder . address , maxUnderlyingSupply ) ;
9496 }
9597
9698 await expect (
@@ -100,22 +102,25 @@ describe('ERC7984Wrapper', function () {
100102 this . wrapper . target ,
101103 this . holder ,
102104 ) ,
103- ) . to . eventually . equal ( ethers . parseUnits ( maxAmount . toString ( ) , 6 ) ) ;
105+ ) . to . eventually . equal ( maxConfidentialSupply ) ;
104106 } ) ;
105107
106108 it ( 'amount exceeding max fails' , async function ( ) {
107- const maxAmount = ( 2n ** 64n - 1n ) / 10n ** 6n ;
108- await this . token . $_mint ( this . holder . address , ethers . parseUnits ( maxAmount . toString ( ) , 18 ) ) ;
109- const amountToWrap = ethers . parseUnits ( ( maxAmount + 1n ) . toString ( ) , 18 ) ;
109+ await this . token . $_mint ( this . holder . address , ethers . MaxUint256 / 2n ) ; // mint a lot of tokens
110110
111- let tx ;
112- if ( viaCallback ) {
113- tx = this . token . connect ( this . holder ) . transferAndCall ( this . wrapper , amountToWrap ) ;
114- } else {
115- tx = this . wrapper . connect ( this . holder ) . wrap ( this . holder . address , amountToWrap ) ;
116- }
111+ const rate = await this . wrapper . rate ( ) ;
112+ const maxConfidentialSupply = await this . wrapper . maxTotalSupply ( ) ;
113+ const maxUnderlyingSupply = maxConfidentialSupply * rate ;
117114
118- await expect ( tx ) . to . be . revertedWithCustomError ( this . wrapper , 'SafeCastOverflowedUintDowncast' ) ;
115+ // first deposit close to the max
116+ await this . wrapper . connect ( this . holder ) . wrap ( this . holder . address , maxUnderlyingSupply ) ;
117+
118+ // try to deposit more, causing the total supply to exceed the max supported amount
119+ await expect (
120+ viaCallback
121+ ? this . token . connect ( this . holder ) . transferAndCall ( this . wrapper , rate )
122+ : this . wrapper . connect ( this . holder ) . wrap ( this . holder . address , rate ) ,
123+ ) . to . be . revertedWithCustomError ( this . wrapper , 'ERC7984TotalSupplyOverflow' ) ;
119124 } ) ;
120125
121126 if ( viaCallback ) {
0 commit comments