-
Notifications
You must be signed in to change notification settings - Fork 7
Add "areRightsConserved" and "isOfferSafe" functions with tests #123
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the way the tests are structured.
Whoops, Mark reminded me that it will likely be |
Done |
a6c0470
to
aa689a9
Compare
6b4bc70
to
d9ed395
Compare
477a9a9
to
4ff3341
Compare
d9ed395
to
1a4868c
Compare
core/zoe/isOfferSafe.js
Outdated
const refundOk = rulesPerIssuer | ||
.map((rule, i) => { | ||
insist( | ||
allowedRules.includes(rule.rule), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When there are more than two issuers, for many players, they will only submit rules for a subset of the issuers. While this representation can deal with that, it seems unnatural. We should simply allow the rules array for a given player to have a null
or something for the issuers that it doesn't care about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea. Should we support null
and undefined
as offerDescElem
s or only null
? In general, are there benefits to preferring one over the other? I'm allowing both for now.
const anyTrue = (prev, curr) => prev || curr; | ||
|
||
// https://stackoverflow.com/questions/17428587/transposing-a-2d-array-in-javascript/41772644#41772644 | ||
const transpose = matrix => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you actually need both representations, or could you just keep it in the transposed form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only need the transposed version to do the conservation of rights check, because that's summing by issuer column, whereas most everything else is concerned with a player perspective (the rows). Since we don't actually store both, I think this is ok. Did you think this would give bad performance?
0fedf69
to
5081ac6
Compare
0203124
to
f923896
Compare
This PR is part of the Zoe implementation. It adds helper functions for determining whether a reallocation of quantities conserves rights (has the same total quantity per issuer) and whether a reallocation is "offer-safe" for each user.