planetmint-go/x/dao/keeper/challenge_test.go
Julian Strobl 5b25d4cefc
Improve linter setup (#186)
* [linter] Add `musttag`

Enforce field tags in (un)marshaled structs.

* [linter] Add `nestif`

Reports deeply nested if statements.

* [linter] Add `noctx`

Finds sending http request without context.Context.

* [linter] Add `paralleltest`

Paralleltest detects missing usage of t.Parallel() method in your Go
test.

* [linter] Add `tagalign`

Check that struct tags are well aligned.

* [linter] Add `tagliatelle`

Checks the struct tags.

* [linter] Add `whitespace`

Tool for detection of leading and trailing whitespace.

* [paralleltest] Exclude files bc of data race in tests

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
2023-11-17 10:56:25 +01:00

39 lines
1.1 KiB
Go

package keeper_test
import (
"fmt"
"testing"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/stretchr/testify/assert"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/planetmint/planetmint-go/x/dao/keeper"
"github.com/planetmint/planetmint-go/x/dao/types"
)
func createNChallenge(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Challenge {
items := make([]types.Challenge, n)
for i := range items {
items[i].Height = uint64(i)
items[i].Initiator = fmt.Sprintf("initiator%v", i)
items[i].Challenger = fmt.Sprintf("challenger%v", i)
items[i].Challengee = fmt.Sprintf("challengee%v", i)
items[i].Success = true
items[i].Description = fmt.Sprintf("expected %v got %v", i, i)
keeper.StoreChallenge(ctx, items[i])
}
return items
}
func TestGetChallenge(t *testing.T) {
t.Parallel()
keeper, ctx := keepertest.DaoKeeper(t)
items := createNChallenge(keeper, ctx, 10)
for _, item := range items {
challenge, found := keeper.GetChallenge(ctx, item.Height)
assert.True(t, found)
assert.Equal(t, item, challenge)
}
}