Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/golang.org/x/net-0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Oct 16, 2023
2 parents f6e2f40 + 74059bd commit f967be8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 87 deletions.
6 changes: 0 additions & 6 deletions tests/integration/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func SetupAppWithContext(
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())
Expand All @@ -80,10 +79,6 @@ func SetupAppWithContext(
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))

Expand All @@ -94,7 +89,6 @@ func SetupAppWithContext(
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
Expand Down
4 changes: 3 additions & 1 deletion x/airdrop/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ func (s *IntegrationTestSuite) TestMsgServer_ClaimAirdrop() {
},
}

ctx := s.ctx.WithBlockHeight(9) // assumes block height of 9

for _, tc := range testCases {
s.Run(tc.name, func() {
SetParams(s, tc.expiryBlock, &tc.delegationRequirement)
Expand All @@ -73,7 +75,7 @@ func (s *IntegrationTestSuite) TestMsgServer_ClaimAirdrop() {
claimAddress.String(),
)

_, err := s.msgServer.ClaimAirdrop(s.ctx, msgClaimAirdrop)
_, err := s.msgServer.ClaimAirdrop(ctx, msgClaimAirdrop)
if tc.errMsg != "" {
s.Require().Error(err)
s.Require().Contains(err.Error(), tc.errMsg)
Expand Down
89 changes: 9 additions & 80 deletions x/oracle/abci_test.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
package oracle_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"
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/util/decmath"
"github.com/ojo-network/ojo/x/oracle"
"github.com/ojo-network/ojo/x/oracle/types"
Expand All @@ -29,83 +22,16 @@ const (
type IntegrationTestSuite struct {
suite.Suite

ctx sdk.Context
app *ojoapp.App
ctx sdk.Context
app *ojoapp.App
keys []integration.TestValidatorKey
}

const (
initialPower = int64(1000)
)

func (s *IntegrationTestSuite) SetupTest() {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(appparams.AccountAddressPrefix, appparams.AccountPubKeyPrefix)
config.SetBech32PrefixForValidator(appparams.ValidatorAddressPrefix, appparams.ValidatorPubKeyPrefix)
config.SetBech32PrefixForConsensusNode(appparams.ConsNodeAddressPrefix, appparams.ConsNodePubKeyPrefix)

require := s.Require()
isCheckTx := false
app := ojoapp.Setup(s.T())
ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{
ChainID: fmt.Sprintf("test-chain-%s", tmrand.Str(4)),
})

oracle.InitGenesis(ctx, app.OracleKeeper, *types.DefaultGenesisState())

// validate setup... app.Setup creates one validator, with 1uumee self delegation
setupVals := app.StakingKeeper.GetBondedValidatorsByPower(ctx)
s.Require().Len(setupVals, 1)
s.Require().Equal(int64(1), setupVals[0].GetConsensusPower(app.StakingKeeper.PowerReduction(ctx)))

sh := stakingtestutil.NewHelper(s.T(), ctx, app.StakingKeeper)
sh.Denom = bondDenom

// mint and send coins to validators
require.NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, initCoins.MulInt(sdk.NewIntFromUint64(3))))
require.NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr1, initCoins))
require.NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr2, initCoins))
require.NoError(app.BankKeeper.SendCoinsFromModuleToAccount(ctx, minttypes.ModuleName, addr3, initCoins))

// mint and send coins to oracle module to fill up reward pool
require.NoError(app.BankKeeper.MintCoins(ctx, minttypes.ModuleName, initCoins))
require.NoError(app.BankKeeper.SendCoinsFromModuleToModule(ctx, minttypes.ModuleName, types.ModuleName, initCoins))

// self delegate 999 in total ... 1 val with 1uumee is already created in app.Setup
sh.CreateValidatorWithValPower(valAddr1, valPubKey1, 599, true)
sh.CreateValidatorWithValPower(valAddr2, valPubKey2, 398, true)
sh.CreateValidatorWithValPower(valAddr3, valPubKey3, 2, true)

staking.EndBlocker(ctx, app.StakingKeeper)

app.OracleKeeper.SetVoteThreshold(ctx, sdk.MustNewDecFromStr("0.4"))

s.app = app
s.ctx = ctx
s.app, s.ctx, s.keys = integration.SetupAppWithContext(s.T())
s.app.OracleKeeper.SetVoteThreshold(s.ctx, sdk.MustNewDecFromStr("0.4"))
}

// Test addresses
var (
valPubKeys = simtestutil.CreateTestPubKeys(3)

valPubKey1 = valPubKeys[0]
pubKey1 = secp256k1.GenPrivKey().PubKey()
addr1 = sdk.AccAddress(pubKey1.Address())
valAddr1 = sdk.ValAddress(pubKey1.Address())

valPubKey2 = valPubKeys[1]
pubKey2 = secp256k1.GenPrivKey().PubKey()
addr2 = sdk.AccAddress(pubKey2.Address())
valAddr2 = sdk.ValAddress(pubKey2.Address())

valPubKey3 = valPubKeys[2]
pubKey3 = secp256k1.GenPrivKey().PubKey()
addr3 = sdk.AccAddress(pubKey3.Address())
valAddr3 = sdk.ValAddress(pubKey3.Address())

initTokens = sdk.TokensFromConsensusPower(initialPower, sdk.DefaultPowerReduction)
initCoins = sdk.NewCoins(sdk.NewCoin(bondDenom, initTokens))
)

func createVotes(hash string, val sdk.ValAddress, rates sdk.DecCoins, blockHeight uint64) (types.AggregateExchangeRatePrevote, types.AggregateExchangeRateVote) {
preVote := types.AggregateExchangeRatePrevote{
Hash: hash,
Expand All @@ -121,6 +47,7 @@ func createVotes(hash string, val sdk.ValAddress, rates sdk.DecCoins, blockHeigh

func (s *IntegrationTestSuite) TestEndBlockerVoteThreshold() {
app, ctx := s.app, s.ctx
valAddr1, valAddr2, valAddr3 := s.keys[0].ValAddress, s.keys[1].ValAddress, s.keys[2].ValAddress
ctx = ctx.WithBlockHeight(0)
preVoteBlockDiff := int64(app.OracleKeeper.VotePeriod(ctx) / 2)
voteBlockDiff := int64(app.OracleKeeper.VotePeriod(ctx)/2 + 1)
Expand Down Expand Up @@ -253,6 +180,7 @@ func (s *IntegrationTestSuite) TestEndBlockerVoteThreshold() {

func (s *IntegrationTestSuite) TestEndBlockerValidatorRewards() {
app, ctx := s.app, s.ctx
valAddr1, valAddr2, valAddr3 := s.keys[0].ValAddress, s.keys[1].ValAddress, s.keys[2].ValAddress
preVoteBlockDiff := int64(app.OracleKeeper.VotePeriod(ctx) / 2)
voteBlockDiff := int64(app.OracleKeeper.VotePeriod(ctx)/2 + 1)

Expand Down Expand Up @@ -410,6 +338,7 @@ var exchangeRates = map[string][]sdk.Dec{

func (s *IntegrationTestSuite) TestEndblockerHistoracle() {
app, ctx := s.app, s.ctx
valAddr1 := s.keys[0].ValAddress
blockHeight := ctx.BlockHeight()

var historicStampPeriod int64 = 3
Expand Down

0 comments on commit f967be8

Please sign in to comment.