-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add airdrop and oracle genesis tests
- Loading branch information
Showing
8 changed files
with
410 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package integration | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
tmrand "github.com/cometbft/cometbft/libs/rand" | ||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
"github.com/cosmos/cosmos-sdk/x/staking" | ||
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil" | ||
"github.com/stretchr/testify/require" | ||
|
||
ojoapp "github.com/ojo-network/ojo/app" | ||
appparams "github.com/ojo-network/ojo/app/params" | ||
airdropkeeper "github.com/ojo-network/ojo/x/airdrop/keeper" | ||
airdroptypes "github.com/ojo-network/ojo/x/airdrop/types" | ||
oraclekeeper "github.com/ojo-network/ojo/x/oracle/keeper" | ||
oracletypes "github.com/ojo-network/ojo/x/oracle/types" | ||
) | ||
|
||
const ( | ||
bondDenom = appparams.BondDenom | ||
initialPower = int64(1000) | ||
isCheckTx = false | ||
) | ||
|
||
var validatorPowers = []int64{599, 398, 2} | ||
|
||
type TestValidatorKey struct { | ||
PubKey cryptotypes.PubKey | ||
ValAddress sdk.ValAddress | ||
AccAddress sdk.AccAddress | ||
Power int64 | ||
} | ||
|
||
func CreateTestValidatorKeys(numValidators int) []TestValidatorKey { | ||
var validatorKeys []TestValidatorKey | ||
|
||
for i := 0; i < numValidators; i++ { | ||
pubKey := secp256k1.GenPrivKey().PubKey() | ||
valInfo := TestValidatorKey{ | ||
PubKey: pubKey, | ||
ValAddress: sdk.ValAddress(pubKey.Address()), | ||
AccAddress: sdk.AccAddress(pubKey.Address()), | ||
Power: validatorPowers[i], | ||
} | ||
validatorKeys = append(validatorKeys, valInfo) | ||
} | ||
|
||
return validatorKeys | ||
} | ||
|
||
func SetupAppWithContext( | ||
t *testing.T, | ||
) ( | ||
*ojoapp.App, | ||
sdk.Context, | ||
[]TestValidatorKey, | ||
) { | ||
config := sdk.GetConfig() | ||
config.SetBech32PrefixForAccount(appparams.AccountAddressPrefix, appparams.AccountPubKeyPrefix) | ||
config.SetBech32PrefixForValidator(appparams.ValidatorAddressPrefix, appparams.ValidatorPubKeyPrefix) | ||
config.SetBech32PrefixForConsensusNode(appparams.ConsNodeAddressPrefix, appparams.ConsNodePubKeyPrefix) | ||
|
||
app := ojoapp.Setup(t) | ||
ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{ | ||
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)), | ||
Height: 9, | ||
}) | ||
|
||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) | ||
oracletypes.RegisterQueryServer(queryHelper, oraclekeeper.NewQuerier(app.OracleKeeper)) | ||
airdroptypes.RegisterQueryServer(queryHelper, airdropkeeper.NewQuerier(app.AirdropKeeper)) | ||
|
||
sh := stakingtestutil.NewHelper(t, ctx, app.StakingKeeper) | ||
sh.Denom = bondDenom | ||
|
||
// amt := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction) | ||
|
||
// make validators 60%, 29%, 1% of total power | ||
|
||
initTokens := sdk.TokensFromConsensusPower(initialPower, sdk.DefaultPowerReduction) | ||
initCoins := sdk.NewCoins(sdk.NewCoin(appparams.BondDenom, initTokens)) | ||
|
||
validatorKeys := CreateTestValidatorKeys(3) | ||
|
||
// mint and send coins to validators | ||
for _, val := range validatorKeys { | ||
require.NoError(t, app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) | ||
require.NoError(t, app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, val.AccAddress, initCoins)) | ||
sh.CreateValidatorWithValPower(val.ValAddress, val.PubKey, val.Power, true) | ||
// sh.CreateValidator(val.ValAddress, val.PubKey, amt, true) | ||
} | ||
|
||
// mint and send coins to oracle module to fill up reward pool | ||
require.NoError(t, app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) | ||
require.NoError(t, | ||
app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, oracletypes.ModuleName, initCoins), | ||
) | ||
|
||
staking.EndBlocker(ctx, app.StakingKeeper) | ||
|
||
return app, ctx, validatorKeys | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package airdrop_test | ||
|
||
import ( | ||
"gotest.tools/v3/assert" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/ojo-network/ojo/x/airdrop" | ||
"github.com/ojo-network/ojo/x/airdrop/types" | ||
) | ||
|
||
func (s *IntegrationTestSuite) TestGenesis_InitGenesis() { | ||
keeper, ctx := s.app.AirdropKeeper, s.ctx | ||
|
||
genesisState := types.GenesisState{ | ||
Params: types.DefaultParams(), | ||
AirdropAccounts: []*types.AirdropAccount{}, | ||
} | ||
|
||
s.Assertions.NotPanics(func() { airdrop.InitGenesis(ctx, keeper, genesisState) }) | ||
} | ||
|
||
func (s *IntegrationTestSuite) TestGenesis_ExportGenesis() { | ||
keeper, ctx := s.app.AirdropKeeper, s.ctx | ||
|
||
params := types.DefaultParams() | ||
|
||
airdropAccounts := []*types.AirdropAccount{ | ||
{ | ||
VestingEndTime: 100, | ||
OriginAddress: "ojo1ner6kc63xl903wrv2n8p9mtun79gegjld93lx0", | ||
OriginAmount: sdk.NewInt(100).Uint64(), | ||
}, | ||
} | ||
|
||
genesisState := types.GenesisState{ | ||
Params: params, | ||
AirdropAccounts: airdropAccounts, | ||
} | ||
|
||
airdrop.InitGenesis(ctx, keeper, genesisState) | ||
|
||
result := airdrop.ExportGenesis(ctx, keeper) | ||
|
||
assert.DeepEqual(s.T(), params, result.Params) | ||
assert.DeepEqual(s.T(), airdropAccounts, result.AirdropAccounts) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,37 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cometbft/cometbft/crypto/secp256k1" | ||
tmrand "github.com/cometbft/cometbft/libs/rand" | ||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types" | ||
"github.com/cosmos/cosmos-sdk/baseapp" | ||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" | ||
"github.com/cosmos/cosmos-sdk/x/staking" | ||
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil" | ||
"github.com/stretchr/testify/suite" | ||
|
||
ojoapp "github.com/ojo-network/ojo/app" | ||
appparams "github.com/ojo-network/ojo/app/params" | ||
"github.com/ojo-network/ojo/tests/integration" | ||
"github.com/ojo-network/ojo/x/airdrop/keeper" | ||
"github.com/ojo-network/ojo/x/airdrop/types" | ||
) | ||
|
||
const ( | ||
displayDenom string = appparams.DisplayDenom | ||
bondDenom string = appparams.BondDenom | ||
|
||
initialPower = int64(10000000000) | ||
) | ||
|
||
// Test addresses | ||
var ( | ||
valPubKeys = simtestutil.CreateTestPubKeys(2) | ||
|
||
valPubKey = valPubKeys[0] | ||
pubKey = secp256k1.GenPrivKey().PubKey() | ||
addr = sdk.AccAddress(pubKey.Address()) | ||
valAddr = sdk.ValAddress(pubKey.Address()) | ||
|
||
valPubKey2 = valPubKeys[1] | ||
pubKey2 = secp256k1.GenPrivKey().PubKey() | ||
addr2 = sdk.AccAddress(pubKey2.Address()) | ||
valAddr2 = sdk.ValAddress(pubKey2.Address()) | ||
|
||
initTokens = sdk.TokensFromConsensusPower(initialPower, sdk.DefaultPowerReduction) | ||
initCoins = sdk.NewCoins(sdk.NewCoin(appparams.BondDenom, initTokens)) | ||
) | ||
|
||
type IntegrationTestSuite struct { | ||
suite.Suite | ||
|
||
ctx sdk.Context | ||
app *ojoapp.App | ||
queryClient types.QueryClient | ||
msgServer types.MsgServer | ||
ctx sdk.Context | ||
app *ojoapp.App | ||
keys []integration.TestValidatorKey | ||
msgServer types.MsgServer | ||
} | ||
|
||
func TestIntegrationTestSuite(t *testing.T) { | ||
suite.Run(t, new(IntegrationTestSuite)) | ||
} | ||
|
||
func (s *IntegrationTestSuite) SetupSuite() { | ||
require := s.Require() | ||
isCheckTx := false | ||
|
||
config := sdk.GetConfig() | ||
config.SetBech32PrefixForAccount(appparams.AccountAddressPrefix, appparams.AccountPubKeyPrefix) | ||
config.SetBech32PrefixForValidator(appparams.ValidatorAddressPrefix, appparams.ValidatorPubKeyPrefix) | ||
config.SetBech32PrefixForConsensusNode(appparams.ConsNodeAddressPrefix, appparams.ConsNodePubKeyPrefix) | ||
|
||
app := ojoapp.Setup(s.T()) | ||
ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{ | ||
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)), | ||
Height: 9, | ||
}) | ||
|
||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry()) | ||
types.RegisterQueryServer(queryHelper, keeper.NewQuerier(app.AirdropKeeper)) | ||
|
||
sh := stakingtestutil.NewHelper(s.T(), ctx, app.StakingKeeper) | ||
sh.Denom = bondDenom | ||
amt := sdk.TokensFromConsensusPower(100, sdk.DefaultPowerReduction) | ||
|
||
// mint and send coins to validators | ||
require.NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) | ||
require.NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr, initCoins)) | ||
require.NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, initCoins)) | ||
require.NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr2, initCoins)) | ||
|
||
sh.CreateValidator(valAddr, valPubKey, amt, true) | ||
sh.CreateValidator(valAddr2, valPubKey2, amt, true) | ||
|
||
staking.EndBlocker(ctx, app.StakingKeeper) | ||
|
||
s.app = app | ||
s.ctx = ctx | ||
s.queryClient = types.NewQueryClient(queryHelper) | ||
s.msgServer = keeper.NewMsgServerImpl(app.AirdropKeeper) | ||
s.app, s.ctx, s.keys = integration.SetupAppWithContext(s.T()) | ||
s.msgServer = keeper.NewMsgServerImpl(s.app.AirdropKeeper) | ||
} |
Oops, something went wrong.