@@ -2,7 +2,7 @@ const { expect } = require("chai");
2
2
const { ethers } = require ( "hardhat" ) ;
3
3
const { BigNumber } = ethers ;
4
4
const crypto = require ( "crypto" ) ;
5
- const { constants } = require ( "ethers" ) ;
5
+ const { constants, utils } = require ( "ethers" ) ;
6
6
7
7
const EXAMPLE_IPFS_CIDv1 = "bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi" ;
8
8
const ANOTHER_EXAMPLE_IPFS_CIDv1 = "bafybeigdyrzt5sfp7OKOKAHLSKASLK2LK3JLlqabf3oclgtqy55fbzdi" ;
@@ -13,7 +13,7 @@ const APPEAL_WINDOW = 1000;
13
13
const ONE_ETH = BigNumber . from ( BigInt ( 1e18 ) ) ;
14
14
const TWO_ETH = BigNumber . from ( 2 ) . mul ( BigNumber . from ( BigInt ( 1e18 ) ) ) ;
15
15
const FIVE_ETH = BigNumber . from ( 5 ) . mul ( BigNumber . from ( BigInt ( 1e18 ) ) ) ;
16
- const TEN_ETH = BigNumber . from ( 1000 ) . mul ( BigNumber . from ( BigInt ( 1e18 ) ) ) ;
16
+ const TEN_ETH = BigNumber . from ( 10 ) . mul ( BigNumber . from ( BigInt ( 1e18 ) ) ) ;
17
17
18
18
const TIMELOCK_PERIOD = 1000000 ;
19
19
@@ -28,8 +28,8 @@ function sleep(ms) {
28
28
29
29
describe ( "The Truth Post" , ( ) => {
30
30
before ( "Deploying" , async ( ) => {
31
- [ deployer , author , supporter , challenger , innocentBystander ] = await ethers . getSigners ( ) ;
32
- ( { arbitrator, truthPost } = await deployContracts ( deployer ) ) ;
31
+ [ deployer , newAdmin , author , supporter , challenger , innocentBystander , treasury ] = await ethers . getSigners ( ) ;
32
+ ( { arbitrator, truthPost } = await deployContracts ( deployer , treasury ) ) ;
33
33
await sleep ( 9000 ) ; // To wait for eth gas reporter to fetch data. Remove this line when the issue is fixed. https://github.com/cgewecke/hardhat-gas-reporter/issues/72
34
34
NUMBER_OF_LEAST_SIGNIFICANT_BITS_TO_IGNORE = await truthPost . connect ( deployer ) . NUMBER_OF_LEAST_SIGNIFICANT_BITS_TO_IGNORE ( ) ;
35
35
MULTIPLIER_DENOMINATOR = await truthPost . connect ( deployer ) . MULTIPLIER_DENOMINATOR ( ) ;
@@ -94,7 +94,7 @@ describe("The Truth Post", () => {
94
94
}
95
95
} ) ;
96
96
97
- it ( "Should challenge a article" , async ( ) => {
97
+ it ( "Should challenge an article" , async ( ) => {
98
98
const ARTICLE_ADDRESS = 0 ;
99
99
100
100
const challengeFee = await truthPost . connect ( deployer ) . challengeFee ( ARTICLE_ADDRESS ) ;
@@ -113,7 +113,6 @@ describe("The Truth Post", () => {
113
113
114
114
it ( "Should fund appeal of a dispute" , async ( ) => {
115
115
const DISPUTE_ID = disputeCounter - 1 ;
116
- const ARTICLE_ADDRESS = 0 ;
117
116
118
117
await arbitrator . connect ( deployer ) . giveRuling ( DISPUTE_ID , RULING_OUTCOMES . ChallengeFailed , APPEAL_WINDOW ) ;
119
118
await ethers . provider . send ( "evm_increaseTime" , [ 10 ] ) ;
@@ -258,10 +257,59 @@ describe("The Truth Post", () => {
258
257
expect ( await truthPost . getAmountRemainsToBeRaised ( DISPUTE_ID , RULING_OUTCOMES . Debunked ) ) . to . eq ( WINNER_FUNDING ) ;
259
258
expect ( await truthPost . getAmountRemainsToBeRaised ( DISPUTE_ID , RULING_OUTCOMES . ChallengeFailed ) ) . to . eq ( LOSER_FUNDING ) ;
260
259
} ) ;
260
+
261
+ it ( "Should collect correct amount of taxes" , async ( ) => {
262
+ const vacantSlotIndex = await truthPost . findVacantStorageSlot ( 0 ) ;
263
+ const bounty = TEN_ETH ;
264
+
265
+ const args = [ crypto . randomBytes ( 30 ) . toString ( "hex" ) , 0 , vacantSlotIndex ] ;
266
+ await truthPost . connect ( deployer ) . initializeArticle ( ...args , { value : bounty } ) ;
267
+
268
+ const challengeFee = await truthPost . challengeFee ( vacantSlotIndex ) ;
269
+
270
+ let storageTreasuryBalanceBefore = await truthPost . treasuryBalance ( ) ;
271
+ await truthPost . connect ( challenger ) . challenge ( vacantSlotIndex , { value : challengeFee } ) ;
272
+ const storageTreasuryBalanceAfter = await truthPost . treasuryBalance ( ) ;
273
+ const storageTreasuryBalanceDelta = storageTreasuryBalanceAfter . sub ( storageTreasuryBalanceBefore ) ;
274
+
275
+ const challengeTaxRate = await truthPost . challengeTaxRate ( ) ;
276
+ const denominator = await truthPost . MULTIPLIER_DENOMINATOR ( ) ;
277
+
278
+ expect ( challengeTaxRate . mul ( 10000 ) . div ( denominator ) ) . equal ( storageTreasuryBalanceDelta . mul ( 10000 ) . div ( bounty ) ) ;
279
+
280
+ storageTreasuryBalanceBefore = storageTreasuryBalanceAfter ;
281
+ const treasuryBalanceBefore = await ethers . provider . getBalance ( treasury . address ) ;
282
+ await truthPost . connect ( deployer ) . transferBalanceToTreasury ( ) ;
283
+ const treasuryBalanceAfter = await ethers . provider . getBalance ( treasury . address ) ;
284
+ const treasuryBalanceDelta = treasuryBalanceAfter . sub ( treasuryBalanceBefore ) ;
285
+
286
+ expect ( storageTreasuryBalanceBefore ) . equal ( treasuryBalanceDelta ) ;
287
+ expect ( await truthPost . treasuryBalance ( ) ) . equal ( BigNumber . from ( 0 ) ) ;
288
+ } ) ;
289
+
290
+ it ( "should not allow to set a new admin" , async ( ) => {
291
+ await expect ( truthPost . connect ( newAdmin ) . changeAdmin ( newAdmin . address ) ) . to . be . reverted ;
292
+ } ) ;
293
+
294
+ it ( "Should set a new admin" , async ( ) => {
295
+ await truthPost . connect ( deployer ) . changeAdmin ( newAdmin . address ) ;
296
+ expect ( await truthPost . admin ( ) ) . equal ( newAdmin . address ) ;
297
+ } ) ;
298
+
299
+ it ( "Should allow only admin to set new tax rate" , async ( ) => {
300
+ const newTaxRate = 128 ;
301
+ await truthPost . connect ( newAdmin ) . updateChallengeTaxRate ( newTaxRate ) ;
302
+ expect ( await truthPost . challengeTaxRate ( ) ) . equal ( BigNumber . from ( newTaxRate ) ) ;
303
+ } ) ;
304
+
305
+ it ( "Should not allow to increase the tax rate more than 25%" , async ( ) => {
306
+ await expect ( truthPost . connect ( newAdmin ) . updateChallengeTaxRate ( 512 ) )
307
+ . to . be . revertedWith ( "The tax rate can only be increased by a maximum of 25%" ) ;
308
+ } ) ;
261
309
} ) ;
262
310
} ) ;
263
311
264
- async function deployContracts ( deployer ) {
312
+ async function deployContracts ( deployer , treasury ) {
265
313
const SHARE_DENOMINATOR = 1_000_000 ;
266
314
const MIN_FUND_INCREASE_PERCENT = 25 ;
267
315
const MIN_BOUNTY = ONE_ETH . div ( BigNumber . from ( 1e3 ) ) ;
@@ -272,7 +320,7 @@ async function deployContracts(deployer) {
272
320
273
321
const TruthPost = await ethers . getContractFactory ( "TruthPost" , deployer ) ;
274
322
// const truthPost = await PMW.deploy({ arbitrator: arbitrator.address, arbitratorExtraData: "0x00" }, SHARE_DENOMINATOR, MIN_FUND_INCREASE_PERCENT, MIN_BOUNTY);
275
- const truthPost = await TruthPost . deploy ( arbitrator . address , "0x00" , "Metaevidence" , TIMELOCK_PERIOD , WINNER_STAKE_MULTIPLIER , LOSER_STAKE_MULTIPLIER ) ;
323
+ const truthPost = await TruthPost . deploy ( arbitrator . address , "0x00" , "Metaevidence" , TIMELOCK_PERIOD , WINNER_STAKE_MULTIPLIER , LOSER_STAKE_MULTIPLIER , treasury . address ) ;
276
324
277
325
await truthPost . deployed ( ) ;
278
326
0 commit comments