Skip to content

Commit

Permalink
genesis import export check for superfluid (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
antstalepresh authored Mar 14, 2022
1 parent 00b4b2c commit 86b4836
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
1 change: 1 addition & 0 deletions x/superfluid/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
// ExportGenesis returns the capability module's exported genesis.
func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
return &types.GenesisState{
Params: k.GetParams(ctx),
SuperfluidAssets: k.GetAllSuperfluidAssets(ctx),
OsmoEquivalentMultipliers: k.GetAllOsmoEquivalentMultipliers(ctx),
IntermediaryAccounts: k.GetAllIntermediaryAccounts(ctx),
Expand Down
116 changes: 116 additions & 0 deletions x/superfluid/genesis_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package superfluid_test

import (
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
simapp "github.com/osmosis-labs/osmosis/v7/app"
"github.com/osmosis-labs/osmosis/v7/x/superfluid"
"github.com/osmosis-labs/osmosis/v7/x/superfluid/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
)

var now = time.Now().UTC()

var testGenesis = types.GenesisState{
Params: types.Params{
MinimumRiskFactor: sdk.NewDecWithPrec(5, 1), // 50%
},
SuperfluidAssets: []types.SuperfluidAsset{
{
Denom: "gamm/pool/1",
AssetType: types.SuperfluidAssetTypeLPShare,
},
},
OsmoEquivalentMultipliers: []types.OsmoEquivalentMultiplierRecord{
{
EpochNumber: 1,
Denom: "gamm/pool/1",
Multiplier: sdk.NewDec(1000),
},
},
IntermediaryAccounts: []types.SuperfluidIntermediaryAccount{
{
Denom: "gamm/pool/1",
ValAddr: "osmovaloper1cyw4vw20el8e7ez8080md0r8psg25n0cq98a9n",
GaugeId: 1,
},
},
IntemediaryAccountConnections: []types.LockIdIntermediaryAccountConnection{
{
LockId: 1,
IntermediaryAccount: "osmo1hpgapnfl3thkevvl0jp3wqtk8jw7mpqumuuc2f",
},
},
}

func TestMarshalUnmarshalGenesis(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithBlockTime(now.Add(time.Second))

encodingConfig := simapp.MakeEncodingConfig()
appCodec := encodingConfig.Marshaler
am := superfluid.NewAppModule(appCodec, *app.SuperfluidKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.LockupKeeper, app.GAMMKeeper, app.EpochsKeeper)

genesis := testGenesis
superfluid.InitGenesis(ctx, *app.SuperfluidKeeper, genesis)

genesisExported := am.ExportGenesis(ctx, appCodec)
assert.NotPanics(t, func() {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithBlockTime(now.Add(time.Second))
am := superfluid.NewAppModule(appCodec, *app.SuperfluidKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.LockupKeeper, app.GAMMKeeper, app.EpochsKeeper)
am.InitGenesis(ctx, appCodec, genesisExported)
})
}

func TestInitGenesis(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithBlockTime(now.Add(time.Second))
genesis := testGenesis
superfluid.InitGenesis(ctx, *app.SuperfluidKeeper, genesis)

params := app.SuperfluidKeeper.GetParams(ctx)
require.Equal(t, params, genesis.Params)

assets := app.SuperfluidKeeper.GetAllSuperfluidAssets(ctx)
require.Equal(t, assets, genesis.SuperfluidAssets)

multipliers := app.SuperfluidKeeper.GetAllOsmoEquivalentMultipliers(ctx)
require.Equal(t, multipliers, genesis.OsmoEquivalentMultipliers)

accounts := app.SuperfluidKeeper.GetAllIntermediaryAccounts(ctx)
require.Equal(t, accounts, genesis.IntermediaryAccounts)

connections := app.SuperfluidKeeper.GetAllLockIdIntermediaryAccountConnections(ctx)
require.Equal(t, connections, genesis.IntemediaryAccountConnections)
}

func TestExportGenesis(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
ctx = ctx.WithBlockTime(now.Add(time.Second))
genesis := testGenesis
superfluid.InitGenesis(ctx, *app.SuperfluidKeeper, genesis)

asset := types.SuperfluidAsset{
Denom: "gamm/pool/2",
AssetType: types.SuperfluidAssetTypeLPShare,
}
app.SuperfluidKeeper.SetSuperfluidAsset(ctx, asset)
savedAsset := app.SuperfluidKeeper.GetSuperfluidAsset(ctx, "gamm/pool/2")
require.Equal(t, savedAsset, asset)

genesisExported := superfluid.ExportGenesis(ctx, *app.SuperfluidKeeper)
require.Equal(t, genesisExported.Params, genesis.Params)
require.Equal(t, genesisExported.SuperfluidAssets, append(genesis.SuperfluidAssets, asset))
require.Equal(t, genesis.OsmoEquivalentMultipliers, genesis.OsmoEquivalentMultipliers)
require.Equal(t, genesis.IntermediaryAccounts, genesis.IntermediaryAccounts)
require.Equal(t, genesis.IntemediaryAccountConnections, genesis.IntemediaryAccountConnections)
}

0 comments on commit 86b4836

Please sign in to comment.