Hi @mcgrane5 ,
Thanks much for the prompt reply, and for the explanations and thoughts about the edge cases, some of which I hadn’t thought about!
Anyway…below is my response. #2 is my most important item and is where I am currently blocked so would appreciate any comments/suggestions regarding #2.
-
Appreciate the code example for the delete function. Filip talked about something similar in his video on clearing filled orders from the order book. My plan was to implement something similar to your example, but, in true TDD fashion, not until my test fails at that point (could not find a delete function)
-
However, as you write, we first need to identify the index we want to delete. To do this, I want to generate a list of orders specific to a particular trader, so the trader can pick one of his orders to delete. I don’t want the whole BUY order book because I don’t want the trader to delete someone else’s order. This would be similar to a UI where a trader logs in and views a list of his current orders on an Orders screen.
And this is exactly where my test is currently failing. The traderBuyLimitOrders array is returning empty and I am getting the AssertionError (expected 0 to equal 3). See the When section of the test.
In order to make this assertion pass, I believe I need to figure out how to load an array with a subset of Orders where:
- trader = trader1.address
- ticker = Tokens.LINK
- Side = Side.BUY
so, 3 filter criteria, not just the 2 filter criteria we use for orderBook.
To do this, in the Dex.sol code, I wrapped the original orderBook mapping inside another mapping named traderOrderBook. See my code above. But this does not seem to be working. Seems like we should be able to create a mapping based on 3 keys. Do you have any comments or suggestions?
-
Regarding your last tip, so far my tests are running pretty fast. And I actually like the TDD approach of writing the tests first and then writing just enough code, and only the code required, to make the tests pass (à la Red, Green, Refactor). In any event, I want to keep coding this way for a while, get used to it, and see what I think. So far I like it because the tests make the requirements explicit (instead of in my head) and subsequently the tests are always there to catch problems when I refactor, such as your suggestion to move the sorting procedures to a separate function.
-
Lastly, I am currently coding in Atom on a Mac. So I have no way to easily try out code via point and click, like in Remix. So debugging is a challenge, and as a last resort, I have had to copy my files to Remix just to get the point & click and debugging features. I see that many of the Moralis instructors, including Ivan in a recent video I watched, use VisualStudio. Do you recommend that I move to VisualStudio? Does VisualStudio support point & click debugging similar to Remix?
Many thanks and look forward to your comments about #2. Best!