mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-11-26 07:25:46 +00:00
refactored testutils to have sample types and samples objects by keepers seperated
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
4dcf32a86b
commit
5e45084f0b
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/planetmint/planetmint-go/lib"
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||||
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||||
"github.com/planetmint/planetmint-go/testutil/network"
|
"github.com/planetmint/planetmint-go/testutil/network"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
||||||
@ -155,7 +156,7 @@ func (s *GasConsumptionE2ETestSuite) TestNetworkBasedTxGasLimit() {
|
|||||||
var msgs []sdk.Msg
|
var msgs []sdk.Msg
|
||||||
|
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
mintRequest := sample.MintRequest(s.minterAddr.String(), 1, "hash"+strconv.Itoa(i))
|
mintRequest := moduleobject.MintRequest(s.minterAddr.String(), 1, "hash"+strconv.Itoa(i))
|
||||||
msg := daotypes.NewMsgMintToken(s.minterAddr.String(), &mintRequest)
|
msg := daotypes.NewMsgMintToken(s.minterAddr.String(), &mintRequest)
|
||||||
msgs = append(msgs, msg)
|
msgs = append(msgs, msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import (
|
|||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||||
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ func (s *E2ETestSuite) TearDownSuite() {
|
|||||||
func (s *E2ETestSuite) TestMintToken() {
|
func (s *E2ETestSuite) TestMintToken() {
|
||||||
val := s.network.Validators[0]
|
val := s.network.Validators[0]
|
||||||
|
|
||||||
mintRequest := sample.MintRequest(s.aliceAddr.String(), 1000, "hash")
|
mintRequest := moduleobject.MintRequest(s.aliceAddr.String(), 1000, "hash")
|
||||||
msg1 := daotypes.NewMsgMintToken(val.Address.String(), &mintRequest)
|
msg1 := daotypes.NewMsgMintToken(val.Address.String(), &mintRequest)
|
||||||
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|||||||
@ -15,6 +15,8 @@ import (
|
|||||||
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
e2etestutil "github.com/planetmint/planetmint-go/testutil/e2e"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||||
)
|
)
|
||||||
|
|
||||||
// E2ETestSuite struct definition of machine suite
|
// E2ETestSuite struct definition of machine suite
|
||||||
@ -57,7 +59,7 @@ func (s *E2ETestSuite) TestAttestMachine() {
|
|||||||
// register Ta
|
// register Ta
|
||||||
prvKey, pubKey := sample.KeyPair()
|
prvKey, pubKey := sample.KeyPair()
|
||||||
|
|
||||||
ta := sample.TrustAnchor(pubKey)
|
ta := moduleobject.TrustAnchor(pubKey)
|
||||||
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||||
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
out, err := e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
@ -72,7 +74,7 @@ func (s *E2ETestSuite) TestAttestMachine() {
|
|||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
addr, _ := k.GetAddress()
|
addr, _ := k.GetAddress()
|
||||||
|
|
||||||
machine := sample.Machine(sample.Name, pubKey, prvKey, addr.String())
|
machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||||
msg2 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
msg2 := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||||
out, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg2)
|
out, err = e2etestutil.BuildSignBroadcastTx(s.T(), addr, msg2)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
@ -105,7 +107,7 @@ func (s *E2ETestSuite) TestInvalidAttestMachine() {
|
|||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
addr, _ := k.GetAddress()
|
addr, _ := k.GetAddress()
|
||||||
|
|
||||||
machine := sample.Machine(sample.Name, pubKey, prvKey, addr.String())
|
machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
msg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
msg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||||
@ -115,7 +117,7 @@ func (s *E2ETestSuite) TestInvalidAttestMachine() {
|
|||||||
s.Require().Equal(int(txResponse.Code), int(4))
|
s.Require().Equal(int(txResponse.Code), int(4))
|
||||||
|
|
||||||
unregisteredPubKey, unregisteredPrivKey := sample.KeyPair(2)
|
unregisteredPubKey, unregisteredPrivKey := sample.KeyPair(2)
|
||||||
machine = sample.Machine(sample.Name, unregisteredPubKey, unregisteredPrivKey, addr.String())
|
machine = moduleobject.Machine(sample.Name, unregisteredPubKey, unregisteredPrivKey, addr.String())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
msg = machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
msg = machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||||
@ -139,7 +141,7 @@ func (s *E2ETestSuite) TestMachineAllowanceAttestation() {
|
|||||||
// register TA
|
// register TA
|
||||||
prvKey, pubKey := sample.KeyPair(3)
|
prvKey, pubKey := sample.KeyPair(3)
|
||||||
|
|
||||||
ta := sample.TrustAnchor(pubKey)
|
ta := moduleobject.TrustAnchor(pubKey)
|
||||||
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
msg1 := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||||
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
_, err = e2etestutil.BuildSignBroadcastTx(s.T(), val.Address, msg1)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
@ -163,7 +165,7 @@ func (s *E2ETestSuite) TestMachineAllowanceAttestation() {
|
|||||||
s.Require().NoError(s.network.WaitForNextBlock())
|
s.Require().NoError(s.network.WaitForNextBlock())
|
||||||
|
|
||||||
// attest machine with fee granter without funding the machine account first
|
// attest machine with fee granter without funding the machine account first
|
||||||
machine := sample.Machine(sample.Name, pubKey, prvKey, addr.String())
|
machine := moduleobject.Machine(sample.Name, pubKey, prvKey, addr.String())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
// name and address of private key with which to sign
|
// name and address of private key with which to sign
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import (
|
|||||||
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
|
||||||
"github.com/planetmint/planetmint-go/lib"
|
"github.com/planetmint/planetmint-go/lib"
|
||||||
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
clitestutil "github.com/planetmint/planetmint-go/testutil/cli"
|
||||||
|
moduleobjects "github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||||
"github.com/planetmint/planetmint-go/testutil/network"
|
"github.com/planetmint/planetmint-go/testutil/network"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||||
@ -75,8 +76,7 @@ func AttestMachine(network *network.Network, name string, mnemonic string, num i
|
|||||||
|
|
||||||
// register Ta
|
// register Ta
|
||||||
prvKey, pubKey := sample.KeyPair(num)
|
prvKey, pubKey := sample.KeyPair(num)
|
||||||
|
ta := moduleobjects.TrustAnchor(pubKey)
|
||||||
ta := sample.TrustAnchor(pubKey)
|
|
||||||
registerMsg := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
registerMsg := machinetypes.NewMsgRegisterTrustAnchor(val.Address.String(), &ta)
|
||||||
_, err = lib.BroadcastTxWithFileLock(val.Address, registerMsg)
|
_, err = lib.BroadcastTxWithFileLock(val.Address, registerMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -92,7 +92,7 @@ func AttestMachine(network *network.Network, name string, mnemonic string, num i
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
machine := sample.Machine(name, pubKey, prvKey, addr.String())
|
machine := moduleobjects.Machine(name, pubKey, prvKey, addr.String())
|
||||||
attestMsg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
attestMsg := machinetypes.NewMsgAttestMachine(addr.String(), &machine)
|
||||||
_, err = lib.BroadcastTxWithFileLock(addr, attestMsg)
|
_, err = lib.BroadcastTxWithFileLock(addr, attestMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package sample
|
package errormsg
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrorInvalidAddress = "invalid_address"
|
ErrorInvalidAddress = "invalid_address"
|
||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/planetmint/planetmint-go/config"
|
"github.com/planetmint/planetmint-go/config"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
"github.com/planetmint/planetmint-go/x/asset/keeper"
|
"github.com/planetmint/planetmint-go/x/asset/keeper"
|
||||||
"github.com/planetmint/planetmint-go/x/asset/types"
|
"github.com/planetmint/planetmint-go/x/asset/types"
|
||||||
@ -49,15 +50,15 @@ func AssetKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
|
|||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
mk := assettestutils.NewMockMachineKeeper(ctrl)
|
mk := assettestutils.NewMockMachineKeeper(ctrl)
|
||||||
sk, pk := sample.KeyPair()
|
sk, pk := sample.KeyPair()
|
||||||
_, ppk := sample.ExtendedKeyPair(config.PlmntNetParams)
|
_, ppk := moduleobject.ExtendedKeyPair(config.PlmntNetParams)
|
||||||
_, lpk := sample.ExtendedKeyPair(config.LiquidNetParams)
|
_, lpk := moduleobject.ExtendedKeyPair(config.LiquidNetParams)
|
||||||
|
|
||||||
id := sample.MachineIndex(pk, ppk, lpk)
|
id := moduleobject.MachineIndex(pk, ppk, lpk)
|
||||||
mk.EXPECT().GetMachineIndexByPubKey(ctx, pk).Return(id, true).AnyTimes()
|
mk.EXPECT().GetMachineIndexByPubKey(ctx, pk).Return(id, true).AnyTimes()
|
||||||
mk.EXPECT().GetMachineIndexByPubKey(ctx, ppk).Return(id, true).AnyTimes()
|
mk.EXPECT().GetMachineIndexByPubKey(ctx, ppk).Return(id, true).AnyTimes()
|
||||||
mk.EXPECT().GetMachineIndexByPubKey(ctx, sk).Return(id, false).AnyTimes()
|
mk.EXPECT().GetMachineIndexByPubKey(ctx, sk).Return(id, false).AnyTimes()
|
||||||
mk.EXPECT().GetMachine(ctx, id).Return(sample.Machine(pk, pk, sk, ""), true).AnyTimes()
|
mk.EXPECT().GetMachine(ctx, id).Return(moduleobject.Machine(pk, pk, sk, ""), true).AnyTimes()
|
||||||
mk.EXPECT().GetMachine(ctx, sk).Return(sample.Machine(pk, pk, sk, ""), false).AnyTimes()
|
mk.EXPECT().GetMachine(ctx, sk).Return(moduleobject.Machine(pk, pk, sk, ""), false).AnyTimes()
|
||||||
|
|
||||||
k := keeper.NewKeeper(
|
k := keeper.NewKeeper(
|
||||||
cdc,
|
cdc,
|
||||||
|
|||||||
98
testutil/moduleobject/sampleobject.go
Normal file
98
testutil/moduleobject/sampleobject.go
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
package moduleobject
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/hex"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
||||||
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
|
"github.com/planetmint/planetmint-go/config"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
|
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
||||||
|
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
|
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||||
|
"github.com/cosmos/go-bip39"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ExtendedKeyPair(cfg chaincfg.Params) (string, string) {
|
||||||
|
seed, err := bip39.NewSeedWithErrorChecking(sample.Mnemonic, keyring.DefaultBIP39Passphrase)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
xprivKey, err := hdkeychain.NewMaster(seed, &cfg)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
xpubKey, err := xprivKey.Neuter()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return xprivKey.String(), xpubKey.String()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Machine creates a new machine object
|
||||||
|
// TODO: make address deterministic for test cases
|
||||||
|
func Machine(name, pubKey string, prvKey string, address string) machinetypes.Machine {
|
||||||
|
metadata := Metadata()
|
||||||
|
_, liquidPubKey := ExtendedKeyPair(config.LiquidNetParams)
|
||||||
|
_, planetmintPubKey := ExtendedKeyPair(config.PlmntNetParams)
|
||||||
|
|
||||||
|
prvKeyBytes, _ := hex.DecodeString(prvKey)
|
||||||
|
sk := &secp256k1.PrivKey{Key: prvKeyBytes}
|
||||||
|
pubKeyBytes, _ := hex.DecodeString(pubKey)
|
||||||
|
sign, _ := sk.Sign(pubKeyBytes)
|
||||||
|
signatureHex := hex.EncodeToString(sign)
|
||||||
|
|
||||||
|
if address == "" {
|
||||||
|
address = sample.Secp256k1AccAddress().String()
|
||||||
|
}
|
||||||
|
|
||||||
|
m := machinetypes.Machine{
|
||||||
|
Name: name,
|
||||||
|
Ticker: name + "_ticker",
|
||||||
|
Domain: "lab.r3c.network",
|
||||||
|
Reissue: true,
|
||||||
|
Amount: 1000,
|
||||||
|
Precision: 8,
|
||||||
|
IssuerPlanetmint: planetmintPubKey,
|
||||||
|
IssuerLiquid: liquidPubKey,
|
||||||
|
MachineId: pubKey,
|
||||||
|
Metadata: &metadata,
|
||||||
|
Type: 1,
|
||||||
|
MachineIdSignature: signatureHex,
|
||||||
|
Address: address,
|
||||||
|
}
|
||||||
|
return m
|
||||||
|
}
|
||||||
|
|
||||||
|
func MachineIndex(pubKey string, planetmintPubKey string, liquidPubKey string) machinetypes.MachineIndex {
|
||||||
|
return machinetypes.MachineIndex{
|
||||||
|
MachineId: pubKey,
|
||||||
|
IssuerPlanetmint: planetmintPubKey,
|
||||||
|
IssuerLiquid: liquidPubKey,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Metadata() machinetypes.Metadata {
|
||||||
|
return machinetypes.Metadata{
|
||||||
|
Gps: "{\"Latitude\":\"-48.876667\",\"Longitude\":\"-123.393333\"}",
|
||||||
|
Device: "{\"Manufacturer\": \"RDDL\",\"Serial\":\"AdnT2uyt\"}",
|
||||||
|
AssetDefinition: "{\"Version\": \"0.1\"}",
|
||||||
|
AdditionalDataCID: "CID",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TrustAnchor(pubkey string) machinetypes.TrustAnchor {
|
||||||
|
return machinetypes.TrustAnchor{
|
||||||
|
Pubkey: pubkey,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func MintRequest(beneficiaryAddr string, amount uint64, txhash string) daotypes.MintRequest {
|
||||||
|
return daotypes.MintRequest{
|
||||||
|
Beneficiary: beneficiaryAddr,
|
||||||
|
Amount: amount,
|
||||||
|
LiquidTxHash: txhash,
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,10 +4,6 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/planetmint/planetmint-go/config"
|
|
||||||
daotypes "github.com/planetmint/planetmint-go/x/dao/types"
|
|
||||||
machinetypes "github.com/planetmint/planetmint-go/x/machine/types"
|
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
"github.com/btcsuite/btcd/btcutil/hdkeychain"
|
||||||
"github.com/btcsuite/btcd/chaincfg"
|
"github.com/btcsuite/btcd/chaincfg"
|
||||||
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
"github.com/cosmos/cosmos-sdk/crypto/keyring"
|
||||||
@ -60,58 +56,6 @@ func Secp256k1AccAddress() sdk.AccAddress {
|
|||||||
return sdk.AccAddress(addr)
|
return sdk.AccAddress(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Machine creates a new machine object
|
|
||||||
// TODO: make address deterministic for test cases
|
|
||||||
func Machine(name, pubKey string, prvKey string, address string) machinetypes.Machine {
|
|
||||||
metadata := Metadata()
|
|
||||||
_, liquidPubKey := ExtendedKeyPair(config.LiquidNetParams)
|
|
||||||
_, planetmintPubKey := ExtendedKeyPair(config.PlmntNetParams)
|
|
||||||
|
|
||||||
prvKeyBytes, _ := hex.DecodeString(prvKey)
|
|
||||||
sk := &secp256k1.PrivKey{Key: prvKeyBytes}
|
|
||||||
pubKeyBytes, _ := hex.DecodeString(pubKey)
|
|
||||||
sign, _ := sk.Sign(pubKeyBytes)
|
|
||||||
signatureHex := hex.EncodeToString(sign)
|
|
||||||
|
|
||||||
if address == "" {
|
|
||||||
address = Secp256k1AccAddress().String()
|
|
||||||
}
|
|
||||||
|
|
||||||
m := machinetypes.Machine{
|
|
||||||
Name: name,
|
|
||||||
Ticker: name + "_ticker",
|
|
||||||
Domain: "lab.r3c.network",
|
|
||||||
Reissue: true,
|
|
||||||
Amount: 1000,
|
|
||||||
Precision: 8,
|
|
||||||
IssuerPlanetmint: planetmintPubKey,
|
|
||||||
IssuerLiquid: liquidPubKey,
|
|
||||||
MachineId: pubKey,
|
|
||||||
Metadata: &metadata,
|
|
||||||
Type: 1,
|
|
||||||
MachineIdSignature: signatureHex,
|
|
||||||
Address: address,
|
|
||||||
}
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|
||||||
func MachineIndex(pubKey string, planetmintPubKey string, liquidPubKey string) machinetypes.MachineIndex {
|
|
||||||
return machinetypes.MachineIndex{
|
|
||||||
MachineId: pubKey,
|
|
||||||
IssuerPlanetmint: planetmintPubKey,
|
|
||||||
IssuerLiquid: liquidPubKey,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Metadata() machinetypes.Metadata {
|
|
||||||
return machinetypes.Metadata{
|
|
||||||
Gps: "{\"Latitude\":\"-48.876667\",\"Longitude\":\"-123.393333\"}",
|
|
||||||
Device: "{\"Manufacturer\": \"RDDL\",\"Serial\":\"AdnT2uyt\"}",
|
|
||||||
AssetDefinition: "{\"Version\": \"0.1\"}",
|
|
||||||
AdditionalDataCID: "CID",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func Asset() string {
|
func Asset() string {
|
||||||
cid := "cid0"
|
cid := "cid0"
|
||||||
return cid
|
return cid
|
||||||
@ -132,17 +76,3 @@ func ExtendedKeyPair(cfg chaincfg.Params) (string, string) {
|
|||||||
}
|
}
|
||||||
return xprivKey.String(), xpubKey.String()
|
return xprivKey.String(), xpubKey.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TrustAnchor(pubkey string) machinetypes.TrustAnchor {
|
|
||||||
return machinetypes.TrustAnchor{
|
|
||||||
Pubkey: pubkey,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func MintRequest(beneficiaryAddr string, amount uint64, txhash string) daotypes.MintRequest {
|
|
||||||
return daotypes.MintRequest{
|
|
||||||
Beneficiary: beneficiaryAddr,
|
|
||||||
Amount: amount,
|
|
||||||
LiquidTxHash: txhash,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -6,7 +6,9 @@ import (
|
|||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
var rddlTokenAmount string = "998.85844748"
|
const (
|
||||||
|
rddlTokenAmount string = "998.85844748"
|
||||||
|
)
|
||||||
|
|
||||||
func Test2FloatConvertion(t *testing.T) {
|
func Test2FloatConvertion(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|||||||
@ -3,7 +3,7 @@ package types
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -19,14 +19,9 @@ func TestMsgNotarizeAssetValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgNotarizeAsset{
|
msg: MsgNotarizeAsset{
|
||||||
Creator: sample.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
}, {
|
|
||||||
name: "valid address",
|
|
||||||
msg: MsgNotarizeAsset{
|
|
||||||
Creator: sample.AccAddress(),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/sample"
|
||||||
"github.com/planetmint/planetmint-go/x/dao/keeper"
|
"github.com/planetmint/planetmint-go/x/dao/keeper"
|
||||||
"github.com/planetmint/planetmint-go/x/dao/types"
|
"github.com/planetmint/planetmint-go/x/dao/types"
|
||||||
@ -170,7 +171,7 @@ func TestMsgServerMintToken(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
minter := sample.AccAddress()
|
minter := sample.AccAddress()
|
||||||
beneficiary := sample.ConstBech32Addr
|
beneficiary := sample.ConstBech32Addr
|
||||||
mintRequest := sample.MintRequest(beneficiary, 1000, "hash")
|
mintRequest := moduleobject.MintRequest(beneficiary, 1000, "hash")
|
||||||
|
|
||||||
msg := types.NewMsgMintToken(minter, &mintRequest)
|
msg := types.NewMsgMintToken(minter, &mintRequest)
|
||||||
msgServer, ctx, _ := setupMsgServer(t)
|
msgServer, ctx, _ := setupMsgServer(t)
|
||||||
@ -190,7 +191,7 @@ func TestMsgServerMintTokenInvalidAddress(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
minter := sample.AccAddress()
|
minter := sample.AccAddress()
|
||||||
beneficiary := "invalid address"
|
beneficiary := "invalid address"
|
||||||
mintRequest := sample.MintRequest(beneficiary, 1000, "hash")
|
mintRequest := moduleobject.MintRequest(beneficiary, 1000, "hash")
|
||||||
|
|
||||||
msg := types.NewMsgMintToken(minter, &mintRequest)
|
msg := types.NewMsgMintToken(minter, &mintRequest)
|
||||||
msgServer, ctx, _ := setupMsgServer(t)
|
msgServer, ctx, _ := setupMsgServer(t)
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ func TestMsgInitPop_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgInitPop{
|
msg: MsgInitPop{
|
||||||
Creator: sample.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ func TestMsgMintToken_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgMintToken{
|
msg: MsgMintToken{
|
||||||
Creator: sample.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgUpdateParams{
|
msg: MsgUpdateParams{
|
||||||
Authority: sample.ErrorInvalidAddress,
|
Authority: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ func TestMsgCreateRedeemClaim_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgCreateRedeemClaim{
|
msg: MsgCreateRedeemClaim{
|
||||||
Creator: sample.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
},
|
},
|
||||||
@ -47,7 +47,7 @@ func TestMsgUpdateRedeemClaim_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgUpdateRedeemClaim{
|
msg: MsgUpdateRedeemClaim{
|
||||||
Creator: sample.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
},
|
},
|
||||||
@ -76,7 +76,7 @@ func TestMsgConfirmRedeemClaim_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgConfirmRedeemClaim{
|
msg: MsgConfirmRedeemClaim{
|
||||||
Creator: sample.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
keepertest "github.com/planetmint/planetmint-go/testutil/keeper"
|
||||||
|
"github.com/planetmint/planetmint-go/testutil/moduleobject"
|
||||||
"github.com/planetmint/planetmint-go/x/machine/keeper"
|
"github.com/planetmint/planetmint-go/x/machine/keeper"
|
||||||
"github.com/planetmint/planetmint-go/x/machine/types"
|
"github.com/planetmint/planetmint-go/x/machine/types"
|
||||||
|
|
||||||
@ -30,9 +31,9 @@ func TestMsgServer(t *testing.T) {
|
|||||||
func TestMsgServerAttestMachine(t *testing.T) {
|
func TestMsgServerAttestMachine(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
sk, pk := sample.KeyPair()
|
sk, pk := sample.KeyPair()
|
||||||
ta := sample.TrustAnchor(pk)
|
ta := moduleobject.TrustAnchor(pk)
|
||||||
taMsg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
taMsg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
||||||
machine := sample.Machine(pk, pk, sk, "")
|
machine := moduleobject.Machine(pk, pk, sk, "")
|
||||||
msg := types.NewMsgAttestMachine(pk, &machine)
|
msg := types.NewMsgAttestMachine(pk, &machine)
|
||||||
msgServer, ctx := setupMsgServer(t)
|
msgServer, ctx := setupMsgServer(t)
|
||||||
_, err := msgServer.RegisterTrustAnchor(ctx, taMsg)
|
_, err := msgServer.RegisterTrustAnchor(ctx, taMsg)
|
||||||
@ -46,9 +47,9 @@ func TestMsgServerAttestMachine(t *testing.T) {
|
|||||||
func TestMsgServerAttestMachineInvalidLiquidKey(t *testing.T) {
|
func TestMsgServerAttestMachineInvalidLiquidKey(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
sk, pk := sample.KeyPair()
|
sk, pk := sample.KeyPair()
|
||||||
ta := sample.TrustAnchor(pk)
|
ta := moduleobject.TrustAnchor(pk)
|
||||||
taMsg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
taMsg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
||||||
machine := sample.Machine(pk, pk, sk, "")
|
machine := moduleobject.Machine(pk, pk, sk, "")
|
||||||
machine.IssuerLiquid = "invalidkey"
|
machine.IssuerLiquid = "invalidkey"
|
||||||
msg := types.NewMsgAttestMachine(pk, &machine)
|
msg := types.NewMsgAttestMachine(pk, &machine)
|
||||||
msgServer, ctx := setupMsgServer(t)
|
msgServer, ctx := setupMsgServer(t)
|
||||||
@ -61,7 +62,7 @@ func TestMsgServerAttestMachineInvalidLiquidKey(t *testing.T) {
|
|||||||
func TestMsgServerRegisterTrustAnchor(t *testing.T) {
|
func TestMsgServerRegisterTrustAnchor(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
_, pk := sample.KeyPair()
|
_, pk := sample.KeyPair()
|
||||||
ta := sample.TrustAnchor(pk)
|
ta := moduleobject.TrustAnchor(pk)
|
||||||
msg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
msg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
||||||
msgServer, ctx := setupMsgServer(t)
|
msgServer, ctx := setupMsgServer(t)
|
||||||
res, err := msgServer.RegisterTrustAnchor(ctx, msg)
|
res, err := msgServer.RegisterTrustAnchor(ctx, msg)
|
||||||
@ -73,7 +74,7 @@ func TestMsgServerRegisterTrustAnchor(t *testing.T) {
|
|||||||
func TestMsgServerRegisterTrustAnchorTwice(t *testing.T) {
|
func TestMsgServerRegisterTrustAnchorTwice(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
_, pk := sample.KeyPair()
|
_, pk := sample.KeyPair()
|
||||||
ta := sample.TrustAnchor(pk)
|
ta := moduleobject.TrustAnchor(pk)
|
||||||
msg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
msg := types.NewMsgRegisterTrustAnchor(pk, &ta)
|
||||||
msgServer, ctx := setupMsgServer(t)
|
msgServer, ctx := setupMsgServer(t)
|
||||||
res, err := msgServer.RegisterTrustAnchor(ctx, msg)
|
res, err := msgServer.RegisterTrustAnchor(ctx, msg)
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ func TestMsgAttestMachineValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgAttestMachine{
|
msg: MsgAttestMachine{
|
||||||
Creator: sample.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ func TestMsgRegisterTrustAnchor_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgRegisterTrustAnchor{
|
msg: MsgRegisterTrustAnchor{
|
||||||
Creator: sample.ErrorInvalidAddress,
|
Creator: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
},
|
},
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
"github.com/planetmint/planetmint-go/testutil/sample"
|
"github.com/planetmint/planetmint-go/testutil/errormsg"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ func TestMsgUpdateParams_ValidateBasic(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid address",
|
name: "invalid address",
|
||||||
msg: MsgUpdateParams{
|
msg: MsgUpdateParams{
|
||||||
Authority: sample.ErrorInvalidAddress,
|
Authority: errormsg.ErrorInvalidAddress,
|
||||||
},
|
},
|
||||||
err: sdkerrors.ErrInvalidAddress,
|
err: sdkerrors.ErrInvalidAddress,
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user