mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-05-22 23:06:42 +00:00

This is the quasi-standard and fixes the error below: ``` $ go get -u github.com/planetmint/planetmint-go@v0.1.0 go: github.com/planetmint/planetmint-go@v0.1.0: parsing go.mod: module declares its path as: planetmint-go but was required as: github.com/planetmint/planetmint-go ``` Signed-off-by: Julian Strobl <jmastr@mailbox.org>
92 lines
2.8 KiB
Go
92 lines
2.8 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
|
"github.com/planetmint/planetmint-go/x/machine/keeper"
|
|
"github.com/planetmint/planetmint-go/x/machine/types"
|
|
|
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
|
|
|
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.MachineKeeper(t)
|
|
return keeper.NewMsgServerImpl(*k), sdk.WrapSDKContext(ctx)
|
|
}
|
|
|
|
func TestMsgServer(t *testing.T) {
|
|
ms, ctx := setupMsgServer(t)
|
|
require.NotNil(t, ms)
|
|
require.NotNil(t, ctx)
|
|
}
|
|
|
|
func TestMsgServerAttestMachine(t *testing.T) {
|
|
sk, pk := sample.KeyPair()
|
|
ta := sample.TrustAnchor(pk)
|
|
taMsg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
|
machine := sample.Machine(pk, pk, sk)
|
|
msg := types.NewMsgAttestMachine(pk, &machine)
|
|
msgServer, ctx := setupMsgServer(t)
|
|
_, err := msgServer.RegisterTrustAnchor(ctx, taMsg)
|
|
assert.NoError(t, err)
|
|
res, err := msgServer.AttestMachine(ctx, msg)
|
|
if assert.NoError(t, err) {
|
|
assert.Equal(t, &types.MsgAttestMachineResponse{}, res)
|
|
}
|
|
}
|
|
|
|
func TestMsgServerAttestMachineInvalidLiquidKey(t *testing.T) {
|
|
sk, pk := sample.KeyPair()
|
|
ta := sample.TrustAnchor(pk)
|
|
taMsg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
|
machine := sample.Machine(pk, pk, sk)
|
|
machine.IssuerLiquid = "invalidkey"
|
|
msg := types.NewMsgAttestMachine(pk, &machine)
|
|
msgServer, ctx := setupMsgServer(t)
|
|
_, err := msgServer.RegisterTrustAnchor(ctx, taMsg)
|
|
assert.NoError(t, err)
|
|
_, err = msgServer.AttestMachine(ctx, msg)
|
|
assert.EqualError(t, err, "invalid liquid key")
|
|
}
|
|
|
|
func TestMsgServerRegisterTrustAnchor(t *testing.T) {
|
|
_, pk := sample.KeyPair()
|
|
ta := sample.TrustAnchor(pk)
|
|
msg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
|
msgServer, ctx := setupMsgServer(t)
|
|
res, err := msgServer.RegisterTrustAnchor(ctx, msg)
|
|
if assert.NoError(t, err) {
|
|
assert.Equal(t, &types.MsgRegisterTrustAnchorResponse{}, res)
|
|
}
|
|
}
|
|
|
|
func TestMsgServerRegisterTrustAnchorTwice(t *testing.T) {
|
|
_, pk := sample.KeyPair()
|
|
ta := sample.TrustAnchor(pk)
|
|
msg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
|
msgServer, ctx := setupMsgServer(t)
|
|
res, err := msgServer.RegisterTrustAnchor(ctx, msg)
|
|
if assert.NoError(t, err) {
|
|
assert.Equal(t, &types.MsgRegisterTrustAnchorResponse{}, res)
|
|
}
|
|
_, err = msgServer.RegisterTrustAnchor(ctx, msg)
|
|
assert.EqualError(t, err, "trust anchor is already registered")
|
|
}
|
|
|
|
func TestMsgServerRegisterTrustAnchorInvalidPubkey(t *testing.T) {
|
|
_, pk := sample.KeyPair()
|
|
ta := types.TrustAnchor{
|
|
Pubkey: "invalidpublickey",
|
|
}
|
|
msg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
|
msgServer, ctx := setupMsgServer(t)
|
|
_, err := msgServer.RegisterTrustAnchor(ctx, msg)
|
|
assert.EqualError(t, err, "invalid trust anchor pubkey")
|
|
}
|