mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-06-01 19:56:39 +00:00

* [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>
63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"strconv"
|
|
"testing"
|
|
|
|
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
|
"github.com/planetmint/planetmint-go/x/asset/keeper"
|
|
"github.com/planetmint/planetmint-go/x/asset/types"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func createNAsset(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.MsgNotarizeAsset {
|
|
items := make([]types.MsgNotarizeAsset, n)
|
|
for i := range items {
|
|
hash := sha256.Sum256([]byte(strconv.FormatInt(int64(i), 2)))
|
|
hashStr := string(hash[:])
|
|
items[i].Cid = hashStr
|
|
items[i].Creator = "plmnt_address"
|
|
if i%2 == 0 {
|
|
items[i].Creator = "plmnt_address1"
|
|
}
|
|
keeper.StoreAsset(ctx, items[i])
|
|
}
|
|
return items
|
|
}
|
|
|
|
func TestGetAsset(t *testing.T) {
|
|
t.Parallel()
|
|
keeper, ctx := keepertest.AssetKeeper(t)
|
|
items := createNAsset(keeper, ctx, 10)
|
|
for _, item := range items {
|
|
asset, found := keeper.GetAsset(ctx, item.Cid)
|
|
assert.True(t, found)
|
|
assert.Equal(t, item, asset)
|
|
}
|
|
}
|
|
func TestGetCids(t *testing.T) {
|
|
t.Parallel()
|
|
keeper, ctx := keepertest.AssetKeeper(t)
|
|
items := createNAsset(keeper, ctx, 10)
|
|
for _, item := range items {
|
|
asset, found := keeper.GetAsset(ctx, item.Cid)
|
|
assert.True(t, found)
|
|
assert.Equal(t, item, asset)
|
|
}
|
|
}
|
|
|
|
func TestGetAssetByPubKeys(t *testing.T) {
|
|
t.Parallel()
|
|
keeper, ctx := keepertest.AssetKeeper(t)
|
|
_ = createNAsset(keeper, ctx, 10)
|
|
assets, found := keeper.GetCidsByAddress(ctx, "plmnt_address")
|
|
assert.True(t, found)
|
|
assert.Equal(t, len(assets), 5)
|
|
assets, found = keeper.GetCidsByAddress(ctx, "plmnt_address1")
|
|
assert.True(t, found)
|
|
assert.Equal(t, len(assets), 5)
|
|
}
|