-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update oracle endblocker for historic pricing (#1580)
* Update oracle endblocker for historic pricing * Stamp prices and set median after updating exchange rate * Empty-Commit * Update endblocker based on keeper updates * Integrate keeper and param changes * Fix comment * Comment out median calc and setting in endblocker * Make historacle keeper methods only called in experimental mode in oracle endblocker * Add abci_test
- Loading branch information
1 parent
3953226
commit f468a4c
Showing
7 changed files
with
189 additions
and
17 deletions.
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
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)) | ||
) | ||
|
||
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 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