@@ -167,6 +167,89 @@ describe('CollateralizationOracle', function () {
167167 } ) ;
168168 } ) ;
169169
170+ describe ( 'swapDeposit()' , function ( ) {
171+ beforeEach ( async function ( ) {
172+ this . deposit1bis = await MockPCVDepositV2 . new (
173+ this . core . address ,
174+ this . token1 . address ,
175+ `2000${ e18 } ` , // balance
176+ `1000${ e18 } ` // protocol FEI
177+ ) ;
178+ await this . oracle . setOracle ( this . token1 . address , this . oracle1 . address , { from : governorAddress } ) ;
179+ await this . oracle . addDeposit ( this . deposit1 . address , { from : governorAddress } ) ;
180+ } ) ;
181+ it ( 'should emit DepositRemove' , async function ( ) {
182+ expectEvent (
183+ await this . oracle . swapDeposit ( this . deposit1 . address , this . deposit1bis . address , { from : governorAddress } ) ,
184+ 'DepositRemove' ,
185+ {
186+ from : governorAddress ,
187+ deposit : this . deposit1 . address
188+ }
189+ ) ;
190+ } ) ;
191+ it ( 'should emit DepositAdd' , async function ( ) {
192+ expectEvent (
193+ await this . oracle . swapDeposit ( this . deposit1 . address , this . deposit1bis . address , { from : governorAddress } ) ,
194+ 'DepositAdd' ,
195+ {
196+ from : governorAddress ,
197+ deposit : this . deposit1bis . address ,
198+ token : this . token1 . address
199+ }
200+ ) ;
201+ } ) ;
202+ it ( 'should update maps & array properties' , async function ( ) {
203+ // initial situation : 1 deposit
204+ expect ( await this . oracle . pcvDeposits ( '0' ) ) . to . be . equal ( this . deposit1 . address ) ;
205+ expect ( await this . oracle . tokenToDeposits ( this . token1 . address , '0' ) ) . to . be . equal ( this . deposit1 . address ) ;
206+ expect ( await this . oracle . depositToToken ( this . deposit1 . address ) ) . to . be . equal ( this . token1 . address ) ;
207+ expect ( await this . oracle . tokensInPcv ( '0' ) ) . to . be . equal ( this . token1 . address ) ;
208+ expect ( await this . oracle . isTokenInPcv ( this . token1 . address ) ) . to . be . equal ( true ) ;
209+ // swap deposit
210+ await this . oracle . swapDeposit ( this . deposit1 . address , this . deposit1bis . address , { from : governorAddress } ) ;
211+ // after swap
212+ expect ( await this . oracle . pcvDeposits ( '0' ) ) . to . be . equal ( this . deposit1bis . address ) ;
213+ await expectRevert . unspecified ( this . oracle . pcvDeposits ( '1' ) ) ;
214+ expect ( await this . oracle . tokenToDeposits ( this . token1 . address , '0' ) ) . to . be . equal ( this . deposit1bis . address ) ;
215+ await expectRevert . unspecified ( this . oracle . tokenToDeposits ( this . token1 . address , '1' ) ) ;
216+ expect ( await this . oracle . depositToToken ( this . deposit1bis . address ) ) . to . be . equal ( this . token1 . address ) ;
217+ expect ( await this . oracle . depositToToken ( this . deposit1 . address ) ) . to . be . equal ( ZERO_ADDRESS ) ;
218+ expect ( await this . oracle . tokensInPcv ( '0' ) ) . to . be . equal ( this . token1 . address ) ;
219+ expect ( await this . oracle . isTokenInPcv ( this . token1 . address ) ) . to . be . equal ( true ) ;
220+ } ) ;
221+ it ( 'should revert if not governor' , async function ( ) {
222+ await expectRevert (
223+ this . oracle . swapDeposit (
224+ this . deposit1 . address ,
225+ this . deposit1bis . address ,
226+ { from : userAddress }
227+ ) ,
228+ 'CoreRef: Caller is not a governor'
229+ ) ;
230+ } ) ;
231+ it ( 'should revert if deposit is not found' , async function ( ) {
232+ await expectRevert (
233+ this . oracle . swapDeposit (
234+ this . deposit2 . address ,
235+ this . deposit1bis . address ,
236+ { from : governorAddress }
237+ ) ,
238+ 'CollateralizationOracle: deposit not found'
239+ ) ;
240+ } ) ;
241+ it ( 'should revert if new deposit is already found' , async function ( ) {
242+ await expectRevert (
243+ this . oracle . swapDeposit (
244+ this . deposit1 . address ,
245+ this . deposit1 . address ,
246+ { from : governorAddress }
247+ ) ,
248+ 'CollateralizationOracle: deposit duplicate'
249+ ) ;
250+ } ) ;
251+ } ) ;
252+
170253 describe ( 'setOracle()' , function ( ) {
171254 it ( 'should emit OracleUpdate' , async function ( ) {
172255 expectEvent (
0 commit comments