error at test contract #6043
-
I tried to write a test for array remove by shifting but I got errors could you help me with it Contract
Test
errorError: missing argument: passed to contract (count=0, expectedCount=1, code=MISSING_ARGUMENT, `version=contracts/5.7.0) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
error
|
Beta Was this translation helpful? Give feedback.
-
Hello @muhammet72 I have tip for you, if you are removing items from array in for loop your array is changing and that is why you are keep getting errors, you should keep track of current array. Also very good practice to work on removals is to make reverse loops, so no i++ but use i-- instead :) |
Beta Was this translation helpful? Give feedback.
-
Hi @muhammet72 Some tips and examples for you below: for (uint borrower = borrowersLength[tokenId] - 1; borrower >= 0; borrower--) {
if (cert.tokenIdToBorrowToEnd[cert.tokenIdToBorrowers[borrower]] < block.timestamp) {
licenseStatusUpdater(tokenId, cert.tokenIdToBorrowers[borrower]);
}
} LicenseStatusUpdater function: // Removing borrower from array of borrowers for given tokenId
for (uint i = 0; i < cert.tokenIdToBorrowers.length; i++) {
if (cert.tokenIdToBorrowers[i] == borrower) {
emit LicenseRemoved(borrower, tokenId);
// Swapping borrower to be removed with last borrower in array
cert.tokenIdToBorrowers[i] = cert.tokenIdToBorrowers[cert.tokenIdToBorrowers.length - 1];
cert.tokenIdToBorrowers.pop();
}
} In this example we are searching for element in array, which we want to remove (meets certain conditions), once we find it we simply swaping it with last element in array and do |
Beta Was this translation helpful? Give feedback.
Hi @muhammet72
Some tips and examples for you below:
LicenseStatusUpdater function: