[tests] Use sample.Machine()

Signed-off-by: Julian Strobl <jmastr@mailbox.org>
This commit is contained in:
Julian Strobl 2023-07-19 08:02:31 +02:00
parent 5a435575b5
commit 18ce58f139
No known key found for this signature in database
GPG Key ID: E0A8F9AD733499A7
6 changed files with 21 additions and 61 deletions

View File

@ -14,8 +14,6 @@ import (
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
machinetypes "planetmint-go/x/machine/types"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
@ -72,20 +70,7 @@ func (s *E2ETestSuite) SetupSuite() {
s.Require().NoError(s.network.WaitForNextBlock())
machine := machinetypes.Machine{
Name: "machine",
Ticker: "machine_ticker",
Issued: 1,
Amount: 1000,
Precision: 8,
IssuerPlanetmint: pkHex,
IssuerLiquid: pkHex,
MachineId: pkHex,
Metadata: &machinetypes.Metadata{
AdditionalDataCID: "CID",
Gps: "{\"Latitude\":\"-48.876667\",\"Longitude\":\"-123.393333\"}",
},
}
machine := sample.Machine("machine", pkHex)
machineJSON, err := json.Marshal(&machine)
s.Require().NoError(err)

View File

@ -3,6 +3,7 @@ package machine
import (
"fmt"
"planetmint-go/testutil"
"planetmint-go/testutil/sample"
machinetypes "planetmint-go/x/machine/types"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
@ -20,21 +21,7 @@ func (s *E2ETestSuite) TestAttestMachineREST() {
s.Require().NoError(err)
// Create Attest Machine TX
machine := machinetypes.Machine{
Name: "machine",
Ticker: "machine_ticker",
Issued: 1,
Amount: 1000,
Precision: 8,
IssuerPlanetmint: pubKey,
IssuerLiquid: pubKey,
MachineId: pubKey,
Metadata: &machinetypes.Metadata{
AdditionalDataCID: "CID",
Gps: "{\"Latitude\":\"-48.876667\",\"Longitude\":\"-123.393333\"}",
},
}
machine := sample.Machine("machine", pubKey)
msg := machinetypes.MsgAttestMachine{
Creator: addr.String(),
Machine: &machine,

View File

@ -5,6 +5,7 @@ import (
"fmt"
clitestutil "planetmint-go/testutil/cli"
"planetmint-go/testutil/network"
"planetmint-go/testutil/sample"
machinecli "planetmint-go/x/machine/client/cli"
"github.com/cosmos/cosmos-sdk/client/flags"
@ -13,8 +14,6 @@ import (
bank "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
"github.com/stretchr/testify/suite"
machinetypes "planetmint-go/x/machine/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)
@ -71,20 +70,7 @@ func (s *E2ETestSuite) TearDownSuite() {
func (s *E2ETestSuite) TestAttestMachine() {
val := s.network.Validators[0]
machine := machinetypes.Machine{
Name: "machine",
Ticker: "machine_ticker",
Issued: 1,
Amount: 1000,
Precision: 8,
IssuerPlanetmint: pubKey,
IssuerLiquid: pubKey,
MachineId: pubKey,
Metadata: &machinetypes.Metadata{
AdditionalDataCID: "CID",
Gps: "{\"Latitude\":\"-48.876667\",\"Longitude\":\"-123.393333\"}",
},
}
machine := sample.Machine("machine", pubKey)
machineJSON, err := json.Marshal(&machine)
s.Require().NoError(err)

View File

@ -48,11 +48,11 @@ func AssetKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
ctrl := gomock.NewController(t)
mk := assettestutils.NewMockMachineKeeper(ctrl)
sk, pk := sample.KeyPair()
id := sample.MachineIndex(pk, pk, pk)
id := sample.MachineIndex(pk)
mk.EXPECT().GetMachineIndex(ctx, pk).Return(id, true).AnyTimes()
mk.EXPECT().GetMachineIndex(ctx, sk).Return(id, false).AnyTimes()
mk.EXPECT().GetMachine(ctx, id).Return(sample.Machine(pk, pk, pk), true).AnyTimes()
mk.EXPECT().GetMachine(ctx, sk).Return(sample.Machine(pk, pk, pk), false).AnyTimes()
mk.EXPECT().GetMachine(ctx, id).Return(sample.Machine(pk, pk), true).AnyTimes()
mk.EXPECT().GetMachine(ctx, sk).Return(sample.Machine(pk, pk), false).AnyTimes()
k := keeper.NewKeeper(
cdc,

View File

@ -26,25 +26,27 @@ func AccAddress() string {
return sdk.AccAddress(addr).String()
}
func Machine(machineId string, pkPM string, pkL string) machinetypes.Machine {
func Machine(name, pubKey string) machinetypes.Machine {
metadata := Metadata()
m := machinetypes.Machine{
Name: "machine",
Ticker: "PM",
Name: name,
Ticker: name + "_ticker",
Issued: 1,
Amount: 1000,
Precision: 8,
IssuerPlanetmint: pkPM,
IssuerLiquid: pkL,
MachineId: machineId,
IssuerPlanetmint: pubKey,
IssuerLiquid: pubKey,
MachineId: pubKey,
Metadata: &metadata,
}
return m
}
func MachineIndex(machineId string, pkPM string, pkL string) machinetypes.MachineIndex {
func MachineIndex(pubKey string) machinetypes.MachineIndex {
return machinetypes.MachineIndex{
MachineId: machineId,
IssuerPlanetmint: pkPM,
IssuerLiquid: pkL,
MachineId: pubKey,
IssuerPlanetmint: pubKey,
IssuerLiquid: pubKey,
}
}

View File

@ -28,7 +28,7 @@ func TestMsgServer(t *testing.T) {
func TestMsgServerAttestMachine(t *testing.T) {
_, pk := sample.KeyPair()
machine := sample.Machine(pk, pk, pk)
machine := sample.Machine(pk, pk)
msg := types.NewMsgAttestMachine(pk, &machine)
msgServer, ctx := setupMsgServer(t)
res, err := msgServer.AttestMachine(ctx, msg)