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

feat: Add apptesting #12

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
71 changes: 71 additions & 0 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package apptesting

import (
"time"

"github.com/cometbft/cometbft/crypto/ed25519"
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
"github.com/stretchr/testify/suite"

"github.com/onomyprotocol/reserve/app"
)

type KeeperTestHelper struct {
suite.Suite

App *app.App
Ctx sdk.Context
TestAccs []sdk.AccAddress
}

var (
baseTestAccts = []sdk.AccAddress{}
defaultTestStartTime = time.Now().UTC()
)

// CreateRandomAccounts is a function return a list of randomly generated AccAddresses
func CreateRandomAccounts(numAccts int) []sdk.AccAddress {
testAddrs := make([]sdk.AccAddress, numAccts)
for i := 0; i < numAccts; i++ {
pk := ed25519.GenPrivKey().PubKey()
testAddrs[i] = sdk.AccAddress(pk.Address())
}

return testAddrs
}

func init() {
baseTestAccts = CreateRandomAccounts(3)
}

func (s *KeeperTestHelper) Setup() {
s.App = app.Setup(s.T(), false)
s.Ctx = s.App.BaseApp.NewContextLegacy(false, cmtproto.Header{Height: 1, ChainID: s.App.ChainID(), Time: defaultTestStartTime})

vals, err := s.App.StakingKeeper.GetAllValidators(s.Ctx)

s.TestAccs = []sdk.AccAddress{}
s.TestAccs = append(s.TestAccs, baseTestAccts...)
if err != nil {
panic(err)
}
for _, val := range vals {
var consAddr sdk.ConsAddress
consAddr, _ = val.GetConsAddr()
// newConsAddr := sdk.ConsAddress(pubkey.Address().Bytes())
signingInfo := slashingtypes.NewValidatorSigningInfo(
consAddr,
s.Ctx.BlockHeight(),
0,
time.Unix(0, 0),
false,
0,
)
err := s.App.SlashingKeeper.SetValidatorSigningInfo(s.Ctx, consAddr, signingInfo)
if err != nil {
panic(err)
}
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/errors v1.0.1
cosmossdk.io/log v1.3.1
cosmossdk.io/math v1.3.0
cosmossdk.io/store v1.0.2
cosmossdk.io/tools/confix v0.1.1
cosmossdk.io/x/circuit v0.1.0
Expand Down Expand Up @@ -55,7 +56,6 @@ require (
connectrpc.com/connect v1.15.0 // indirect
connectrpc.com/otelconnect v0.7.0 // indirect
cosmossdk.io/collections v0.4.0 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/x/tx v0.13.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
Expand Down