-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: min and max operators on coins #11200
Changes from all commits
50bd97e
6ebc10d
e1d1873
56d3a13
2059cd8
9ab5dbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -657,6 +657,33 @@ func (s *coinTestSuite) TestCoins_Validate() { | |||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func (s *coinTestSuite) TestMinMax() { | ||||||||||||||||||||||
one := sdk.OneInt() | ||||||||||||||||||||||
two := sdk.NewInt(2) | ||||||||||||||||||||||
|
||||||||||||||||||||||
cases := []struct { | ||||||||||||||||||||||
name string | ||||||||||||||||||||||
input1 sdk.Coins | ||||||||||||||||||||||
input2 sdk.Coins | ||||||||||||||||||||||
min sdk.Coins | ||||||||||||||||||||||
max sdk.Coins | ||||||||||||||||||||||
}{ | ||||||||||||||||||||||
{"zero-zero", sdk.Coins{}, sdk.Coins{}, sdk.Coins{}, sdk.Coins{}}, | ||||||||||||||||||||||
{"zero-one", sdk.Coins{}, sdk.Coins{{testDenom1, one}}, sdk.Coins{}, sdk.Coins{{testDenom1, one}}}, | ||||||||||||||||||||||
{"two-zero", sdk.Coins{{testDenom2, two}}, sdk.Coins{}, sdk.Coins{}, sdk.Coins{{testDenom2, two}}}, | ||||||||||||||||||||||
{"disjoint", sdk.Coins{{testDenom1, one}}, sdk.Coins{{testDenom2, two}}, sdk.Coins{}, sdk.Coins{{testDenom1, one}, {testDenom2, two}}}, | ||||||||||||||||||||||
{"overlap", sdk.Coins{{testDenom1, one}, {testDenom2, two}}, sdk.Coins{{testDenom1, two}, {testDenom2, one}}, | ||||||||||||||||||||||
sdk.Coins{{testDenom1, one}, {testDenom2, one}}, sdk.Coins{{testDenom1, two}, {testDenom2, two}}}, | ||||||||||||||||||||||
Comment on lines
+672
to
+676
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation for these methods claims
Which means that every denomination present in either input set-of-coins will be represented in the output set-of-coins. But that's different than the current behavior. Concretely, shouldn't this be as follows?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I understand it, zero-quantity denominations are omitted from Coins, so for instance in the "zero-one" case, we're comparing 0 vs 1 of testDenom1, and the min is zero, hence omitted from the result. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, zero must be ommitted from the result due to the guarantees expected on a valid coins object. I believe whats implemented is correct, perhaps we just need to update the code comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's surprising behavior! But then I'd agree an update to the documentation would be good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. I'll be filing an issue to clean up |
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
for _, tc := range cases { | ||||||||||||||||||||||
min := tc.input1.Min(tc.input2) | ||||||||||||||||||||||
max := tc.input1.Max(tc.input2) | ||||||||||||||||||||||
s.Require().True(min.IsEqual(tc.min), tc.name) | ||||||||||||||||||||||
s.Require().True(max.IsEqual(tc.max), tc.name) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
func (s *coinTestSuite) TestCoinsGT() { | ||||||||||||||||||||||
one := sdk.OneInt() | ||||||||||||||||||||||
two := sdk.NewInt(2) | ||||||||||||||||||||||
|
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.