diff --git a/contracts/chat/ChatContextV1.sol b/contracts/chat/ChatContextV1.sol index c6de8df..19d79f7 100644 --- a/contracts/chat/ChatContextV1.sol +++ b/contracts/chat/ChatContextV1.sol @@ -26,7 +26,7 @@ contract ChatContextV1 is Ownable { address public modTokenAddress; // NFT, SBT, or ERC-20 token which is used to determine if an address is a mod uint256 public modMinBalance; // minimum balance of mod token required to be considered a mod bool public paused = false; // whether the contract is paused or not - uint256 public price = 0.0001 ether; // price to post a message (can serve as anti-spam measure; can be set to 0 to disable) + uint256 public price = 0.00001 ether; // price to post a message (can serve as anti-spam measure; can be set to 0 to disable) Message[] public mainMessages; // array of main messages mapping(uint256 => Message[]) public replies; // mapping from main message index to array of replies @@ -166,6 +166,10 @@ contract ChatContextV1 is Ownable { return replies[mainMsgIndex_].length; } + function isUserMod(address user_) external view returns (bool) { + return IModToken(modTokenAddress).balanceOf(user_) >= modMinBalance || user_ == owner(); + } + // WRITE FUNCTIONS /** diff --git a/contracts/chat/CommentsContextV1.sol b/contracts/chat/CommentsContextV1.sol index 9041acc..fac32df 100644 --- a/contracts/chat/CommentsContextV1.sol +++ b/contracts/chat/CommentsContextV1.sol @@ -26,7 +26,7 @@ contract CommentsContextV1 is Ownable { address public modTokenAddress; // NFT, SBT, or ERC-20 token which is used to determine if an address is a mod uint256 public modMinBalance; // minimum balance of mod token required to be considered a mod bool public paused = false; // whether the contract is paused or not - uint256 public price = 0.0001 ether; // price of a comment + uint256 public price = 0.00001 ether; // price of a comment mapping(address => Comment[]) public comments; // mapping from subject address to array of comments mapping(address => bool) public suspended; // whether an address is suspended from posting or not @@ -116,6 +116,10 @@ contract CommentsContextV1 is Ownable { return comments[subjectAddress_].length; } + function isUserMod(address user_) external view returns (bool) { + return IModToken(modTokenAddress).balanceOf(user_) >= modMinBalance || user_ == owner(); + } + // WRITE FUNCTIONS /** diff --git a/hardhat.config.js b/hardhat.config.js index 6a24eeb..34c6e78 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -200,7 +200,7 @@ module.exports = { gasPrice: 1000000000, // 1 gwei }, sepolia: { // Sepolia testnet - url: 'https://rpc2.sepolia.org', + url: 'https://rpc.sepolia.org', chainId: 11155111, accounts: [process.env.DEPLOYER_PRIVATE_KEY], gas: "auto", // gas limit diff --git a/test/chat/chatContextV1.test.js b/test/chat/chatContextV1.test.js index fca5ff2..9c9dabf 100644 --- a/test/chat/chatContextV1.test.js +++ b/test/chat/chatContextV1.test.js @@ -23,7 +23,7 @@ describe("ChatContextV1", function () { let chatContract; let modTokenContract; let owner, user1, user2, user3; - const price = ethers.utils.parseEther("0.0001"); + const price = ethers.utils.parseEther("0.00001"); beforeEach(async function () { [owner, user1, user2, user3] = await ethers.getSigners(); @@ -425,12 +425,16 @@ describe("ChatContextV1", function () { }); it("allows owner to withdraw revenue", async function () { + // change price to 0.01 + const newPrice = ethers.utils.parseEther("0.01"); + await chatContract.connect(owner).setPrice(newPrice); + // Create a message to generate revenue - await chatContract.connect(user2).createMessage("ipfs://message1", { value: price }); + await chatContract.connect(user2).createMessage("ipfs://message1", { value: newPrice }); // Check contract balance const contractBalance = await ethers.provider.getBalance(chatContract.address); - expect(contractBalance).to.equal(price); + expect(contractBalance).to.equal(newPrice); // Withdraw revenue const initialOwnerBalance = await ethers.provider.getBalance(owner.address); @@ -442,4 +446,29 @@ describe("ChatContextV1", function () { expect(finalOwnerBalance).to.be.above(initialOwnerBalance); }); + it("correctly identifies mods and non-mods", async function () { + // Check if owner is considered a mod + expect(await chatContract.isUserMod(owner.address)).to.be.true; + + // Check if user1 (who has a mod token) is considered a mod + expect(await chatContract.isUserMod(user1.address)).to.be.true; + + // Check if user2 (who doesn't have a mod token) is not considered a mod + expect(await chatContract.isUserMod(user2.address)).to.be.false; + + // Mint a mod token to user2 and check again + await modTokenContract.mint(user2.address); + expect(await chatContract.isUserMod(user2.address)).to.be.true; + + // Change the minimum balance required to be a mod + await chatContract.connect(owner).setModMinBalance(2); + + // Check if user2 (who now has 1 token) is no longer considered a mod + expect(await chatContract.isUserMod(user2.address)).to.be.false; + + // Mint another token to user2 and check again + await modTokenContract.mint(user2.address); + expect(await chatContract.isUserMod(user2.address)).to.be.true; + }); + }); \ No newline at end of file diff --git a/test/chat/commentsContextV1.test.js b/test/chat/commentsContextV1.test.js index 46d12d2..b916766 100644 --- a/test/chat/commentsContextV1.test.js +++ b/test/chat/commentsContextV1.test.js @@ -24,7 +24,7 @@ describe("CommentsContextV1", function () { let modTokenContract; let owner, user1, user2, user3; let subjectAddress; - const price = ethers.utils.parseEther("0.0001"); + const price = ethers.utils.parseEther("0.00001"); beforeEach(async function () { [owner, user1, user2, user3] = await ethers.getSigners(); @@ -406,4 +406,29 @@ describe("CommentsContextV1", function () { expect(await commentsContract.price()).to.equal(maxPrice); }); + it("correctly identifies mods and non-mods", async function () { + // Check if owner is considered a mod + expect(await commentsContract.isUserMod(owner.address)).to.be.true; + + // Check if user1 (who has a mod token) is considered a mod + expect(await commentsContract.isUserMod(user1.address)).to.be.true; + + // Check if user2 (who doesn't have a mod token) is not considered a mod + expect(await commentsContract.isUserMod(user2.address)).to.be.false; + + // Mint a mod token to user2 and check again + await modTokenContract.mint(user2.address); + expect(await commentsContract.isUserMod(user2.address)).to.be.true; + + // Change the minimum balance required to be a mod + await commentsContract.connect(owner).setModMinBalance(2); + + // Check if user2 (who now has 1 token) is no longer considered a mod + expect(await commentsContract.isUserMod(user2.address)).to.be.false; + + // Mint another token to user2 and check again + await modTokenContract.mint(user2.address); + expect(await commentsContract.isUserMod(user2.address)).to.be.true; + }); + }); \ No newline at end of file