-
Notifications
You must be signed in to change notification settings - Fork 114
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: Enforce MarketParam.Pair uniqueness constraint #1193
Merged
Christopher-Li
merged 7 commits into
dydxprotocol:main
from
skip-mev:eric/restrict-unique-pairs
Mar 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9dc0311
Enforce MarketParam.Pair uniqueness constraint
Eric-Warehime c867d60
Fix perps tests
Eric-Warehime 4d7e839
Fix the rest of the tests
Eric-Warehime 0524fc8
Prevent updating MarketParam.Pair
Eric-Warehime bde69f3
Fix lint
Eric-Warehime 2082e88
Fix prices test
Eric-Warehime e138330
Allow updates again
Eric-Warehime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -158,7 +158,7 @@ func TestCreateMarket_Errors(t *testing.T) { | |||
exchangeConfigJson: validExchangeConfigJson, | ||||
expectedErr: errorsmod.Wrap( | ||||
types.ErrInvalidInput, | ||||
"market param id 0 does not match market price id 1", | ||||
"market param id 1 does not match market price id 2", | ||||
).Error(), | ||||
}, | ||||
"Market param and price exponents don't match": { | ||||
|
@@ -170,15 +170,29 @@ func TestCreateMarket_Errors(t *testing.T) { | |||
exchangeConfigJson: validExchangeConfigJson, | ||||
expectedErr: errorsmod.Wrap( | ||||
types.ErrInvalidInput, | ||||
"market param 0 exponent -6 does not match market price 0 exponent -5", | ||||
"market param 1 exponent -6 does not match market price 1 exponent -5", | ||||
).Error(), | ||||
}, | ||||
"Pair already exists": { | ||||
pair: "0-0", | ||||
minExchanges: uint32(2), | ||||
minPriceChangePpm: uint32(50), | ||||
price: constants.FiveBillion, | ||||
exchangeConfigJson: validExchangeConfigJson, | ||||
expectedErr: errorsmod.Wrap( | ||||
types.ErrMarketParamPairAlreadyExists, | ||||
"0-0", | ||||
).Error(), | ||||
}, | ||||
} | ||||
for name, tc := range tests { | ||||
t.Run(name, func(t *testing.T) { | ||||
ctx, keeper, _, _, _, _ := keepertest.PricesKeepers(t) | ||||
ctx, keeper, _, _, _, mockTimeKeeper := keepertest.PricesKeepers(t) | ||||
ctx = ctx.WithTxBytes(constants.TestTxBytes) | ||||
|
||||
mockTimeKeeper.On("Now").Return(constants.TimeT) | ||||
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. Why do we need a timekeeper now? 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 other test cases never succesfully create a market param. They all fail before hitting this line
The additional test case relies on a market param already existing so it has to be able to succeed once. |
||||
keepertest.CreateNMarkets(t, ctx, keeper, 1) | ||||
|
||||
marketPriceIdOffset := uint32(0) | ||||
if tc.marketPriceIdDoesntMatchMarketParamId { | ||||
marketPriceIdOffset = uint32(1) | ||||
|
@@ -192,31 +206,31 @@ func TestCreateMarket_Errors(t *testing.T) { | |||
_, err := keeper.CreateMarket( | ||||
ctx, | ||||
types.MarketParam{ | ||||
Id: 0, | ||||
Id: 1, | ||||
Pair: tc.pair, | ||||
Exponent: int32(-6), | ||||
MinExchanges: tc.minExchanges, | ||||
MinPriceChangePpm: tc.minPriceChangePpm, | ||||
ExchangeConfigJson: tc.exchangeConfigJson, | ||||
}, | ||||
types.MarketPrice{ | ||||
Id: 0 + marketPriceIdOffset, | ||||
Id: 1 + marketPriceIdOffset, | ||||
Exponent: int32(-6) + marketPriceExponentOffset, | ||||
Price: tc.price, | ||||
}, | ||||
) | ||||
require.EqualError(t, err, tc.expectedErr) | ||||
|
||||
// Verify no new MarketPrice created. | ||||
_, err = keeper.GetMarketPrice(ctx, 0) | ||||
_, err = keeper.GetMarketPrice(ctx, 1) | ||||
require.EqualError( | ||||
t, | ||||
err, | ||||
errorsmod.Wrap(types.ErrMarketPriceDoesNotExist, lib.UintToString(uint32(0))).Error(), | ||||
errorsmod.Wrap(types.ErrMarketPriceDoesNotExist, lib.UintToString(uint32(1))).Error(), | ||||
) | ||||
|
||||
// Verify no new market event. | ||||
keepertest.AssertMarketEventsNotInIndexerBlock(t, keeper, ctx) | ||||
keepertest.AssertNMarketEventsNotInIndexerBlock(t, keeper, ctx, 1) | ||||
}) | ||||
} | ||||
} | ||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This doesn't seem necessary? Isn't there already a check that the updatedMarket must already exist in state + we've introduced a uniqueness constraint across all market-pairs in state?
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.
Looks like this check is actually necessary, as it's possible for a
MarketParam
update to change the marketParam.Pair, and the updated Pair may conflict with one in state