Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add e2e and oracle keeper tests #97

Merged
merged 41 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
14b570f
add oracle keeper tests, remove printlns from functions
danflo27 Feb 5, 2024
2086bde
merge main
danflo27 Feb 5, 2024
2399a71
oracle keeper tests
danflo27 Feb 7, 2024
88d8025
add tests
danflo27 Feb 9, 2024
c65cf33
add module.proto, module.pulsar.go
danflo27 Feb 9, 2024
e6e97a6
tests
danflo27 Feb 9, 2024
a0ed711
Merge branch 'main' into salt
akremstudy Feb 13, 2024
e21a154
fix some tests including e2e test
akremstudy Feb 13, 2024
ca65dca
mint troubles
danflo27 Feb 13, 2024
6da11af
e2e tests
danflo27 Feb 14, 2024
c4478de
TestInitialMint, TestTransfer, TestStake
danflo27 Feb 14, 2024
7d7b0ee
tests
danflo27 Feb 15, 2024
78cfd65
endblock err
danflo27 Feb 15, 2024
60a2e49
tests
danflo27 Feb 27, 2024
92751b0
merge main into salt
danflo27 Mar 3, 2024
e02f5d8
merge main, chain starts
danflo27 Mar 3, 2024
883d419
comment out e2e staking test
danflo27 Mar 12, 2024
14fd75d
e2e tests
danflo27 Mar 14, 2024
508249e
clean up e2e tests
danflo27 Mar 14, 2024
438b7c9
fix/commented failing tests
danflo27 Mar 14, 2024
761abae
add reporter module to e2e suite
danflo27 Mar 18, 2024
16000ba
setup delegator reporter validator in e2e suite
danflo27 Mar 19, 2024
84edc23
organize
danflo27 Mar 21, 2024
73466c6
Merge branch 'main' into salt
danflo27 Mar 21, 2024
2d7c3e3
tests need fixed
danflo27 Mar 21, 2024
4ad94b1
oracle and e2e test cleanup
danflo27 Mar 22, 2024
9c907a9
Merge remote-tracking branch 'origin' into salt
danflo27 Mar 22, 2024
70b3f91
mint module not getting registered in e2e suite i think
danflo27 Mar 25, 2024
ee1022b
minor test cleanup
danflo27 Mar 26, 2024
7b5fa91
update delegation test
danflo27 Mar 26, 2024
b2d24fd
TestBasicReport failing
danflo27 Mar 27, 2024
4df1438
passing full report test
danflo27 Mar 28, 2024
eb11712
trying to track tbr
danflo27 Apr 1, 2024
2e846ff
fix block no.
danflo27 Apr 1, 2024
df46bde
errors on withdrawing tip
danflo27 Apr 3, 2024
0034ce0
merge main into salt
danflo27 Apr 3, 2024
06bcce1
error on WithdrawTip
danflo27 Apr 4, 2024
031849f
clean up
danflo27 Apr 4, 2024
8295204
tip/commit/reveal/claim rewards test
danflo27 Apr 5, 2024
a504a7a
random cleanup
danflo27 Apr 5, 2024
052d95c
readd bsearch test
danflo27 Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading