@@ -22,6 +22,17 @@ const XActionType = {
2222 TokenAnalysis : 5 ,
2323}
2424
25+ /**
26+ * @param {bigint } totalAmount
27+ * @param {bigint } burnPercentage
28+ * @returns {[bigint, bigint] }
29+ */
30+ const applyBurnPercentage = ( totalAmount , burnPercentage ) => {
31+ const burnAmount = ( totalAmount * burnPercentage ) / 100n
32+ const remainingAmount = totalAmount - burnAmount
33+ return [ remainingAmount , burnAmount ]
34+ }
35+
2536describe ( `XRequestProcessor tests` , function ( ) {
2637 async function deployXRequestProcessorFixture ( ) {
2738 const [ owner , user1 ] = await ethers . getSigners ( )
@@ -179,8 +190,14 @@ describe(`XRequestProcessor tests`, function () {
179190 const userBalanceAfter = await tokenContract . balanceOf ( user1 . address )
180191 expect ( userBalanceAfter ) . to . equal ( 0n )
181192
193+ const burnPercent = await processorContract . getBurnPercentage ( )
194+ const [ paymentAmount , burnAmount ] = applyBurnPercentage ( repostAmount , burnPercent )
195+
182196 const processorContractBalance = await tokenContract . balanceOf ( processorContractAddress )
183- expect ( processorContractBalance ) . to . equal ( repostAmount )
197+ expect ( processorContractBalance ) . to . equal ( paymentAmount )
198+
199+ const deadAddressBalance = await tokenContract . balanceOf ( await processorContract . DEAD_ADDRESS ( ) )
200+ expect ( deadAddressBalance ) . to . equal ( burnAmount )
184201 } )
185202
186203 it ( 'interactWithPost() - User should be able to invoke XActionType.TokenAnalysis actions' , async function ( ) {
@@ -305,6 +322,28 @@ describe(`XRequestProcessor tests`, function () {
305322 . reverted
306323 } )
307324
325+ it ( 'setBurnPercentage() - Regular user should NOT be able to change the burn percentage' , async function ( ) {
326+ const { user1, processorContract } = await loadFixture ( deployXRequestProcessorFixture )
327+
328+ const newBurnPercent = 0n
329+ await expect ( processorContract . connect ( user1 ) . setBurnPercentage ( newBurnPercent ) ) . to . be . reverted
330+ } )
331+
332+ it ( 'setBurnPercentage() - Owner should be able to change the burn percentage between 0-100' , async function ( ) {
333+ const { owner, processorContract } = await loadFixture ( deployXRequestProcessorFixture )
334+
335+ const validPercentages = [ 0n , 15n , 25n , 50n , 80n , 100n ]
336+ for ( let percent of validPercentages ) {
337+ await expect ( processorContract . connect ( owner ) . setBurnPercentage ( percent ) ) . not . to . be . reverted
338+ expect ( await processorContract . getBurnPercentage ( ) , percent )
339+ }
340+
341+ const invalidPercentages = [ 101n , 150n , 200n ]
342+ for ( let percent of invalidPercentages ) {
343+ await expect ( processorContract . connect ( owner ) . setBurnPercentage ( percent ) ) . to . be . reverted
344+ }
345+ } )
346+
308347 it ( 'withdrawFunds() - Owner should be able to withdraw funds to a new address' , async function ( ) {
309348 const { owner, processorContract, tokenContract } = await loadFixture (
310349 deployXRequestProcessorFixture
@@ -315,13 +354,14 @@ describe(`XRequestProcessor tests`, function () {
315354 await tokenContract . connect ( owner ) . approve ( processorContractAddress , replyToThreadAmount )
316355 const xPostUri = 'https://x.com/SpaceX/status/1928107204931940365'
317356 await processorContract . connect ( owner ) . interactWithPost ( XActionType . ReplyToThread , xPostUri )
357+ const processorContractBalance = await tokenContract . balanceOf ( processorContractAddress )
318358
319359 const otherWallet = ethers . Wallet . createRandom ( )
320360 await expect ( processorContract . connect ( owner ) . withdrawFunds ( otherWallet . address ) ) . not . to . be
321361 . reverted
322362
323363 const otherWalletBalance = await tokenContract . balanceOf ( otherWallet . address )
324- expect ( otherWalletBalance ) . to . equal ( replyToThreadAmount )
364+ expect ( otherWalletBalance ) . to . equal ( processorContractBalance )
325365 } )
326366
327367 it ( 'withdrawFunds() - Regular user should NOT be able to withdraw funds' , async function ( ) {
0 commit comments