Skip to content
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

Added tests and corrected code #32

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

DarkLord017
Copy link

@DarkLord017 DarkLord017 commented May 20, 2024

  1. Deleted looping and use teamIndex to directly enter a team
  2. Added some view function and tests
  3. Since contract size was large and had to comment out many function to test so i created new file of test just to test the team initialization , join other team and leave a team

@DarkLord017 DarkLord017 marked this pull request as draft May 22, 2024 05:03
@DarkLord017 DarkLord017 marked this pull request as ready for review May 22, 2024 10:38
@lordshashank lordshashank self-requested a review June 13, 2024 12:17
Comment on lines 448 to 460
for (uint256 i = 0; i < totalParticipants.length; i++) {
if(duplication[totalParticipants[i]] == false){
duplication[totalParticipants[i]] = true;
builderToTeam[totalParticipants[i]] = s_teams[s_teams.length - 1];
}else{
revert("Duplication detected");
}

}

for(uint256 i = 0 ; i < totalParticipants.length; i++){
duplication[totalParticipants[i]] = false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DarkLord017 I am not able to understand whats the use of duplication mapping here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that so as if same address are passed in the array the array will store both the address and count both the same addresses as unique member to remove this I did this check . Should I remove it ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just create a modifier for that to check the array.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok sir

@@ -134,9 +137,20 @@ contract DappHack is ProjectNFTs {
}

//create mapping for this
modifier NotInTeam() {
modifier NotInTeam(address[] memory participants, address MsgSender) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better make modifier take just an array of addresses (remove second param), would become more handy. And send the participant array adding msg.sender to it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sir i did all the changes please check

1. Added few test to check for duplicate participants 
2.updated the code to correct NotInTeam modifier and added  modifier to check Duplication
@lordshashank lordshashank self-requested a review June 23, 2024 06:31
@@ -68,7 +70,8 @@ contract DappHack is ProjectNFTs {
//winners
Winner[] public s_winners;

mapping(uint256 => Winner) public sponsorToWinner; //track number to winner number
mapping(uint256 => Winner) public sponsorToWinner;
mapping(address => bool) private duplication; //track number to winner number
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for duplication array

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SIr corrected and committed the changes

contracts/contracts/dapphack.sol Outdated Show resolved Hide resolved
_;
}

modifier DuplicateParticipants(address[] memory participant) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey this is quite inefficient, you can do something like this

modifier DuplicateParticipants(address[] memory participant) {
    mapping(address => bool) seen;
    for (uint i = 0; i < participant.length; i++) {
        if (seen[participant[i]]) {
            revert("Duplicate Participants");
        }
        seen[participant[i]] = true;
    }
    // Check msg.sender separately if needed
    if (seen[msg.sender]) {
        revert("Duplicate Participants including msg.sender");
    }
    _;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
image
Ye error aa rhe hai sir

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants