Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Bulk Update Currencies for Listings #1423

Merged
merged 17 commits into from
Feb 25, 2019
Merged

Bulk Update Currencies for Listings #1423

merged 17 commits into from
Feb 25, 2019

Conversation

hoffmabc
Copy link
Member

This is a very similar API call to the one used to update moderators for all listings.

POST http://localhost:4002/ob/bulkupdatecurrency
Payload: { "currencies":["ZEC", "BTC", "BCH", "LTC"] }

This will update the listings.json as well as ALL listings themselves with the updated currency array.

@hoffmabc hoffmabc added the feature Feature or enhancement to openbazaar-go label Jan 23, 2019
@hoffmabc hoffmabc self-assigned this Jan 23, 2019
@hoffmabc hoffmabc requested review from placer14 and cpacia January 23, 2019 16:17
@cpacia
Copy link
Member

cpacia commented Jan 23, 2019

Looks good at first glance. I'll take a deeper look and test it later today.

@coveralls
Copy link

coveralls commented Jan 23, 2019

Coverage Status

Coverage increased (+0.04%) to 34.873% when pulling 4499e3a on update-currencies into 7df4799 on master.

Copy link
Member

@placer14 placer14 left a comment

Choose a reason for hiding this comment

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

This is fine as a quick solution. Before this is merged, I'd like to ensure theres:

  • unit test protecting the success case
  • unit test protecting walkpath's failure handling
  • unit test protecting updater's failure handling
  • updating the postman docs for this new endpoint

api/jsonapi.go Outdated Show resolved Hide resolved
Copy link
Member

@placer14 placer14 left a comment

Choose a reason for hiding this comment

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

I think we should also suspend the root hash updater while this bulk update is completing. Otherwise, each individual listing update will trigger the root hash to be updated in the push nodes and create a lot of network chatter. The root hash could be resumed after the bulk update and the final merkle root could be enough to cover all the changes.

@jjeffryes
Copy link
Collaborator

It looks like this branch set all the listings to track inventory, zero inventory on 2 of my nodes. I'll try and confirm that.

@jjeffryes
Copy link
Collaborator

I've verified that calling bulkupdatecurrency will set all of your listings' skus to have a quantity of zero instead of whatever they had before, which sets them to track inventory with an inventory of 0, making them unbuyable.

If they have a coupon, it also removes the discountCode entirely, which makes the coupon invalid.

This is a fairly serious bug, in my opinion.

@hoffmabc
Copy link
Member Author

The reason this bug occurs is that we perform this bulk update incorrectly.

The way it currently works is:

  • It pulls in a listing off disk
  • Update the currencies in the JSON
  • Update the listing by sending that to the API

This causes a problem because what's on disk is not what actually should get sent to the API. It's missing inventory and coupon information.

I will go ahead and update this code to perform this properly.

@hoffmabc hoffmabc changed the title Bulk Update Currencies for Listings Bulk Update Currencies for Listings [DO NOT MERGE] Jan 26, 2019
@hoffmabc hoffmabc changed the title Bulk Update Currencies for Listings [DO NOT MERGE] Bulk Update Currencies for Listings Jan 26, 2019
@hoffmabc
Copy link
Member Author

Ok @jjeffryes it looks like this is now considering the inventory and coupons. It wasn't as bad as I thought it would be. @placer14 we need a double check to make sure we're not doing anything else wrong here as we completely overlooked that it wasn't putting the coupons and inventory in there.

@jjeffryes
Copy link
Collaborator

This seems to be working as intended now.

@hoffmabc
Copy link
Member Author

Great. I just need to apply the other fixes @placer14 suggested.

@placer14 placer14 changed the title Bulk Update Currencies for Listings [WIP] Bulk Update Currencies for Listings Jan 28, 2019
@hoffmabc
Copy link
Member Author

I think we should also suspend the root hash updater while this bulk update is completing. Otherwise, each individual listing update will trigger the root hash to be updated in the push nodes and create a lot of network chatter. The root hash could be resumed after the bulk update and the final merkle root could be enough to cover all the changes.

This latest commit should defer the publish until everything is completed.

@hoffmabc
Copy link
Member Author

@jjeffryes ready for testing again with updates.

@placer14 what else is needed here?

Copy link
Member

@placer14 placer14 left a comment

Choose a reason for hiding this comment

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

Some thoughts on how to approach the testing.

return err
}

n.SeedNode()
Copy link
Member

Choose a reason for hiding this comment

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

This returns an error that needs to be checked and handled.


}
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Looking over the code again, my biggest concern is the amount of behavior we have inside of walkpath that is not verified. (https://github.com/OpenBazaar/openbazaar-go/pull/1423/files#diff-3ef083f7462052e03c5b8d5fed226805R188) The API test verifies the response, but doesn't look at the data to make sure the walkpath functionality worked properly. And it touches a bunch of points.

Two ways to solve this:
The harder (but preferred) of the ways to solve this would be pulling out each piece of behavior and unit testing the individual behavior. Then you can call the methods and be confident they are doing the right thing. You wouldn't need to test in the API layer and could have tighter tests around each specific behavior by itself. Bonus points if you walk through the code and replace other matching uses with your extracted/tested version.

The other easier way to solve this (though costs more in the longterm) would be by crafting a listing which exercises all of these features. A proper exercise would ensure:

  • sl.Listing.Metadata.AcceptedCurrencies = currencies was changed to a new value from an old different value
  • that coupons were properly reapplied to the listing
  • that shippingService.AdditionalItemPrice is set properly on legacy listings (how did you know to check this?)
  • that inventory is properly reapplied to the listing
    If you could craft such a perfect listing, you could simply do a GET /listing and ensure the above items match. (you might need to do more with inventory checking...)

Copy link
Member

Choose a reason for hiding this comment

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

A magic listing test runs the risk of not creating the example to sufficiently catch any regressions which may happen later (an impossible task). Another reason the unit tests would be preferred, as regressions in one part wouldn't necessarily be hard to fix across the codebase once it occurs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok I believe the 100% coverage on this stuff should cover your requests.

@hoffmabc
Copy link
Member Author

Ready for review @placer14

@hoffmabc hoffmabc changed the title [WIP] Bulk Update Currencies for Listings Bulk Update Currencies for Listings Feb 16, 2019
@hoffmabc
Copy link
Member Author

GTG @cpacia

@cpacia cpacia merged commit c92e4d4 into master Feb 25, 2019
@placer14 placer14 deleted the update-currencies branch March 21, 2019 22:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature or enhancement to openbazaar-go needs confirmation needs rebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants