@@ -17,6 +17,7 @@ import {
1717 getRewardForQuote ,
1818 getTestPeginQuote ,
1919 totalValue ,
20+ expectedRoundedAmount ,
2021} from "../utils/quotes" ;
2122import { expect } from "chai" ;
2223import { ethers } from "hardhat" ;
@@ -234,9 +235,10 @@ describe("PegInContract registerPegIn function should", () => {
234235 ) ;
235236 } ) ;
236237
237- it ( "refund user when call was not done and user under paid the quote" , async ( ) => {
238- const { contract, fullLp, signers, bridgeMock, collateralManagement } =
239- await loadFixture ( deployPegInContractFixture ) ;
238+ it ( "revert when user under paid the quote" , async ( ) => {
239+ const { contract, fullLp, signers, bridgeMock } = await loadFixture (
240+ deployPegInContractFixture
241+ ) ;
240242 const lbcAddress = await contract . getAddress ( ) ;
241243 const user = signers [ 0 ] ;
242244
@@ -259,6 +261,12 @@ describe("PegInContract registerPegIn function should", () => {
259261 nConfirmationSeconds : 600 ,
260262 } ) ;
261263
264+ const QuotesLib = new ethers . Contract (
265+ ethers . ZeroAddress ,
266+ Quotes__factory . abi ,
267+ ethers . provider
268+ ) ;
269+
262270 const height = PEGIN_CONSTANTS . HEIGHT_MOCK ;
263271 const peginAmount = totalValue ( quote ) - ethers . parseEther ( "0.0001" ) ;
264272 await bridgeMock . setPegin ( quoteHash , { value : peginAmount } ) ;
@@ -268,32 +276,22 @@ describe("PegInContract registerPegIn function should", () => {
268276 nConfirmationHeader
269277 ) ;
270278
271- const tx = contract
272- . connect ( fullLp )
273- . registerPegIn (
274- quote ,
275- signature ,
276- PEGIN_CONSTANTS . RAW_TRANSACTION_MOCK ,
277- PEGIN_CONSTANTS . PMT_MOCK ,
278- height
279- ) ;
280- await expect ( tx )
281- . to . emit ( contract , "PegInRegistered" )
282- . withArgs ( quoteHash , peginAmount ) ;
283- await expect ( tx ) . not . to . emit ( collateralManagement , "Penalized" ) ;
284- await expect ( tx )
285- . to . emit ( contract , "Refund" )
286- . withArgs ( user . address , quoteHash , peginAmount , true ) ;
287- await expect ( tx ) . not . to . emit ( contract , "CallForUser" ) ;
288- await expect ( tx ) . not . to . emit ( contract , "BridgeCapExceeded" ) ;
289- await expect ( tx ) . not . to . emit ( contract , "DaoContribution" ) ;
279+ await expect (
280+ contract
281+ . connect ( fullLp )
282+ . registerPegIn (
283+ quote ,
284+ signature ,
285+ PEGIN_CONSTANTS . RAW_TRANSACTION_MOCK ,
286+ PEGIN_CONSTANTS . PMT_MOCK ,
287+ height
288+ )
289+ )
290+ . to . be . revertedWithCustomError ( QuotesLib , "AmountTooLow" )
291+ . withArgs ( peginAmount , expectedRoundedAmount ( quote ) ) ;
290292 await expect ( contract . getCurrentContribution ( ) ) . to . eventually . eq ( 0n ) ;
291293 await expect ( contract . getQuoteStatus ( quoteHash ) ) . to . eventually . eq (
292- PegInStates . PROCESSED_QUOTE
293- ) ;
294- await expect ( tx ) . to . changeEtherBalances (
295- [ user , fullLp , contract ] ,
296- [ peginAmount , 0n , 0n ]
294+ PegInStates . UNPROCESSED_QUOTE
297295 ) ;
298296 await expect ( contract . getBalance ( fullLp ) ) . to . eventually . eq ( 0n ) ;
299297 } ) ;
@@ -821,7 +819,6 @@ describe("PegInContract registerPegIn function should", () => {
821819 height + Number ( quote . depositConfirmations ) - 1 ,
822820 nConfirmationHeader
823821 ) ;
824- const minValue = totalValue ( quote ) - totalValue ( quote ) / 10_000n ;
825822 await expect (
826823 contract
827824 . connect ( fullLp )
@@ -834,7 +831,7 @@ describe("PegInContract registerPegIn function should", () => {
834831 )
835832 )
836833 . to . be . revertedWithCustomError ( QuotesLib , "AmountTooLow" )
837- . withArgs ( peginAmount , minValue ) ;
834+ . withArgs ( peginAmount , expectedRoundedAmount ( quote ) ) ;
838835 await expect ( contract . getCurrentContribution ( ) ) . to . eventually . eq ( 0n ) ;
839836 await expect ( contract . getQuoteStatus ( quoteHash ) ) . to . eventually . eq (
840837 PegInStates . UNPROCESSED_QUOTE
0 commit comments