-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,4 +135,71 @@ contract ComplexDelete { | |
function clearAllEducationHistory(uint256 userId) public { | ||
delete users[userId].educationHistory; | ||
} | ||
|
||
} | ||
|
||
contract UseComplexDelete { | ||
ComplexDelete t; | ||
|
||
constructor() { | ||
t = new ComplexDelete(); | ||
} | ||
|
||
function useIt() public { | ||
// Add users | ||
t.addUser(1, "Alice", "[email protected]", "1234567890"); | ||
t.addUser(2, "Bob", "[email protected]", "0987654321"); | ||
|
||
// Add addresses | ||
t.addUserAddress(1, "123 Main St", "New York", "USA", 10001); | ||
t.addUserAddress(1, "456 Elm St", "Los Angeles", "USA", 90001); | ||
t.addUserAddress(2, "789 Oak St", "Chicago", "USA", 60601); | ||
|
||
// Add employment history | ||
t.addEmploymentHistory(1, "TechCorp", "Developer", 1609459200, 1640995200); | ||
t.addEmploymentHistory(1, "WebSoft", "Senior Developer", 1641081600, 0); | ||
t.addEmploymentHistory(2, "DataFirm", "Analyst", 1577836800, 0); | ||
|
||
// Add education history | ||
t.addEducationHistory(1, "Tech University", "BSc Computer Science", 2020); | ||
t.addEducationHistory(2, "Data College", "MSc Data Science", 2019); | ||
|
||
// Set preferences | ||
t.setUserPreference(1, "receiveNewsletter", true); | ||
t.setUserPreference(1, "darkMode", false); | ||
t.setUserPreference(2, "receiveNewsletter", false); | ||
|
||
// Test deletions and updates | ||
|
||
// Delete an address | ||
t.deleteUserAddress(1, 0); | ||
|
||
// Delete employment history | ||
t.deleteEmploymentHistory(1, 0); | ||
|
||
// Delete education history | ||
t.deleteEducationHistory(2, 0); | ||
|
||
// Delete user preference | ||
t.deleteUserPreference(1, "darkMode"); | ||
|
||
// Update contact info | ||
t.updateContactInfo(2, "[email protected]", "1122334455"); | ||
|
||
// Clear all addresses for a user | ||
t.clearAllUserAddresses(1); | ||
|
||
// Clear all employment history for a user | ||
t.clearAllEmploymentHistory(2); | ||
|
||
// Clear all education history for a user | ||
t.clearAllEducationHistory(1); | ||
|
||
// Delete an entire user | ||
t.deleteUser(1); | ||
|
||
// Add a new user to test after deletions | ||
t.addUser(3, "Charlie", "[email protected]", "5556667777"); | ||
t.addUserAddress(3, "321 Pine St", "San Francisco", "USA", 94101); | ||
} | ||
} |