From 1e7fab294857b8c93b8ea5284d8bc864b9fb43d2 Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Tue, 29 Nov 2022 01:35:21 -0600 Subject: [PATCH 1/5] refactor!: revive dex module using intermediate test app --- app/app.go | 86 +++++++------ simapp/app.go | 1 + x/dex/client/testutil/cli_test.go | 7 +- x/dex/client/testutil/test_helpers.go | 6 +- x/dex/genesis_test.go | 4 +- x/dex/keeper/balances_test.go | 4 +- x/dex/keeper/grpc_query_test.go | 26 ++-- x/dex/keeper/keeper_test.go | 28 ++--- x/dex/keeper/liquidity_test.go | 12 +- x/dex/keeper/msg_server_test.go | 10 +- x/dex/keeper/params_test.go | 4 +- x/dex/keeper/swap_test.go | 4 +- x/testutil/testapp/config.go | 52 ++++++++ x/testutil/testapp/genesis.go | 80 +++++++++++++ x/testutil/testapp/testapp.go | 166 ++++++++++++++++++++++++++ x/testutil/testapp/testapp_test.go | 99 +++++++++++++++ 16 files changed, 502 insertions(+), 87 deletions(-) create mode 100644 x/testutil/testapp/config.go create mode 100644 x/testutil/testapp/genesis.go create mode 100644 x/testutil/testapp/testapp.go create mode 100644 x/testutil/testapp/testapp_test.go diff --git a/app/app.go b/app/app.go index 0b962c16a..d9068485e 100644 --- a/app/app.go +++ b/app/app.go @@ -104,6 +104,9 @@ import ( "github.com/CosmWasm/wasmd/x/wasm" "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/dex" + dexkeeper "github.com/NibiruChain/nibiru/x/dex/keeper" + dextypes "github.com/NibiruChain/nibiru/x/dex/types" "github.com/NibiruChain/nibiru/x/epochs" epochskeeper "github.com/NibiruChain/nibiru/x/epochs/keeper" epochstypes "github.com/NibiruChain/nibiru/x/epochs/types" @@ -168,6 +171,7 @@ var ( ibc.AppModuleBasic{}, ibctransfer.AppModuleBasic{}, // native x/ + dex.AppModuleBasic{}, pricefeed.AppModuleBasic{}, epochs.AppModuleBasic{}, perp.AppModuleBasic{}, @@ -184,6 +188,7 @@ var ( stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, + dextypes.ModuleName: {authtypes.Minter, authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, perptypes.ModuleName: {authtypes.Minter, authtypes.Burner}, perptypes.VaultModuleAccount: {}, @@ -223,8 +228,8 @@ type NibiruApp struct { // accountKeeper encodes/decodes accounts using the go-amino (binary) encoding/decoding library accountKeeper authkeeper.AccountKeeper - // bankKeeper defines a module interface that facilitates the transfer of coins between accounts - bankKeeper bankkeeper.Keeper + // BankKeeper defines a module interface that facilitates the transfer of coins between accounts + BankKeeper bankkeeper.Keeper capabilityKeeper *capabilitykeeper.Keeper stakingKeeper stakingkeeper.Keeper slashingKeeper slashingkeeper.Keeper @@ -262,6 +267,7 @@ type NibiruApp struct { perpKeeper perpkeeper.Keeper pricefeedKeeper pricefeedkeeper.Keeper vpoolKeeper vpoolkeeper.Keeper + DexKeeper dexkeeper.Keeper // WASM keepers wasmKeeper wasm.Keeper @@ -337,6 +343,7 @@ func NewNibiruApp( ibchost.StoreKey, ibctransfertypes.StoreKey, // nibiru x/ keys + dextypes.StoreKey, pricefeedtypes.StoreKey, epochstypes.StoreKey, perptypes.StoreKey, @@ -383,25 +390,25 @@ func NewNibiruApp( app.accountKeeper = authkeeper.NewAccountKeeper( appCodec, keys[authtypes.StoreKey], app.GetSubspace(authtypes.ModuleName), authtypes.ProtoBaseAccount, maccPerms, ) - app.bankKeeper = bankkeeper.NewBaseKeeper( + app.BankKeeper = bankkeeper.NewBaseKeeper( appCodec, keys[banktypes.StoreKey], app.accountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(), ) stakingKeeper := stakingkeeper.NewKeeper( - appCodec, keys[stakingtypes.StoreKey], app.accountKeeper, app.bankKeeper, app.GetSubspace(stakingtypes.ModuleName), + appCodec, keys[stakingtypes.StoreKey], app.accountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), ) app.mintKeeper = mintkeeper.NewKeeper( appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper, - app.accountKeeper, app.bankKeeper, authtypes.FeeCollectorName, + app.accountKeeper, app.BankKeeper, authtypes.FeeCollectorName, ) app.distrKeeper = distrkeeper.NewKeeper( - appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.accountKeeper, app.bankKeeper, + appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.accountKeeper, app.BankKeeper, &stakingKeeper, authtypes.FeeCollectorName, app.ModuleAccountAddrs(), ) app.slashingKeeper = slashingkeeper.NewKeeper( appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName), ) app.crisisKeeper = crisiskeeper.NewKeeper( - app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.bankKeeper, authtypes.FeeCollectorName, + app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName, ) app.feeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.accountKeeper) @@ -424,6 +431,10 @@ func NewNibiruApp( // ---------------------------------- Nibiru Chain x/ keepers + app.DexKeeper = dexkeeper.NewKeeper( + appCodec, keys[dextypes.StoreKey], app.GetSubspace(dextypes.ModuleName), + app.accountKeeper, app.BankKeeper, app.distrKeeper) + app.pricefeedKeeper = pricefeedkeeper.NewKeeper( appCodec, keys[pricefeedtypes.StoreKey], memKeys[pricefeedtypes.MemStoreKey], app.GetSubspace(pricefeedtypes.ModuleName), @@ -442,7 +453,7 @@ func NewNibiruApp( app.perpKeeper = perpkeeper.NewKeeper( appCodec, keys[perptypes.StoreKey], app.GetSubspace(perptypes.ModuleName), - app.accountKeeper, app.bankKeeper, app.pricefeedKeeper, app.vpoolKeeper, app.epochsKeeper, + app.accountKeeper, app.BankKeeper, app.pricefeedKeeper, app.vpoolKeeper, app.epochsKeeper, ) app.epochsKeeper.SetHooks( @@ -476,7 +487,7 @@ func NewNibiruApp( keys[wasm.StoreKey], app.GetSubspace(wasm.ModuleName), app.accountKeeper, - app.bankKeeper, + app.BankKeeper, app.stakingKeeper, app.distrKeeper, app.ibcKeeper.ChannelKeeper, @@ -511,7 +522,7 @@ func NewNibiruApp( /* ibctransfertypes.ChannelKeeper */ app.ibcKeeper.ChannelKeeper, /* ibctransfertypes.PortKeeper */ &app.ibcKeeper.PortKeeper, app.accountKeeper, - app.bankKeeper, + app.BankKeeper, app.scopedTransferKeeper, ) transferModule := ibctransfer.NewAppModule(app.transferKeeper) @@ -539,7 +550,7 @@ func NewNibiruApp( app.govKeeper = govkeeper.NewKeeper( appCodec, keys[govtypes.StoreKey], app.GetSubspace(govtypes.ModuleName), - app.accountKeeper, app.bankKeeper, &app.stakingKeeper, govRouter, + app.accountKeeper, app.BankKeeper, &app.stakingKeeper, govRouter, ) // -------------------------- Module Options -------------------------- @@ -551,17 +562,19 @@ func NewNibiruApp( var skipGenesisInvariants = cast.ToBool( appOpts.Get(crisis.FlagSkipGenesisInvariants)) + dexModule := dex.NewAppModule( + appCodec, app.DexKeeper, app.accountKeeper, app.BankKeeper) pricefeedModule := pricefeed.NewAppModule( - appCodec, app.pricefeedKeeper, app.accountKeeper, app.bankKeeper) + appCodec, app.pricefeedKeeper, app.accountKeeper, app.BankKeeper) epochsModule := epochs.NewAppModule(appCodec, app.epochsKeeper) perpModule := perp.NewAppModule( - appCodec, app.perpKeeper, app.accountKeeper, app.bankKeeper, + appCodec, app.perpKeeper, app.accountKeeper, app.BankKeeper, app.pricefeedKeeper, ) vpoolModule := vpool.NewAppModule( appCodec, app.vpoolKeeper, app.pricefeedKeeper, ) - utilModule := util.NewAppModule(app.bankKeeper) + utilModule := util.NewAppModule(app.BankKeeper) // NOTE: Any module instantiated in the module manager that is later modified // must be passed by reference here. @@ -571,21 +584,22 @@ func NewNibiruApp( encodingConfig.TxConfig, ), auth.NewAppModule(appCodec, app.accountKeeper, authsims.RandomGenesisAccounts), - vesting.NewAppModule(app.accountKeeper, app.bankKeeper), - bank.NewAppModule(appCodec, app.bankKeeper, app.accountKeeper), + vesting.NewAppModule(app.accountKeeper, app.BankKeeper), + bank.NewAppModule(appCodec, app.BankKeeper, app.accountKeeper), capability.NewAppModule(appCodec, *app.capabilityKeeper), crisis.NewAppModule(&app.crisisKeeper, skipGenesisInvariants), - feegrantmodule.NewAppModule(appCodec, app.accountKeeper, app.bankKeeper, app.feeGrantKeeper, app.interfaceRegistry), - gov.NewAppModule(appCodec, app.govKeeper, app.accountKeeper, app.bankKeeper), + feegrantmodule.NewAppModule(appCodec, app.accountKeeper, app.BankKeeper, app.feeGrantKeeper, app.interfaceRegistry), + gov.NewAppModule(appCodec, app.govKeeper, app.accountKeeper, app.BankKeeper), mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper), - slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper), - distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper), - staking.NewAppModule(appCodec, app.stakingKeeper, app.accountKeeper, app.bankKeeper), + slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.BankKeeper, app.stakingKeeper), + distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.BankKeeper, app.stakingKeeper), + staking.NewAppModule(appCodec, app.stakingKeeper, app.accountKeeper, app.BankKeeper), upgrade.NewAppModule(app.upgradeKeeper), params.NewAppModule(app.paramsKeeper), - authzmodule.NewAppModule(appCodec, app.authzKeeper, app.accountKeeper, app.bankKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.authzKeeper, app.accountKeeper, app.BankKeeper, app.interfaceRegistry), // native x/ + dexModule, pricefeedModule, epochsModule, vpoolModule, @@ -597,7 +611,7 @@ func NewNibiruApp( ibc.NewAppModule(app.ibcKeeper), transferModule, - wasm.NewAppModule(appCodec, &app.wasmKeeper, app.stakingKeeper, app.accountKeeper, app.bankKeeper), + wasm.NewAppModule(appCodec, &app.wasmKeeper, app.stakingKeeper, app.accountKeeper, app.BankKeeper), ) // During begin block slashing happens after distr.BeginBlocker so that @@ -623,6 +637,7 @@ func NewNibiruApp( vestingtypes.ModuleName, stakingtypes.ModuleName, // native x/ + dextypes.ModuleName, pricefeedtypes.ModuleName, epochstypes.ModuleName, vpooltypes.ModuleName, @@ -652,6 +667,7 @@ func NewNibiruApp( vestingtypes.ModuleName, // native x/ epochstypes.ModuleName, + dextypes.ModuleName, pricefeedtypes.ModuleName, vpooltypes.ModuleName, perptypes.ModuleName, @@ -687,6 +703,7 @@ func NewNibiruApp( // native x/ pricefeedtypes.ModuleName, epochstypes.ModuleName, + dextypes.ModuleName, vpooltypes.ModuleName, perptypes.ModuleName, utiltypes.ModuleName, @@ -719,15 +736,15 @@ func NewNibiruApp( // transactions app.sm = module.NewSimulationManager( auth.NewAppModule(appCodec, app.accountKeeper, authsims.RandomGenesisAccounts), - bank.NewAppModule(appCodec, app.bankKeeper, app.accountKeeper), - feegrantmodule.NewAppModule(appCodec, app.accountKeeper, app.bankKeeper, app.feeGrantKeeper, app.interfaceRegistry), - gov.NewAppModule(appCodec, app.govKeeper, app.accountKeeper, app.bankKeeper), + bank.NewAppModule(appCodec, app.BankKeeper, app.accountKeeper), + feegrantmodule.NewAppModule(appCodec, app.accountKeeper, app.BankKeeper, app.feeGrantKeeper, app.interfaceRegistry), + gov.NewAppModule(appCodec, app.govKeeper, app.accountKeeper, app.BankKeeper), mint.NewAppModule(appCodec, app.mintKeeper, app.accountKeeper), - staking.NewAppModule(appCodec, app.stakingKeeper, app.accountKeeper, app.bankKeeper), - distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper), - slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper), + staking.NewAppModule(appCodec, app.stakingKeeper, app.accountKeeper, app.BankKeeper), + distr.NewAppModule(appCodec, app.distrKeeper, app.accountKeeper, app.BankKeeper, app.stakingKeeper), + slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.BankKeeper, app.stakingKeeper), params.NewAppModule(app.paramsKeeper), - authzmodule.NewAppModule(appCodec, app.authzKeeper, app.accountKeeper, app.bankKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.authzKeeper, app.accountKeeper, app.BankKeeper, app.interfaceRegistry), // native x/ pricefeedModule, epochsModule, @@ -751,7 +768,7 @@ func NewNibiruApp( anteHandler, err := NewAnteHandler(AnteHandlerOptions{ HandlerOptions: ante.HandlerOptions{ AccountKeeper: app.accountKeeper, - BankKeeper: app.bankKeeper, + BankKeeper: app.BankKeeper, FeegrantKeeper: app.feeGrantKeeper, SignModeHandler: encodingConfig.TxConfig.SignModeHandler(), SigGasConsumer: ante.DefaultSigVerificationGasConsumer, @@ -983,14 +1000,15 @@ func initParamsKeeper( paramsKeeper.Subspace(slashingtypes.ModuleName) paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()) paramsKeeper.Subspace(crisistypes.ModuleName) - // Native module params keepers + // Native params keepers + paramsKeeper.Subspace(dextypes.ModuleName) paramsKeeper.Subspace(pricefeedtypes.ModuleName) paramsKeeper.Subspace(epochstypes.ModuleName) + paramsKeeper.Subspace(perptypes.ModuleName) // ibc params keepers paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) - paramsKeeper.Subspace(perptypes.ModuleName) - + // wasm params keepers paramsKeeper.Subspace(wasm.ModuleName) return paramsKeeper diff --git a/simapp/app.go b/simapp/app.go index 2caa2f294..2aaff54ef 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -1074,6 +1074,7 @@ func initParamsKeeper( // ibc params keepers paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) + // wasm params keepers paramsKeeper.Subspace(wasm.ModuleName) return paramsKeeper diff --git a/x/dex/client/testutil/cli_test.go b/x/dex/client/testutil/cli_test.go index aa1cd61a6..2b678adfa 100644 --- a/x/dex/client/testutil/cli_test.go +++ b/x/dex/client/testutil/cli_test.go @@ -7,9 +7,8 @@ import ( "github.com/stretchr/testify/suite" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" - testutilcli "github.com/NibiruChain/nibiru/x/testutil/cli" + "github.com/NibiruChain/nibiru/x/testutil/testapp" ) func TestIntegrationTestSuite(t *testing.T) { @@ -25,14 +24,14 @@ func TestIntegrationTestSuite(t *testing.T) { } app.SetPrefixes(app.AccountAddressPrefix) - genesisState := simapp.NewTestGenesisStateFromDefault() + genesisState := testapp.NewTestGenesisStateFromDefault() genesisState = WhitelistGenesisAssets( genesisState, coinsFromGenesis, ) - cfg := testutilcli.BuildNetworkConfig(genesisState) + cfg := testapp.BuildNetworkConfig(genesisState) cfg.StartingTokens = sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 2e12), // for pool creation fee and more for tx fees ) diff --git a/x/dex/client/testutil/test_helpers.go b/x/dex/client/testutil/test_helpers.go index a5ee8c001..c29456818 100644 --- a/x/dex/client/testutil/test_helpers.go +++ b/x/dex/client/testutil/test_helpers.go @@ -13,10 +13,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/NibiruChain/nibiru/app" - "github.com/NibiruChain/nibiru/simapp" "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/dex/client/cli" "github.com/NibiruChain/nibiru/x/dex/types" + "github.com/NibiruChain/nibiru/x/testutil/testapp" ) // commonArgs is args for CLI test commands. @@ -140,8 +140,8 @@ func ExecMsgSwapAssets( return clitestutil.ExecTestCLICmd(clientCtx, cli.CmdSwapAssets(), args) } -// WhitelistGenesisAssets given a simapp.GenesisState includes the whitelisted assets into Dex Whitelisted assets. -func WhitelistGenesisAssets(state simapp.GenesisState, assets []string) simapp.GenesisState { +// WhitelistGenesisAssets given a testapp.GenesisState includes the whitelisted assets into Dex Whitelisted assets. +func WhitelistGenesisAssets(state testapp.GenesisState, assets []string) testapp.GenesisState { encConfig := app.MakeTestEncodingConfig() jsonState := state[types.ModuleName] diff --git a/x/dex/genesis_test.go b/x/dex/genesis_test.go index fd753ac35..b5a4ba7be 100644 --- a/x/dex/genesis_test.go +++ b/x/dex/genesis_test.go @@ -5,7 +5,7 @@ import ( "github.com/NibiruChain/nibiru/x/testutil" - "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/testutil/testapp" "github.com/stretchr/testify/require" @@ -18,7 +18,7 @@ func TestGenesis(t *testing.T) { Params: types.DefaultParams(), } - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) dex.InitGenesis(ctx, app.DexKeeper, genesisState) got := dex.ExportGenesis(ctx, app.DexKeeper) require.NotNil(t, got) diff --git a/x/dex/keeper/balances_test.go b/x/dex/keeper/balances_test.go index 61e4d4843..ba8e9b838 100644 --- a/x/dex/keeper/balances_test.go +++ b/x/dex/keeper/balances_test.go @@ -5,7 +5,7 @@ import ( "github.com/NibiruChain/nibiru/x/testutil" - simapp2 "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/testutil/testapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -54,7 +54,7 @@ func TestCheckBalances(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) // fund user account sender := testutil.AccAddress() diff --git a/x/dex/keeper/grpc_query_test.go b/x/dex/keeper/grpc_query_test.go index a0b5b6bb6..11a0aeeec 100644 --- a/x/dex/keeper/grpc_query_test.go +++ b/x/dex/keeper/grpc_query_test.go @@ -5,7 +5,7 @@ import ( "github.com/NibiruChain/nibiru/x/testutil" - simapp2 "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/testutil/testapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -19,7 +19,7 @@ import ( ) func TestParamsQuery(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) params := types.DefaultParams() app.DexKeeper.SetParams(ctx, params) @@ -91,7 +91,7 @@ func TestQueryPoolHappyPath(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.DexKeeper) @@ -117,7 +117,7 @@ func TestQueryPoolFail(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) queryServer := keeper.NewQuerier(app.DexKeeper) resp, err := queryServer.Pool(sdk.WrapSDKContext(ctx), nil) require.Error(t, err) @@ -234,7 +234,7 @@ func TestQueryPools(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) for _, existingPool := range tc.existingPools { app.DexKeeper.SetPool(ctx, existingPool) } @@ -313,7 +313,7 @@ func TestQueryNumPools(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) sender := testutil.AccAddress() // need funds to create pools require.NoError(t, simapp.FundAccount( @@ -422,7 +422,7 @@ func TestQueryPoolParams(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.DexKeeper) @@ -459,7 +459,7 @@ func TestQueryTotalShares(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetPool(ctx, tc.existingPool) @@ -532,7 +532,7 @@ func TestQuerySpotPrice(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetPool(ctx, tc.existingPool) @@ -594,7 +594,7 @@ func TestQueryEstimateSwapExactAmountIn(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.DexKeeper) @@ -656,7 +656,7 @@ func TestQueryEstimateSwapExactAmountOut(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.DexKeeper) @@ -724,7 +724,7 @@ func TestQueryEstimateJoinExactAmountIn(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.DexKeeper) @@ -789,7 +789,7 @@ func TestQueryEstimateExitExactAmountIn(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetPool(ctx, tc.existingPool) queryServer := keeper.NewQuerier(app.DexKeeper) diff --git a/x/dex/keeper/keeper_test.go b/x/dex/keeper/keeper_test.go index 55b2a1a14..c669e1aff 100644 --- a/x/dex/keeper/keeper_test.go +++ b/x/dex/keeper/keeper_test.go @@ -5,7 +5,7 @@ import ( "github.com/NibiruChain/nibiru/x/testutil" - simapp2 "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/testutil/testapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -18,7 +18,7 @@ import ( ) func TestGetAndSetNextPoolNumber(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) // Write to store app.DexKeeper.SetNextPoolNumber(ctx, 150) @@ -30,7 +30,7 @@ func TestGetAndSetNextPoolNumber(t *testing.T) { } func TestGetNextPoolNumberAndIncrement(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) // Write a pool number app.DexKeeper.SetNextPoolNumber(ctx, 200) @@ -45,7 +45,7 @@ func TestGetNextPoolNumberAndIncrement(t *testing.T) { } func TestSetAndFetchPool(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) pool := types.Pool{ Id: 150, @@ -154,7 +154,7 @@ func TestFetchPoolFromPair(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetPool(ctx, types.Pool{ Id: 1, @@ -216,7 +216,7 @@ func TestFetchPoolFromPair(t *testing.T) { } func TestNewPool(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) poolCreationFeeCoin := sdk.NewInt64Coin(common.DenomNIBI, 1000_000_000) app.DexKeeper.SetParams(ctx, types.NewParams( @@ -287,7 +287,7 @@ func TestNewPool(t *testing.T) { } func TestNewPoolNotEnoughFunds(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) app.DexKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, @@ -328,7 +328,7 @@ func TestNewPoolNotEnoughFunds(t *testing.T) { } func TestNewPoolTooLittleAssets(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) @@ -349,7 +349,7 @@ func TestNewPoolTooLittleAssets(t *testing.T) { } func TestKeeperNewPoolNotWhitelistedAssets(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) @@ -374,7 +374,7 @@ func TestKeeperNewPoolNotWhitelistedAssets(t *testing.T) { } func TestNewPoolTooManyAssets(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) @@ -419,7 +419,7 @@ func TestNewPoolTooManyAssets(t *testing.T) { } func TestNewPoolDups(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) userAddr, err := sdk.AccAddressFromBech32(testutil.AccAddress().String()) require.NoError(t, err) @@ -574,7 +574,7 @@ func TestJoinPool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() @@ -703,7 +703,7 @@ func TestJoinPoolAllAssets(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() @@ -815,7 +815,7 @@ func TestExitPool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() diff --git a/x/dex/keeper/liquidity_test.go b/x/dex/keeper/liquidity_test.go index fc876ea22..357855c48 100644 --- a/x/dex/keeper/liquidity_test.go +++ b/x/dex/keeper/liquidity_test.go @@ -3,14 +3,14 @@ package keeper_test import ( "testing" - "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/testutil/testapp" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" ) func TestGetSetDenomLiquidity(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) // Write to store app.DexKeeper.SetDenomLiquidity(ctx, "nibi", sdk.NewInt(1000)) @@ -22,7 +22,7 @@ func TestGetSetDenomLiquidity(t *testing.T) { } func TestGetTotalLiquidity(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) // Write to store app.DexKeeper.SetDenomLiquidity(ctx, "atom", sdk.NewInt(123)) @@ -40,7 +40,7 @@ func TestGetTotalLiquidity(t *testing.T) { } func TestSetTotalLiquidity(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) // Write to store app.DexKeeper.SetTotalLiquidity(ctx, sdk.NewCoins( @@ -56,7 +56,7 @@ func TestSetTotalLiquidity(t *testing.T) { } func TestRecordTotalLiquidityIncrease(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) // Write to store app.DexKeeper.SetTotalLiquidity(ctx, sdk.NewCoins( @@ -73,7 +73,7 @@ func TestRecordTotalLiquidityIncrease(t *testing.T) { } func TestRecordTotalLiquidityDecrease(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) // Write to store app.DexKeeper.SetTotalLiquidity(ctx, sdk.NewCoins( diff --git a/x/dex/keeper/msg_server_test.go b/x/dex/keeper/msg_server_test.go index fbde21d54..d5849afad 100644 --- a/x/dex/keeper/msg_server_test.go +++ b/x/dex/keeper/msg_server_test.go @@ -6,7 +6,7 @@ import ( "github.com/NibiruChain/nibiru/x/testutil" - simapp2 "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/testutil/testapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -274,7 +274,7 @@ func TestCreatePool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) msgServer := keeper.NewMsgServerImpl(app.DexKeeper) if tc.creatorAddr == nil { @@ -511,7 +511,7 @@ func TestMsgServerJoinPool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() @@ -713,7 +713,7 @@ func TestMsgServerExitPool(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) poolAddr := testutil.AccAddress() tc.initialPool.Address = poolAddr.String() @@ -1056,7 +1056,7 @@ func TestMsgServerSwapAssets(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) msgServer := keeper.NewMsgServerImpl(app.DexKeeper) // fund pool account diff --git a/x/dex/keeper/params_test.go b/x/dex/keeper/params_test.go index e37eb30cb..3f8924045 100644 --- a/x/dex/keeper/params_test.go +++ b/x/dex/keeper/params_test.go @@ -3,7 +3,7 @@ package keeper_test import ( "testing" - "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/testutil/testapp" "github.com/stretchr/testify/require" @@ -11,7 +11,7 @@ import ( ) func TestGetParams(t *testing.T) { - app, ctx := simapp.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) params := types.DefaultParams() app.DexKeeper.SetParams(ctx, params) diff --git a/x/dex/keeper/swap_test.go b/x/dex/keeper/swap_test.go index 76570487e..fd2180819 100644 --- a/x/dex/keeper/swap_test.go +++ b/x/dex/keeper/swap_test.go @@ -5,7 +5,7 @@ import ( "github.com/NibiruChain/nibiru/x/testutil" - simapp2 "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/testutil/testapp" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -179,7 +179,7 @@ func TestSwapExactAmountIn(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - app, ctx := simapp2.NewTestNibiruAppAndContext(true) + app, ctx := testapp.NewTestNibiruAppAndContext(true) // fund pool account poolAddr := testutil.AccAddress() diff --git a/x/testutil/testapp/config.go b/x/testutil/testapp/config.go new file mode 100644 index 000000000..9a9e3baeb --- /dev/null +++ b/x/testutil/testapp/config.go @@ -0,0 +1,52 @@ +package testapp + +import ( + "fmt" + "time" + + "github.com/cosmos/cosmos-sdk/crypto/hd" + "github.com/cosmos/cosmos-sdk/crypto/keyring" + servertypes "github.com/cosmos/cosmos-sdk/server/types" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + tmrand "github.com/tendermint/tendermint/libs/rand" + + "github.com/NibiruChain/nibiru/app" + "github.com/NibiruChain/nibiru/x/common" + "github.com/NibiruChain/nibiru/x/testutil/cli" +) + +// BuildNetworkConfig returns a configuration for a local in-testing network +func BuildNetworkConfig(appGenesis GenesisState) cli.Config { + encCfg := app.MakeTestEncodingConfig() + + return cli.Config{ + Codec: encCfg.Marshaler, + TxConfig: encCfg.TxConfig, + LegacyAmino: encCfg.Amino, + InterfaceRegistry: encCfg.InterfaceRegistry, + AccountRetriever: authtypes.AccountRetriever{}, + AppConstructor: func(val cli.Validator) servertypes.Application { + return NewTestNibiruAppWithGenesis(appGenesis) + }, + GenesisState: appGenesis, + TimeoutCommit: time.Second / 2, + ChainID: "chain-" + tmrand.NewRand().Str(6), + NumValidators: 1, + BondDenom: common.DenomNIBI, + MinGasPrices: fmt.Sprintf("0.000006%s", common.DenomNIBI), + AccountTokens: sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction), + StakingTokens: sdk.TokensFromConsensusPower(500, sdk.DefaultPowerReduction), + BondedTokens: sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction), + StartingTokens: sdk.NewCoins( + sdk.NewCoin(common.DenomNUSD, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + sdk.NewCoin(common.DenomNIBI, sdk.TokensFromConsensusPower(1000, sdk.DefaultPowerReduction)), + sdk.NewCoin(common.DenomUSDC, sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction)), + ), + PruningStrategy: storetypes.PruningOptionNothing, + CleanupDir: true, + SigningAlgo: string(hd.Secp256k1Type), + KeyringOptions: []keyring.Option{}, + } +} diff --git a/x/testutil/testapp/genesis.go b/x/testutil/testapp/genesis.go new file mode 100644 index 000000000..f0e466d87 --- /dev/null +++ b/x/testutil/testapp/genesis.go @@ -0,0 +1,80 @@ +package testapp + +import ( + "encoding/json" + "io" + "os" + + "github.com/NibiruChain/nibiru/app" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + tmjson "github.com/tendermint/tendermint/libs/json" + tmtypes "github.com/tendermint/tendermint/types" +) + +// AppStateFromGenesisFileFn util function to generate the genesis AppState +// from a genesis.json file. +func AppStateFromGenesisFileFn(r io.Reader, cdc codec.JSONCodec, genesisFile string) (tmtypes.GenesisDoc, []simtypes.Account) { + bytes, err := os.ReadFile(genesisFile) + if err != nil { + panic(err) + } + + var genesis tmtypes.GenesisDoc + // NOTE: Tendermint uses a custom JSON decoder for GenesisDoc + err = tmjson.Unmarshal(bytes, &genesis) + if err != nil { + panic(err) + } + + var appState GenesisState + err = json.Unmarshal(genesis.AppState, &appState) + if err != nil { + panic(err) + } + + var authGenesis authtypes.GenesisState + if appState[authtypes.ModuleName] != nil { + cdc.MustUnmarshalJSON(appState[authtypes.ModuleName], &authGenesis) + } + + newAccs := make([]simtypes.Account, len(authGenesis.Accounts)) + for i, acc := range authGenesis.Accounts { + // Pick a random private key, since we don't know the actual key + // This should be fine as it's only used for mock Tendermint validators + // and these keys are never actually used to sign by mock Tendermint. + privkeySeed := make([]byte, 15) + if _, err := r.Read(privkeySeed); err != nil { + panic(err) + } + + privKey := secp256k1.GenPrivKeyFromSecret(privkeySeed) + + a, ok := acc.GetCachedValue().(authtypes.AccountI) + if !ok { + panic("expected account") + } + + // create simulator accounts + simAcc := simtypes.Account{PrivKey: privKey, PubKey: privKey.PubKey(), Address: a.GetAddress()} + newAccs[i] = simAcc + } + + return genesis, newAccs +} + +// GenesisState of the blockchain is represented here as a map of raw json +// messages key'd by a identifier string. +// The identifier is used to determine which module genesis information belongs +// to so it may be appropriately routed during init chain. +// Within this application default genesis information is retrieved from +// the ModuleBasicManager which populates json from each BasicModule +// object provided to it during init. +type GenesisState map[string]json.RawMessage + +// NewDefaultGenesisState generates the default state for the application. +func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { + return app.ModuleBasics.DefaultGenesis(cdc) +} diff --git a/x/testutil/testapp/testapp.go b/x/testutil/testapp/testapp.go new file mode 100644 index 000000000..6f62078c2 --- /dev/null +++ b/x/testutil/testapp/testapp.go @@ -0,0 +1,166 @@ +package testapp + +import ( + "encoding/json" + "os" + "path/filepath" + "time" + + "github.com/NibiruChain/nibiru/app" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + abci "github.com/tendermint/tendermint/abci/types" + "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + tmdb "github.com/tendermint/tm-db" + + "github.com/NibiruChain/nibiru/x/common" + pricefeedtypes "github.com/NibiruChain/nibiru/x/pricefeed/types" +) + +// NewTestNibiruApp creates an application instance ('app.NibiruApp') with an in-memory +// database ('tmdb.MemDB') and disabled logging. It either uses the application's +// default genesis state or a blank one. +func NewTestNibiruApp(shouldUseDefaultGenesis bool) *app.NibiruApp { + encoding := simapp.MakeTestEncodingConfig() + var appGenesis GenesisState + if shouldUseDefaultGenesis { + appGenesis = NewDefaultGenesisState(encoding.Marshaler) + } + return NewTestNibiruAppWithGenesis(appGenesis) +} + +// NewTestNibiruAppAndContext creates an 'app.NibiruApp' instance with an in-memory +// 'tmdb.MemDB' and fresh 'sdk.Context'. +func NewTestNibiruAppAndContext(shouldUseDefaultGenesis bool) (*app.NibiruApp, sdk.Context) { + newNibiruApp := NewTestNibiruApp(shouldUseDefaultGenesis) + ctx := newNibiruApp.NewContext(false, tmproto.Header{}) + + return newNibiruApp, ctx +} + +// NewTestNibiruAppWithGenesis initializes a chain with the given genesis state to +// creates an application instance ('app.NibiruApp'). This app uses an +// in-memory database ('tmdb.MemDB') and has logging disabled. +func NewTestNibiruAppWithGenesis(gen GenesisState) *app.NibiruApp { + userHomeDir, err := os.UserHomeDir() + if err != nil { + panic(err) + } + + nodeHome := filepath.Join(userHomeDir, ".nibid") + db := tmdb.NewMemDB() + logger := log.NewNopLogger() + + encoding := app.MakeTestEncodingConfig() + + nibiruApp := app.NewNibiruApp( + logger, + db, + /*traceStore=*/ nil, + /*loadLatest=*/ true, + /*skipUpgradeHeights=*/ map[int64]bool{}, + /*homePath=*/ nodeHome, + /*invCheckPeriod=*/ 0, + /*encodingConfig=*/ encoding, + /*appOpts=*/ simapp.EmptyAppOptions{}, + ) + + stateBytes, err := json.MarshalIndent(gen, "", " ") + if err != nil { + panic(err) + } + + nibiruApp.InitChain(abci.RequestInitChain{ + ConsensusParams: simapp.DefaultConsensusParams, + AppStateBytes: stateBytes, + }) + + return nibiruApp +} + +// ---------------------------------------------------------------------------- +// Genesis +// ---------------------------------------------------------------------------- + +const ( + GenOracleAddress = "nibi1zuxt7fvuxgj69mjxu3auca96zemqef5u2yemly" +) + +/* + NewTestGenesisStateFromDefault returns 'NewGenesisState' using the default + +genesis as input. The blockchain genesis state is represented as a map from module +identifier strings to raw json messages. +*/ +func NewTestGenesisStateFromDefault() GenesisState { + encodingConfig := app.MakeTestEncodingConfig() + codec := encodingConfig.Marshaler + genState := NewDefaultGenesisState(codec) + return NewTestGenesisState(codec, genState) +} + +/* +NewTestGenesisState transforms 'inGenState' to add genesis parameter changes +that are well suited to integration testing, then returns the transformed genesis. +The blockchain genesis state is represented as a map from module identifier strings +to raw json messages. + +Args: +- codec: Serializer for the module genesis state proto.Messages +- inGenState: Input genesis state before the custom test setup is applied +*/ +func NewTestGenesisState(codec codec.Codec, inGenState GenesisState, +) (testGenState GenesisState) { + testGenState = inGenState + + // Set short voting period to allow fast gov proposals in tests + var govGenState govtypes.GenesisState + codec.MustUnmarshalJSON(testGenState[govtypes.ModuleName], &govGenState) + govGenState.VotingParams.VotingPeriod = time.Second * 20 + govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1_000_000)) // min deposit of 1 NIBI + testGenState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) + + // pricefeed genesis state + pfGenState := PricefeedGenesis() + testGenState[pricefeedtypes.ModuleName] = codec.MustMarshalJSON(&pfGenState) + + return testGenState +} + +// ---------------------------------------------------------------------------- +// Module types.GenesisState functions + +/* + PricefeedGenesis returns an x/pricefeed GenesisState with additional + +configuration for convenience during integration tests. +*/ +func PricefeedGenesis() pricefeedtypes.GenesisState { + oracle := sdk.MustAccAddressFromBech32(GenOracleAddress) + oracleStrings := []string{oracle.String()} + + var gen pricefeedtypes.GenesisState + pairs := pricefeedtypes.DefaultPairs + gen.Params.Pairs = pairs + gen.Params.TwapLookbackWindow = 15 * time.Minute + gen.PostedPrices = []pricefeedtypes.PostedPrice{ + { + PairID: pairs[0].String(), // PairGovStable + Oracle: oracle.String(), + Price: sdk.NewDec(10), + Expiry: time.Now().Add(1 * time.Hour), + }, + { + PairID: pairs[1].String(), // PairCollStable + Oracle: oracle.String(), + Price: sdk.OneDec(), + Expiry: time.Now().Add(1 * time.Hour), + }, + } + gen.GenesisOracles = oracleStrings + + return gen +} diff --git a/x/testutil/testapp/testapp_test.go b/x/testutil/testapp/testapp_test.go new file mode 100644 index 000000000..c50b0927d --- /dev/null +++ b/x/testutil/testapp/testapp_test.go @@ -0,0 +1,99 @@ +package testapp_test + +import ( + "testing" + "time" + + "github.com/NibiruChain/nibiru/simapp" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/suite" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + "github.com/NibiruChain/nibiru/app" + "github.com/NibiruChain/nibiru/x/common" + pricefeedtypes "github.com/NibiruChain/nibiru/x/pricefeed/types" +) + +type TestappSuite struct { + suite.Suite + + genOracle sdk.AccAddress + pairs common.AssetPairs + twapLookbackWindow time.Duration +} + +func (s *TestappSuite) SetupSuite() { + app.SetPrefixes(app.AccountAddressPrefix) + s.genOracle = sdk.MustAccAddressFromBech32(simapp.GenOracleAddress) + s.pairs = pricefeedtypes.DefaultPairs + s.twapLookbackWindow = pricefeedtypes.DefaultLookbackWindow +} + +// TestPricefeedGenesis verifies that the expected pricefeed state for integration tests +func (s *TestappSuite) TestPricefeedGenesis() { + genPf := simapp.PricefeedGenesis() + s.Assert().EqualValues(pricefeedtypes.NewParams(s.pairs, s.twapLookbackWindow), genPf.Params) + s.Assert().EqualValues(pricefeedtypes.NewParams(s.pairs, s.twapLookbackWindow), genPf.Params) + s.Assert().EqualValues(s.pairs[0].String(), genPf.PostedPrices[0].PairID) + s.Assert().EqualValues(s.pairs[1].String(), genPf.PostedPrices[1].PairID) + expectedGenesisOracles := []string{s.genOracle.String()} + for _, oracleStr := range expectedGenesisOracles { + s.Assert().Contains(genPf.GenesisOracles, oracleStr) + } +} + +func (s *TestappSuite) TestNewTestGenesisState() { + encodingConfig := app.MakeTestEncodingConfig() + codec := encodingConfig.Marshaler + + defaultGenState := app.NewDefaultGenesisState(codec) + testGenState := simapp.NewTestGenesisStateFromDefault() + + var testGenPfState pricefeedtypes.GenesisState + testGenPfStateJSON := testGenState[pricefeedtypes.ModuleName] + codec.MustUnmarshalJSON(testGenPfStateJSON, &testGenPfState) + bzTest := codec.MustMarshalJSON(&testGenPfState) + + var defaultGenPfState pricefeedtypes.GenesisState + defaultGenPfStateJSON := defaultGenState[pricefeedtypes.ModuleName] + codec.MustUnmarshalJSON(defaultGenPfStateJSON, &defaultGenPfState) + bzDefault := codec.MustMarshalJSON(&defaultGenPfState) + + s.Assert().NotEqualValues(bzTest, bzDefault) + s.Assert().NotEqualValues(testGenPfState, defaultGenPfState) + + s.Assert().EqualValues(pricefeedtypes.NewParams(s.pairs, s.twapLookbackWindow), testGenPfState.Params) + s.Assert().EqualValues(pricefeedtypes.NewParams(s.pairs, s.twapLookbackWindow), testGenPfState.Params) + s.Assert().EqualValues(s.pairs[0].String(), testGenPfState.PostedPrices[0].PairID) + s.Assert().EqualValues(s.pairs[1].String(), testGenPfState.PostedPrices[1].PairID) + expectedGenesisOracles := []string{s.genOracle.String()} + for _, oracleStr := range expectedGenesisOracles { + s.Assert().Contains(testGenPfState.GenesisOracles, oracleStr) + } +} + +func (s *TestappSuite) TestPricefeedGenesis_PostedPrices() { + s.T().Log("no prices posted for default genesis") + nibiruApp := simapp.NewTestNibiruApp(true) + ctx := nibiruApp.NewContext(false, tmproto.Header{}) + currentPrices := nibiruApp.PricefeedKeeper.GetCurrentPrices(ctx) + s.Assert().Len(currentPrices, 0) + + s.T().Log("prices posted for testing genesis") + nibiruApp = simapp.NewTestNibiruAppWithGenesis(simapp.NewTestGenesisStateFromDefault()) + ctx = nibiruApp.NewContext(false, tmproto.Header{}) + oracles := []sdk.AccAddress{s.genOracle} + oracleMap := nibiruApp.PricefeedKeeper.GetOraclesForPairs(ctx, s.pairs) + for _, pair := range s.pairs { + s.Assert().EqualValues(oracles, oracleMap[pair]) + } + currentPrices = nibiruApp.PricefeedKeeper.GetCurrentPrices(ctx) + s.Assert().Len(currentPrices, 2) + s.Assert().Equal(common.Pair_NIBI_NUSD.String(), currentPrices[0].PairID) + s.Assert().Equal(common.Pair_USDC_NUSD.String(), currentPrices[1].PairID) +} + +func TestTestappSuite(t *testing.T) { + suite.Run(t, new(TestappSuite)) +} From 510887402a44f9f7c793c084fa915eef139a6663 Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Tue, 29 Nov 2022 01:37:41 -0600 Subject: [PATCH 2/5] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e17333aa2..d6c364d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1058](https://github.com/NibiruChain/nibiru/pull/1058) - feature: use collections external lib * [#1074](https://github.com/NibiruChain/nibiru/pull/1074) - feat(vpool): Add gov proposal for editing the vpool config without changing the reserves. * [#1082](https://github.com/NibiruChain/nibiru/pull/1082) - feat(vpool): Add gov proposal for editing the sswap invariant of a vpool.. +* [#1092](https://github.com/NibiruChain/nibiru/pull/1092) - refactor(dex)!: revive dex module using intermediate test app ### Improvements From 9d59614fcaac3fd9a7d209ed7b676fe0c8c0cfcd Mon Sep 17 00:00:00 2001 From: Unique-Divine Date: Tue, 29 Nov 2022 01:46:34 -0600 Subject: [PATCH 3/5] fix linter --- x/testutil/testapp/genesis.go | 3 ++- x/testutil/testapp/testapp.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/x/testutil/testapp/genesis.go b/x/testutil/testapp/genesis.go index f0e466d87..a7aaea9f7 100644 --- a/x/testutil/testapp/genesis.go +++ b/x/testutil/testapp/genesis.go @@ -5,13 +5,14 @@ import ( "io" "os" - "github.com/NibiruChain/nibiru/app" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" tmjson "github.com/tendermint/tendermint/libs/json" tmtypes "github.com/tendermint/tendermint/types" + + "github.com/NibiruChain/nibiru/app" ) // AppStateFromGenesisFileFn util function to generate the genesis AppState diff --git a/x/testutil/testapp/testapp.go b/x/testutil/testapp/testapp.go index 6f62078c2..e06539d53 100644 --- a/x/testutil/testapp/testapp.go +++ b/x/testutil/testapp/testapp.go @@ -6,7 +6,6 @@ import ( "path/filepath" "time" - "github.com/NibiruChain/nibiru/app" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/simapp" sdk "github.com/cosmos/cosmos-sdk/types" @@ -16,6 +15,8 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" tmdb "github.com/tendermint/tm-db" + "github.com/NibiruChain/nibiru/app" + "github.com/NibiruChain/nibiru/x/common" pricefeedtypes "github.com/NibiruChain/nibiru/x/pricefeed/types" ) From 64b30e274b3a160c27bffc5c3491c6b5d4116cc6 Mon Sep 17 00:00:00 2001 From: NibiruHeisenberg <101130700+NibiruHeisenberg@users.noreply.github.com> Date: Tue, 29 Nov 2022 13:09:07 -0500 Subject: [PATCH 4/5] fix: flaky oracle test (#1098) --- CHANGELOG.md | 1 + app/antedecorators/gasless/gasless_test.go | 3 +- scripts/testing/stableswap_model.py | 2 +- simapp/testapp.go | 2 +- x/common/common.go | 3 + x/dex/keeper/keeper_test.go | 6 +- x/dex/simulation/operations.go | 2 +- x/dex/types/params.go | 2 +- x/dex/types/pool_asset_test.go | 8 ++- x/dex/types/pool_test.go | 11 ++-- x/dex/types/price_test.go | 21 +++---- x/dex/types/swap_test.go | 18 +++--- x/lockup/client/cli/cli_test.go | 9 +-- x/oracle/keeper/reward_test.go | 2 +- x/oracle/keeper/tally_fuzz_test.go | 3 +- x/oracle/keeper/update_exchange_rates_test.go | 12 ++-- x/perp/client/cli/cli_test.go | 32 +++++----- x/perp/keeper/calc_test.go | 8 +-- .../keeper/clearing_house_integration_test.go | 32 +++++----- x/perp/keeper/clearing_house_unit_test.go | 2 +- x/perp/keeper/grpc_query_test.go | 8 +-- x/perp/keeper/liquidate_test.go | 20 +++---- x/perp/keeper/margin_test.go | 12 ++-- x/perp/keeper/msg_server_test.go | 28 ++++----- x/perp/keeper/perp_test.go | 4 +- x/pricefeed/abci_test.go | 10 ++-- x/pricefeed/client/cli/cli_test.go | 2 +- x/stablecoin/client/cli/cli_test.go | 16 ++--- x/stablecoin/keeper/collateral_ratio.go | 4 +- x/stablecoin/keeper/collateral_ratio_test.go | 42 +++++++------- x/stablecoin/keeper/mint_burn_stable_test.go | 30 +++++----- x/stablecoin/keeper/params_test.go | 7 ++- x/stablecoin/keeper/supply_test.go | 20 +++---- x/stablecoin/types/params.go | 18 +++--- x/testutil/cli/tx.go | 2 +- x/testutil/sample.go | 20 +++++++ x/util/keeper/query_server_test.go | 5 +- x/vpool/client/cli/cli_test.go | 10 ++-- x/vpool/genesis_test.go | 8 +-- x/vpool/keeper/keeper_test.go | 58 +++++++++---------- x/vpool/keeper/pool_state_test.go | 28 ++++----- x/vpool/keeper/query_server_test.go | 6 +- x/vpool/types/gov_test.go | 4 +- x/vpool/types/pool_test.go | 58 +++++++++---------- x/wasm/cli/cli_test.go | 4 +- 45 files changed, 320 insertions(+), 283 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6c364d28..7a580a550 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1080](https://github.com/NibiruChain/nibiru/pull/1080) - feat(perp): Add exchanged notional to the position changed event #1080 * [#1082](https://github.com/NibiruChain/nibiru/pull/1082) - feat(localnet.sh): Set genesis prices based on real BTC and ETH prices * [#1086](https://github.com/NibiruChain/nibiru/pull/1086) - refactor(perp)!: Removed unused field, `LiquidationPenalty`, from `PositionChangedEvent` +* [#1091](https://github.com/NibiruChain/nibiru/pull/1091) - refactor: Use common.Precision instead of 1_000_000 in the codebase ## v0.15.0 diff --git a/app/antedecorators/gasless/gasless_test.go b/app/antedecorators/gasless/gasless_test.go index d9e295443..ab485dc52 100644 --- a/app/antedecorators/gasless/gasless_test.go +++ b/app/antedecorators/gasless/gasless_test.go @@ -10,6 +10,7 @@ import ( gaslessante "github.com/NibiruChain/nibiru/app/antedecorators/gasless" types2 "github.com/NibiruChain/nibiru/app/antedecorators/types" "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/pricefeed/types" "github.com/NibiruChain/nibiru/x/testutil" ) @@ -113,7 +114,7 @@ func TestGaslessDecorator_Whitelisted(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { app, ctx := simapp.NewTestNibiruAppAndContext(true) - ctx = ctx.WithGasMeter(sdk.NewGasMeter(10000000)) + ctx = ctx.WithGasMeter(sdk.NewGasMeter(uint64(10 * common.Precision))) if tc.isWhitelisted { // If we whitelist, the gas meter changes. diff --git a/scripts/testing/stableswap_model.py b/scripts/testing/stableswap_model.py index e0f1e77e3..e903a0c84 100644 --- a/scripts/testing/stableswap_model.py +++ b/scripts/testing/stableswap_model.py @@ -6,7 +6,7 @@ The curve class comes directly from the curve codebase, and is being used to create the tests, stored in `x/dex/types/misc/stabletests.csv`;. Theses test are then used to compare the value of python model's DY against the one obtained with our go code. -These are created for pools with random amount of assets (from 2 to 5), random amplification parameter (from 1 to 4_000_000) and for random coins of the pool. +These are created for pools with random amount of assets (from 2 to 5), random amplification parameter (from 1 to 4* common.Precision) and for random coins of the pool. By computing this, we ensure the validity of our SolveConstantProductInvariant function. """ diff --git a/simapp/testapp.go b/simapp/testapp.go index db7affc3b..83f2fee73 100644 --- a/simapp/testapp.go +++ b/simapp/testapp.go @@ -119,7 +119,7 @@ func NewTestGenesisState(codec codec.Codec, inGenState GenesisState, var govGenState govtypes.GenesisState codec.MustUnmarshalJSON(testGenState[govtypes.ModuleName], &govGenState) govGenState.VotingParams.VotingPeriod = time.Second * 20 - govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1_000_000)) // min deposit of 1 NIBI + govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision)) // min deposit of 1 NIBI testGenState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) // pricefeed genesis state diff --git a/x/common/common.go b/x/common/common.go index 532364989..529f5f738 100644 --- a/x/common/common.go +++ b/x/common/common.go @@ -34,6 +34,9 @@ var ( ErrInvalidTokenPair = sdkerrors.Register(ModuleName, 1, "invalid token pair") APrecision = uint256.NewInt().SetUint64(1) + + // Precision for int representation in sdk.Int objects + Precision = int64(1_000_000) ) //----------------------------------------------------------------------------- diff --git a/x/dex/keeper/keeper_test.go b/x/dex/keeper/keeper_test.go index c669e1aff..ad59654fa 100644 --- a/x/dex/keeper/keeper_test.go +++ b/x/dex/keeper/keeper_test.go @@ -218,7 +218,7 @@ func TestFetchPoolFromPair(t *testing.T) { func TestNewPool(t *testing.T) { app, ctx := testapp.NewTestNibiruAppAndContext(true) - poolCreationFeeCoin := sdk.NewInt64Coin(common.DenomNIBI, 1000_000_000) + poolCreationFeeCoin := sdk.NewInt64Coin(common.DenomNIBI, 1000*common.Precision) app.DexKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, /*poolCreationFee=*/ sdk.NewCoins(poolCreationFeeCoin), @@ -291,7 +291,7 @@ func TestNewPoolNotEnoughFunds(t *testing.T) { app.DexKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, - /*poolCreationFee=*/ sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000_000_000)), + /*poolCreationFee=*/ sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000*common.Precision)), /*whitelistedAssets*/ []string{}, )) @@ -300,7 +300,7 @@ func TestNewPoolNotEnoughFunds(t *testing.T) { err := simapp.FundAccount(app.BankKeeper, ctx, userAddr, sdk.NewCoins( sdk.NewCoin("uatom", sdk.NewInt(1000)), sdk.NewCoin("uosmo", sdk.NewInt(1000)), - sdk.NewCoin("unibi", sdk.NewInt(999_000_000)), + sdk.NewCoin("unibi", sdk.NewInt(999*common.Precision)), )) require.NoError(t, err) diff --git a/x/dex/simulation/operations.go b/x/dex/simulation/operations.go index 01765d2af..a414af78b 100644 --- a/x/dex/simulation/operations.go +++ b/x/dex/simulation/operations.go @@ -330,7 +330,7 @@ func genPoolAssets( // fundAccountWithTokens fund the account with some gov, coll and stable denom. // When simulation for stablecoin is done, we should consider only funding with stable. func fundAccountWithTokens(ctx sdk.Context, address sdk.AccAddress, bk types.BankKeeper) { - million := 1_000_000 + million := 1 * common.Precision newTokens := sdk.NewCoins( sdk.NewCoin(common.DenomNIBI, sdk.NewInt(int64(10*million))), sdk.NewCoin(common.DenomUSDC, sdk.NewInt(int64(10*million))), diff --git a/x/dex/types/params.go b/x/dex/types/params.go index 81afbd2dd..ba2668875 100644 --- a/x/dex/types/params.go +++ b/x/dex/types/params.go @@ -30,7 +30,7 @@ func NewParams(startingPoolNumber uint64, poolCreationFee sdk.Coins, whitelisted func DefaultParams() Params { return Params{ StartingPoolNumber: 1, - PoolCreationFee: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000_000_000)), // 1000 NIBI + PoolCreationFee: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000*common.Precision)), // 1000 NIBI WhitelistedAsset: []string{ common.DenomNIBI, common.DenomUSDC, diff --git a/x/dex/types/pool_asset_test.go b/x/dex/types/pool_asset_test.go index 9b94c51f5..d940459d5 100644 --- a/x/dex/types/pool_asset_test.go +++ b/x/dex/types/pool_asset_test.go @@ -5,6 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + "github.com/NibiruChain/nibiru/x/common" ) func TestPoolAssetValidateError(t *testing.T) { @@ -82,7 +84,7 @@ func TestSubtractPoolAssetBalance(t *testing.T) { pool: Pool{ PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 1_000_000), + Token: sdk.NewInt64Coin("aaa", 1*common.Precision), }, }, }, @@ -95,12 +97,12 @@ func TestSubtractPoolAssetBalance(t *testing.T) { pool: Pool{ PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 1_000_000), + Token: sdk.NewInt64Coin("aaa", 1*common.Precision), }, }, }, tokenDenom: "aaa", - subAmt: sdk.NewInt(1_000_000), + subAmt: sdk.NewInt(1 * common.Precision), expectedCoins: nil, }, } { diff --git a/x/dex/types/pool_test.go b/x/dex/types/pool_test.go index b6151fc52..f636329f9 100644 --- a/x/dex/types/pool_test.go +++ b/x/dex/types/pool_test.go @@ -8,6 +8,7 @@ import ( "strconv" "testing" + "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -227,7 +228,7 @@ func TestJoinPoolHappyPath(t *testing.T) { Token: sdk.NewInt64Coin("bbb", 1_403_945), }, }, - TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1_000_000), + TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1*common.Precision), PoolParams: PoolParams{A: sdk.NewInt(100), PoolType: PoolType_BALANCER}, }, tokensIn: sdk.NewCoins( @@ -262,7 +263,7 @@ func TestJoinPoolHappyPath(t *testing.T) { Token: sdk.NewInt64Coin("bbb", 1_403_945), }, }, - TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1_000_000), + TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1*common.Precision), PoolParams: PoolParams{A: sdk.NewInt(100), PoolType: PoolType_STABLESWAP}, }, tokensIn: sdk.NewCoins( @@ -398,7 +399,7 @@ func TestJoinPoolAllTokens(t *testing.T) { Weight: sdk.NewInt(1 << 30), }, }, - TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1_000_000), + TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1*common.Precision), TotalWeight: sdk.NewInt(2 << 30), PoolParams: PoolParams{PoolType: PoolType_BALANCER, SwapFee: sdk.ZeroDec()}, }, @@ -745,10 +746,10 @@ func TestGetD(t *testing.T) { name: "Compute D - 2 assets, A big, high values - tested against Curve contracts code..", poolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 200_000_000), + Token: sdk.NewInt64Coin("aaa", 200*common.Precision), }, { - Token: sdk.NewInt64Coin("bbb", 100_000_000), + Token: sdk.NewInt64Coin("bbb", 100*common.Precision), }, }, amplificationParameter: sdk.NewInt(4000), diff --git a/x/dex/types/price_test.go b/x/dex/types/price_test.go index be37b4de5..beb965fec 100644 --- a/x/dex/types/price_test.go +++ b/x/dex/types/price_test.go @@ -3,6 +3,7 @@ package types import ( "testing" + "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -19,11 +20,11 @@ func TestCalSpotPrice(t *testing.T) { "equal weight: 2 tokens", []PoolAsset{ { - Token: sdk.NewInt64Coin("foo", 2_000_000), + Token: sdk.NewInt64Coin("foo", 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin("bar", 1_000_000), + Token: sdk.NewInt64Coin("bar", 1*common.Precision), Weight: sdk.NewInt(100), }, }, @@ -33,11 +34,11 @@ func TestCalSpotPrice(t *testing.T) { "different weight: 2 tokens", []PoolAsset{ { - Token: sdk.NewInt64Coin("foo", 2_000_000), + Token: sdk.NewInt64Coin("foo", 2*common.Precision), Weight: sdk.NewInt(80), }, { - Token: sdk.NewInt64Coin("bar", 1_000_000), + Token: sdk.NewInt64Coin("bar", 1*common.Precision), Weight: sdk.NewInt(20), }, }, @@ -47,15 +48,15 @@ func TestCalSpotPrice(t *testing.T) { "equal weight: 3 tokens", []PoolAsset{ { - Token: sdk.NewInt64Coin("foo", 2_000_000), + Token: sdk.NewInt64Coin("foo", 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin("goo", 1_000_000), + Token: sdk.NewInt64Coin("goo", 1*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin("bar", 1_000_000), + Token: sdk.NewInt64Coin("bar", 1*common.Precision), Weight: sdk.NewInt(100), }, }, @@ -65,15 +66,15 @@ func TestCalSpotPrice(t *testing.T) { "different weight: 3 tokens", []PoolAsset{ { - Token: sdk.NewInt64Coin("foo", 2_000_000), + Token: sdk.NewInt64Coin("foo", 2*common.Precision), Weight: sdk.NewInt(60), }, { - Token: sdk.NewInt64Coin("bar", 1_000_000), + Token: sdk.NewInt64Coin("bar", 1*common.Precision), Weight: sdk.NewInt(20), }, { - Token: sdk.NewInt64Coin("foobar", 1_000_000), + Token: sdk.NewInt64Coin("foobar", 1*common.Precision), Weight: sdk.NewInt(20), }, }, diff --git a/x/dex/types/swap_test.go b/x/dex/types/swap_test.go index 824bf3976..825d93183 100644 --- a/x/dex/types/swap_test.go +++ b/x/dex/types/swap_test.go @@ -5,6 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + + "github.com/NibiruChain/nibiru/x/common" ) func TestCalcOutAmtGivenIn(t *testing.T) { @@ -48,11 +50,11 @@ func TestCalcOutAmtGivenIn(t *testing.T) { }, PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 100_000_000), + Token: sdk.NewInt64Coin("aaa", 100*common.Precision), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin("bbb", 100_000_000), + Token: sdk.NewInt64Coin("bbb", 100*common.Precision), Weight: sdk.OneInt(), }, }, @@ -71,11 +73,11 @@ func TestCalcOutAmtGivenIn(t *testing.T) { }, PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 1_000_000), + Token: sdk.NewInt64Coin("aaa", 1*common.Precision), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin("bbb", 1_000_000), + Token: sdk.NewInt64Coin("bbb", 1*common.Precision), Weight: sdk.OneInt(), }, }, @@ -186,11 +188,11 @@ func TestCalcInAmtGivenOut(t *testing.T) { }, PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 100_000_000), + Token: sdk.NewInt64Coin("aaa", 100*common.Precision), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin("bbb", 100_000_000), + Token: sdk.NewInt64Coin("bbb", 100*common.Precision), Weight: sdk.OneInt(), }, }, @@ -209,11 +211,11 @@ func TestCalcInAmtGivenOut(t *testing.T) { }, PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 1_000_000), + Token: sdk.NewInt64Coin("aaa", 1*common.Precision), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin("bbb", 1_000_000), + Token: sdk.NewInt64Coin("bbb", 1*common.Precision), Weight: sdk.OneInt(), }, }, diff --git a/x/lockup/client/cli/cli_test.go b/x/lockup/client/cli/cli_test.go index 01ad91fed..29f107651 100644 --- a/x/lockup/client/cli/cli_test.go +++ b/x/lockup/client/cli/cli_test.go @@ -6,6 +6,7 @@ import ( "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/lockup/types" "github.com/cosmos/cosmos-sdk/crypto/hd" @@ -38,9 +39,9 @@ func (s *IntegrationTestSuite) SetupSuite() { app.SetPrefixes(app.AccountAddressPrefix) s.cfg = testutilcli.BuildNetworkConfig(simapp.NewTestGenesisStateFromDefault()) s.cfg.StartingTokens = sdk.NewCoins( - sdk.NewInt64Coin("ATOM", 1_000_000), - sdk.NewInt64Coin("OSMO", 1_000_000), - sdk.NewInt64Coin("unibi", 1_000_000_000)) + sdk.NewInt64Coin("ATOM", 1*common.Precision), + sdk.NewInt64Coin("OSMO", 1*common.Precision), + sdk.NewInt64Coin("unibi", 1_000*common.Precision)) s.network = testutilcli.NewNetwork(s.T(), s.cfg) _, err := s.network.WaitForHeight(1) @@ -60,7 +61,7 @@ func (s *IntegrationTestSuite) SetupSuite() { sdk.NewCoins( sdk.NewInt64Coin("ATOM", 20000), sdk.NewInt64Coin("OSMO", 20000), - sdk.NewInt64Coin("unibi", 1_000_000), + sdk.NewInt64Coin("unibi", 1*common.Precision), ), val, s.cfg.BondDenom, diff --git a/x/oracle/keeper/reward_test.go b/x/oracle/keeper/reward_test.go index 98ecae0e6..a54a5858c 100644 --- a/x/oracle/keeper/reward_test.go +++ b/x/oracle/keeper/reward_test.go @@ -53,7 +53,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { params := input.OracleKeeper.GetParams(input.Ctx) input.OracleKeeper.SetParams(input.Ctx, params) - rewards := sdk.NewInt64Coin("reward", 1_000_000) + rewards := sdk.NewInt64Coin("reward", 1*common.Precision) valPeriodicRewards := sdk.NewDecCoinsFromCoins(rewards). QuoDec(sdk.NewDec(int64(periods))). QuoDec(sdk.NewDec(int64(validators))) diff --git a/x/oracle/keeper/tally_fuzz_test.go b/x/oracle/keeper/tally_fuzz_test.go index 87a5cff68..563cb1912 100644 --- a/x/oracle/keeper/tally_fuzz_test.go +++ b/x/oracle/keeper/tally_fuzz_test.go @@ -9,6 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/oracle/types" + "github.com/NibiruChain/nibiru/x/testutil" ) func TestFuzz_Tally(t *testing.T) { @@ -72,7 +73,7 @@ func TestFuzz_PickReferencePair(t *testing.T) { numPairs := c.Intn(100) + 5 for i := 0; i < numPairs; i++ { - *e = append(*e, c.RandString()) + *e = append(*e, testutil.RandStringBytes(5)) } }, func(e *sdk.Dec, c fuzz.Continue) { diff --git a/x/oracle/keeper/update_exchange_rates_test.go b/x/oracle/keeper/update_exchange_rates_test.go index c48623e8d..e159ad5aa 100644 --- a/x/oracle/keeper/update_exchange_rates_test.go +++ b/x/oracle/keeper/update_exchange_rates_test.go @@ -251,7 +251,7 @@ func TestOracleRewardDistribution(t *testing.T) { // Account 2, btcstable makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_BTC_NUSD.String(), ExchangeRate: randomExchangeRate}}, 1) - rewardAllocation := sdk.NewCoins(sdk.NewCoin("reward", sdk.NewInt(1_000_000))) + rewardAllocation := sdk.NewCoins(sdk.NewCoin("reward", sdk.NewInt(1*common.Precision))) keeper.AllocateRewards(t, input, common.Pair_BTC_NUSD.String(), rewardAllocation, 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -363,15 +363,15 @@ func TestOracleExchangeRate(t *testing.T) { // Account 3, govstable, btcstable makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD.String(), ExchangeRate: govStableExchangeRate}, {Pair: common.Pair_BTC_NUSD.String(), ExchangeRate: randomExchangeRate}}, 2) - ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1_000_000) - govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1_000_000) + ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) + govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) keeper.AllocateRewards(t, input, common.Pair_ETH_NUSD.String(), sdk.NewCoins(ethStableRewards), 1) keeper.AllocateRewards(t, input, common.Pair_NIBI_NUSD.String(), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - // total reward pool for the current vote period is 1_000_000ETHSTABLE, 1_000_000GOVSTABLE + // total reward pool for the current vote period is 1* common.PrecisionETHSTABLE, 1* common.PrecisionGOVSTABLE // val 1,2 won on 2 pairs // val 3 won on 1 pair // so total votes are 2 * 2 + 1 = 5 @@ -441,8 +441,8 @@ func TestOracleExchangeRateVal5(t *testing.T) { // Account 5, govstable, ethstable makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD.String(), ExchangeRate: govStableRate2}, {Pair: common.Pair_ETH_NUSD.String(), ExchangeRate: ethStableRate2}}, 4) - ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1_000_000) - govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1_000_000) + ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) + govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) keeper.AllocateRewards(t, input, common.Pair_ETH_NUSD.String(), sdk.NewCoins(ethStableRewards), 1) keeper.AllocateRewards(t, input, common.Pair_NIBI_NUSD.String(), sdk.NewCoins(govStableRewards), 1) diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 6135bbb52..4c0092669 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -76,8 +76,8 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis.Vpools = []vpooltypes.Vpool{ { Pair: common.Pair_BTC_NUSD, - BaseAssetReserve: sdk.NewDec(10_000_000), - QuoteAssetReserve: sdk.NewDec(60_000_000_000), + BaseAssetReserve: sdk.NewDec(10 * common.Precision), + QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.8"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), @@ -88,8 +88,8 @@ func (s *IntegrationTestSuite) SetupSuite() { }, { Pair: common.Pair_ETH_NUSD, - BaseAssetReserve: sdk.NewDec(10_000_000), - QuoteAssetReserve: sdk.NewDec(60_000_000_000), + BaseAssetReserve: sdk.NewDec(10 * common.Precision), + QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.8"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), @@ -142,9 +142,9 @@ func (s *IntegrationTestSuite) SetupSuite() { s.NoError( testutilcli.FillWalletFromValidator(user1, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 10_000_000), - sdk.NewInt64Coin(common.DenomUSDC, 10_000_000), - sdk.NewInt64Coin(common.DenomNUSD, 50_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 10*common.Precision), + sdk.NewInt64Coin(common.DenomUSDC, 10*common.Precision), + sdk.NewInt64Coin(common.DenomNUSD, 50*common.Precision), ), val, common.DenomNIBI, @@ -168,7 +168,7 @@ func (s *IntegrationTestSuite) SetupSuite() { sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 1000), sdk.NewInt64Coin(common.DenomUSDC, 1000), - sdk.NewInt64Coin(common.DenomNUSD, 49_000_000), + sdk.NewInt64Coin(common.DenomNUSD, 49*common.Precision), ), val, common.DenomNIBI, @@ -209,8 +209,8 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.Pair_BTC_NUSD) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) - s.EqualValues(sdk.NewDec(10_000_000), reserveAssets.BaseAssetReserve) - s.EqualValues(sdk.NewDec(60_000_000_000), reserveAssets.QuoteAssetReserve) + s.EqualValues(sdk.NewDec(10*common.Precision), reserveAssets.BaseAssetReserve) + s.EqualValues(sdk.NewDec(60_000*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("A. check trader has no existing positions") _, err = testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) @@ -232,7 +232,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("9999833.336111064815586407"), reserveAssets.BaseAssetReserve) - s.EqualValues(sdk.NewDec(60_001_000_000), reserveAssets.QuoteAssetReserve) + s.EqualValues(sdk.NewDec(60_001*common.Precision), reserveAssets.QuoteAssetReserve) s.T().Log("B. check trader position") queryResp, err := testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) @@ -241,8 +241,8 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(user.String(), queryResp.Position.TraderAddress) s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("166.663888935184413593"), queryResp.Position.Size_) - s.EqualValues(sdk.NewDec(1_000_000), queryResp.Position.Margin) - s.EqualValues(sdk.NewDec(1_000_000), queryResp.Position.OpenNotional) + s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.Margin) + s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("999999.999999999999999359"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("-0.000000000000000641"), queryResp.UnrealizedPnl) s.EqualValues(sdk.NewDec(1), queryResp.MarginRatioMark) @@ -266,8 +266,8 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(user.String(), queryResp.Position.TraderAddress) s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.975001249937503125"), queryResp.Position.Size_) - s.EqualValues(sdk.NewDec(2_000_000), queryResp.Position.Margin) - s.EqualValues(sdk.NewDec(3_000_000), queryResp.Position.OpenNotional) + s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) + s.EqualValues(sdk.NewDec(3*common.Precision), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("3000000.000000000000000938"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("0.000000000000000938"), queryResp.UnrealizedPnl) s.EqualValues(sdk.MustNewDecFromStr("0.666666666666666667"), queryResp.MarginRatioMark) @@ -297,7 +297,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(user.String(), queryResp.Position.TraderAddress) s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.958336249784737846"), queryResp.Position.Size_) - s.EqualValues(sdk.NewDec(2_000_000), queryResp.Position.Margin) + s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(2_999_900), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("2999899.999999999999999506"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("-0.000000000000000494"), queryResp.UnrealizedPnl) diff --git a/x/perp/keeper/calc_test.go b/x/perp/keeper/calc_test.go index 042e7bbdd..926195baf 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -48,8 +48,8 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - /* y */ sdk.NewDec(1_000_000), // - /* x */ sdk.NewDec(1_000_000), // + /* y */ sdk.NewDec(1*common.Precision), // + /* x */ sdk.NewDec(1*common.Precision), // vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("1.0"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -102,8 +102,8 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - /* y */ sdk.NewDec(1_000_000), // - /* x */ sdk.NewDec(1_000_000), // + /* y */ sdk.NewDec(1*common.Precision), // + /* x */ sdk.NewDec(1*common.Precision), // vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("1.0"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/perp/keeper/clearing_house_integration_test.go b/x/perp/keeper/clearing_house_integration_test.go index 32a101430..608e4da5d 100644 --- a/x/perp/keeper/clearing_house_integration_test.go +++ b/x/perp/keeper/clearing_house_integration_test.go @@ -133,7 +133,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new long position just under fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000_000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), initialPosition: nil, side: types.Side_BUY, margin: sdk.NewInt(47_619_047_619), @@ -239,7 +239,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new short position just under fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000_000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), initialPosition: nil, side: types.Side_SELL, margin: sdk.NewInt(47_619_047_619), @@ -274,8 +274,8 @@ func TestOpenPositionSuccess(t *testing.T) { nibiruApp.VpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteReserve */ sdk.NewDec(1_000_000_000_000), - /* baseReserve */ sdk.NewDec(1_000_000_000_000), + /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), + /* baseReserve */ sdk.NewDec(1*common.Precision*common.Precision), vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -471,44 +471,44 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new long position over fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000_000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, - margin: sdk.NewInt(100_000_000_000), + margin: sdk.NewInt(100_000 * common.Precision), leverage: sdk.OneDec(), baseLimit: sdk.ZeroDec(), expectedErr: vpooltypes.ErrOverFluctuationLimit, }, { name: "new short position over fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000_000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, - margin: sdk.NewInt(100_000_000_000), + margin: sdk.NewInt(100_000 * common.Precision), leverage: sdk.OneDec(), baseLimit: sdk.ZeroDec(), expectedErr: vpooltypes.ErrOverFluctuationLimit, }, { name: "new long position over trade limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000_000_000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000*common.Precision)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_BUY, - margin: sdk.NewInt(100_000_000_000), + margin: sdk.NewInt(100_000 * common.Precision), leverage: sdk.OneDec(), baseLimit: sdk.ZeroDec(), expectedErr: vpooltypes.ErrOverTradingLimit, }, { name: "new short position over trade limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000_000_000)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000*common.Precision)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_SELL, - margin: sdk.NewInt(100_000_000_000), + margin: sdk.NewInt(100_000 * common.Precision), leverage: sdk.OneDec(), baseLimit: sdk.ZeroDec(), expectedErr: vpooltypes.ErrOverTradingLimit, @@ -534,8 +534,8 @@ func TestOpenPositionError(t *testing.T) { common.Pair_BTC_NUSD, /* tradeLimitRatio */ /* quoteReserve */ - sdk.NewDec(1_000_000_000_000), - /* baseReserve */ sdk.NewDec(1_000_000_000_000), + sdk.NewDec(1*common.Precision*common.Precision), + /* baseReserve */ sdk.NewDec(1*common.Precision*common.Precision), vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -603,8 +603,8 @@ func TestOpenPositionInvalidPair(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - sdk.NewDec(10_000_000), // - sdk.NewDec(5_000_000), // 5 tokens + sdk.NewDec(10*common.Precision), // + sdk.NewDec(5*common.Precision), // 5 tokens vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/perp/keeper/clearing_house_unit_test.go b/x/perp/keeper/clearing_house_unit_test.go index f92ea1091..e36e7edf2 100644 --- a/x/perp/keeper/clearing_house_unit_test.go +++ b/x/perp/keeper/clearing_house_unit_test.go @@ -1887,7 +1887,7 @@ func TestClosePosition(t *testing.T) { ).Return(nil) mocks.mockBankKeeper.EXPECT().GetBalance(ctx, sdk.AccAddress{0x1, 0x2, 0x3}, tc.initialPosition.Pair.QuoteDenom()). - Return(sdk.NewCoin("NUSD", sdk.NewInt(100000000000))) + Return(sdk.NewCoin("NUSD", sdk.NewInt(100000*common.Precision))) mocks.mockAccountKeeper.EXPECT().GetModuleAddress(types.VaultModuleAccount). Return(sdk.AccAddress{0x1, 0x2, 0x3}) diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index fb06ed219..5afc42c4e 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -40,7 +40,7 @@ func TestQueryPosition(t *testing.T) { BlockNumber: 1, LatestCumulativePremiumFraction: sdk.ZeroDec(), }, - quoteAssetReserve: sdk.NewDec(1_000_000), + quoteAssetReserve: sdk.NewDec(1 * common.Precision), baseAssetReserve: sdk.NewDec(500_000), expectedPositionNotional: sdk.MustNewDecFromStr("19.999600007999840003"), @@ -57,8 +57,8 @@ func TestQueryPosition(t *testing.T) { BlockNumber: 1, LatestCumulativePremiumFraction: sdk.ZeroDec(), }, - quoteAssetReserve: sdk.NewDec(1_000_000), - baseAssetReserve: sdk.NewDec(1_000_000), + quoteAssetReserve: sdk.NewDec(1 * common.Precision), + baseAssetReserve: sdk.NewDec(1 * common.Precision), expectedPositionNotional: sdk.MustNewDecFromStr("9.99990000099999"), expectedUnrealizedPnl: sdk.MustNewDecFromStr("-0.00009999900001"), @@ -75,7 +75,7 @@ func TestQueryPosition(t *testing.T) { LatestCumulativePremiumFraction: sdk.ZeroDec(), }, quoteAssetReserve: sdk.NewDec(500_000), - baseAssetReserve: sdk.NewDec(1_000_000), + baseAssetReserve: sdk.NewDec(1 * common.Precision), expectedPositionNotional: sdk.MustNewDecFromStr("4.999950000499995"), expectedUnrealizedPnl: sdk.MustNewDecFromStr("-5.000049999500005"), diff --git a/x/perp/keeper/liquidate_test.go b/x/perp/keeper/liquidate_test.go index a7b19c828..e5b04eb54 100644 --- a/x/perp/keeper/liquidate_test.go +++ b/x/perp/keeper/liquidate_test.go @@ -54,7 +54,7 @@ func TestExecuteFullLiquidation(t *testing.T) { // = positionResp.ExchangedNotionalValue * liquidationFee / 2 // = 50_000 * 0.1 / 2 = 2500 expectedLiquidatorBalance: sdk.NewInt64Coin("NUSD", 2_500), - // startingBalance = 1_000_000 + // startingBalance = 1* common.Precision // perpEFBalance = startingBalance + openPositionDelta + liquidateDelta expectedPerpEFBalance: sdk.NewInt64Coin("NUSD", 1_047_550), }, @@ -72,7 +72,7 @@ func TestExecuteFullLiquidation(t *testing.T) { // = positionResp.ExchangedNotionalValue * liquidationFee / 2 // = 50_000 * 0.123123 / 2 = 3078.025 → 3078 expectedLiquidatorBalance: sdk.NewInt64Coin("NUSD", 3078), - // startingBalance = 1_000_000 + // startingBalance = 1* common.Precision // perpEFBalance = startingBalance + openPositionDelta + liquidateDelta expectedPerpEFBalance: sdk.NewInt64Coin("NUSD", 1_046_972), }, @@ -90,8 +90,8 @@ func TestExecuteFullLiquidation(t *testing.T) { vpoolKeeper.CreatePool( ctx, tokenPair, - /* quoteAssetReserves */ sdk.NewDec(10_000_000), - /* baseAssetReserves */ sdk.NewDec(5_000_000), + /* quoteAssetReserves */ sdk.NewDec(10*common.Precision), + /* baseAssetReserves */ sdk.NewDec(5*common.Precision), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.OneDec(), @@ -136,7 +136,7 @@ func TestExecuteFullLiquidation(t *testing.T) { t.Log("Artificially populate Vault and PerpEF to prevent bankKeeper errors") startingModuleFunds := sdk.NewCoins(sdk.NewInt64Coin( - tokenPair.QuoteDenom(), 1_000_000)) + tokenPair.QuoteDenom(), 1*common.Precision)) assert.NoError(t, simapp.FundModuleAccount( nibiruApp.BankKeeper, ctx, types.VaultModuleAccount, startingModuleFunds)) assert.NoError(t, simapp.FundModuleAccount( @@ -226,7 +226,7 @@ func TestExecutePartialLiquidation(t *testing.T) { // = 50_000 * 0.4 * 0.1 / 2 = 1_000 expectedLiquidatorBalance: sdk.NewInt64Coin("yyy", 1_000), - // startingBalance = 1_000_000 + // startingBalance = 1* common.Precision // perpEFBalance = startingBalance + openPositionDelta + liquidateDelta expectedPerpEFBalance: sdk.NewInt64Coin("yyy", 1_001_050), }, @@ -250,7 +250,7 @@ func TestExecutePartialLiquidation(t *testing.T) { // = 50_000 * 0.4 * 0.1 / 2 = 1_000 expectedLiquidatorBalance: sdk.NewInt64Coin("yyy", 1_000), - // startingBalance = 1_000_000 + // startingBalance = 1* common.Precision // perpEFBalance = startingBalance + openPositionDelta + liquidateDelta expectedPerpEFBalance: sdk.NewInt64Coin("yyy", 1_001_050), }, @@ -267,8 +267,8 @@ func TestExecutePartialLiquidation(t *testing.T) { vpoolKeeper.CreatePool( ctx, tokenPair, - /* quoteAssetReserves */ sdk.NewDec(10_000_000_000_000_000), - /* baseAssetReserves */ sdk.NewDec(5_000_000_000_000_000), + /* quoteAssetReserves */ sdk.NewDec(10_000*common.Precision*common.Precision), + /* baseAssetReserves */ sdk.NewDec(5_000*common.Precision*common.Precision), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.OneDec(), @@ -316,7 +316,7 @@ func TestExecutePartialLiquidation(t *testing.T) { t.Log("Artificially populate Vault and PerpEF to prevent bankKeeper errors") startingModuleFunds := sdk.NewCoins(sdk.NewInt64Coin( - tokenPair.QuoteDenom(), 1_000_000)) + tokenPair.QuoteDenom(), 1*common.Precision)) assert.NoError(t, simapp.FundModuleAccount( nibiruApp.BankKeeper, ctx, types.VaultModuleAccount, startingModuleFunds)) assert.NoError(t, simapp.FundModuleAccount( diff --git a/x/perp/keeper/margin_test.go b/x/perp/keeper/margin_test.go index b3802e090..094107128 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -68,8 +68,8 @@ func TestAddMarginSuccess(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - sdk.NewDec(10_000_000), // 10 tokens - sdk.NewDec(5_000_000), // 5 tokens + sdk.NewDec(10*common.Precision), // 10 tokens + sdk.NewDec(5*common.Precision), // 5 tokens vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), // 0.1 ratio @@ -140,8 +140,8 @@ func TestRemoveMargin(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - /* y */ sdk.NewDec(1_000_000), // - /* x */ sdk.NewDec(1_000_000), // + /* y */ sdk.NewDec(1*common.Precision), // + /* x */ sdk.NewDec(1*common.Precision), // vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.OneDec(), @@ -169,8 +169,8 @@ func TestRemoveMargin(t *testing.T) { t.Log("Set vpool defined by pair on VpoolKeeper") vpoolKeeper := &nibiruApp.VpoolKeeper - quoteReserves := sdk.NewDec(1_000_000) - baseReserves := sdk.NewDec(1_000_000) + quoteReserves := sdk.NewDec(1 * common.Precision) + baseReserves := sdk.NewDec(1 * common.Precision) vpoolKeeper.CreatePool( ctx, pair, diff --git a/x/perp/keeper/msg_server_test.go b/x/perp/keeper/msg_server_test.go index 7e22ed8a1..bc1d2ce49 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -79,8 +79,8 @@ func TestMsgServerAddMargin(t *testing.T) { app.VpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteReserve */ sdk.NewDec(1_000_000), - /* baseReserve */ sdk.NewDec(1_000_000), + /* quoteReserve */ sdk.NewDec(1*common.Precision), + /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -165,7 +165,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { initialPosition: &types.Position{ Pair: common.Pair_BTC_NUSD, Size_: sdk.OneDec(), - Margin: sdk.NewDec(1_000_000), + Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, @@ -179,7 +179,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { initialPosition: &types.Position{ Pair: common.Pair_BTC_NUSD, Size_: sdk.OneDec(), - Margin: sdk.NewDec(1_000_000), + Margin: sdk.NewDec(1 * common.Precision), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, @@ -200,8 +200,8 @@ func TestMsgServerRemoveMargin(t *testing.T) { app.VpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteReserve */ sdk.NewDec(1_000_000), - /* baseReserve */ sdk.NewDec(1_000_000), + /* quoteReserve */ sdk.NewDec(1*common.Precision), + /* baseReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -289,8 +289,8 @@ func TestMsgServerOpenPosition(t *testing.T) { app.VpoolKeeper.CreatePool( /* ctx */ ctx, /* pair */ common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(1_000_000), - /* baseAssetReserve */ sdk.NewDec(1_000_000), + /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), + /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -376,8 +376,8 @@ func TestMsgServerClosePosition(t *testing.T) { app.VpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(1_000_000), - /* baseAssetReserve */ sdk.NewDec(1_000_000), + /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), + /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -455,8 +455,8 @@ func TestMsgServerLiquidate(t *testing.T) { app.VpoolKeeper.CreatePool( /* ctx */ ctx, /* pair */ common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(1_000_000), - /* baseAssetReserve */ sdk.NewDec(1_000_000), + /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), + /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -532,8 +532,8 @@ func TestMsgServerMultiLiquidate(t *testing.T) { app.VpoolKeeper.CreatePool( /* ctx */ ctx, /* pair */ pair, - /* quoteAssetReserve */ sdk.NewDec(1_000_000), - /* baseAssetReserve */ sdk.NewDec(1_000_000), + /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), + /* baseAssetReserve */ sdk.NewDec(1*common.Precision), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), diff --git a/x/perp/keeper/perp_test.go b/x/perp/keeper/perp_test.go index 766567318..f420a3996 100644 --- a/x/perp/keeper/perp_test.go +++ b/x/perp/keeper/perp_test.go @@ -30,8 +30,8 @@ func TestKeeperClosePosition(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - /*quoteAssetReserve*/ sdk.NewDec(10_000_000), - /*baseAssetReserve*/ sdk.NewDec(5_000_000), + /*quoteAssetReserve*/ sdk.NewDec(10*common.Precision), + /*baseAssetReserve*/ sdk.NewDec(5*common.Precision), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), diff --git a/x/pricefeed/abci_test.go b/x/pricefeed/abci_test.go index f9f04b6d0..5fa50507d 100644 --- a/x/pricefeed/abci_test.go +++ b/x/pricefeed/abci_test.go @@ -64,9 +64,9 @@ func TestTWAPriceUpdates(t *testing.T) { New price should be. deltaT1: 10minutes / 600_000 - deltaT2: 5000hours / 18_000_000_000 + deltaT2: 5000hours / 18_000 * common.Precision - (0.8 * 600_000 + 0.9 * 18_000_000_000) / 18_000_600_000 = 0.899996666777774074 + (0.8 * 600_000 + 0.9 * 18_000 * common.Precision) / 18_000_600_000 = 0.899996666777774074 */ ctx = ctx.WithBlockTime(ctx.BlockTime().Add(10 * time.Minute)) @@ -89,7 +89,7 @@ func TestTWAPriceUpdates(t *testing.T) { deltaT2: 5000h + 10min / 18_000_600_000 deltaT3: 5000h + 10min / 18_000_600_000 - (0.82 * 600_000 + 0.8 * 18_000_600_000 + 0.9 * 18_000_000_000) / 36_001_200_000 = 0.849998666711109629 + (0.82 * 600_000 + 0.8 * 18_000_600_000 + 0.9 * 18_000 * common.Precision) / 36_001_200_000 = 0.849998666711109629 */ ctx = ctx.WithBlockTime(ctx.BlockTime().Add(10 * time.Minute)) price, err = nibiruApp.PricefeedKeeper.GetCurrentTWAP( @@ -108,7 +108,7 @@ func TestTWAPriceUpdates(t *testing.T) { deltaT3: 5000h + 10min/ 18_000_600_000 deltaT4: 5000h + 10min/ 18_000_600_000 - (0.83 * 600_000 + 0.82 * 18_000_600_000 + 0.8 * 18_000_600_000 + 0.9 * 18_000_000_000) / 54_001_800_000 = 0.839999222248147283 + (0.83 * 600_000 + 0.82 * 18_000_600_000 + 0.8 * 18_000_600_000 + 0.9 * 18_000 * common.Precision) / 54_001_800_000 = 0.839999222248147283 */ setPrice("0.83") runBlock(time.Hour * 5000) @@ -129,7 +129,7 @@ func TestTWAPriceUpdates(t *testing.T) { deltaT2: 5000h + 10min / 18_000_600_000 deltaT4: 2000h - 20min / 7_198_800_000 - (0.83 * 600_000 + 0.82 * 18_000_600_000 + 0.8 * 7_198_800_000) / 25_200_000_000 = 0.839999222248147283 + (0.83 * 600_000 + 0.82 * 18_000_600_000 + 0.8 * 7_198_800_000) / 25_200* common.Precision = 0.839999222248147283 */ setLookbackWindow(ctx, nibiruApp.PricefeedKeeper, 7_000*time.Hour) price, err = nibiruApp.PricefeedKeeper.GetCurrentTWAP( diff --git a/x/pricefeed/client/cli/cli_test.go b/x/pricefeed/client/cli/cli_test.go index 4b21436c4..da158c956 100644 --- a/x/pricefeed/client/cli/cli_test.go +++ b/x/pricefeed/client/cli/cli_test.go @@ -475,7 +475,7 @@ func (s IntegrationTestSuite) TestX_AddOracleProposalAndVote() { clientCtx := val.ClientCtx.WithOutputFormat("json") s.T().Log("Fill oracle wallet to pay gas on post price") - gasTokens := sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 100_000_000)) + gasTokens := sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 100*common.Precision)) oracle := testutilcli.NewAccount(s.network, "delphi-oracle") s.NoError(testutilcli.FillWalletFromValidator(oracle, gasTokens, val, s.cfg.BondDenom)) diff --git a/x/stablecoin/client/cli/cli_test.go b/x/stablecoin/client/cli/cli_test.go index 10ce402be..8e257706f 100644 --- a/x/stablecoin/client/cli/cli_test.go +++ b/x/stablecoin/client/cli/cli_test.go @@ -76,7 +76,7 @@ func (s *IntegrationTestSuite) SetupSuite() { // x/stablecoin genesis state stableGen := stabletypes.DefaultGenesis() stableGen.Params.IsCollateralRatioValid = true - stableGen.ModuleAccountBalance = sdk.NewCoin(common.DenomUSDC, sdk.NewInt(10000000000)) + stableGen.ModuleAccountBalance = sdk.NewCoin(common.DenomUSDC, sdk.NewInt(10000*common.Precision)) genesisState[stabletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(stableGen) genesisState[pftypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(NewPricefeedGen()) @@ -100,8 +100,8 @@ func (s IntegrationTestSuite) TestMintStableCmd() { s.NoError(testutilcli.FillWalletFromValidator( minter, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100_000_000), - sdk.NewInt64Coin(common.DenomUSDC, 100_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 100*common.Precision), + sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), ), val, s.cfg.BondDenom, @@ -127,7 +127,7 @@ func (s IntegrationTestSuite) TestMintStableCmd() { args: append([]string{ "1000000unusd", fmt.Sprintf("--%s=%s", flags.FlagFrom, "minter2")}, commonArgs...), - expectedStable: sdk.NewInt(1000000), + expectedStable: sdk.NewInt(1 * common.Precision), expectErr: false, respType: &sdk.TxResponse{}, expectedCode: 0, @@ -175,7 +175,7 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { burner, sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 20_000), - sdk.NewInt64Coin(common.DenomNUSD, 50_000_000), + sdk.NewInt64Coin(common.DenomNUSD, 50*common.Precision), ), val, s.cfg.BondDenom, @@ -209,7 +209,7 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { "50000000unusd", fmt.Sprintf("--%s=%s", flags.FlagFrom, "burn")}, commonArgs...), expectedStable: sdk.ZeroInt(), - expectedColl: sdk.NewInt(50_000_000 - 100_000), // Collateral minus 0,02% fees + expectedColl: sdk.NewInt(50*common.Precision - 100_000), // Collateral minus 0,02% fees expectedGov: sdk.NewInt(19_990), expectedTreasury: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 50_000)), expectedEf: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 50_000)), @@ -223,8 +223,8 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { // "100000000unusd", // fmt.Sprintf("--%s=%s", flags.FlagFrom, "burn")}, commonArgs...), // expectedStable: sdk.NewInt(0), - // expectedColl: sdk.NewInt(90_000_000), - // expectedGov: sdk.NewInt(1_000_000), + // expectedColl: sdk.NewInt(90* common.Precision), + // expectedGov: sdk.NewInt(1* common.Precision), // expectErr: false, // respType: &sdk.TxResponse{}, // expectedCode: 0, diff --git a/x/stablecoin/keeper/collateral_ratio.go b/x/stablecoin/keeper/collateral_ratio.go index d6f2cea6e..e4583875e 100644 --- a/x/stablecoin/keeper/collateral_ratio.go +++ b/x/stablecoin/keeper/collateral_ratio.go @@ -22,7 +22,7 @@ stablecoin mints and burns. // GetCollRatio queries the 'collRatio'. func (k *Keeper) GetCollRatio(ctx sdk.Context) (collRatio sdk.Dec) { - return sdk.NewDec(k.GetParams(ctx).CollRatio).QuoInt64(1_000_000) + return sdk.NewDec(k.GetParams(ctx).CollRatio).QuoInt64(1 * common.Precision) } /* @@ -40,7 +40,7 @@ func (k *Keeper) SetCollRatio(ctx sdk.Context, collRatio sdk.Dec) (err error) { } params := k.GetParams(ctx) - million := sdk.NewDec(1_000_000) + million := sdk.NewDec(1 * common.Precision) collRatioInt := collRatio.Mul(million).RoundInt().Int64() params.CollRatio = collRatioInt diff --git a/x/stablecoin/keeper/collateral_ratio_test.go b/x/stablecoin/keeper/collateral_ratio_test.go index 89b4e57be..712c28b2f 100644 --- a/x/stablecoin/keeper/collateral_ratio_test.go +++ b/x/stablecoin/keeper/collateral_ratio_test.go @@ -613,13 +613,13 @@ func TestRecollateralize(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (500e3 *1) = 100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1_000_000_000), + sdk.NewInt64Coin(common.DenomUSDC, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(100_000), @@ -646,13 +646,13 @@ func TestRecollateralize(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), priceCollStable: sdk.MustNewDecFromStr("1.099999"), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.7"), // neededUSD = (0.7 * 1000e3) - (500e3 *1.09999) = 150_000.5 }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1_000_000_000), + sdk.NewInt64Coin(common.DenomUSDC, 1_000*common.Precision), ), expectedNeededUSD: sdk.MustNewDecFromStr("150000.5"), @@ -688,7 +688,7 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("-49.9995"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1_000_000), + sdk.NewInt64Coin(common.DenomUSDC, 1*common.Precision), ), // Since 'neededUSD' is @@ -969,13 +969,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), ), expectedAccFundsAfter: sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 900_000), // accFunds - inGov.Amount @@ -1005,13 +1005,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(850_000), priceCollStable: sdk.MustNewDecFromStr("1.099999"), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.7"), // neededUSD = (0.7 * 1000e3) - (850e3 *1.09999) = -234999.15 }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), ), expectedAccFundsAfter: sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 953_000), // accFunds - inGov.Amount @@ -1046,13 +1046,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), ), expectedAccFundsAfter: sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 900_000), // accFunds - inGov.Amount @@ -1079,13 +1079,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.8"), // neededUSD = (0.8 * 1000e3) - (700e3 *1) = 100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(100_000), @@ -1105,7 +1105,7 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, @@ -1130,13 +1130,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(-100_000), @@ -1155,13 +1155,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 1_000*common.Precision), ), expectedNeededUSD: sdk.NewDec(-100_000), @@ -1274,7 +1274,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, @@ -1288,7 +1288,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, @@ -1304,7 +1304,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1_000_000), + stableSupply: sdk.NewInt(1 * common.Precision), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, diff --git a/x/stablecoin/keeper/mint_burn_stable_test.go b/x/stablecoin/keeper/mint_burn_stable_test.go index 3a2921341..0fc575478 100644 --- a/x/stablecoin/keeper/mint_burn_stable_test.go +++ b/x/stablecoin/keeper/mint_burn_stable_test.go @@ -83,7 +83,7 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { accFunds: accFundsAmt, msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000)), + Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), @@ -95,10 +95,10 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { accFunds: accFundsAmt, msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000)), + Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000)), + Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), UsedCoins: sdk.NewCoins(accFundsCollAmount, accFundsGovAmount), FeesPayed: sdk.NewCoins(neededCollFees, neededGovFees), }, @@ -106,7 +106,7 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { collPrice: sdk.MustNewDecFromStr("1"), supplyNIBI: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(10)), // 10_000 - 20 (neededAmt - fees) - 10 (0.5 of fees from EFund are burned) - supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000)), + supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), err: nil, isCollateralRatioValid: true, }, @@ -437,10 +437,10 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1000000000), + sdk.NewInt64Coin(common.DenomNUSD, 1000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100000000), + sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), @@ -557,14 +557,14 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000), + sdk.NewInt64Coin(common.DenomNUSD, 1_000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100_000_000), + sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 10_000_000), + Stable: sdk.NewInt64Coin(common.DenomNUSD, 10*common.Precision), }, ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000)), treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000), sdk.NewInt64Coin(common.DenomNIBI, 100)), @@ -577,25 +577,25 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000), + sdk.NewInt64Coin(common.DenomNUSD, 1_000*common.Precision), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100_000_000), + sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 10_000_000), + Stable: sdk.NewInt64Coin(common.DenomNUSD, 10*common.Precision), }, msgResponse: types.MsgBurnStableResponse{ - Gov: sdk.NewInt64Coin(common.DenomNIBI, 100_000-200), // amount - fees 0,02% - Collateral: sdk.NewInt64Coin(common.DenomUSDC, 9_000_000-18_000), // amount - fees 0,02% + Gov: sdk.NewInt64Coin(common.DenomNIBI, 100_000-200), // amount - fees 0,02% + Collateral: sdk.NewInt64Coin(common.DenomUSDC, 9*common.Precision-18_000), // amount - fees 0,02% FeesPayed: sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 200), sdk.NewInt64Coin(common.DenomUSDC, 18_000), ), }, supplyNIBI: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(100_000-100)), // nibiru minus 0.5 of fees burned (the part that goes to EF) - supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000_000-10_000_000)), + supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000*common.Precision-10*common.Precision)), ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000)), treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000), sdk.NewInt64Coin(common.DenomNIBI, 100)), expectedPass: true, diff --git a/x/stablecoin/keeper/params_test.go b/x/stablecoin/keeper/params_test.go index 10e72b6da..b5b5e2d95 100644 --- a/x/stablecoin/keeper/params_test.go +++ b/x/stablecoin/keeper/params_test.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" + "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -44,7 +45,7 @@ func TestNewParams_Errors(t *testing.T) { ), fmt.Errorf( "collateral ratio is above max value(1e6): %s", - sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1_000_000)).TruncateInt()), + sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1*common.Precision)).TruncateInt()), }, { "fee ratio bigger than 1", @@ -61,7 +62,7 @@ func TestNewParams_Errors(t *testing.T) { ), fmt.Errorf( "fee ratio is above max value(1e6): %s", - sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1_000_000)).TruncateInt()), + sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1*common.Precision)).TruncateInt()), }, { "stable EF fee ratio bigger than 1", @@ -78,7 +79,7 @@ func TestNewParams_Errors(t *testing.T) { ), fmt.Errorf( "stable EF fee ratio is above max value(1e6): %s", - sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1_000_000)).TruncateInt()), + sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1*common.Precision)).TruncateInt()), }, } diff --git a/x/stablecoin/keeper/supply_test.go b/x/stablecoin/keeper/supply_test.go index 8e6d9e2e2..4a77bd87a 100644 --- a/x/stablecoin/keeper/supply_test.go +++ b/x/stablecoin/keeper/supply_test.go @@ -22,14 +22,14 @@ func TestKeeper_GetStableMarketCap(t *testing.T) { // We set some supply err := k.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1_000_000), + sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), )) require.NoError(t, err) // We set some supply marketCap := k.GetStableMarketCap(ctx) - require.Equal(t, sdk.NewInt(1_000_000), marketCap) + require.Equal(t, sdk.NewInt(1*common.Precision), marketCap) } func TestKeeper_GetGovMarketCap(t *testing.T) { @@ -44,11 +44,11 @@ func TestKeeper_GetGovMarketCap(t *testing.T) { } poolAssets := []dextypes.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNIBI, 2_000_000), + Token: sdk.NewInt64Coin(common.DenomNIBI, 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1_000_000), + Token: sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), Weight: sdk.NewInt(100), }, } @@ -59,14 +59,14 @@ func TestKeeper_GetGovMarketCap(t *testing.T) { // We set some supply err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), )) require.NoError(t, err) marketCap, err := keeper.GetGovMarketCap(ctx) require.NoError(t, err) - require.Equal(t, sdk.NewInt(2_000_000), marketCap) // 1 * 10^6 * 2 (price of gov token) + require.Equal(t, sdk.NewInt(2*common.Precision), marketCap) // 1 * 10^6 * 2 (price of gov token) } func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { @@ -81,11 +81,11 @@ func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { } poolAssets := []dextypes.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNIBI, 2_000_000), + Token: sdk.NewInt64Coin(common.DenomNIBI, 2*common.Precision), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1_000_000), + Token: sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), Weight: sdk.NewInt(100), }, } @@ -96,12 +96,12 @@ func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { // We set some supply err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), + sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), )) require.NoError(t, err) err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1_000_000), + sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), )) require.NoError(t, err) diff --git a/x/stablecoin/types/params.go b/x/stablecoin/types/params.go index b0c239ffd..3b3d90b75 100644 --- a/x/stablecoin/types/params.go +++ b/x/stablecoin/types/params.go @@ -5,6 +5,8 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" + + "github.com/NibiruChain/nibiru/x/common" ) var _ paramtypes.ParamSet = (*Params)(nil) @@ -26,7 +28,7 @@ func NewParams( priceUpperBound sdk.Dec, isCollateralRatioValid bool, ) Params { - million := sdk.NewDec(1_000_000) + million := sdk.NewDec(1 * common.Precision) collRatioInt := collRatio.Mul(million).RoundInt().Int64() feeRationInt := feeRatio.Mul(million).RoundInt().Int64() efFeeRatioInt := efFeeRatio.Mul(million).RoundInt().Int64() @@ -174,7 +176,7 @@ func validateCollRatio(i interface{}) error { return err } - if collRatio > 1_000_000 { + if collRatio > 1*common.Precision { return fmt.Errorf("collateral ratio is above max value(1e6): %d", collRatio) } else if collRatio < 0 { return fmt.Errorf("collateral Ratio is negative: %d", collRatio) @@ -197,7 +199,7 @@ func validateBonusRateRecoll(i interface{}) error { return err } - if bonusRateRecoll > 1_000_000 { + if bonusRateRecoll > 1*common.Precision { return fmt.Errorf("collateral Ratio is above max value(1e6): %d", bonusRateRecoll) } else if bonusRateRecoll < 0 { return fmt.Errorf("collateral Ratio is negative: %d", bonusRateRecoll) @@ -212,7 +214,7 @@ func validateFeeRatio(i interface{}) error { return err } - if feeRatio > 1_000_000 { + if feeRatio > 1*common.Precision { return fmt.Errorf("fee ratio is above max value(1e6): %d", feeRatio) } else if feeRatio < 0 { return fmt.Errorf("fee ratio is negative: %d", feeRatio) @@ -227,7 +229,7 @@ func validateEfFeeRatio(i interface{}) error { return err } - if efFeeRatio > 1_000_000 { + if efFeeRatio > 1*common.Precision { return fmt.Errorf("stable EF fee ratio is above max value(1e6): %d", efFeeRatio) } else if efFeeRatio < 0 { return fmt.Errorf("stable EF fee ratio is negative: %d", efFeeRatio) @@ -250,7 +252,7 @@ func validateAdjustmentStep(i interface{}) error { return err } - if adjustmentStep > 1_000_000 { + if adjustmentStep > 1*common.Precision { return fmt.Errorf("AdjustmentStep is above max value(1e6): %d", adjustmentStep) } else if adjustmentStep < 0 { return fmt.Errorf("AdjustmentStep is negative: %d", adjustmentStep) @@ -265,7 +267,7 @@ func validatePriceLowerBound(i interface{}) error { return err } - if priceLowerBound > 1_000_000 { + if priceLowerBound > 1*common.Precision { return fmt.Errorf("PriceLowerBound is above max value(1e6): %d", priceLowerBound) } else if priceLowerBound < 0 { return fmt.Errorf("PriceLowerBound is negative: %d", priceLowerBound) @@ -280,7 +282,7 @@ func validatePriceUpperBound(i interface{}) error { return err } - if priceUpperBound > 2_000_000 { + if priceUpperBound > 2*common.Precision { return fmt.Errorf("PriceUpperBound is above max value(1e6): %d", priceUpperBound) } else if priceUpperBound < 0 { return fmt.Errorf("PriceUpperBound is negative: %d", priceUpperBound) diff --git a/x/testutil/cli/tx.go b/x/testutil/cli/tx.go index b640240f3..4b90721ae 100644 --- a/x/testutil/cli/tx.go +++ b/x/testutil/cli/tx.go @@ -118,7 +118,7 @@ func (n *Network) SendTx(addr sdk.AccAddress, msgs ...sdk.Msg) (*sdk.TxResponse, txBuilder := cfg.TxConfig.NewTxBuilder() require.NoError(n.T, txBuilder.SetMsgs(msgs...)) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(cfg.BondDenom, sdk.NewInt(1)))) - txBuilder.SetGasLimit(1000000) + txBuilder.SetGasLimit(uint64(1 * common.Precision)) acc, err := cfg.AccountRetriever.GetAccount(n.Validators[0].ClientCtx, addr) require.NoError(n.T, err) diff --git a/x/testutil/sample.go b/x/testutil/sample.go index 0a6fbfd4b..ee98e152b 100644 --- a/x/testutil/sample.go +++ b/x/testutil/sample.go @@ -46,3 +46,23 @@ func BlankContext(storeKeyName string) sdk.Context { ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) return ctx } + +type TypeLatin struct { + Letters string + CapLetters string + Numbers string +} + +var Latin = TypeLatin{ + Letters: "abcdefghijklmnopqrstuvwxyz", + CapLetters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", + Numbers: "0123456789", +} + +func RandStringBytes(n int) string { + b := make([]byte, n) + for i := range b { + b[i] = Latin.Letters[rand.Intn(len(Latin.Letters))] + } + return string(b) +} diff --git a/x/util/keeper/query_server_test.go b/x/util/keeper/query_server_test.go index 08b4c568f..8cc74926a 100644 --- a/x/util/keeper/query_server_test.go +++ b/x/util/keeper/query_server_test.go @@ -7,6 +7,7 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/simapp" + "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/util/keeper" "github.com/NibiruChain/nibiru/x/util/types" ) @@ -28,7 +29,7 @@ func TestQueryServer_ModuleAccounts(t *testing.T) { err = app.BankKeeper.MintCoins( ctx, someModuleAccount, - sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1_000_000)), + sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1*common.Precision)), ) require.NoError(t, err) @@ -36,5 +37,5 @@ func TestQueryServer_ModuleAccounts(t *testing.T) { accounts, err = qServer.ModuleAccounts(goCtx, &types.QueryModuleAccountsRequest{}) require.NoError(t, err) require.Len(t, accounts.Accounts, len(types.ModuleAccounts)) - require.Equal(t, accounts.Accounts[0].Balance, sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1_000_000))) + require.Equal(t, accounts.Accounts[0].Balance, sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1*common.Precision))) } diff --git a/x/vpool/client/cli/cli_test.go b/x/vpool/client/cli/cli_test.go index 09bc7042e..b0269aa7c 100644 --- a/x/vpool/client/cli/cli_test.go +++ b/x/vpool/client/cli/cli_test.go @@ -35,8 +35,8 @@ func TestIntegrationTestSuite(t *testing.T) { var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ common.Pair_ETH_NUSD: { Pair: common.Pair_ETH_NUSD, - BaseAssetReserve: sdk.NewDec(10_000_000), - QuoteAssetReserve: sdk.NewDec(60_000_000_000), + BaseAssetReserve: sdk.NewDec(10 * common.Precision), + QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.8"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), @@ -48,7 +48,7 @@ var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ common.Pair_NIBI_NUSD: { Pair: common.Pair_NIBI_NUSD, BaseAssetReserve: sdk.NewDec(500_000), - QuoteAssetReserve: sdk.NewDec(5_000_000), + QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.8"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), @@ -98,8 +98,8 @@ func (s *IntegrationTestSuite) TestCmdCreatePoolProposal() { Title: "Create ETH:USD pool", Description: "Creates an ETH:USD pool", Pair: "ETH:USD", - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.05"), diff --git a/x/vpool/genesis_test.go b/x/vpool/genesis_test.go index 558c77745..a77b65333 100644 --- a/x/vpool/genesis_test.go +++ b/x/vpool/genesis_test.go @@ -20,8 +20,8 @@ func TestGenesis(t *testing.T) { vpools := []types.Vpool{ { Pair: common.MustNewAssetPair("BTC:NUSD"), - BaseAssetReserve: sdk.NewDec(1_000_000), // 1 - QuoteAssetReserve: sdk.NewDec(30_000_000_000), // 30,000 + BaseAssetReserve: sdk.NewDec(1 * common.Precision), // 1 + QuoteAssetReserve: sdk.NewDec(30_000 * common.Precision), // 30,000 Config: types.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.88"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.20"), @@ -32,8 +32,8 @@ func TestGenesis(t *testing.T) { }, { Pair: common.MustNewAssetPair("ETH:NUSD"), - BaseAssetReserve: sdk.NewDec(2_000_000), // 2 - QuoteAssetReserve: sdk.NewDec(60_000_000_000), // 60,000 + BaseAssetReserve: sdk.NewDec(2 * common.Precision), // 2 + QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), // 60,000 Config: types.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.77"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.30"), diff --git a/x/vpool/keeper/keeper_test.go b/x/vpool/keeper/keeper_test.go index 2e0b8a22e..2508d9ec1 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -38,8 +38,8 @@ func TestSwapQuoteForBase(t *testing.T) { baseLimit: sdk.NewDec(10), skipFluctuationLimitCheck: false, - expectedQuoteReserve: sdk.NewDec(10_000_000), - expectedBaseReserve: sdk.NewDec(5_000_000), + expectedQuoteReserve: sdk.NewDec(10 * common.Precision), + expectedBaseReserve: sdk.NewDec(5 * common.Precision), expectedBaseAmount: sdk.ZeroDec(), }, { @@ -90,7 +90,7 @@ func TestSwapQuoteForBase(t *testing.T) { name: "base amount more than base limit in Short", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - quoteAmount: sdk.NewDec(1_000_000), + quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_500), skipFluctuationLimitCheck: false, @@ -120,7 +120,7 @@ func TestSwapQuoteForBase(t *testing.T) { name: "over fluctuation limit fails on add", pair: common.Pair_BTC_NUSD, direction: types.Direction_ADD_TO_POOL, - quoteAmount: sdk.NewDec(1_000_000), + quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), skipFluctuationLimitCheck: false, @@ -130,7 +130,7 @@ func TestSwapQuoteForBase(t *testing.T) { name: "over fluctuation limit fails on remove", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - quoteAmount: sdk.NewDec(1_000_000), + quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), skipFluctuationLimitCheck: false, @@ -140,11 +140,11 @@ func TestSwapQuoteForBase(t *testing.T) { name: "over fluctuation limit allowed on add", pair: common.Pair_BTC_NUSD, direction: types.Direction_ADD_TO_POOL, - quoteAmount: sdk.NewDec(1_000_000), + quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(454_544), skipFluctuationLimitCheck: true, - expectedQuoteReserve: sdk.NewDec(11_000_000), + expectedQuoteReserve: sdk.NewDec(11 * common.Precision), expectedBaseReserve: sdk.MustNewDecFromStr("4545454.545454545454545455"), expectedBaseAmount: sdk.MustNewDecFromStr("454545.454545454545454545"), }, @@ -152,11 +152,11 @@ func TestSwapQuoteForBase(t *testing.T) { name: "over fluctuation limit allowed on remove", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - quoteAmount: sdk.NewDec(1_000_000), + quoteAmount: sdk.NewDec(1 * common.Precision), baseLimit: sdk.NewDec(555_556), skipFluctuationLimitCheck: true, - expectedQuoteReserve: sdk.NewDec(9_000_000), + expectedQuoteReserve: sdk.NewDec(9 * common.Precision), expectedBaseReserve: sdk.MustNewDecFromStr("5555555.555555555555555556"), expectedBaseAmount: sdk.MustNewDecFromStr("555555.555555555555555556"), }, @@ -173,8 +173,8 @@ func TestSwapQuoteForBase(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(10_000_000), // 10 tokens - /* baseAssetReserve */ sdk.NewDec(5_000_000), // 5 tokens + /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens + /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), @@ -231,8 +231,8 @@ func TestSwapBaseForQuote(t *testing.T) { quoteLimit: sdk.ZeroDec(), skipFluctuationLimitCheck: false, - expectedQuoteReserve: sdk.NewDec(10_000_000), - expectedBaseReserve: sdk.NewDec(5_000_000), + expectedQuoteReserve: sdk.NewDec(10 * common.Precision), + expectedBaseReserve: sdk.NewDec(5 * common.Precision), expectedQuoteAssetAmount: sdk.ZeroDec(), }, { @@ -313,7 +313,7 @@ func TestSwapBaseForQuote(t *testing.T) { name: "over fluctuation limit fails on add", pair: common.Pair_BTC_NUSD, direction: types.Direction_ADD_TO_POOL, - baseAmt: sdk.NewDec(1_000_000), + baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), skipFluctuationLimitCheck: false, @@ -323,7 +323,7 @@ func TestSwapBaseForQuote(t *testing.T) { name: "over fluctuation limit fails on remove", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - baseAmt: sdk.NewDec(1_000_000), + baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), skipFluctuationLimitCheck: false, @@ -333,24 +333,24 @@ func TestSwapBaseForQuote(t *testing.T) { name: "over fluctuation limit allowed on add", pair: common.Pair_BTC_NUSD, direction: types.Direction_ADD_TO_POOL, - baseAmt: sdk.NewDec(1_000_000), + baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(1_666_666), skipFluctuationLimitCheck: true, expectedQuoteReserve: sdk.MustNewDecFromStr("8333333.333333333333333333"), - expectedBaseReserve: sdk.NewDec(6_000_000), + expectedBaseReserve: sdk.NewDec(6 * common.Precision), expectedQuoteAssetAmount: sdk.MustNewDecFromStr("1666666.666666666666666667"), }, { name: "over fluctuation limit allowed on remove", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - baseAmt: sdk.NewDec(1_000_000), + baseAmt: sdk.NewDec(1 * common.Precision), quoteLimit: sdk.NewDec(2_500_001), skipFluctuationLimitCheck: true, expectedQuoteReserve: sdk.NewDec(12_500_000), - expectedBaseReserve: sdk.NewDec(4_000_000), + expectedBaseReserve: sdk.NewDec(4 * common.Precision), expectedQuoteAssetAmount: sdk.NewDec(2_500_000), }, } @@ -366,8 +366,8 @@ func TestSwapBaseForQuote(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(10_000_000), // 10 tokens - /* baseAssetReserve */ sdk.NewDec(5_000_000), // 5 tokens + /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens + /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), @@ -411,8 +411,8 @@ func TestGetVpools(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - sdk.NewDec(10_000_000), - sdk.NewDec(5_000_000), + sdk.NewDec(10*common.Precision), + sdk.NewDec(5*common.Precision), types.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -424,8 +424,8 @@ func TestGetVpools(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_ETH_NUSD, - sdk.NewDec(5_000_000), - sdk.NewDec(10_000_000), + sdk.NewDec(5*common.Precision), + sdk.NewDec(10*common.Precision), types.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -441,8 +441,8 @@ func TestGetVpools(t *testing.T) { require.EqualValues(t, pools[0], types.Vpool{ Pair: common.Pair_BTC_NUSD, - BaseAssetReserve: sdk.NewDec(5_000_000), - QuoteAssetReserve: sdk.NewDec(10_000_000), + BaseAssetReserve: sdk.NewDec(5 * common.Precision), + QuoteAssetReserve: sdk.NewDec(10 * common.Precision), Config: types.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -453,8 +453,8 @@ func TestGetVpools(t *testing.T) { }) require.EqualValues(t, pools[1], types.Vpool{ Pair: common.Pair_ETH_NUSD, - BaseAssetReserve: sdk.NewDec(10_000_000), - QuoteAssetReserve: sdk.NewDec(5_000_000), + BaseAssetReserve: sdk.NewDec(10 * common.Precision), + QuoteAssetReserve: sdk.NewDec(5 * common.Precision), Config: types.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), diff --git a/x/vpool/keeper/pool_state_test.go b/x/vpool/keeper/pool_state_test.go index d4e567f31..2b0b43401 100644 --- a/x/vpool/keeper/pool_state_test.go +++ b/x/vpool/keeper/pool_state_test.go @@ -21,8 +21,8 @@ func TestCreatePool(t *testing.T) { ctx, common.Pair_BTC_NUSD, - sdk.NewDec(10_000_000), // 10 tokens - sdk.NewDec(5_000_000), // 5 tokens + sdk.NewDec(10*common.Precision), // 10 tokens + sdk.NewDec(5*common.Precision), // 5 tokens types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -46,8 +46,8 @@ func TestEditPoolConfig(t *testing.T) { pair := common.Pair_BTC_NUSD vpoolStart := types.Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(10_000_000), - BaseAssetReserve: sdk.NewDec(5_000_000), + QuoteAssetReserve: sdk.NewDec(10 * common.Precision), + BaseAssetReserve: sdk.NewDec(5 * common.Precision), Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -194,8 +194,8 @@ func TestGetPoolPrices(t *testing.T) { name: "happy path - vpool + pricefeed active", vpool: types.Vpool{ Pair: common.Pair_ETH_NUSD, - QuoteAssetReserve: sdk.NewDec(3_000_000), // 3e6 - BaseAssetReserve: sdk.NewDec(1_000), // 1e3 + QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 + BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.30"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -211,7 +211,7 @@ func TestGetPoolPrices(t *testing.T) { MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.NewDec(99).String(), - SwapInvariant: sdk.NewInt(3_000_000_000), // 1e3 * 3e6 = 3e9 + SwapInvariant: sdk.NewInt(3_000 * common.Precision), // 1e3 * 3e6 = 3e9 BlockNumber: 2, }, }, @@ -219,8 +219,8 @@ func TestGetPoolPrices(t *testing.T) { name: "happy path - vpool active, but no index price", vpool: types.Vpool{ Pair: common.Pair_ETH_NUSD, - QuoteAssetReserve: sdk.NewDec(3_000_000), // 3e6 - BaseAssetReserve: sdk.NewDec(1_000), // 1e3 + QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 + BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.30"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -237,7 +237,7 @@ func TestGetPoolPrices(t *testing.T) { MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.OneDec().Neg().String(), - SwapInvariant: sdk.NewInt(3_000_000_000), // 1e3 * 3e6 = 3e9 + SwapInvariant: sdk.NewInt(3_000 * common.Precision), // 1e3 * 3e6 = 3e9 BlockNumber: 2, }, }, @@ -245,8 +245,8 @@ func TestGetPoolPrices(t *testing.T) { name: "vpool doesn't exist", vpool: types.Vpool{ Pair: common.Pair_ETH_NUSD, - QuoteAssetReserve: sdk.NewDec(3_000_000), // 3e6 - BaseAssetReserve: sdk.NewDec(1_000), // 1e3 + QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 + BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.30"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -303,8 +303,8 @@ func TestEditSwapInvariant(t *testing.T) { pair := common.Pair_NIBI_NUSD vpoolStart := types.Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(10_000_000), - BaseAssetReserve: sdk.NewDec(5_000_000), + QuoteAssetReserve: sdk.NewDec(10 * common.Precision), + BaseAssetReserve: sdk.NewDec(5 * common.Precision), Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/vpool/keeper/query_server_test.go b/x/vpool/keeper/query_server_test.go index d64253deb..4afe87cbf 100644 --- a/x/vpool/keeper/query_server_test.go +++ b/x/vpool/keeper/query_server_test.go @@ -25,7 +25,7 @@ func TestQueryReserveAssets(t *testing.T) { t.Log("initialize vpool") pool := types.Vpool{ Pair: common.Pair_BTC_NUSD, - QuoteAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.ZeroDec(), @@ -61,7 +61,7 @@ func TestQueryAllPools(t *testing.T) { pair := common.Pair_BTC_NUSD pool := &types.Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.ZeroDec(), @@ -92,7 +92,7 @@ func TestQueryAllPools(t *testing.T) { MarkPrice: markPriceWanted, IndexPrice: indexPrice.String(), TwapMark: markPriceWanted.String(), - SwapInvariant: sdk.NewInt(1_000_000_000), // 1e6 * 1e3 + SwapInvariant: sdk.NewInt(1_000 * common.Precision), BlockNumber: 2, } require.NoError(t, err) diff --git a/x/vpool/types/gov_test.go b/x/vpool/types/gov_test.go index 4cc19a654..ceadf9d75 100644 --- a/x/vpool/types/gov_test.go +++ b/x/vpool/types/gov_test.go @@ -38,8 +38,8 @@ func TestCreatePoolProposal_ValidateBasic(t *testing.T) { Title: "add proposal", Description: "some weird description", Pair: "valid:pair", - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/vpool/types/pool_test.go b/x/vpool/types/pool_test.go index b1fe5f915..041033862 100644 --- a/x/vpool/types/pool_test.go +++ b/x/vpool/types/pool_test.go @@ -18,8 +18,8 @@ func TestPoolHasEnoughQuoteReserve(t *testing.T) { pool := &Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(10_000_000), - BaseAssetReserve: sdk.NewDec(10_000_000), + QuoteAssetReserve: sdk.NewDec(10 * common.Precision), + BaseAssetReserve: sdk.NewDec(10 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaxOracleSpreadRatio: sdk.MustNewDecFromStr("0.1"), @@ -30,10 +30,10 @@ func TestPoolHasEnoughQuoteReserve(t *testing.T) { } // less than max ratio - require.True(t, pool.HasEnoughQuoteReserve(sdk.NewDec(8_000_000))) + require.True(t, pool.HasEnoughQuoteReserve(sdk.NewDec(8*common.Precision))) // equal to ratio limit - require.True(t, pool.HasEnoughQuoteReserve(sdk.NewDec(9_000_000))) + require.True(t, pool.HasEnoughQuoteReserve(sdk.NewDec(9*common.Precision))) // more than ratio limit require.False(t, pool.HasEnoughQuoteReserve(sdk.NewDec(9_000_001))) @@ -44,8 +44,8 @@ func TestSetMarginRatioAndLeverage(t *testing.T) { pool := &Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(10_000_000), - BaseAssetReserve: sdk.NewDec(10_000_000), + QuoteAssetReserve: sdk.NewDec(10 * common.Precision), + BaseAssetReserve: sdk.NewDec(10 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.42"), @@ -216,8 +216,8 @@ func TestIncreaseDecreaseReserves(t *testing.T) { pool := &Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -233,7 +233,7 @@ func TestIncreaseDecreaseReserves(t *testing.T) { t.Log("increase quote asset reserve") pool.IncreaseQuoteAssetReserve(sdk.NewDec(100)) - require.Equal(t, sdk.NewDec(1_000_000), pool.QuoteAssetReserve) + require.Equal(t, sdk.NewDec(1*common.Precision), pool.QuoteAssetReserve) t.Log("decrease base asset reserve") pool.DecreaseBaseAssetReserve(sdk.NewDec(100)) @@ -241,7 +241,7 @@ func TestIncreaseDecreaseReserves(t *testing.T) { t.Log("increase base asset reserve") pool.IncreaseBaseAssetReserve(sdk.NewDec(100)) - require.Equal(t, sdk.NewDec(1_000_000), pool.BaseAssetReserve) + require.Equal(t, sdk.NewDec(1*common.Precision), pool.BaseAssetReserve) } func TestPool_Validate(t *testing.T) { @@ -318,7 +318,7 @@ func TestPool_Validate(t *testing.T) { "base asset reserve 0": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), BaseAssetReserve: sdk.ZeroDec(), Config: VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), @@ -334,8 +334,8 @@ func TestPool_Validate(t *testing.T) { "fluctuation < 0": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), FluctuationLimitRatio: sdk.NewDec(-1), @@ -350,8 +350,8 @@ func TestPool_Validate(t *testing.T) { "fluctuation > 1": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), FluctuationLimitRatio: sdk.NewDec(2), @@ -366,8 +366,8 @@ func TestPool_Validate(t *testing.T) { "max oracle spread ratio < 0": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.OneDec(), @@ -382,8 +382,8 @@ func TestPool_Validate(t *testing.T) { "max oracle spread ratio > 1": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.OneDec(), @@ -405,8 +405,8 @@ func TestPool_Validate(t *testing.T) { MaxOracleSpreadRatio: sdk.MustNewDecFromStr("0.10"), TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), }, - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), }, expectErr: true, }, @@ -414,8 +414,8 @@ func TestPool_Validate(t *testing.T) { "maintenance ratio > 1": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.NewDec(2), @@ -430,8 +430,8 @@ func TestPool_Validate(t *testing.T) { "max leverage < 0": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.10"), @@ -446,8 +446,8 @@ func TestPool_Validate(t *testing.T) { "max leverage too high for maintenance margin ratio": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.10"), // Equivalent to 10 leverage @@ -462,8 +462,8 @@ func TestPool_Validate(t *testing.T) { "success": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1_000_000), - BaseAssetReserve: sdk.NewDec(1_000_000), + QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + BaseAssetReserve: sdk.NewDec(1 * common.Precision), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/wasm/cli/cli_test.go b/x/wasm/cli/cli_test.go index 2c6617eb6..9f16197a7 100644 --- a/x/wasm/cli/cli_test.go +++ b/x/wasm/cli/cli_test.go @@ -49,8 +49,8 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis.Vpools = []vpooltypes.Vpool{ { Pair: common.Pair_ETH_NUSD, - BaseAssetReserve: sdk.NewDec(10_000_000), - QuoteAssetReserve: sdk.NewDec(60_000_000_000), + BaseAssetReserve: sdk.NewDec(10 * common.Precision), + QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), Config: vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), From b3ccad237191611e8f7d91bf5ad3116c965b4238 Mon Sep 17 00:00:00 2001 From: Unique Divine <51418232+Unique-Divine@users.noreply.github.com> Date: Tue, 29 Nov 2022 12:09:54 -0600 Subject: [PATCH 5/5] Revert "fix: flaky oracle test" (#1099) Revert "fix: flaky oracle test (#1098)" This reverts commit 64b30e274b3a160c27bffc5c3491c6b5d4116cc6. --- CHANGELOG.md | 1 - app/antedecorators/gasless/gasless_test.go | 3 +- scripts/testing/stableswap_model.py | 2 +- simapp/testapp.go | 2 +- x/common/common.go | 3 - x/dex/keeper/keeper_test.go | 6 +- x/dex/simulation/operations.go | 2 +- x/dex/types/params.go | 2 +- x/dex/types/pool_asset_test.go | 8 +-- x/dex/types/pool_test.go | 11 ++-- x/dex/types/price_test.go | 21 ++++--- x/dex/types/swap_test.go | 18 +++--- x/lockup/client/cli/cli_test.go | 9 ++- x/oracle/keeper/reward_test.go | 2 +- x/oracle/keeper/tally_fuzz_test.go | 3 +- x/oracle/keeper/update_exchange_rates_test.go | 12 ++-- x/perp/client/cli/cli_test.go | 32 +++++----- x/perp/keeper/calc_test.go | 8 +-- .../keeper/clearing_house_integration_test.go | 32 +++++----- x/perp/keeper/clearing_house_unit_test.go | 2 +- x/perp/keeper/grpc_query_test.go | 8 +-- x/perp/keeper/liquidate_test.go | 20 +++---- x/perp/keeper/margin_test.go | 12 ++-- x/perp/keeper/msg_server_test.go | 28 ++++----- x/perp/keeper/perp_test.go | 4 +- x/pricefeed/abci_test.go | 10 ++-- x/pricefeed/client/cli/cli_test.go | 2 +- x/stablecoin/client/cli/cli_test.go | 16 ++--- x/stablecoin/keeper/collateral_ratio.go | 4 +- x/stablecoin/keeper/collateral_ratio_test.go | 42 +++++++------- x/stablecoin/keeper/mint_burn_stable_test.go | 30 +++++----- x/stablecoin/keeper/params_test.go | 7 +-- x/stablecoin/keeper/supply_test.go | 20 +++---- x/stablecoin/types/params.go | 18 +++--- x/testutil/cli/tx.go | 2 +- x/testutil/sample.go | 20 ------- x/util/keeper/query_server_test.go | 5 +- x/vpool/client/cli/cli_test.go | 10 ++-- x/vpool/genesis_test.go | 8 +-- x/vpool/keeper/keeper_test.go | 58 +++++++++---------- x/vpool/keeper/pool_state_test.go | 28 ++++----- x/vpool/keeper/query_server_test.go | 6 +- x/vpool/types/gov_test.go | 4 +- x/vpool/types/pool_test.go | 58 +++++++++---------- x/wasm/cli/cli_test.go | 4 +- 45 files changed, 283 insertions(+), 320 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a580a550..d6c364d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#1080](https://github.com/NibiruChain/nibiru/pull/1080) - feat(perp): Add exchanged notional to the position changed event #1080 * [#1082](https://github.com/NibiruChain/nibiru/pull/1082) - feat(localnet.sh): Set genesis prices based on real BTC and ETH prices * [#1086](https://github.com/NibiruChain/nibiru/pull/1086) - refactor(perp)!: Removed unused field, `LiquidationPenalty`, from `PositionChangedEvent` -* [#1091](https://github.com/NibiruChain/nibiru/pull/1091) - refactor: Use common.Precision instead of 1_000_000 in the codebase ## v0.15.0 diff --git a/app/antedecorators/gasless/gasless_test.go b/app/antedecorators/gasless/gasless_test.go index ab485dc52..d9e295443 100644 --- a/app/antedecorators/gasless/gasless_test.go +++ b/app/antedecorators/gasless/gasless_test.go @@ -10,7 +10,6 @@ import ( gaslessante "github.com/NibiruChain/nibiru/app/antedecorators/gasless" types2 "github.com/NibiruChain/nibiru/app/antedecorators/types" "github.com/NibiruChain/nibiru/simapp" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/pricefeed/types" "github.com/NibiruChain/nibiru/x/testutil" ) @@ -114,7 +113,7 @@ func TestGaslessDecorator_Whitelisted(t *testing.T) { tc := tc t.Run(tc.name, func(t *testing.T) { app, ctx := simapp.NewTestNibiruAppAndContext(true) - ctx = ctx.WithGasMeter(sdk.NewGasMeter(uint64(10 * common.Precision))) + ctx = ctx.WithGasMeter(sdk.NewGasMeter(10000000)) if tc.isWhitelisted { // If we whitelist, the gas meter changes. diff --git a/scripts/testing/stableswap_model.py b/scripts/testing/stableswap_model.py index e903a0c84..e0f1e77e3 100644 --- a/scripts/testing/stableswap_model.py +++ b/scripts/testing/stableswap_model.py @@ -6,7 +6,7 @@ The curve class comes directly from the curve codebase, and is being used to create the tests, stored in `x/dex/types/misc/stabletests.csv`;. Theses test are then used to compare the value of python model's DY against the one obtained with our go code. -These are created for pools with random amount of assets (from 2 to 5), random amplification parameter (from 1 to 4* common.Precision) and for random coins of the pool. +These are created for pools with random amount of assets (from 2 to 5), random amplification parameter (from 1 to 4_000_000) and for random coins of the pool. By computing this, we ensure the validity of our SolveConstantProductInvariant function. """ diff --git a/simapp/testapp.go b/simapp/testapp.go index 83f2fee73..db7affc3b 100644 --- a/simapp/testapp.go +++ b/simapp/testapp.go @@ -119,7 +119,7 @@ func NewTestGenesisState(codec codec.Codec, inGenState GenesisState, var govGenState govtypes.GenesisState codec.MustUnmarshalJSON(testGenState[govtypes.ModuleName], &govGenState) govGenState.VotingParams.VotingPeriod = time.Second * 20 - govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision)) // min deposit of 1 NIBI + govGenState.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1_000_000)) // min deposit of 1 NIBI testGenState[govtypes.ModuleName] = codec.MustMarshalJSON(&govGenState) // pricefeed genesis state diff --git a/x/common/common.go b/x/common/common.go index 529f5f738..532364989 100644 --- a/x/common/common.go +++ b/x/common/common.go @@ -34,9 +34,6 @@ var ( ErrInvalidTokenPair = sdkerrors.Register(ModuleName, 1, "invalid token pair") APrecision = uint256.NewInt().SetUint64(1) - - // Precision for int representation in sdk.Int objects - Precision = int64(1_000_000) ) //----------------------------------------------------------------------------- diff --git a/x/dex/keeper/keeper_test.go b/x/dex/keeper/keeper_test.go index ad59654fa..c669e1aff 100644 --- a/x/dex/keeper/keeper_test.go +++ b/x/dex/keeper/keeper_test.go @@ -218,7 +218,7 @@ func TestFetchPoolFromPair(t *testing.T) { func TestNewPool(t *testing.T) { app, ctx := testapp.NewTestNibiruAppAndContext(true) - poolCreationFeeCoin := sdk.NewInt64Coin(common.DenomNIBI, 1000*common.Precision) + poolCreationFeeCoin := sdk.NewInt64Coin(common.DenomNIBI, 1000_000_000) app.DexKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, /*poolCreationFee=*/ sdk.NewCoins(poolCreationFeeCoin), @@ -291,7 +291,7 @@ func TestNewPoolNotEnoughFunds(t *testing.T) { app.DexKeeper.SetParams(ctx, types.NewParams( /*startingPoolNumber=*/ 1, - /*poolCreationFee=*/ sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000*common.Precision)), + /*poolCreationFee=*/ sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000_000_000)), /*whitelistedAssets*/ []string{}, )) @@ -300,7 +300,7 @@ func TestNewPoolNotEnoughFunds(t *testing.T) { err := simapp.FundAccount(app.BankKeeper, ctx, userAddr, sdk.NewCoins( sdk.NewCoin("uatom", sdk.NewInt(1000)), sdk.NewCoin("uosmo", sdk.NewInt(1000)), - sdk.NewCoin("unibi", sdk.NewInt(999*common.Precision)), + sdk.NewCoin("unibi", sdk.NewInt(999_000_000)), )) require.NoError(t, err) diff --git a/x/dex/simulation/operations.go b/x/dex/simulation/operations.go index a414af78b..01765d2af 100644 --- a/x/dex/simulation/operations.go +++ b/x/dex/simulation/operations.go @@ -330,7 +330,7 @@ func genPoolAssets( // fundAccountWithTokens fund the account with some gov, coll and stable denom. // When simulation for stablecoin is done, we should consider only funding with stable. func fundAccountWithTokens(ctx sdk.Context, address sdk.AccAddress, bk types.BankKeeper) { - million := 1 * common.Precision + million := 1_000_000 newTokens := sdk.NewCoins( sdk.NewCoin(common.DenomNIBI, sdk.NewInt(int64(10*million))), sdk.NewCoin(common.DenomUSDC, sdk.NewInt(int64(10*million))), diff --git a/x/dex/types/params.go b/x/dex/types/params.go index ba2668875..81afbd2dd 100644 --- a/x/dex/types/params.go +++ b/x/dex/types/params.go @@ -30,7 +30,7 @@ func NewParams(startingPoolNumber uint64, poolCreationFee sdk.Coins, whitelisted func DefaultParams() Params { return Params{ StartingPoolNumber: 1, - PoolCreationFee: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000*common.Precision)), // 1000 NIBI + PoolCreationFee: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNIBI, 1000_000_000)), // 1000 NIBI WhitelistedAsset: []string{ common.DenomNIBI, common.DenomUSDC, diff --git a/x/dex/types/pool_asset_test.go b/x/dex/types/pool_asset_test.go index d940459d5..9b94c51f5 100644 --- a/x/dex/types/pool_asset_test.go +++ b/x/dex/types/pool_asset_test.go @@ -5,8 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - - "github.com/NibiruChain/nibiru/x/common" ) func TestPoolAssetValidateError(t *testing.T) { @@ -84,7 +82,7 @@ func TestSubtractPoolAssetBalance(t *testing.T) { pool: Pool{ PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 1*common.Precision), + Token: sdk.NewInt64Coin("aaa", 1_000_000), }, }, }, @@ -97,12 +95,12 @@ func TestSubtractPoolAssetBalance(t *testing.T) { pool: Pool{ PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 1*common.Precision), + Token: sdk.NewInt64Coin("aaa", 1_000_000), }, }, }, tokenDenom: "aaa", - subAmt: sdk.NewInt(1 * common.Precision), + subAmt: sdk.NewInt(1_000_000), expectedCoins: nil, }, } { diff --git a/x/dex/types/pool_test.go b/x/dex/types/pool_test.go index f636329f9..b6151fc52 100644 --- a/x/dex/types/pool_test.go +++ b/x/dex/types/pool_test.go @@ -8,7 +8,6 @@ import ( "strconv" "testing" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -228,7 +227,7 @@ func TestJoinPoolHappyPath(t *testing.T) { Token: sdk.NewInt64Coin("bbb", 1_403_945), }, }, - TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1*common.Precision), + TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1_000_000), PoolParams: PoolParams{A: sdk.NewInt(100), PoolType: PoolType_BALANCER}, }, tokensIn: sdk.NewCoins( @@ -263,7 +262,7 @@ func TestJoinPoolHappyPath(t *testing.T) { Token: sdk.NewInt64Coin("bbb", 1_403_945), }, }, - TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1*common.Precision), + TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1_000_000), PoolParams: PoolParams{A: sdk.NewInt(100), PoolType: PoolType_STABLESWAP}, }, tokensIn: sdk.NewCoins( @@ -399,7 +398,7 @@ func TestJoinPoolAllTokens(t *testing.T) { Weight: sdk.NewInt(1 << 30), }, }, - TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1*common.Precision), + TotalShares: sdk.NewInt64Coin("nibiru/pool/1", 1_000_000), TotalWeight: sdk.NewInt(2 << 30), PoolParams: PoolParams{PoolType: PoolType_BALANCER, SwapFee: sdk.ZeroDec()}, }, @@ -746,10 +745,10 @@ func TestGetD(t *testing.T) { name: "Compute D - 2 assets, A big, high values - tested against Curve contracts code..", poolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 200*common.Precision), + Token: sdk.NewInt64Coin("aaa", 200_000_000), }, { - Token: sdk.NewInt64Coin("bbb", 100*common.Precision), + Token: sdk.NewInt64Coin("bbb", 100_000_000), }, }, amplificationParameter: sdk.NewInt(4000), diff --git a/x/dex/types/price_test.go b/x/dex/types/price_test.go index beb965fec..be37b4de5 100644 --- a/x/dex/types/price_test.go +++ b/x/dex/types/price_test.go @@ -3,7 +3,6 @@ package types import ( "testing" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/testutil" sdk "github.com/cosmos/cosmos-sdk/types" @@ -20,11 +19,11 @@ func TestCalSpotPrice(t *testing.T) { "equal weight: 2 tokens", []PoolAsset{ { - Token: sdk.NewInt64Coin("foo", 2*common.Precision), + Token: sdk.NewInt64Coin("foo", 2_000_000), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin("bar", 1*common.Precision), + Token: sdk.NewInt64Coin("bar", 1_000_000), Weight: sdk.NewInt(100), }, }, @@ -34,11 +33,11 @@ func TestCalSpotPrice(t *testing.T) { "different weight: 2 tokens", []PoolAsset{ { - Token: sdk.NewInt64Coin("foo", 2*common.Precision), + Token: sdk.NewInt64Coin("foo", 2_000_000), Weight: sdk.NewInt(80), }, { - Token: sdk.NewInt64Coin("bar", 1*common.Precision), + Token: sdk.NewInt64Coin("bar", 1_000_000), Weight: sdk.NewInt(20), }, }, @@ -48,15 +47,15 @@ func TestCalSpotPrice(t *testing.T) { "equal weight: 3 tokens", []PoolAsset{ { - Token: sdk.NewInt64Coin("foo", 2*common.Precision), + Token: sdk.NewInt64Coin("foo", 2_000_000), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin("goo", 1*common.Precision), + Token: sdk.NewInt64Coin("goo", 1_000_000), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin("bar", 1*common.Precision), + Token: sdk.NewInt64Coin("bar", 1_000_000), Weight: sdk.NewInt(100), }, }, @@ -66,15 +65,15 @@ func TestCalSpotPrice(t *testing.T) { "different weight: 3 tokens", []PoolAsset{ { - Token: sdk.NewInt64Coin("foo", 2*common.Precision), + Token: sdk.NewInt64Coin("foo", 2_000_000), Weight: sdk.NewInt(60), }, { - Token: sdk.NewInt64Coin("bar", 1*common.Precision), + Token: sdk.NewInt64Coin("bar", 1_000_000), Weight: sdk.NewInt(20), }, { - Token: sdk.NewInt64Coin("foobar", 1*common.Precision), + Token: sdk.NewInt64Coin("foobar", 1_000_000), Weight: sdk.NewInt(20), }, }, diff --git a/x/dex/types/swap_test.go b/x/dex/types/swap_test.go index 825d93183..824bf3976 100644 --- a/x/dex/types/swap_test.go +++ b/x/dex/types/swap_test.go @@ -5,8 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - - "github.com/NibiruChain/nibiru/x/common" ) func TestCalcOutAmtGivenIn(t *testing.T) { @@ -50,11 +48,11 @@ func TestCalcOutAmtGivenIn(t *testing.T) { }, PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 100*common.Precision), + Token: sdk.NewInt64Coin("aaa", 100_000_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin("bbb", 100*common.Precision), + Token: sdk.NewInt64Coin("bbb", 100_000_000), Weight: sdk.OneInt(), }, }, @@ -73,11 +71,11 @@ func TestCalcOutAmtGivenIn(t *testing.T) { }, PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 1*common.Precision), + Token: sdk.NewInt64Coin("aaa", 1_000_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin("bbb", 1*common.Precision), + Token: sdk.NewInt64Coin("bbb", 1_000_000), Weight: sdk.OneInt(), }, }, @@ -188,11 +186,11 @@ func TestCalcInAmtGivenOut(t *testing.T) { }, PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 100*common.Precision), + Token: sdk.NewInt64Coin("aaa", 100_000_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin("bbb", 100*common.Precision), + Token: sdk.NewInt64Coin("bbb", 100_000_000), Weight: sdk.OneInt(), }, }, @@ -211,11 +209,11 @@ func TestCalcInAmtGivenOut(t *testing.T) { }, PoolAssets: []PoolAsset{ { - Token: sdk.NewInt64Coin("aaa", 1*common.Precision), + Token: sdk.NewInt64Coin("aaa", 1_000_000), Weight: sdk.OneInt(), }, { - Token: sdk.NewInt64Coin("bbb", 1*common.Precision), + Token: sdk.NewInt64Coin("bbb", 1_000_000), Weight: sdk.OneInt(), }, }, diff --git a/x/lockup/client/cli/cli_test.go b/x/lockup/client/cli/cli_test.go index 29f107651..01ad91fed 100644 --- a/x/lockup/client/cli/cli_test.go +++ b/x/lockup/client/cli/cli_test.go @@ -6,7 +6,6 @@ import ( "github.com/NibiruChain/nibiru/simapp" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/lockup/types" "github.com/cosmos/cosmos-sdk/crypto/hd" @@ -39,9 +38,9 @@ func (s *IntegrationTestSuite) SetupSuite() { app.SetPrefixes(app.AccountAddressPrefix) s.cfg = testutilcli.BuildNetworkConfig(simapp.NewTestGenesisStateFromDefault()) s.cfg.StartingTokens = sdk.NewCoins( - sdk.NewInt64Coin("ATOM", 1*common.Precision), - sdk.NewInt64Coin("OSMO", 1*common.Precision), - sdk.NewInt64Coin("unibi", 1_000*common.Precision)) + sdk.NewInt64Coin("ATOM", 1_000_000), + sdk.NewInt64Coin("OSMO", 1_000_000), + sdk.NewInt64Coin("unibi", 1_000_000_000)) s.network = testutilcli.NewNetwork(s.T(), s.cfg) _, err := s.network.WaitForHeight(1) @@ -61,7 +60,7 @@ func (s *IntegrationTestSuite) SetupSuite() { sdk.NewCoins( sdk.NewInt64Coin("ATOM", 20000), sdk.NewInt64Coin("OSMO", 20000), - sdk.NewInt64Coin("unibi", 1*common.Precision), + sdk.NewInt64Coin("unibi", 1_000_000), ), val, s.cfg.BondDenom, diff --git a/x/oracle/keeper/reward_test.go b/x/oracle/keeper/reward_test.go index a54a5858c..98ecae0e6 100644 --- a/x/oracle/keeper/reward_test.go +++ b/x/oracle/keeper/reward_test.go @@ -53,7 +53,7 @@ func TestKeeper_RewardsDistributionMultiVotePeriods(t *testing.T) { params := input.OracleKeeper.GetParams(input.Ctx) input.OracleKeeper.SetParams(input.Ctx, params) - rewards := sdk.NewInt64Coin("reward", 1*common.Precision) + rewards := sdk.NewInt64Coin("reward", 1_000_000) valPeriodicRewards := sdk.NewDecCoinsFromCoins(rewards). QuoDec(sdk.NewDec(int64(periods))). QuoDec(sdk.NewDec(int64(validators))) diff --git a/x/oracle/keeper/tally_fuzz_test.go b/x/oracle/keeper/tally_fuzz_test.go index 563cb1912..87a5cff68 100644 --- a/x/oracle/keeper/tally_fuzz_test.go +++ b/x/oracle/keeper/tally_fuzz_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/x/oracle/types" - "github.com/NibiruChain/nibiru/x/testutil" ) func TestFuzz_Tally(t *testing.T) { @@ -73,7 +72,7 @@ func TestFuzz_PickReferencePair(t *testing.T) { numPairs := c.Intn(100) + 5 for i := 0; i < numPairs; i++ { - *e = append(*e, testutil.RandStringBytes(5)) + *e = append(*e, c.RandString()) } }, func(e *sdk.Dec, c fuzz.Continue) { diff --git a/x/oracle/keeper/update_exchange_rates_test.go b/x/oracle/keeper/update_exchange_rates_test.go index e159ad5aa..c48623e8d 100644 --- a/x/oracle/keeper/update_exchange_rates_test.go +++ b/x/oracle/keeper/update_exchange_rates_test.go @@ -251,7 +251,7 @@ func TestOracleRewardDistribution(t *testing.T) { // Account 2, btcstable makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_BTC_NUSD.String(), ExchangeRate: randomExchangeRate}}, 1) - rewardAllocation := sdk.NewCoins(sdk.NewCoin("reward", sdk.NewInt(1*common.Precision))) + rewardAllocation := sdk.NewCoins(sdk.NewCoin("reward", sdk.NewInt(1_000_000))) keeper.AllocateRewards(t, input, common.Pair_BTC_NUSD.String(), rewardAllocation, 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) @@ -363,15 +363,15 @@ func TestOracleExchangeRate(t *testing.T) { // Account 3, govstable, btcstable makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD.String(), ExchangeRate: govStableExchangeRate}, {Pair: common.Pair_BTC_NUSD.String(), ExchangeRate: randomExchangeRate}}, 2) - ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) - govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) + ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1_000_000) + govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1_000_000) keeper.AllocateRewards(t, input, common.Pair_ETH_NUSD.String(), sdk.NewCoins(ethStableRewards), 1) keeper.AllocateRewards(t, input, common.Pair_NIBI_NUSD.String(), sdk.NewCoins(govStableRewards), 1) oracle.EndBlocker(input.Ctx.WithBlockHeight(1), input.OracleKeeper) - // total reward pool for the current vote period is 1* common.PrecisionETHSTABLE, 1* common.PrecisionGOVSTABLE + // total reward pool for the current vote period is 1_000_000ETHSTABLE, 1_000_000GOVSTABLE // val 1,2 won on 2 pairs // val 3 won on 1 pair // so total votes are 2 * 2 + 1 = 5 @@ -441,8 +441,8 @@ func TestOracleExchangeRateVal5(t *testing.T) { // Account 5, govstable, ethstable makeAggregatePrevoteAndVote(t, input, h, 0, types.ExchangeRateTuples{{Pair: common.Pair_NIBI_NUSD.String(), ExchangeRate: govStableRate2}, {Pair: common.Pair_ETH_NUSD.String(), ExchangeRate: ethStableRate2}}, 4) - ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1*common.Precision) - govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1*common.Precision) + ethStableRewards := sdk.NewInt64Coin("ETHSTABLE", 1_000_000) + govStableRewards := sdk.NewInt64Coin("GOVSTABLE", 1_000_000) keeper.AllocateRewards(t, input, common.Pair_ETH_NUSD.String(), sdk.NewCoins(ethStableRewards), 1) keeper.AllocateRewards(t, input, common.Pair_NIBI_NUSD.String(), sdk.NewCoins(govStableRewards), 1) diff --git a/x/perp/client/cli/cli_test.go b/x/perp/client/cli/cli_test.go index 4c0092669..6135bbb52 100644 --- a/x/perp/client/cli/cli_test.go +++ b/x/perp/client/cli/cli_test.go @@ -76,8 +76,8 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis.Vpools = []vpooltypes.Vpool{ { Pair: common.Pair_BTC_NUSD, - BaseAssetReserve: sdk.NewDec(10 * common.Precision), - QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), + BaseAssetReserve: sdk.NewDec(10_000_000), + QuoteAssetReserve: sdk.NewDec(60_000_000_000), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.8"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), @@ -88,8 +88,8 @@ func (s *IntegrationTestSuite) SetupSuite() { }, { Pair: common.Pair_ETH_NUSD, - BaseAssetReserve: sdk.NewDec(10 * common.Precision), - QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), + BaseAssetReserve: sdk.NewDec(10_000_000), + QuoteAssetReserve: sdk.NewDec(60_000_000_000), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.8"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), @@ -142,9 +142,9 @@ func (s *IntegrationTestSuite) SetupSuite() { s.NoError( testutilcli.FillWalletFromValidator(user1, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 10*common.Precision), - sdk.NewInt64Coin(common.DenomUSDC, 10*common.Precision), - sdk.NewInt64Coin(common.DenomNUSD, 50*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 10_000_000), + sdk.NewInt64Coin(common.DenomUSDC, 10_000_000), + sdk.NewInt64Coin(common.DenomNUSD, 50_000_000), ), val, common.DenomNIBI, @@ -168,7 +168,7 @@ func (s *IntegrationTestSuite) SetupSuite() { sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 1000), sdk.NewInt64Coin(common.DenomUSDC, 1000), - sdk.NewInt64Coin(common.DenomNUSD, 49*common.Precision), + sdk.NewInt64Coin(common.DenomNUSD, 49_000_000), ), val, common.DenomNIBI, @@ -209,8 +209,8 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { reserveAssets, err := testutilcli.QueryVpoolReserveAssets(val.ClientCtx, common.Pair_BTC_NUSD) s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) - s.EqualValues(sdk.NewDec(10*common.Precision), reserveAssets.BaseAssetReserve) - s.EqualValues(sdk.NewDec(60_000*common.Precision), reserveAssets.QuoteAssetReserve) + s.EqualValues(sdk.NewDec(10_000_000), reserveAssets.BaseAssetReserve) + s.EqualValues(sdk.NewDec(60_000_000_000), reserveAssets.QuoteAssetReserve) s.T().Log("A. check trader has no existing positions") _, err = testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) @@ -232,7 +232,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.T().Logf("reserve assets: %+v", reserveAssets) s.NoError(err) s.EqualValues(sdk.MustNewDecFromStr("9999833.336111064815586407"), reserveAssets.BaseAssetReserve) - s.EqualValues(sdk.NewDec(60_001*common.Precision), reserveAssets.QuoteAssetReserve) + s.EqualValues(sdk.NewDec(60_001_000_000), reserveAssets.QuoteAssetReserve) s.T().Log("B. check trader position") queryResp, err := testutilcli.QueryPosition(val.ClientCtx, common.Pair_BTC_NUSD, user) @@ -241,8 +241,8 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(user.String(), queryResp.Position.TraderAddress) s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("166.663888935184413593"), queryResp.Position.Size_) - s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.Margin) - s.EqualValues(sdk.NewDec(1*common.Precision), queryResp.Position.OpenNotional) + s.EqualValues(sdk.NewDec(1_000_000), queryResp.Position.Margin) + s.EqualValues(sdk.NewDec(1_000_000), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("999999.999999999999999359"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("-0.000000000000000641"), queryResp.UnrealizedPnl) s.EqualValues(sdk.NewDec(1), queryResp.MarginRatioMark) @@ -266,8 +266,8 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(user.String(), queryResp.Position.TraderAddress) s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.975001249937503125"), queryResp.Position.Size_) - s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) - s.EqualValues(sdk.NewDec(3*common.Precision), queryResp.Position.OpenNotional) + s.EqualValues(sdk.NewDec(2_000_000), queryResp.Position.Margin) + s.EqualValues(sdk.NewDec(3_000_000), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("3000000.000000000000000938"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("0.000000000000000938"), queryResp.UnrealizedPnl) s.EqualValues(sdk.MustNewDecFromStr("0.666666666666666667"), queryResp.MarginRatioMark) @@ -297,7 +297,7 @@ func (s *IntegrationTestSuite) TestOpenPositionsAndCloseCmd() { s.EqualValues(user.String(), queryResp.Position.TraderAddress) s.EqualValues(common.Pair_BTC_NUSD, queryResp.Position.Pair) s.EqualValues(sdk.MustNewDecFromStr("499.958336249784737846"), queryResp.Position.Size_) - s.EqualValues(sdk.NewDec(2*common.Precision), queryResp.Position.Margin) + s.EqualValues(sdk.NewDec(2_000_000), queryResp.Position.Margin) s.EqualValues(sdk.NewDec(2_999_900), queryResp.Position.OpenNotional) s.EqualValues(sdk.MustNewDecFromStr("2999899.999999999999999506"), queryResp.PositionNotional) s.EqualValues(sdk.MustNewDecFromStr("-0.000000000000000494"), queryResp.UnrealizedPnl) diff --git a/x/perp/keeper/calc_test.go b/x/perp/keeper/calc_test.go index 926195baf..042e7bbdd 100644 --- a/x/perp/keeper/calc_test.go +++ b/x/perp/keeper/calc_test.go @@ -48,8 +48,8 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - /* y */ sdk.NewDec(1*common.Precision), // - /* x */ sdk.NewDec(1*common.Precision), // + /* y */ sdk.NewDec(1_000_000), // + /* x */ sdk.NewDec(1_000_000), // vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("1.0"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -102,8 +102,8 @@ func TestCalcRemainMarginWithFundingPayment(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - /* y */ sdk.NewDec(1*common.Precision), // - /* x */ sdk.NewDec(1*common.Precision), // + /* y */ sdk.NewDec(1_000_000), // + /* x */ sdk.NewDec(1_000_000), // vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("1.0"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/perp/keeper/clearing_house_integration_test.go b/x/perp/keeper/clearing_house_integration_test.go index 608e4da5d..32a101430 100644 --- a/x/perp/keeper/clearing_house_integration_test.go +++ b/x/perp/keeper/clearing_house_integration_test.go @@ -133,7 +133,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new long position just under fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000_000)), initialPosition: nil, side: types.Side_BUY, margin: sdk.NewInt(47_619_047_619), @@ -239,7 +239,7 @@ func TestOpenPositionSuccess(t *testing.T) { }, { name: "new short position just under fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000_000)), initialPosition: nil, side: types.Side_SELL, margin: sdk.NewInt(47_619_047_619), @@ -274,8 +274,8 @@ func TestOpenPositionSuccess(t *testing.T) { nibiruApp.VpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteReserve */ sdk.NewDec(1*common.Precision*common.Precision), - /* baseReserve */ sdk.NewDec(1*common.Precision*common.Precision), + /* quoteReserve */ sdk.NewDec(1_000_000_000_000), + /* baseReserve */ sdk.NewDec(1_000_000_000_000), vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -471,44 +471,44 @@ func TestOpenPositionError(t *testing.T) { }, { name: "new long position over fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000_000)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_BUY, - margin: sdk.NewInt(100_000 * common.Precision), + margin: sdk.NewInt(100_000_000_000), leverage: sdk.OneDec(), baseLimit: sdk.ZeroDec(), expectedErr: vpooltypes.ErrOverFluctuationLimit, }, { name: "new short position over fluctuation limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000_000)), poolTradeLimitRatio: sdk.OneDec(), initialPosition: nil, side: types.Side_SELL, - margin: sdk.NewInt(100_000 * common.Precision), + margin: sdk.NewInt(100_000_000_000), leverage: sdk.OneDec(), baseLimit: sdk.ZeroDec(), expectedErr: vpooltypes.ErrOverFluctuationLimit, }, { name: "new long position over trade limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000_000_000)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_BUY, - margin: sdk.NewInt(100_000 * common.Precision), + margin: sdk.NewInt(100_000_000_000), leverage: sdk.OneDec(), baseLimit: sdk.ZeroDec(), expectedErr: vpooltypes.ErrOverTradingLimit, }, { name: "new short position over trade limit", - traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000*common.Precision)), + traderFunds: sdk.NewCoins(sdk.NewInt64Coin(common.DenomNUSD, 10_000_000_000)), poolTradeLimitRatio: sdk.MustNewDecFromStr("0.01"), initialPosition: nil, side: types.Side_SELL, - margin: sdk.NewInt(100_000 * common.Precision), + margin: sdk.NewInt(100_000_000_000), leverage: sdk.OneDec(), baseLimit: sdk.ZeroDec(), expectedErr: vpooltypes.ErrOverTradingLimit, @@ -534,8 +534,8 @@ func TestOpenPositionError(t *testing.T) { common.Pair_BTC_NUSD, /* tradeLimitRatio */ /* quoteReserve */ - sdk.NewDec(1*common.Precision*common.Precision), - /* baseReserve */ sdk.NewDec(1*common.Precision*common.Precision), + sdk.NewDec(1_000_000_000_000), + /* baseReserve */ sdk.NewDec(1_000_000_000_000), vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -603,8 +603,8 @@ func TestOpenPositionInvalidPair(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - sdk.NewDec(10*common.Precision), // - sdk.NewDec(5*common.Precision), // 5 tokens + sdk.NewDec(10_000_000), // + sdk.NewDec(5_000_000), // 5 tokens vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/perp/keeper/clearing_house_unit_test.go b/x/perp/keeper/clearing_house_unit_test.go index e36e7edf2..f92ea1091 100644 --- a/x/perp/keeper/clearing_house_unit_test.go +++ b/x/perp/keeper/clearing_house_unit_test.go @@ -1887,7 +1887,7 @@ func TestClosePosition(t *testing.T) { ).Return(nil) mocks.mockBankKeeper.EXPECT().GetBalance(ctx, sdk.AccAddress{0x1, 0x2, 0x3}, tc.initialPosition.Pair.QuoteDenom()). - Return(sdk.NewCoin("NUSD", sdk.NewInt(100000*common.Precision))) + Return(sdk.NewCoin("NUSD", sdk.NewInt(100000000000))) mocks.mockAccountKeeper.EXPECT().GetModuleAddress(types.VaultModuleAccount). Return(sdk.AccAddress{0x1, 0x2, 0x3}) diff --git a/x/perp/keeper/grpc_query_test.go b/x/perp/keeper/grpc_query_test.go index 5afc42c4e..fb06ed219 100644 --- a/x/perp/keeper/grpc_query_test.go +++ b/x/perp/keeper/grpc_query_test.go @@ -40,7 +40,7 @@ func TestQueryPosition(t *testing.T) { BlockNumber: 1, LatestCumulativePremiumFraction: sdk.ZeroDec(), }, - quoteAssetReserve: sdk.NewDec(1 * common.Precision), + quoteAssetReserve: sdk.NewDec(1_000_000), baseAssetReserve: sdk.NewDec(500_000), expectedPositionNotional: sdk.MustNewDecFromStr("19.999600007999840003"), @@ -57,8 +57,8 @@ func TestQueryPosition(t *testing.T) { BlockNumber: 1, LatestCumulativePremiumFraction: sdk.ZeroDec(), }, - quoteAssetReserve: sdk.NewDec(1 * common.Precision), - baseAssetReserve: sdk.NewDec(1 * common.Precision), + quoteAssetReserve: sdk.NewDec(1_000_000), + baseAssetReserve: sdk.NewDec(1_000_000), expectedPositionNotional: sdk.MustNewDecFromStr("9.99990000099999"), expectedUnrealizedPnl: sdk.MustNewDecFromStr("-0.00009999900001"), @@ -75,7 +75,7 @@ func TestQueryPosition(t *testing.T) { LatestCumulativePremiumFraction: sdk.ZeroDec(), }, quoteAssetReserve: sdk.NewDec(500_000), - baseAssetReserve: sdk.NewDec(1 * common.Precision), + baseAssetReserve: sdk.NewDec(1_000_000), expectedPositionNotional: sdk.MustNewDecFromStr("4.999950000499995"), expectedUnrealizedPnl: sdk.MustNewDecFromStr("-5.000049999500005"), diff --git a/x/perp/keeper/liquidate_test.go b/x/perp/keeper/liquidate_test.go index e5b04eb54..a7b19c828 100644 --- a/x/perp/keeper/liquidate_test.go +++ b/x/perp/keeper/liquidate_test.go @@ -54,7 +54,7 @@ func TestExecuteFullLiquidation(t *testing.T) { // = positionResp.ExchangedNotionalValue * liquidationFee / 2 // = 50_000 * 0.1 / 2 = 2500 expectedLiquidatorBalance: sdk.NewInt64Coin("NUSD", 2_500), - // startingBalance = 1* common.Precision + // startingBalance = 1_000_000 // perpEFBalance = startingBalance + openPositionDelta + liquidateDelta expectedPerpEFBalance: sdk.NewInt64Coin("NUSD", 1_047_550), }, @@ -72,7 +72,7 @@ func TestExecuteFullLiquidation(t *testing.T) { // = positionResp.ExchangedNotionalValue * liquidationFee / 2 // = 50_000 * 0.123123 / 2 = 3078.025 → 3078 expectedLiquidatorBalance: sdk.NewInt64Coin("NUSD", 3078), - // startingBalance = 1* common.Precision + // startingBalance = 1_000_000 // perpEFBalance = startingBalance + openPositionDelta + liquidateDelta expectedPerpEFBalance: sdk.NewInt64Coin("NUSD", 1_046_972), }, @@ -90,8 +90,8 @@ func TestExecuteFullLiquidation(t *testing.T) { vpoolKeeper.CreatePool( ctx, tokenPair, - /* quoteAssetReserves */ sdk.NewDec(10*common.Precision), - /* baseAssetReserves */ sdk.NewDec(5*common.Precision), + /* quoteAssetReserves */ sdk.NewDec(10_000_000), + /* baseAssetReserves */ sdk.NewDec(5_000_000), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.OneDec(), @@ -136,7 +136,7 @@ func TestExecuteFullLiquidation(t *testing.T) { t.Log("Artificially populate Vault and PerpEF to prevent bankKeeper errors") startingModuleFunds := sdk.NewCoins(sdk.NewInt64Coin( - tokenPair.QuoteDenom(), 1*common.Precision)) + tokenPair.QuoteDenom(), 1_000_000)) assert.NoError(t, simapp.FundModuleAccount( nibiruApp.BankKeeper, ctx, types.VaultModuleAccount, startingModuleFunds)) assert.NoError(t, simapp.FundModuleAccount( @@ -226,7 +226,7 @@ func TestExecutePartialLiquidation(t *testing.T) { // = 50_000 * 0.4 * 0.1 / 2 = 1_000 expectedLiquidatorBalance: sdk.NewInt64Coin("yyy", 1_000), - // startingBalance = 1* common.Precision + // startingBalance = 1_000_000 // perpEFBalance = startingBalance + openPositionDelta + liquidateDelta expectedPerpEFBalance: sdk.NewInt64Coin("yyy", 1_001_050), }, @@ -250,7 +250,7 @@ func TestExecutePartialLiquidation(t *testing.T) { // = 50_000 * 0.4 * 0.1 / 2 = 1_000 expectedLiquidatorBalance: sdk.NewInt64Coin("yyy", 1_000), - // startingBalance = 1* common.Precision + // startingBalance = 1_000_000 // perpEFBalance = startingBalance + openPositionDelta + liquidateDelta expectedPerpEFBalance: sdk.NewInt64Coin("yyy", 1_001_050), }, @@ -267,8 +267,8 @@ func TestExecutePartialLiquidation(t *testing.T) { vpoolKeeper.CreatePool( ctx, tokenPair, - /* quoteAssetReserves */ sdk.NewDec(10_000*common.Precision*common.Precision), - /* baseAssetReserves */ sdk.NewDec(5_000*common.Precision*common.Precision), + /* quoteAssetReserves */ sdk.NewDec(10_000_000_000_000_000), + /* baseAssetReserves */ sdk.NewDec(5_000_000_000_000_000), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.OneDec(), @@ -316,7 +316,7 @@ func TestExecutePartialLiquidation(t *testing.T) { t.Log("Artificially populate Vault and PerpEF to prevent bankKeeper errors") startingModuleFunds := sdk.NewCoins(sdk.NewInt64Coin( - tokenPair.QuoteDenom(), 1*common.Precision)) + tokenPair.QuoteDenom(), 1_000_000)) assert.NoError(t, simapp.FundModuleAccount( nibiruApp.BankKeeper, ctx, types.VaultModuleAccount, startingModuleFunds)) assert.NoError(t, simapp.FundModuleAccount( diff --git a/x/perp/keeper/margin_test.go b/x/perp/keeper/margin_test.go index 094107128..b3802e090 100644 --- a/x/perp/keeper/margin_test.go +++ b/x/perp/keeper/margin_test.go @@ -68,8 +68,8 @@ func TestAddMarginSuccess(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - sdk.NewDec(10*common.Precision), // 10 tokens - sdk.NewDec(5*common.Precision), // 5 tokens + sdk.NewDec(10_000_000), // 10 tokens + sdk.NewDec(5_000_000), // 5 tokens vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), // 0.1 ratio @@ -140,8 +140,8 @@ func TestRemoveMargin(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - /* y */ sdk.NewDec(1*common.Precision), // - /* x */ sdk.NewDec(1*common.Precision), // + /* y */ sdk.NewDec(1_000_000), // + /* x */ sdk.NewDec(1_000_000), // vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.OneDec(), @@ -169,8 +169,8 @@ func TestRemoveMargin(t *testing.T) { t.Log("Set vpool defined by pair on VpoolKeeper") vpoolKeeper := &nibiruApp.VpoolKeeper - quoteReserves := sdk.NewDec(1 * common.Precision) - baseReserves := sdk.NewDec(1 * common.Precision) + quoteReserves := sdk.NewDec(1_000_000) + baseReserves := sdk.NewDec(1_000_000) vpoolKeeper.CreatePool( ctx, pair, diff --git a/x/perp/keeper/msg_server_test.go b/x/perp/keeper/msg_server_test.go index bc1d2ce49..7e22ed8a1 100644 --- a/x/perp/keeper/msg_server_test.go +++ b/x/perp/keeper/msg_server_test.go @@ -79,8 +79,8 @@ func TestMsgServerAddMargin(t *testing.T) { app.VpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteReserve */ sdk.NewDec(1*common.Precision), - /* baseReserve */ sdk.NewDec(1*common.Precision), + /* quoteReserve */ sdk.NewDec(1_000_000), + /* baseReserve */ sdk.NewDec(1_000_000), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -165,7 +165,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { initialPosition: &types.Position{ Pair: common.Pair_BTC_NUSD, Size_: sdk.OneDec(), - Margin: sdk.NewDec(1 * common.Precision), + Margin: sdk.NewDec(1_000_000), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, @@ -179,7 +179,7 @@ func TestMsgServerRemoveMargin(t *testing.T) { initialPosition: &types.Position{ Pair: common.Pair_BTC_NUSD, Size_: sdk.OneDec(), - Margin: sdk.NewDec(1 * common.Precision), + Margin: sdk.NewDec(1_000_000), OpenNotional: sdk.OneDec(), LatestCumulativePremiumFraction: sdk.ZeroDec(), BlockNumber: 1, @@ -200,8 +200,8 @@ func TestMsgServerRemoveMargin(t *testing.T) { app.VpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteReserve */ sdk.NewDec(1*common.Precision), - /* baseReserve */ sdk.NewDec(1*common.Precision), + /* quoteReserve */ sdk.NewDec(1_000_000), + /* baseReserve */ sdk.NewDec(1_000_000), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -289,8 +289,8 @@ func TestMsgServerOpenPosition(t *testing.T) { app.VpoolKeeper.CreatePool( /* ctx */ ctx, /* pair */ common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), - /* baseAssetReserve */ sdk.NewDec(1*common.Precision), + /* quoteAssetReserve */ sdk.NewDec(1_000_000), + /* baseAssetReserve */ sdk.NewDec(1_000_000), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -376,8 +376,8 @@ func TestMsgServerClosePosition(t *testing.T) { app.VpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), - /* baseAssetReserve */ sdk.NewDec(1*common.Precision), + /* quoteAssetReserve */ sdk.NewDec(1_000_000), + /* baseAssetReserve */ sdk.NewDec(1_000_000), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -455,8 +455,8 @@ func TestMsgServerLiquidate(t *testing.T) { app.VpoolKeeper.CreatePool( /* ctx */ ctx, /* pair */ common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), - /* baseAssetReserve */ sdk.NewDec(1*common.Precision), + /* quoteAssetReserve */ sdk.NewDec(1_000_000), + /* baseAssetReserve */ sdk.NewDec(1_000_000), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -532,8 +532,8 @@ func TestMsgServerMultiLiquidate(t *testing.T) { app.VpoolKeeper.CreatePool( /* ctx */ ctx, /* pair */ pair, - /* quoteAssetReserve */ sdk.NewDec(1*common.Precision), - /* baseAssetReserve */ sdk.NewDec(1*common.Precision), + /* quoteAssetReserve */ sdk.NewDec(1_000_000), + /* baseAssetReserve */ sdk.NewDec(1_000_000), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), diff --git a/x/perp/keeper/perp_test.go b/x/perp/keeper/perp_test.go index f420a3996..766567318 100644 --- a/x/perp/keeper/perp_test.go +++ b/x/perp/keeper/perp_test.go @@ -30,8 +30,8 @@ func TestKeeperClosePosition(t *testing.T) { vpoolKeeper.CreatePool( ctx, pair, - /*quoteAssetReserve*/ sdk.NewDec(10*common.Precision), - /*baseAssetReserve*/ sdk.NewDec(5*common.Precision), + /*quoteAssetReserve*/ sdk.NewDec(10_000_000), + /*baseAssetReserve*/ sdk.NewDec(5_000_000), vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), diff --git a/x/pricefeed/abci_test.go b/x/pricefeed/abci_test.go index 5fa50507d..f9f04b6d0 100644 --- a/x/pricefeed/abci_test.go +++ b/x/pricefeed/abci_test.go @@ -64,9 +64,9 @@ func TestTWAPriceUpdates(t *testing.T) { New price should be. deltaT1: 10minutes / 600_000 - deltaT2: 5000hours / 18_000 * common.Precision + deltaT2: 5000hours / 18_000_000_000 - (0.8 * 600_000 + 0.9 * 18_000 * common.Precision) / 18_000_600_000 = 0.899996666777774074 + (0.8 * 600_000 + 0.9 * 18_000_000_000) / 18_000_600_000 = 0.899996666777774074 */ ctx = ctx.WithBlockTime(ctx.BlockTime().Add(10 * time.Minute)) @@ -89,7 +89,7 @@ func TestTWAPriceUpdates(t *testing.T) { deltaT2: 5000h + 10min / 18_000_600_000 deltaT3: 5000h + 10min / 18_000_600_000 - (0.82 * 600_000 + 0.8 * 18_000_600_000 + 0.9 * 18_000 * common.Precision) / 36_001_200_000 = 0.849998666711109629 + (0.82 * 600_000 + 0.8 * 18_000_600_000 + 0.9 * 18_000_000_000) / 36_001_200_000 = 0.849998666711109629 */ ctx = ctx.WithBlockTime(ctx.BlockTime().Add(10 * time.Minute)) price, err = nibiruApp.PricefeedKeeper.GetCurrentTWAP( @@ -108,7 +108,7 @@ func TestTWAPriceUpdates(t *testing.T) { deltaT3: 5000h + 10min/ 18_000_600_000 deltaT4: 5000h + 10min/ 18_000_600_000 - (0.83 * 600_000 + 0.82 * 18_000_600_000 + 0.8 * 18_000_600_000 + 0.9 * 18_000 * common.Precision) / 54_001_800_000 = 0.839999222248147283 + (0.83 * 600_000 + 0.82 * 18_000_600_000 + 0.8 * 18_000_600_000 + 0.9 * 18_000_000_000) / 54_001_800_000 = 0.839999222248147283 */ setPrice("0.83") runBlock(time.Hour * 5000) @@ -129,7 +129,7 @@ func TestTWAPriceUpdates(t *testing.T) { deltaT2: 5000h + 10min / 18_000_600_000 deltaT4: 2000h - 20min / 7_198_800_000 - (0.83 * 600_000 + 0.82 * 18_000_600_000 + 0.8 * 7_198_800_000) / 25_200* common.Precision = 0.839999222248147283 + (0.83 * 600_000 + 0.82 * 18_000_600_000 + 0.8 * 7_198_800_000) / 25_200_000_000 = 0.839999222248147283 */ setLookbackWindow(ctx, nibiruApp.PricefeedKeeper, 7_000*time.Hour) price, err = nibiruApp.PricefeedKeeper.GetCurrentTWAP( diff --git a/x/pricefeed/client/cli/cli_test.go b/x/pricefeed/client/cli/cli_test.go index da158c956..4b21436c4 100644 --- a/x/pricefeed/client/cli/cli_test.go +++ b/x/pricefeed/client/cli/cli_test.go @@ -475,7 +475,7 @@ func (s IntegrationTestSuite) TestX_AddOracleProposalAndVote() { clientCtx := val.ClientCtx.WithOutputFormat("json") s.T().Log("Fill oracle wallet to pay gas on post price") - gasTokens := sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 100*common.Precision)) + gasTokens := sdk.NewCoins(sdk.NewInt64Coin(s.cfg.BondDenom, 100_000_000)) oracle := testutilcli.NewAccount(s.network, "delphi-oracle") s.NoError(testutilcli.FillWalletFromValidator(oracle, gasTokens, val, s.cfg.BondDenom)) diff --git a/x/stablecoin/client/cli/cli_test.go b/x/stablecoin/client/cli/cli_test.go index 8e257706f..10ce402be 100644 --- a/x/stablecoin/client/cli/cli_test.go +++ b/x/stablecoin/client/cli/cli_test.go @@ -76,7 +76,7 @@ func (s *IntegrationTestSuite) SetupSuite() { // x/stablecoin genesis state stableGen := stabletypes.DefaultGenesis() stableGen.Params.IsCollateralRatioValid = true - stableGen.ModuleAccountBalance = sdk.NewCoin(common.DenomUSDC, sdk.NewInt(10000*common.Precision)) + stableGen.ModuleAccountBalance = sdk.NewCoin(common.DenomUSDC, sdk.NewInt(10000000000)) genesisState[stabletypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(stableGen) genesisState[pftypes.ModuleName] = encodingConfig.Marshaler.MustMarshalJSON(NewPricefeedGen()) @@ -100,8 +100,8 @@ func (s IntegrationTestSuite) TestMintStableCmd() { s.NoError(testutilcli.FillWalletFromValidator( minter, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 100*common.Precision), - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 100_000_000), + sdk.NewInt64Coin(common.DenomUSDC, 100_000_000), ), val, s.cfg.BondDenom, @@ -127,7 +127,7 @@ func (s IntegrationTestSuite) TestMintStableCmd() { args: append([]string{ "1000000unusd", fmt.Sprintf("--%s=%s", flags.FlagFrom, "minter2")}, commonArgs...), - expectedStable: sdk.NewInt(1 * common.Precision), + expectedStable: sdk.NewInt(1000000), expectErr: false, respType: &sdk.TxResponse{}, expectedCode: 0, @@ -175,7 +175,7 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { burner, sdk.NewCoins( sdk.NewInt64Coin(s.cfg.BondDenom, 20_000), - sdk.NewInt64Coin(common.DenomNUSD, 50*common.Precision), + sdk.NewInt64Coin(common.DenomNUSD, 50_000_000), ), val, s.cfg.BondDenom, @@ -209,7 +209,7 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { "50000000unusd", fmt.Sprintf("--%s=%s", flags.FlagFrom, "burn")}, commonArgs...), expectedStable: sdk.ZeroInt(), - expectedColl: sdk.NewInt(50*common.Precision - 100_000), // Collateral minus 0,02% fees + expectedColl: sdk.NewInt(50_000_000 - 100_000), // Collateral minus 0,02% fees expectedGov: sdk.NewInt(19_990), expectedTreasury: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 50_000)), expectedEf: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 50_000)), @@ -223,8 +223,8 @@ func (s IntegrationTestSuite) TestBurnStableCmd() { // "100000000unusd", // fmt.Sprintf("--%s=%s", flags.FlagFrom, "burn")}, commonArgs...), // expectedStable: sdk.NewInt(0), - // expectedColl: sdk.NewInt(90* common.Precision), - // expectedGov: sdk.NewInt(1* common.Precision), + // expectedColl: sdk.NewInt(90_000_000), + // expectedGov: sdk.NewInt(1_000_000), // expectErr: false, // respType: &sdk.TxResponse{}, // expectedCode: 0, diff --git a/x/stablecoin/keeper/collateral_ratio.go b/x/stablecoin/keeper/collateral_ratio.go index e4583875e..d6f2cea6e 100644 --- a/x/stablecoin/keeper/collateral_ratio.go +++ b/x/stablecoin/keeper/collateral_ratio.go @@ -22,7 +22,7 @@ stablecoin mints and burns. // GetCollRatio queries the 'collRatio'. func (k *Keeper) GetCollRatio(ctx sdk.Context) (collRatio sdk.Dec) { - return sdk.NewDec(k.GetParams(ctx).CollRatio).QuoInt64(1 * common.Precision) + return sdk.NewDec(k.GetParams(ctx).CollRatio).QuoInt64(1_000_000) } /* @@ -40,7 +40,7 @@ func (k *Keeper) SetCollRatio(ctx sdk.Context, collRatio sdk.Dec) (err error) { } params := k.GetParams(ctx) - million := sdk.NewDec(1 * common.Precision) + million := sdk.NewDec(1_000_000) collRatioInt := collRatio.Mul(million).RoundInt().Int64() params.CollRatio = collRatioInt diff --git a/x/stablecoin/keeper/collateral_ratio_test.go b/x/stablecoin/keeper/collateral_ratio_test.go index 712c28b2f..89b4e57be 100644 --- a/x/stablecoin/keeper/collateral_ratio_test.go +++ b/x/stablecoin/keeper/collateral_ratio_test.go @@ -613,13 +613,13 @@ func TestRecollateralize(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (500e3 *1) = 100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1_000*common.Precision), + sdk.NewInt64Coin(common.DenomUSDC, 1_000_000_000), ), expectedNeededUSD: sdk.NewDec(100_000), @@ -646,13 +646,13 @@ func TestRecollateralize(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(500_000), priceCollStable: sdk.MustNewDecFromStr("1.099999"), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.7"), // neededUSD = (0.7 * 1000e3) - (500e3 *1.09999) = 150_000.5 }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1_000*common.Precision), + sdk.NewInt64Coin(common.DenomUSDC, 1_000_000_000), ), expectedNeededUSD: sdk.MustNewDecFromStr("150000.5"), @@ -688,7 +688,7 @@ func TestRecollateralize(t *testing.T) { }, expectedNeededUSD: sdk.MustNewDecFromStr("-49.9995"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 1*common.Precision), + sdk.NewInt64Coin(common.DenomUSDC, 1_000_000), ), // Since 'neededUSD' is @@ -969,13 +969,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), ), expectedAccFundsAfter: sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 900_000), // accFunds - inGov.Amount @@ -1005,13 +1005,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(850_000), priceCollStable: sdk.MustNewDecFromStr("1.099999"), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.7"), // neededUSD = (0.7 * 1000e3) - (850e3 *1.09999) = -234999.15 }, priceGovStable: sdk.NewDec(5), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), ), expectedAccFundsAfter: sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 953_000), // accFunds - inGov.Amount @@ -1046,13 +1046,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), ), expectedAccFundsAfter: sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 900_000), // accFunds - inGov.Amount @@ -1079,13 +1079,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.8"), // neededUSD = (0.8 * 1000e3) - (700e3 *1) = 100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 1_000_000_000), ), expectedNeededUSD: sdk.NewDec(100_000), @@ -1105,7 +1105,7 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, @@ -1130,13 +1130,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 1_000_000_000), ), expectedNeededUSD: sdk.NewDec(-100_000), @@ -1155,13 +1155,13 @@ func TestBuyback(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, priceGovStable: sdk.OneDec(), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1_000*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 1_000_000_000), ), expectedNeededUSD: sdk.NewDec(-100_000), @@ -1274,7 +1274,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, @@ -1288,7 +1288,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, @@ -1304,7 +1304,7 @@ func TestBuybackGovAmtForTargetCollRatio(t *testing.T) { scenario: NeededCollScenario{ protocolColl: sdk.NewInt(700_000), priceCollStable: sdk.OneDec(), - stableSupply: sdk.NewInt(1 * common.Precision), + stableSupply: sdk.NewInt(1_000_000), collRatio: sdk.MustNewDecFromStr("0.6"), // neededUSD = (0.6 * 1000e3) - (700e3 *1) = -100_000 }, diff --git a/x/stablecoin/keeper/mint_burn_stable_test.go b/x/stablecoin/keeper/mint_burn_stable_test.go index 0fc575478..3a2921341 100644 --- a/x/stablecoin/keeper/mint_burn_stable_test.go +++ b/x/stablecoin/keeper/mint_burn_stable_test.go @@ -83,7 +83,7 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { accFunds: accFundsAmt, msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), + Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000)), }, govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), @@ -95,10 +95,10 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { accFunds: accFundsAmt, msgMint: types.MsgMintStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), + Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000)), }, msgResponse: types.MsgMintStableResponse{ - Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), + Stable: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000)), UsedCoins: sdk.NewCoins(accFundsCollAmount, accFundsGovAmount), FeesPayed: sdk.NewCoins(neededCollFees, neededGovFees), }, @@ -106,7 +106,7 @@ func TestMsgMintStableResponse_HappyPath(t *testing.T) { collPrice: sdk.MustNewDecFromStr("1"), supplyNIBI: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(10)), // 10_000 - 20 (neededAmt - fees) - 10 (0.5 of fees from EFund are burned) - supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1*common.Precision)), + supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000)), err: nil, isCollateralRatioValid: true, }, @@ -437,10 +437,10 @@ func TestMsgBurnResponse_NotEnoughFunds(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1000*common.Precision), + sdk.NewInt64Coin(common.DenomNUSD, 1000000000), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(common.DenomUSDC, 100000000), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), @@ -557,14 +557,14 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1_000*common.Precision), + sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(common.DenomUSDC, 100_000_000), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 10*common.Precision), + Stable: sdk.NewInt64Coin(common.DenomNUSD, 10_000_000), }, ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000)), treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000), sdk.NewInt64Coin(common.DenomNIBI, 100)), @@ -577,25 +577,25 @@ func TestMsgBurnResponse_HappyPath(t *testing.T) { govPrice: sdk.MustNewDecFromStr("10"), collPrice: sdk.MustNewDecFromStr("1"), accFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1_000*common.Precision), + sdk.NewInt64Coin(common.DenomNUSD, 1_000_000_000), ), moduleFunds: sdk.NewCoins( - sdk.NewInt64Coin(common.DenomUSDC, 100*common.Precision), + sdk.NewInt64Coin(common.DenomUSDC, 100_000_000), ), msgBurn: types.MsgBurnStable{ Creator: testutil.AccAddress().String(), - Stable: sdk.NewInt64Coin(common.DenomNUSD, 10*common.Precision), + Stable: sdk.NewInt64Coin(common.DenomNUSD, 10_000_000), }, msgResponse: types.MsgBurnStableResponse{ - Gov: sdk.NewInt64Coin(common.DenomNIBI, 100_000-200), // amount - fees 0,02% - Collateral: sdk.NewInt64Coin(common.DenomUSDC, 9*common.Precision-18_000), // amount - fees 0,02% + Gov: sdk.NewInt64Coin(common.DenomNIBI, 100_000-200), // amount - fees 0,02% + Collateral: sdk.NewInt64Coin(common.DenomUSDC, 9_000_000-18_000), // amount - fees 0,02% FeesPayed: sdk.NewCoins( sdk.NewInt64Coin(common.DenomNIBI, 200), sdk.NewInt64Coin(common.DenomUSDC, 18_000), ), }, supplyNIBI: sdk.NewCoin(common.DenomNIBI, sdk.NewInt(100_000-100)), // nibiru minus 0.5 of fees burned (the part that goes to EF) - supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000*common.Precision-10*common.Precision)), + supplyNUSD: sdk.NewCoin(common.DenomNUSD, sdk.NewInt(1_000_000_000-10_000_000)), ecosystemFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000)), treasuryFund: sdk.NewCoins(sdk.NewInt64Coin(common.DenomUSDC, 9000), sdk.NewInt64Coin(common.DenomNIBI, 100)), expectedPass: true, diff --git a/x/stablecoin/keeper/params_test.go b/x/stablecoin/keeper/params_test.go index b5b5e2d95..10e72b6da 100644 --- a/x/stablecoin/keeper/params_test.go +++ b/x/stablecoin/keeper/params_test.go @@ -9,7 +9,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/require" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/stablecoin/types" ) @@ -45,7 +44,7 @@ func TestNewParams_Errors(t *testing.T) { ), fmt.Errorf( "collateral ratio is above max value(1e6): %s", - sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1*common.Precision)).TruncateInt()), + sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1_000_000)).TruncateInt()), }, { "fee ratio bigger than 1", @@ -62,7 +61,7 @@ func TestNewParams_Errors(t *testing.T) { ), fmt.Errorf( "fee ratio is above max value(1e6): %s", - sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1*common.Precision)).TruncateInt()), + sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1_000_000)).TruncateInt()), }, { "stable EF fee ratio bigger than 1", @@ -79,7 +78,7 @@ func TestNewParams_Errors(t *testing.T) { ), fmt.Errorf( "stable EF fee ratio is above max value(1e6): %s", - sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1*common.Precision)).TruncateInt()), + sdk.MustNewDecFromStr("2").Mul(sdk.NewDec(1_000_000)).TruncateInt()), }, } diff --git a/x/stablecoin/keeper/supply_test.go b/x/stablecoin/keeper/supply_test.go index 4a77bd87a..8e6d9e2e2 100644 --- a/x/stablecoin/keeper/supply_test.go +++ b/x/stablecoin/keeper/supply_test.go @@ -22,14 +22,14 @@ func TestKeeper_GetStableMarketCap(t *testing.T) { // We set some supply err := k.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + sdk.NewInt64Coin(common.DenomNUSD, 1_000_000), )) require.NoError(t, err) // We set some supply marketCap := k.GetStableMarketCap(ctx) - require.Equal(t, sdk.NewInt(1*common.Precision), marketCap) + require.Equal(t, sdk.NewInt(1_000_000), marketCap) } func TestKeeper_GetGovMarketCap(t *testing.T) { @@ -44,11 +44,11 @@ func TestKeeper_GetGovMarketCap(t *testing.T) { } poolAssets := []dextypes.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNIBI, 2*common.Precision), + Token: sdk.NewInt64Coin(common.DenomNIBI, 2_000_000), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + Token: sdk.NewInt64Coin(common.DenomNUSD, 1_000_000), Weight: sdk.NewInt(100), }, } @@ -59,14 +59,14 @@ func TestKeeper_GetGovMarketCap(t *testing.T) { // We set some supply err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), )) require.NoError(t, err) marketCap, err := keeper.GetGovMarketCap(ctx) require.NoError(t, err) - require.Equal(t, sdk.NewInt(2*common.Precision), marketCap) // 1 * 10^6 * 2 (price of gov token) + require.Equal(t, sdk.NewInt(2_000_000), marketCap) // 1 * 10^6 * 2 (price of gov token) } func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { @@ -81,11 +81,11 @@ func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { } poolAssets := []dextypes.PoolAsset{ { - Token: sdk.NewInt64Coin(common.DenomNIBI, 2*common.Precision), + Token: sdk.NewInt64Coin(common.DenomNIBI, 2_000_000), Weight: sdk.NewInt(100), }, { - Token: sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + Token: sdk.NewInt64Coin(common.DenomNUSD, 1_000_000), Weight: sdk.NewInt(100), }, } @@ -96,12 +96,12 @@ func TestKeeper_GetLiquidityRatio_AndBands(t *testing.T) { // We set some supply err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNIBI, 1*common.Precision), + sdk.NewInt64Coin(common.DenomNIBI, 1_000_000), )) require.NoError(t, err) err = keeper.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins( - sdk.NewInt64Coin(common.DenomNUSD, 1*common.Precision), + sdk.NewInt64Coin(common.DenomNUSD, 1_000_000), )) require.NoError(t, err) diff --git a/x/stablecoin/types/params.go b/x/stablecoin/types/params.go index 3b3d90b75..b0c239ffd 100644 --- a/x/stablecoin/types/params.go +++ b/x/stablecoin/types/params.go @@ -5,8 +5,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" - - "github.com/NibiruChain/nibiru/x/common" ) var _ paramtypes.ParamSet = (*Params)(nil) @@ -28,7 +26,7 @@ func NewParams( priceUpperBound sdk.Dec, isCollateralRatioValid bool, ) Params { - million := sdk.NewDec(1 * common.Precision) + million := sdk.NewDec(1_000_000) collRatioInt := collRatio.Mul(million).RoundInt().Int64() feeRationInt := feeRatio.Mul(million).RoundInt().Int64() efFeeRatioInt := efFeeRatio.Mul(million).RoundInt().Int64() @@ -176,7 +174,7 @@ func validateCollRatio(i interface{}) error { return err } - if collRatio > 1*common.Precision { + if collRatio > 1_000_000 { return fmt.Errorf("collateral ratio is above max value(1e6): %d", collRatio) } else if collRatio < 0 { return fmt.Errorf("collateral Ratio is negative: %d", collRatio) @@ -199,7 +197,7 @@ func validateBonusRateRecoll(i interface{}) error { return err } - if bonusRateRecoll > 1*common.Precision { + if bonusRateRecoll > 1_000_000 { return fmt.Errorf("collateral Ratio is above max value(1e6): %d", bonusRateRecoll) } else if bonusRateRecoll < 0 { return fmt.Errorf("collateral Ratio is negative: %d", bonusRateRecoll) @@ -214,7 +212,7 @@ func validateFeeRatio(i interface{}) error { return err } - if feeRatio > 1*common.Precision { + if feeRatio > 1_000_000 { return fmt.Errorf("fee ratio is above max value(1e6): %d", feeRatio) } else if feeRatio < 0 { return fmt.Errorf("fee ratio is negative: %d", feeRatio) @@ -229,7 +227,7 @@ func validateEfFeeRatio(i interface{}) error { return err } - if efFeeRatio > 1*common.Precision { + if efFeeRatio > 1_000_000 { return fmt.Errorf("stable EF fee ratio is above max value(1e6): %d", efFeeRatio) } else if efFeeRatio < 0 { return fmt.Errorf("stable EF fee ratio is negative: %d", efFeeRatio) @@ -252,7 +250,7 @@ func validateAdjustmentStep(i interface{}) error { return err } - if adjustmentStep > 1*common.Precision { + if adjustmentStep > 1_000_000 { return fmt.Errorf("AdjustmentStep is above max value(1e6): %d", adjustmentStep) } else if adjustmentStep < 0 { return fmt.Errorf("AdjustmentStep is negative: %d", adjustmentStep) @@ -267,7 +265,7 @@ func validatePriceLowerBound(i interface{}) error { return err } - if priceLowerBound > 1*common.Precision { + if priceLowerBound > 1_000_000 { return fmt.Errorf("PriceLowerBound is above max value(1e6): %d", priceLowerBound) } else if priceLowerBound < 0 { return fmt.Errorf("PriceLowerBound is negative: %d", priceLowerBound) @@ -282,7 +280,7 @@ func validatePriceUpperBound(i interface{}) error { return err } - if priceUpperBound > 2*common.Precision { + if priceUpperBound > 2_000_000 { return fmt.Errorf("PriceUpperBound is above max value(1e6): %d", priceUpperBound) } else if priceUpperBound < 0 { return fmt.Errorf("PriceUpperBound is negative: %d", priceUpperBound) diff --git a/x/testutil/cli/tx.go b/x/testutil/cli/tx.go index 4b90721ae..b640240f3 100644 --- a/x/testutil/cli/tx.go +++ b/x/testutil/cli/tx.go @@ -118,7 +118,7 @@ func (n *Network) SendTx(addr sdk.AccAddress, msgs ...sdk.Msg) (*sdk.TxResponse, txBuilder := cfg.TxConfig.NewTxBuilder() require.NoError(n.T, txBuilder.SetMsgs(msgs...)) txBuilder.SetFeeAmount(sdk.NewCoins(sdk.NewCoin(cfg.BondDenom, sdk.NewInt(1)))) - txBuilder.SetGasLimit(uint64(1 * common.Precision)) + txBuilder.SetGasLimit(1000000) acc, err := cfg.AccountRetriever.GetAccount(n.Validators[0].ClientCtx, addr) require.NoError(n.T, err) diff --git a/x/testutil/sample.go b/x/testutil/sample.go index ee98e152b..0a6fbfd4b 100644 --- a/x/testutil/sample.go +++ b/x/testutil/sample.go @@ -46,23 +46,3 @@ func BlankContext(storeKeyName string) sdk.Context { ctx := sdk.NewContext(stateStore, tmproto.Header{}, false, log.NewNopLogger()) return ctx } - -type TypeLatin struct { - Letters string - CapLetters string - Numbers string -} - -var Latin = TypeLatin{ - Letters: "abcdefghijklmnopqrstuvwxyz", - CapLetters: "ABCDEFGHIJKLMNOPQRSTUVWXYZ", - Numbers: "0123456789", -} - -func RandStringBytes(n int) string { - b := make([]byte, n) - for i := range b { - b[i] = Latin.Letters[rand.Intn(len(Latin.Letters))] - } - return string(b) -} diff --git a/x/util/keeper/query_server_test.go b/x/util/keeper/query_server_test.go index 8cc74926a..08b4c568f 100644 --- a/x/util/keeper/query_server_test.go +++ b/x/util/keeper/query_server_test.go @@ -7,7 +7,6 @@ import ( "github.com/stretchr/testify/require" "github.com/NibiruChain/nibiru/simapp" - "github.com/NibiruChain/nibiru/x/common" "github.com/NibiruChain/nibiru/x/util/keeper" "github.com/NibiruChain/nibiru/x/util/types" ) @@ -29,7 +28,7 @@ func TestQueryServer_ModuleAccounts(t *testing.T) { err = app.BankKeeper.MintCoins( ctx, someModuleAccount, - sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1*common.Precision)), + sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1_000_000)), ) require.NoError(t, err) @@ -37,5 +36,5 @@ func TestQueryServer_ModuleAccounts(t *testing.T) { accounts, err = qServer.ModuleAccounts(goCtx, &types.QueryModuleAccountsRequest{}) require.NoError(t, err) require.Len(t, accounts.Accounts, len(types.ModuleAccounts)) - require.Equal(t, accounts.Accounts[0].Balance, sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1*common.Precision))) + require.Equal(t, accounts.Accounts[0].Balance, sdktypes.NewCoins(sdktypes.NewInt64Coin("uniques", 1_000_000))) } diff --git a/x/vpool/client/cli/cli_test.go b/x/vpool/client/cli/cli_test.go index b0269aa7c..09bc7042e 100644 --- a/x/vpool/client/cli/cli_test.go +++ b/x/vpool/client/cli/cli_test.go @@ -35,8 +35,8 @@ func TestIntegrationTestSuite(t *testing.T) { var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ common.Pair_ETH_NUSD: { Pair: common.Pair_ETH_NUSD, - BaseAssetReserve: sdk.NewDec(10 * common.Precision), - QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), + BaseAssetReserve: sdk.NewDec(10_000_000), + QuoteAssetReserve: sdk.NewDec(60_000_000_000), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.8"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), @@ -48,7 +48,7 @@ var START_VPOOLS = map[common.AssetPair]vpooltypes.Vpool{ common.Pair_NIBI_NUSD: { Pair: common.Pair_NIBI_NUSD, BaseAssetReserve: sdk.NewDec(500_000), - QuoteAssetReserve: sdk.NewDec(5 * common.Precision), + QuoteAssetReserve: sdk.NewDec(5_000_000), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.8"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), @@ -98,8 +98,8 @@ func (s *IntegrationTestSuite) TestCmdCreatePoolProposal() { Title: "Create ETH:USD pool", Description: "Creates an ETH:USD pool", Pair: "ETH:USD", - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: vpooltypes.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.05"), diff --git a/x/vpool/genesis_test.go b/x/vpool/genesis_test.go index a77b65333..558c77745 100644 --- a/x/vpool/genesis_test.go +++ b/x/vpool/genesis_test.go @@ -20,8 +20,8 @@ func TestGenesis(t *testing.T) { vpools := []types.Vpool{ { Pair: common.MustNewAssetPair("BTC:NUSD"), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), // 1 - QuoteAssetReserve: sdk.NewDec(30_000 * common.Precision), // 30,000 + BaseAssetReserve: sdk.NewDec(1_000_000), // 1 + QuoteAssetReserve: sdk.NewDec(30_000_000_000), // 30,000 Config: types.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.88"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.20"), @@ -32,8 +32,8 @@ func TestGenesis(t *testing.T) { }, { Pair: common.MustNewAssetPair("ETH:NUSD"), - BaseAssetReserve: sdk.NewDec(2 * common.Precision), // 2 - QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), // 60,000 + BaseAssetReserve: sdk.NewDec(2_000_000), // 2 + QuoteAssetReserve: sdk.NewDec(60_000_000_000), // 60,000 Config: types.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.77"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.30"), diff --git a/x/vpool/keeper/keeper_test.go b/x/vpool/keeper/keeper_test.go index 2508d9ec1..2e0b8a22e 100644 --- a/x/vpool/keeper/keeper_test.go +++ b/x/vpool/keeper/keeper_test.go @@ -38,8 +38,8 @@ func TestSwapQuoteForBase(t *testing.T) { baseLimit: sdk.NewDec(10), skipFluctuationLimitCheck: false, - expectedQuoteReserve: sdk.NewDec(10 * common.Precision), - expectedBaseReserve: sdk.NewDec(5 * common.Precision), + expectedQuoteReserve: sdk.NewDec(10_000_000), + expectedBaseReserve: sdk.NewDec(5_000_000), expectedBaseAmount: sdk.ZeroDec(), }, { @@ -90,7 +90,7 @@ func TestSwapQuoteForBase(t *testing.T) { name: "base amount more than base limit in Short", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - quoteAmount: sdk.NewDec(1 * common.Precision), + quoteAmount: sdk.NewDec(1_000_000), baseLimit: sdk.NewDec(454_500), skipFluctuationLimitCheck: false, @@ -120,7 +120,7 @@ func TestSwapQuoteForBase(t *testing.T) { name: "over fluctuation limit fails on add", pair: common.Pair_BTC_NUSD, direction: types.Direction_ADD_TO_POOL, - quoteAmount: sdk.NewDec(1 * common.Precision), + quoteAmount: sdk.NewDec(1_000_000), baseLimit: sdk.NewDec(454_544), skipFluctuationLimitCheck: false, @@ -130,7 +130,7 @@ func TestSwapQuoteForBase(t *testing.T) { name: "over fluctuation limit fails on remove", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - quoteAmount: sdk.NewDec(1 * common.Precision), + quoteAmount: sdk.NewDec(1_000_000), baseLimit: sdk.NewDec(555_556), skipFluctuationLimitCheck: false, @@ -140,11 +140,11 @@ func TestSwapQuoteForBase(t *testing.T) { name: "over fluctuation limit allowed on add", pair: common.Pair_BTC_NUSD, direction: types.Direction_ADD_TO_POOL, - quoteAmount: sdk.NewDec(1 * common.Precision), + quoteAmount: sdk.NewDec(1_000_000), baseLimit: sdk.NewDec(454_544), skipFluctuationLimitCheck: true, - expectedQuoteReserve: sdk.NewDec(11 * common.Precision), + expectedQuoteReserve: sdk.NewDec(11_000_000), expectedBaseReserve: sdk.MustNewDecFromStr("4545454.545454545454545455"), expectedBaseAmount: sdk.MustNewDecFromStr("454545.454545454545454545"), }, @@ -152,11 +152,11 @@ func TestSwapQuoteForBase(t *testing.T) { name: "over fluctuation limit allowed on remove", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - quoteAmount: sdk.NewDec(1 * common.Precision), + quoteAmount: sdk.NewDec(1_000_000), baseLimit: sdk.NewDec(555_556), skipFluctuationLimitCheck: true, - expectedQuoteReserve: sdk.NewDec(9 * common.Precision), + expectedQuoteReserve: sdk.NewDec(9_000_000), expectedBaseReserve: sdk.MustNewDecFromStr("5555555.555555555555555556"), expectedBaseAmount: sdk.MustNewDecFromStr("555555.555555555555555556"), }, @@ -173,8 +173,8 @@ func TestSwapQuoteForBase(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens - /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens + /* quoteAssetReserve */ sdk.NewDec(10_000_000), // 10 tokens + /* baseAssetReserve */ sdk.NewDec(5_000_000), // 5 tokens types.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), @@ -231,8 +231,8 @@ func TestSwapBaseForQuote(t *testing.T) { quoteLimit: sdk.ZeroDec(), skipFluctuationLimitCheck: false, - expectedQuoteReserve: sdk.NewDec(10 * common.Precision), - expectedBaseReserve: sdk.NewDec(5 * common.Precision), + expectedQuoteReserve: sdk.NewDec(10_000_000), + expectedBaseReserve: sdk.NewDec(5_000_000), expectedQuoteAssetAmount: sdk.ZeroDec(), }, { @@ -313,7 +313,7 @@ func TestSwapBaseForQuote(t *testing.T) { name: "over fluctuation limit fails on add", pair: common.Pair_BTC_NUSD, direction: types.Direction_ADD_TO_POOL, - baseAmt: sdk.NewDec(1 * common.Precision), + baseAmt: sdk.NewDec(1_000_000), quoteLimit: sdk.NewDec(1_666_666), skipFluctuationLimitCheck: false, @@ -323,7 +323,7 @@ func TestSwapBaseForQuote(t *testing.T) { name: "over fluctuation limit fails on remove", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - baseAmt: sdk.NewDec(1 * common.Precision), + baseAmt: sdk.NewDec(1_000_000), quoteLimit: sdk.NewDec(2_500_001), skipFluctuationLimitCheck: false, @@ -333,24 +333,24 @@ func TestSwapBaseForQuote(t *testing.T) { name: "over fluctuation limit allowed on add", pair: common.Pair_BTC_NUSD, direction: types.Direction_ADD_TO_POOL, - baseAmt: sdk.NewDec(1 * common.Precision), + baseAmt: sdk.NewDec(1_000_000), quoteLimit: sdk.NewDec(1_666_666), skipFluctuationLimitCheck: true, expectedQuoteReserve: sdk.MustNewDecFromStr("8333333.333333333333333333"), - expectedBaseReserve: sdk.NewDec(6 * common.Precision), + expectedBaseReserve: sdk.NewDec(6_000_000), expectedQuoteAssetAmount: sdk.MustNewDecFromStr("1666666.666666666666666667"), }, { name: "over fluctuation limit allowed on remove", pair: common.Pair_BTC_NUSD, direction: types.Direction_REMOVE_FROM_POOL, - baseAmt: sdk.NewDec(1 * common.Precision), + baseAmt: sdk.NewDec(1_000_000), quoteLimit: sdk.NewDec(2_500_001), skipFluctuationLimitCheck: true, expectedQuoteReserve: sdk.NewDec(12_500_000), - expectedBaseReserve: sdk.NewDec(4 * common.Precision), + expectedBaseReserve: sdk.NewDec(4_000_000), expectedQuoteAssetAmount: sdk.NewDec(2_500_000), }, } @@ -366,8 +366,8 @@ func TestSwapBaseForQuote(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - /* quoteAssetReserve */ sdk.NewDec(10*common.Precision), // 10 tokens - /* baseAssetReserve */ sdk.NewDec(5*common.Precision), // 5 tokens + /* quoteAssetReserve */ sdk.NewDec(10_000_000), // 10 tokens + /* baseAssetReserve */ sdk.NewDec(5_000_000), // 5 tokens types.VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.9"), FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), @@ -411,8 +411,8 @@ func TestGetVpools(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_BTC_NUSD, - sdk.NewDec(10*common.Precision), - sdk.NewDec(5*common.Precision), + sdk.NewDec(10_000_000), + sdk.NewDec(5_000_000), types.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -424,8 +424,8 @@ func TestGetVpools(t *testing.T) { vpoolKeeper.CreatePool( ctx, common.Pair_ETH_NUSD, - sdk.NewDec(5*common.Precision), - sdk.NewDec(10*common.Precision), + sdk.NewDec(5_000_000), + sdk.NewDec(10_000_000), types.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -441,8 +441,8 @@ func TestGetVpools(t *testing.T) { require.EqualValues(t, pools[0], types.Vpool{ Pair: common.Pair_BTC_NUSD, - BaseAssetReserve: sdk.NewDec(5 * common.Precision), - QuoteAssetReserve: sdk.NewDec(10 * common.Precision), + BaseAssetReserve: sdk.NewDec(5_000_000), + QuoteAssetReserve: sdk.NewDec(10_000_000), Config: types.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), @@ -453,8 +453,8 @@ func TestGetVpools(t *testing.T) { }) require.EqualValues(t, pools[1], types.Vpool{ Pair: common.Pair_ETH_NUSD, - BaseAssetReserve: sdk.NewDec(10 * common.Precision), - QuoteAssetReserve: sdk.NewDec(5 * common.Precision), + BaseAssetReserve: sdk.NewDec(10_000_000), + QuoteAssetReserve: sdk.NewDec(5_000_000), Config: types.VpoolConfig{ TradeLimitRatio: sdk.OneDec(), FluctuationLimitRatio: sdk.OneDec(), diff --git a/x/vpool/keeper/pool_state_test.go b/x/vpool/keeper/pool_state_test.go index 2b0b43401..d4e567f31 100644 --- a/x/vpool/keeper/pool_state_test.go +++ b/x/vpool/keeper/pool_state_test.go @@ -21,8 +21,8 @@ func TestCreatePool(t *testing.T) { ctx, common.Pair_BTC_NUSD, - sdk.NewDec(10*common.Precision), // 10 tokens - sdk.NewDec(5*common.Precision), // 5 tokens + sdk.NewDec(10_000_000), // 10 tokens + sdk.NewDec(5_000_000), // 5 tokens types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -46,8 +46,8 @@ func TestEditPoolConfig(t *testing.T) { pair := common.Pair_BTC_NUSD vpoolStart := types.Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(10 * common.Precision), - BaseAssetReserve: sdk.NewDec(5 * common.Precision), + QuoteAssetReserve: sdk.NewDec(10_000_000), + BaseAssetReserve: sdk.NewDec(5_000_000), Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -194,8 +194,8 @@ func TestGetPoolPrices(t *testing.T) { name: "happy path - vpool + pricefeed active", vpool: types.Vpool{ Pair: common.Pair_ETH_NUSD, - QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 - BaseAssetReserve: sdk.NewDec(1_000), // 1e3 + QuoteAssetReserve: sdk.NewDec(3_000_000), // 3e6 + BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.30"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -211,7 +211,7 @@ func TestGetPoolPrices(t *testing.T) { MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.NewDec(99).String(), - SwapInvariant: sdk.NewInt(3_000 * common.Precision), // 1e3 * 3e6 = 3e9 + SwapInvariant: sdk.NewInt(3_000_000_000), // 1e3 * 3e6 = 3e9 BlockNumber: 2, }, }, @@ -219,8 +219,8 @@ func TestGetPoolPrices(t *testing.T) { name: "happy path - vpool active, but no index price", vpool: types.Vpool{ Pair: common.Pair_ETH_NUSD, - QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 - BaseAssetReserve: sdk.NewDec(1_000), // 1e3 + QuoteAssetReserve: sdk.NewDec(3_000_000), // 3e6 + BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.30"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -237,7 +237,7 @@ func TestGetPoolPrices(t *testing.T) { MarkPrice: sdk.NewDec(3_000), TwapMark: sdk.NewDec(3_000).String(), IndexPrice: sdk.OneDec().Neg().String(), - SwapInvariant: sdk.NewInt(3_000 * common.Precision), // 1e3 * 3e6 = 3e9 + SwapInvariant: sdk.NewInt(3_000_000_000), // 1e3 * 3e6 = 3e9 BlockNumber: 2, }, }, @@ -245,8 +245,8 @@ func TestGetPoolPrices(t *testing.T) { name: "vpool doesn't exist", vpool: types.Vpool{ Pair: common.Pair_ETH_NUSD, - QuoteAssetReserve: sdk.NewDec(3 * common.Precision), // 3e6 - BaseAssetReserve: sdk.NewDec(1_000), // 1e3 + QuoteAssetReserve: sdk.NewDec(3_000_000), // 3e6 + BaseAssetReserve: sdk.NewDec(1_000), // 1e3 Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.30"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -303,8 +303,8 @@ func TestEditSwapInvariant(t *testing.T) { pair := common.Pair_NIBI_NUSD vpoolStart := types.Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(10 * common.Precision), - BaseAssetReserve: sdk.NewDec(5 * common.Precision), + QuoteAssetReserve: sdk.NewDec(10_000_000), + BaseAssetReserve: sdk.NewDec(5_000_000), Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/vpool/keeper/query_server_test.go b/x/vpool/keeper/query_server_test.go index 4afe87cbf..d64253deb 100644 --- a/x/vpool/keeper/query_server_test.go +++ b/x/vpool/keeper/query_server_test.go @@ -25,7 +25,7 @@ func TestQueryReserveAssets(t *testing.T) { t.Log("initialize vpool") pool := types.Vpool{ Pair: common.Pair_BTC_NUSD, - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.ZeroDec(), @@ -61,7 +61,7 @@ func TestQueryAllPools(t *testing.T) { pair := common.Pair_BTC_NUSD pool := &types.Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), BaseAssetReserve: sdk.NewDec(1000), Config: types.VpoolConfig{ FluctuationLimitRatio: sdk.ZeroDec(), @@ -92,7 +92,7 @@ func TestQueryAllPools(t *testing.T) { MarkPrice: markPriceWanted, IndexPrice: indexPrice.String(), TwapMark: markPriceWanted.String(), - SwapInvariant: sdk.NewInt(1_000 * common.Precision), + SwapInvariant: sdk.NewInt(1_000_000_000), // 1e6 * 1e3 BlockNumber: 2, } require.NoError(t, err) diff --git a/x/vpool/types/gov_test.go b/x/vpool/types/gov_test.go index ceadf9d75..4cc19a654 100644 --- a/x/vpool/types/gov_test.go +++ b/x/vpool/types/gov_test.go @@ -38,8 +38,8 @@ func TestCreatePoolProposal_ValidateBasic(t *testing.T) { Title: "add proposal", Description: "some weird description", Pair: "valid:pair", - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/vpool/types/pool_test.go b/x/vpool/types/pool_test.go index 041033862..b1fe5f915 100644 --- a/x/vpool/types/pool_test.go +++ b/x/vpool/types/pool_test.go @@ -18,8 +18,8 @@ func TestPoolHasEnoughQuoteReserve(t *testing.T) { pool := &Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(10 * common.Precision), - BaseAssetReserve: sdk.NewDec(10 * common.Precision), + QuoteAssetReserve: sdk.NewDec(10_000_000), + BaseAssetReserve: sdk.NewDec(10_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaxOracleSpreadRatio: sdk.MustNewDecFromStr("0.1"), @@ -30,10 +30,10 @@ func TestPoolHasEnoughQuoteReserve(t *testing.T) { } // less than max ratio - require.True(t, pool.HasEnoughQuoteReserve(sdk.NewDec(8*common.Precision))) + require.True(t, pool.HasEnoughQuoteReserve(sdk.NewDec(8_000_000))) // equal to ratio limit - require.True(t, pool.HasEnoughQuoteReserve(sdk.NewDec(9*common.Precision))) + require.True(t, pool.HasEnoughQuoteReserve(sdk.NewDec(9_000_000))) // more than ratio limit require.False(t, pool.HasEnoughQuoteReserve(sdk.NewDec(9_000_001))) @@ -44,8 +44,8 @@ func TestSetMarginRatioAndLeverage(t *testing.T) { pool := &Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(10 * common.Precision), - BaseAssetReserve: sdk.NewDec(10 * common.Precision), + QuoteAssetReserve: sdk.NewDec(10_000_000), + BaseAssetReserve: sdk.NewDec(10_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.42"), @@ -216,8 +216,8 @@ func TestIncreaseDecreaseReserves(t *testing.T) { pool := &Vpool{ Pair: pair, - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.1"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), @@ -233,7 +233,7 @@ func TestIncreaseDecreaseReserves(t *testing.T) { t.Log("increase quote asset reserve") pool.IncreaseQuoteAssetReserve(sdk.NewDec(100)) - require.Equal(t, sdk.NewDec(1*common.Precision), pool.QuoteAssetReserve) + require.Equal(t, sdk.NewDec(1_000_000), pool.QuoteAssetReserve) t.Log("decrease base asset reserve") pool.DecreaseBaseAssetReserve(sdk.NewDec(100)) @@ -241,7 +241,7 @@ func TestIncreaseDecreaseReserves(t *testing.T) { t.Log("increase base asset reserve") pool.IncreaseBaseAssetReserve(sdk.NewDec(100)) - require.Equal(t, sdk.NewDec(1*common.Precision), pool.BaseAssetReserve) + require.Equal(t, sdk.NewDec(1_000_000), pool.BaseAssetReserve) } func TestPool_Validate(t *testing.T) { @@ -318,7 +318,7 @@ func TestPool_Validate(t *testing.T) { "base asset reserve 0": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), BaseAssetReserve: sdk.ZeroDec(), Config: VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), @@ -334,8 +334,8 @@ func TestPool_Validate(t *testing.T) { "fluctuation < 0": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), FluctuationLimitRatio: sdk.NewDec(-1), @@ -350,8 +350,8 @@ func TestPool_Validate(t *testing.T) { "fluctuation > 1": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), FluctuationLimitRatio: sdk.NewDec(2), @@ -366,8 +366,8 @@ func TestPool_Validate(t *testing.T) { "max oracle spread ratio < 0": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.OneDec(), @@ -382,8 +382,8 @@ func TestPool_Validate(t *testing.T) { "max oracle spread ratio > 1": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.OneDec(), @@ -405,8 +405,8 @@ func TestPool_Validate(t *testing.T) { MaxOracleSpreadRatio: sdk.MustNewDecFromStr("0.10"), TradeLimitRatio: sdk.MustNewDecFromStr("0.10"), }, - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), }, expectErr: true, }, @@ -414,8 +414,8 @@ func TestPool_Validate(t *testing.T) { "maintenance ratio > 1": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.NewDec(2), @@ -430,8 +430,8 @@ func TestPool_Validate(t *testing.T) { "max leverage < 0": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.10"), @@ -446,8 +446,8 @@ func TestPool_Validate(t *testing.T) { "max leverage too high for maintenance margin ratio": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.10"), // Equivalent to 10 leverage @@ -462,8 +462,8 @@ func TestPool_Validate(t *testing.T) { "success": { m: &Vpool{ Pair: common.MustNewAssetPair("btc:usd"), - QuoteAssetReserve: sdk.NewDec(1 * common.Precision), - BaseAssetReserve: sdk.NewDec(1 * common.Precision), + QuoteAssetReserve: sdk.NewDec(1_000_000), + BaseAssetReserve: sdk.NewDec(1_000_000), Config: VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.10"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"), diff --git a/x/wasm/cli/cli_test.go b/x/wasm/cli/cli_test.go index 9f16197a7..2c6617eb6 100644 --- a/x/wasm/cli/cli_test.go +++ b/x/wasm/cli/cli_test.go @@ -49,8 +49,8 @@ func (s *IntegrationTestSuite) SetupSuite() { vpoolGenesis.Vpools = []vpooltypes.Vpool{ { Pair: common.Pair_ETH_NUSD, - BaseAssetReserve: sdk.NewDec(10 * common.Precision), - QuoteAssetReserve: sdk.NewDec(60_000 * common.Precision), + BaseAssetReserve: sdk.NewDec(10_000_000), + QuoteAssetReserve: sdk.NewDec(60_000_000_000), Config: vpooltypes.VpoolConfig{ FluctuationLimitRatio: sdk.MustNewDecFromStr("0.2"), MaintenanceMarginRatio: sdk.MustNewDecFromStr("0.0625"),