diff --git a/app/apptesting/test_suite.go b/app/apptesting/test_suite.go new file mode 100644 index 0000000..4f6d15c --- /dev/null +++ b/app/apptesting/test_suite.go @@ -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) + } + } +} diff --git a/go.mod b/go.mod index 7c73d6b..a499b6a 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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