-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add params to IR factory #198
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,9 @@ contract InstantRewardsV2 is InstantRewards { | |
|
||
uint256 public start; | ||
uint256 public end; | ||
string public promoUrl; | ||
string public avatarUrl; | ||
string public description; | ||
Comment on lines
+11
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider adding length validation for metadata fields The new public string variables could lead to excessive gas costs during deployment if the strings are too long. Consider adding length validation in the constructor. + error MetadataFieldTooLong();
+ uint256 private constant MAX_METADATA_LENGTH = 512; // Adjust as needed
constructor(...) {
+ if (
+ bytes(promoUrl_).length > MAX_METADATA_LENGTH ||
+ bytes(avatarUrl_).length > MAX_METADATA_LENGTH ||
+ bytes(description_).length > MAX_METADATA_LENGTH
+ ) revert MetadataFieldTooLong();
// existing code
}
|
||
|
||
event TimeframeUpdated(uint256 start, uint256 end); | ||
|
||
|
@@ -20,13 +23,19 @@ contract InstantRewardsV2 is InstantRewards { | |
address owner, | ||
uint256 start_, | ||
uint256 end_, | ||
string memory name_ | ||
string memory name_, | ||
string memory promoUrl_, | ||
string memory avatarUrl_, | ||
string memory description_ | ||
) InstantRewards(signerAddress_, owner) { | ||
if (signerAddress_ == address(0)) revert InvalidAddress(); | ||
if (start_ > end_) revert InvalidTimeframe(); | ||
start = start_; | ||
end = end_; | ||
name = name_; | ||
promoUrl = promoUrl_; | ||
avatarUrl = avatarUrl_; | ||
description = description_; | ||
} | ||
|
||
function isActive() public view returns (bool) { | ||
|
@@ -48,7 +57,6 @@ contract InstantRewardsV2 is InstantRewards { | |
} | ||
|
||
function withdraw(address wallet, uint256 amount) public override onlyOwner { | ||
if (isActive()) revert InstantRewardStillActive(); | ||
super.withdraw(wallet, amount); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,16 @@ describe("Instant Rewards Contract test", () => { | |
const instantRewardsFactoryF = await ethers.getContractFactory("InstantRewardsFactory"); | ||
instantRewardsFactory = (await instantRewardsFactoryF.deploy(owner.address)) as InstantRewardsFactory; | ||
await instantRewardsFactory.deployed(); | ||
await instantRewardsFactory.connect(owner).acceptOwnership(); | ||
}); | ||
|
||
it("Should deploy an IR instance", async () => { | ||
const currentBlock = await ethers.provider.getBlock("latest"); | ||
const start = currentBlock.timestamp + 1000; | ||
const end = start + 1000; | ||
const name = "Instant Rewards"; | ||
const tx = instantRewardsFactory.connect(owner).createInstantRewards(signer.address, start, end, name); | ||
const tx = instantRewardsFactory | ||
.connect(owner) | ||
.createInstantRewards(signer.address, start, end, name, "http://img.com", "http://avatar.com", "Description"); | ||
Comment on lines
+27
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance test coverage for metadata fields The current tests only verify happy path scenarios with hardcoded values. Consider adding test cases for:
Example test structure: it("Should revert when metadata exceeds maximum length", async () => {
const longString = "a".repeat(1000);
await expect(
instantRewardsFactory.createInstantRewards(
signer.address,
start,
end,
name,
longString,
"http://avatar.com",
"Description"
)
).to.be.revertedWith("MetadataFieldTooLong");
}); Also applies to: 51-59, 70-78 |
||
await expect(tx).to.emit(instantRewardsFactory, "InstantRewardsCreated"); | ||
|
||
const events = await instantRewardsFactory.queryFilter("InstantRewardsCreated"); | ||
|
@@ -47,7 +48,15 @@ describe("Instant Rewards Contract test", () => { | |
const start = currentBlock.timestamp + 1000; | ||
const end = start + 1000; | ||
const name = "Instant Rewards"; | ||
const tx = instantRewardsFactory.createInstantRewards(signer.address, start, end, name); | ||
const tx = instantRewardsFactory.createInstantRewards( | ||
signer.address, | ||
start, | ||
end, | ||
name, | ||
"http://img.com", | ||
"http://avatar.com", | ||
"Description" | ||
); | ||
await expect(tx).to.revertedWith("AccessDenied"); | ||
}); | ||
|
||
|
@@ -58,7 +67,15 @@ describe("Instant Rewards Contract test", () => { | |
const start = currentBlock.timestamp + 1000; | ||
const end = start + 1000; | ||
const name = "Instant Rewards"; | ||
const tx = instantRewardsFactory.createInstantRewards(signer.address, start, end, name); | ||
const tx = instantRewardsFactory.createInstantRewards( | ||
signer.address, | ||
start, | ||
end, | ||
name, | ||
"http://img.com", | ||
"http://avatar.com", | ||
"Description" | ||
); | ||
await expect(tx).to.emit(instantRewardsFactory, "InstantRewardsCreated"); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider validating new string parameters to prevent empty values
The new parameters
promoUrl
,avatarUrl
, anddescription
are accepted without validation. To ensure data integrity, consider adding checks to validate that these strings are not empty and conform to expected formats.Apply this diff to add validation:
Ensure to define the new error types accordingly.