Skip to content

Commit

Permalink
Added check for already existing players
Browse files Browse the repository at this point in the history
  • Loading branch information
kafann committed Sep 2, 2023
1 parent 99b3270 commit 762b630
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 14 deletions.
12 changes: 12 additions & 0 deletions packages/hardhat/contracts/Quest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ contract Quest is IExecutable {
isWhiteList == true,
"ERROR: Can't set the white list to a non-whitelisted contract"
);

bool playerInList = false;

for(uint32 i =0;i<_players.length;i++){

if(findIndexOfPlayer(_players[i])!=-1){
playerInList = true;
}
}

require(playerInList == false,"ERROR: One or more players is already in whitelist");

playerList = _players;
emit QuestWhiteListChanged(_players, block.timestamp);
}
Expand Down
45 changes: 36 additions & 9 deletions packages/hardhat/test/Quest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ describe("[Contract] Quest", function () {
});
describe("setWhiteList()", () => {
it("SHOULD set the player list to the one in the parameters", async () => {
//Arrange
const quest = await deployQuest(
"fakeTitle",
"0x",
Expand All @@ -983,17 +984,47 @@ describe("[Contract] Quest", function () {
0,
true
);
//Act
const act = () =>
quest.connect(creator).setWhiteList([player.address, other.address]);
await expect(act()).to.emit(quest, "QuestWhiteListChanged");
//Assert
await expect(act()).to.emit(quest, "QuestWhiteListChanged");
expect(await quest.getPlayers()).to.deep.eq([
player.address,
other.address,
]);
expect(await quest.canExecute(player.address)).to.eq(true);
expect(await quest.canExecute(other.address)).to.eq(true);
});
it("SHOULD revert if one or more players is already in list", async () => {
//Arrange
const quest = await deployQuest(
"fakeTitle",
"0x",
rewardToken,
epochNow + 3600, // in 1 hour
govern.address,
creator.address,
fromNumber(0),
createDepositToken,
depositAmount,
playDepositToken,
depositAmount,
creator,
0,
true
);
//Act
await quest.connect(creator).setWhiteList([player.address, other.address]);
const act = async () =>
await quest.connect(creator).setWhiteList([player.address]);
//Assert
await expect(act()).to.be.revertedWith(
"ERROR: One or more players is already in whitelist"
);
});
it("SHOULD revert if it's not a whitelisted quest", async () => {
//Arrange
const quest = await deployQuest(
"fakeTitle",
"0x",
Expand All @@ -1010,16 +1041,12 @@ describe("[Contract] Quest", function () {
0,
false
);
// const act = () =>
// quest
// .connect(govern)
// .claim(evidence, player.address, claimAmount, false);

// // Assert
// await expect(act()).to.be.revertedWith("ERROR: No evidence");
//Act
const act = () =>
quest.connect(creator).setWhiteList([player.address, other.address]);
await expect(act()).to.be.revertedWith(

//Assert
await expect(act()).to.be.revertedWith(
"ERROR: Can't set the white list to a non-whitelisted contract"
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/typechain/factories/ERC20__factory.ts

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/hardhat/typechain/factories/Quest__factory.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/hardhat/typechain/factories/TokenMock__factory.ts

Large diffs are not rendered by default.

0 comments on commit 762b630

Please sign in to comment.