-
Notifications
You must be signed in to change notification settings - Fork 173
feat: Update oracle endblocker for historic pricing #1580
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
f071cec
Update oracle endblocker for historic pricing
rbajollari 1869ba0
Stamp prices and set median after updating exchange rate
rbajollari 4b46f4b
Empty-Commit
rbajollari a79b457
Merge branch 'main' into ryan/historacle-endblocker
rbajollari 75b832c
Update endblocker based on keeper updates
rbajollari ee9c854
Merge branch 'main' into ryan/historacle-endblocker
rbajollari e30263d
Merge branch 'main' into ryan/historacle-endblocker
rbajollari ba20509
Merge branch 'main' into ryan/historacle-endblocker
rbajollari d15b5b0
Integrate keeper and param changes
rbajollari c939a47
Merge branch 'main' into ryan/historacle-endblocker
rbajollari 180ee65
Merge branch 'main' into ryan/historacle-endblocker
rbajollari 879271b
Merge branch 'main' into ryan/historacle-endblocker
rbajollari c3de8b6
Fix comment
rbajollari c779eb7
Comment out median calc and setting in endblocker
rbajollari 68671c5
Make historacle keeper methods only called in experimental mode in or…
rbajollari 3bef9b1
Merge branch 'main' into ryan/historacle-endblocker
rbajollari 61a730f
Merge branch 'main' into ryan/historacle-endblocker
rbajollari 1b3ba2a
Merge branch 'main' into ryan/historacle-endblocker
rbajollari 02d813c
Add abci_test
rbajollari 26ce029
Merge branch 'main' into ryan/historacle-endblocker
rbajollari 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package oracle_test | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/simapp" | ||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
| "github.com/cosmos/cosmos-sdk/x/staking" | ||
| "github.com/cosmos/cosmos-sdk/x/staking/teststaking" | ||
| "github.com/stretchr/testify/suite" | ||
| "github.com/tendermint/tendermint/crypto/secp256k1" | ||
| tmrand "github.com/tendermint/tendermint/libs/rand" | ||
| tmproto "github.com/tendermint/tendermint/proto/tendermint/types" | ||
|
|
||
| umeeapp "github.com/umee-network/umee/v3/app" | ||
| appparams "github.com/umee-network/umee/v3/app/params" | ||
| "github.com/umee-network/umee/v3/x/oracle" | ||
| "github.com/umee-network/umee/v3/x/oracle/types" | ||
| ) | ||
|
|
||
| const ( | ||
| displayDenom string = appparams.DisplayDenom | ||
| bondDenom string = appparams.BondDenom | ||
| ) | ||
|
|
||
| type IntegrationTestSuite struct { | ||
| suite.Suite | ||
|
|
||
| ctx sdk.Context | ||
| app *umeeapp.UmeeApp | ||
| } | ||
|
|
||
| const ( | ||
| initialPower = int64(10000000000) | ||
| ) | ||
|
|
||
| func (s *IntegrationTestSuite) SetupTest() { | ||
| require := s.Require() | ||
| isCheckTx := false | ||
| app := umeeapp.Setup(s.T(), isCheckTx, 1) | ||
| ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{ | ||
| ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)), | ||
| Height: int64(types.DefaultMedianPeriod) - 1, | ||
| }) | ||
|
|
||
| oracle.InitGenesis(ctx, app.OracleKeeper, *types.DefaultGenesisState()) | ||
|
|
||
| sh := teststaking.NewHelper(s.T(), ctx, *app.StakingKeeper) | ||
| sh.Denom = bondDenom | ||
| amt := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction) | ||
|
|
||
| // mint and send coins to validators | ||
| require.NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) | ||
| require.NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, initCoins)) | ||
| require.NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) | ||
| require.NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr2, initCoins)) | ||
|
|
||
| sh.CreateValidator(valAddr, valPubKey, amt, true) | ||
| sh.CreateValidator(valAddr2, valPubKey2, amt, true) | ||
|
|
||
| staking.EndBlocker(ctx, *app.StakingKeeper) | ||
|
|
||
| s.app = app | ||
| s.ctx = ctx | ||
| } | ||
|
|
||
| // Test addresses | ||
| var ( | ||
| valPubKeys = simapp.CreateTestPubKeys(2) | ||
|
|
||
| valPubKey = valPubKeys[0] | ||
| pubKey = secp256k1.GenPrivKey().PubKey() | ||
| addr = sdk.AccAddress(pubKey.Address()) | ||
| valAddr = sdk.ValAddress(pubKey.Address()) | ||
|
|
||
| valPubKey2 = valPubKeys[1] | ||
| pubKey2 = secp256k1.GenPrivKey().PubKey() | ||
| addr2 = sdk.AccAddress(pubKey2.Address()) | ||
| valAddr2 = sdk.ValAddress(pubKey2.Address()) | ||
|
|
||
| initTokens = sdk.TokensFromConsensusPower(initialPower, sdk.DefaultPowerReduction) | ||
| initCoins = sdk.NewCoins(sdk.NewCoin(bondDenom, initTokens)) | ||
| ) | ||
rbajollari marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| func (s *IntegrationTestSuite) TestEndblockerExperimentalFlag() { | ||
| app, ctx := s.app, s.ctx | ||
|
|
||
| // add historic price and calcSet median stats | ||
| app.OracleKeeper.AddHistoricPrice(s.ctx, displayDenom, sdk.MustNewDecFromStr("1.0")) | ||
| app.OracleKeeper.CalcAndSetMedian(s.ctx, displayDenom) | ||
|
|
||
| // with experimental flag off median stats don't get cleared | ||
| oracle.EndBlocker(ctx, app.OracleKeeper, false) | ||
| median, err := app.OracleKeeper.GetMedian(s.ctx, displayDenom) | ||
| s.Require().NoError(err) | ||
| s.Require().Equal(sdk.MustNewDecFromStr("1.0"), median) | ||
|
|
||
| // with experimental flag on median stats get cleared | ||
| oracle.EndBlocker(ctx, app.OracleKeeper, true) | ||
| median, err = app.OracleKeeper.GetMedian(s.ctx, displayDenom) | ||
| s.Require().Error(err) | ||
| s.Require().Equal(sdk.ZeroDec(), median) | ||
| } | ||
|
|
||
| func TestOracleTestSuite(t *testing.T) { | ||
| suite.Run(t, new(IntegrationTestSuite)) | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.