planetmint-go/x/asset/keeper/msg_server_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

48 lines
1.3 KiB
Go

package keeper_test
import (
"context"
"encoding/hex"
"testing"
"github.com/planetmint/planetmint-go/config"
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
"github.com/planetmint/planetmint-go/testutil/sample"
"github.com/planetmint/planetmint-go/x/asset/keeper"
"github.com/planetmint/planetmint-go/x/asset/types"
"github.com/btcsuite/btcd/btcutil/hdkeychain"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func setupMsgServer(t testing.TB) (types.MsgServer, context.Context) {
k, ctx := keepertest.AssetKeeper(t)
return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx)
}
func TestMsgServer(t *testing.T) {
t.Parallel()
ms, ctx := setupMsgServer(t)
require.NotNil(t, ms)
require.NotNil(t, ctx)
}
func TestMsgServerNotarizeAsset(t *testing.T) {
t.Parallel()
extSk, _ := sample.ExtendedKeyPair(config.PlmntNetParams)
xskKey, _ := hdkeychain.NewKeyFromString(extSk)
privKey, _ := xskKey.ECPrivKey()
byteKey := privKey.Serialize()
sk := hex.EncodeToString(byteKey)
cid := sample.Asset()
msg := types.NewMsgNotarizeAsset(sk, cid)
msgServer, ctx := setupMsgServer(t)
res, err := msgServer.NotarizeAsset(ctx, msg)
if assert.NoError(t, err) {
assert.Equal(t, &types.MsgNotarizeAssetResponse{}, res)
}
}