Skip to content

Commit

Permalink
Merge pull request #97 from tellor-io/salt
Browse files Browse the repository at this point in the history
Add e2e and oracle keeper tests
  • Loading branch information
themandalore authored Apr 8, 2024
2 parents 9da9402 + 052d95c commit 81cd875
Show file tree
Hide file tree
Showing 21 changed files with 1,712 additions and 21 deletions.
2 changes: 1 addition & 1 deletion api/layer/dispute/tx.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/layer/dispute/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,4 @@ enum VoteEnum {
VOTE_SUPPORT = 1;
VOTE_AGAINST = 2;
}

778 changes: 778 additions & 0 deletions tests/e2e/e2e_test.go

Large diffs are not rendered by default.

524 changes: 524 additions & 0 deletions tests/e2e/keeper_test.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/integration/oracle_keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,13 +608,13 @@ func (s *IntegrationTestSuite) TestTipQueryNotInCycleListSingleDelegator() {
twoPercent := sdk.NewCoin(s.denom, tipAmount.Mul(math.NewInt(2)).Quo(math.NewInt(100)))
require.Equal(tipAmount.Sub(twoPercent.Amount), escrowBalance.Amount)

// withdraw tip
// create reporterMsgServer
reporterMsgServer := reporterkeeper.NewMsgServerImpl(s.reporterkeeper)
// withdraw tip
_, err = reporterMsgServer.WithdrawTip(s.ctx, &reportertypes.MsgWithdrawTip{DelegatorAddress: repAcc.String(), ValidatorAddress: valAddr.String()})
require.NoError(err)

// delegation shares should increase after reporting and escrow balance should go nback to 0
// delegation shares should increase after reporting and escrow balance should go back to 0
delAfter, err := s.stakingKeeper.Delegation(s.ctx, repAcc.Bytes(), valAddr)
s.Nil(err)
s.True(delAfter.GetShares().Equal(delBefore.GetShares().Add(math.LegacyNewDec(980))), "delegation shares plus the tip added") // 1000 - 2% tip
Expand Down
5 changes: 4 additions & 1 deletion tests/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
disputemodulev1 "github.com/tellor-io/layer/api/layer/dispute/module"
mintmodulev1 "github.com/tellor-io/layer/api/layer/mint/module"
oraclemodulev1 "github.com/tellor-io/layer/api/layer/oracle/module"
mintmodulev1 "github.com/tellor-io/layer/api/layer/registry/module"
registrymodulev1 "github.com/tellor-io/layer/api/layer/registry/module"
reportermodulev1 "github.com/tellor-io/layer/api/layer/reporter/module"
)
Expand Down Expand Up @@ -83,6 +83,9 @@ func RegistryModule() configurator.ModuleOption {

func MintModule() configurator.ModuleOption {
return func(config *configurator.Config) {
// config.BeginBlockersOrder = append(config.BeginBlockersOrder, "mint")
// config.EndBlockersOrder = append(config.EndBlockersOrder, "mint")
// config.InitGenesisOrder = append(config.InitGenesisOrder, "mint")
config.ModuleConfigs["mint"] = &appv1alpha1.ModuleConfig{
Name: "mint",
Config: appconfig.WrapAny(&mintmodulev1.Module{}),
Expand Down
7 changes: 7 additions & 0 deletions x/dispute/keeper/execute_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package keeper_test

func (s *KeeperTestSuite) TestRewardVoters() {
// require := s.Require()

// s.disputeKeeper.RewardVoters(s.ctx, )
}
9 changes: 6 additions & 3 deletions x/mint/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"time"

cosmosmath "cosmossdk.io/math"
"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/telemetry"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/tellor-io/layer/x/mint/keeper"
Expand All @@ -18,6 +18,10 @@ func BeginBlocker(ctx context.Context, k keeper.Keeper) error {

sdkCtx := sdk.UnwrapSDKContext(ctx)
currentTime := sdkCtx.BlockTime()
if currentTime.IsZero() {
// return on invalid block time
return nil
}
if err := mintBlockProvision(sdkCtx, k, currentTime); err != nil {
return err
}
Expand All @@ -31,14 +35,13 @@ func mintBlockProvision(ctx sdk.Context, k keeper.Keeper, currentTime time.Time)
if minter.PreviousBlockTime == nil {
return nil
}

toMintCoin, err := minter.CalculateBlockProvision(currentTime, *minter.PreviousBlockTime)
if err != nil {
return err
}
toMintCoins := sdk.NewCoins(toMintCoin)
// mint coins double half going to team and half to oracle
err = k.MintCoins(ctx, toMintCoins.MulInt(cosmosmath.NewInt(2)))
err = k.MintCoins(ctx, toMintCoins.MulInt(math.NewInt(2)))
if err != nil {
return err
}
Expand Down
14 changes: 12 additions & 2 deletions x/mint/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

// mintmodulev1 "github.com/tellor-io/layer/api/layer/mint/module"
mintmodulev1 "github.com/tellor-io/layer/api/layer/mint/module"
"github.com/tellor-io/layer/x/mint/keeper"
"github.com/tellor-io/layer/x/mint/types"
)
Expand Down Expand Up @@ -148,13 +148,23 @@ func (am AppModule) BeginBlock(ctx context.Context) error {
return BeginBlocker(sdkCtx, am.keeper)
}

// ----------------------------------------------------------------------------
// App Wiring Setup
// ----------------------------------------------------------------------------

func init() {
appmodule.Register(&mintmodulev1.Module{},
appmodule.Provide(ProvideModule))

}

type MintInputs struct {
depinject.In

KvStoreKey *storetypes.KVStoreKey
MemStoreKey *storetypes.MemoryStoreKey
Cdc codec.Codec
// Config *mintmodulev1.Module
Config *mintmodulev1.Module

AccountKeeper types.AccountKeeper
BankKeeper types.BankKeeper
Expand Down
88 changes: 88 additions & 0 deletions x/oracle/keeper/cycle_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package keeper_test

import (
oracletypes "github.com/tellor-io/layer/x/oracle/types"
)

// TODO: fix all of these to match bytes

func (s *KeeperTestSuite) TestGetCycleList() {
// require := s.Require()

// list, err := s.oracleKeeper.GetCyclelist(s.ctx)
// require.NoError(err)
// require.Contains(list, ethQueryData[2:])
// require.Contains(list, btcQueryData[2:])
// require.Contains(list, trbQueryData[2:])
}

func (s *KeeperTestSuite) TestRotateQueries() {
require := s.Require()

// todo: match the bytes
list, err := s.oracleKeeper.GetCyclelist(s.ctx)
require.NoError(err)

// first query from cycle list (trb)
firstQuery, err := s.oracleKeeper.GetCurrentQueryInCycleList(s.ctx)
require.NoError(err)
require.Contains(list, firstQuery)
// require.Equal(firstQuery, trbQueryData[2:])

// second query from cycle list (eth)
err = s.oracleKeeper.RotateQueries(s.ctx)
require.NoError(err)
secondQuery, err := s.oracleKeeper.GetCurrentQueryInCycleList(s.ctx)
require.NoError(err)
require.Contains(list, secondQuery)
// require.Equal(secondQuery, ethQueryData[2:])

// third query from cycle list (btc)
err = s.oracleKeeper.RotateQueries(s.ctx)
require.NoError(err)
thirdQuery, err := s.oracleKeeper.GetCurrentQueryInCycleList(s.ctx)
require.NoError(err)
require.Contains(list, thirdQuery)
// require.Equal(thirdQuery, btcQueryData[2:])

// Rotate through a couple times
for i := 0; i < 10; i++ {
query, err := s.oracleKeeper.GetCurrentQueryInCycleList(s.ctx)
require.NoError(err)
err = s.oracleKeeper.RotateQueries(s.ctx)
require.NoError(err)
require.Contains(list, query)
}
}

func (s *KeeperTestSuite) TestInitCycleListQuery() {
// require := s.Require()

// startingList, err := s.oracleKeeper.GetCyclelist(s.ctx)
// require.NoError(err)
// require.Contains(startingList, ethQueryData)
// require.Contains(startingList, btcQueryData)
// require.Contains(startingList, trbQueryData)
// newQueryData := "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706f745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003657469000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"

// s.oracleKeeper.InitCycleListQuery(s.ctx, []string{newQueryData})
// newList, err := s.oracleKeeper.GetCyclelist(s.ctx)
// fmt.Println(newList)
// require.NoError(err)
// require.Contains(newList, newQueryData)
}

func (s *KeeperTestSuite) TestGenesisCycleList() {
require := s.Require()

err := s.oracleKeeper.GenesisCycleList(s.ctx, oracletypes.InitialCycleList())
require.NoError(err)

cycleList, err := s.oracleKeeper.GetCyclelist(s.ctx)
require.NoError(err)
_ = cycleList
// require.Contains(cycleList, ethQueryData[2:])
// require.Contains(cycleList, btcQueryData[2:])
// require.Contains(cycleList, trbQueryData[2:])

}
6 changes: 6 additions & 0 deletions x/oracle/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import (
keepertest "github.com/tellor-io/layer/testutil/keeper"
)

const (
trbQueryData = "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706f745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003747262000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"
ethQueryData = "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706f745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003657468000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"
btcQueryData = "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706f745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003627463000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"
)

type KeeperTestSuite struct {
suite.Suite

Expand Down
9 changes: 5 additions & 4 deletions x/oracle/keeper/msg_server_submit_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
)

func (s *KeeperTestSuite) TestSubmitValue() (reportertypes.OracleReporter, []byte) {
require := s.Require()
value := "000000000000000000000000000000000000000000000058528649cf80ee0000"
// Commit value transaction first
// Commit
stakedReporter, salt, queryData := s.TestCommitValue()
// forward block by 1 and reveal value
s.ctx = s.ctx.WithBlockHeight(s.ctx.BlockHeight() + 1)
Expand All @@ -29,8 +30,8 @@ func (s *KeeperTestSuite) TestSubmitValue() (reportertypes.OracleReporter, []byt
Salt: salt,
}
res, err := s.msgServer.SubmitValue(s.ctx, &submitreq)
s.Nil(err)
s.Equal(&types.MsgSubmitValueResponse{}, res)
require.NoError(err)
require.Equal(&types.MsgSubmitValueResponse{}, res)

queryId := utils.QueryIDFromData(queryData)
report, err := s.queryClient.GetReportsbyQid(s.ctx, &types.QueryGetReportsbyQidRequest{QueryId: queryId})
Expand All @@ -52,7 +53,7 @@ func (s *KeeperTestSuite) TestSubmitValue() (reportertypes.OracleReporter, []byt
MicroReports: []*types.MicroReport{&microReport},
},
}
s.Equal(&expectedReport, report)
require.Equal(&expectedReport, report)

return stakedReporter, queryId
}
Expand Down
74 changes: 74 additions & 0 deletions x/oracle/keeper/msg_server_tip_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package keeper_test

func (s *KeeperTestSuite) TestTip() {
// require := s.Require()

// queryData := "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706F745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003657468000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"
// tip := sdk.NewCoin("loya", math.NewInt(1000))
// msg := types.MsgTip{
// Tipper: Addr.String(),
// QueryData: queryData,
// Amount: tip,
// }
// _, err := s.msgServer.Tip(s.ctx, &msg)
// require.NoError(err)

}

func (s *KeeperTestSuite) TestTipWithInvalidDenom() {
// require := s.Require()

// queryData := "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706F745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003657468000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"
// tip := sdk.NewCoin("invalidDenom", math.NewInt(1000))
// msg := types.MsgTip{
// Tipper: Addr.String(),
// QueryData: queryData,
// Amount: tip,
// }
// _, err := s.msgServer.Tip(s.ctx, &msg)
// require.ErrorContains(err, "invalid request")
}

func (s *KeeperTestSuite) TestTipWithZeroAmount() {
// require := s.Require()

// queryData := "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706F745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003657468000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"
// tip := sdk.NewCoin("loya", math.NewInt(0))
// msg := types.MsgTip{
// Tipper: Addr.String(),
// QueryData: queryData,
// Amount: tip,
// }
// _, err := s.msgServer.Tip(s.ctx, &msg)
// require.ErrorContains(err, "invalid request")
}

func (s *KeeperTestSuite) TestTipWithNegativeAmount() {
// require := s.Require()

// queryData := "0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000953706F745072696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C0000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000003657468000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000037573640000000000000000000000000000000000000000000000000000000000"
// require.Panics(func() {
// tip := sdk.NewCoin("loya", math.NewInt(-1000))
// msg := types.MsgTip{
// Tipper: Addr.String(),
// QueryData: queryData,
// Amount: tip,
// }
// _, _ = s.msgServer.Tip(s.ctx, &msg)
// }, "negative coin amount should panic")
}

func (s *KeeperTestSuite) TestTipWithInvalidQueryData() {
// require := s.Require()

// queryData := "badQueryData"
// tip := sdk.NewCoin("loya", math.NewInt(1000))
// msg := types.MsgTip{
// Tipper: Addr.String(),
// QueryData: queryData,
// Amount: tip,
// }
// _, err := s.msgServer.Tip(s.ctx, &msg)
// require.Error(err)
// require.Panics(func() { _, _ = s.msgServer.Tip(s.ctx, &msg) }, "invalid query data should panic")
}
Loading

0 comments on commit 81cd875

Please sign in to comment.