mirror of
https://github.com/planetmint/planetmint-go.git
synced 2025-03-30 15:08:28 +00:00
resolve merge conflicts
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
commit
dc17cf118c
9
.github/workflows/audit.yaml
vendored
9
.github/workflows/audit.yaml
vendored
@ -33,12 +33,11 @@ jobs:
|
||||
- name: Run staticcheck
|
||||
run: staticcheck ./...
|
||||
|
||||
- name: Install golint
|
||||
run: go install golang.org/x/lint/golint@latest
|
||||
- name: Install golangci-lint
|
||||
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
|
||||
|
||||
- name: Run golint
|
||||
run: golint -set_exit_status ./...
|
||||
continue-on-error: true
|
||||
- name: Run golangci-lint
|
||||
run: golangci-lint run --timeout 5m
|
||||
|
||||
- name: Run tests
|
||||
run: go test -race -vet=off ./...
|
||||
|
@ -77,6 +77,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
|
||||
|
||||
// withdraw all delegator rewards
|
||||
dels := app.StakingKeeper.GetAllDelegations(ctx)
|
||||
//nolint:errcheck
|
||||
app.withdrawAllDelegatorRewards(ctx, dels)
|
||||
|
||||
// clear validator slash events
|
||||
@ -93,6 +94,7 @@ func (app *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []str
|
||||
app.reinitializeAllValidators(ctx)
|
||||
|
||||
// reinitialize all delegations
|
||||
//nolint:errcheck
|
||||
app.reinitializeAllDelegations(ctx, dels)
|
||||
|
||||
// reset context height
|
||||
|
@ -208,6 +208,7 @@ func overwriteFlagDefaults(c *cobra.Command, defaults map[string]string) {
|
||||
set := func(s *pflag.FlagSet, key, val string) {
|
||||
if f := s.Lookup(key); f != nil {
|
||||
f.DefValue = val
|
||||
//nolint:errcheck
|
||||
f.Value.Set(val)
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ func handler(title string) http.HandlerFunc {
|
||||
t, _ := httptemplate.ParseFS(template, indexFile)
|
||||
|
||||
return func(w http.ResponseWriter, req *http.Request) {
|
||||
//nolint:errcheck
|
||||
t.Execute(w, struct {
|
||||
Title string
|
||||
URL string
|
||||
|
@ -74,7 +74,7 @@ func (s *E2ETestSuite) TestNotarizeAssetREST() {
|
||||
broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.network.WaitForNextBlock()
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
tx, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, broadcastTxResponse.TxResponse.TxHash))
|
||||
s.Require().NoError(err)
|
||||
|
@ -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"
|
||||
@ -27,9 +25,6 @@ import (
|
||||
"sigs.k8s.io/yaml"
|
||||
)
|
||||
|
||||
// Queryable pubkey for TestNotarizeAsset
|
||||
const mnemonic = "helmet hedgehog lab actor weekend elbow pelican valid obtain hungry rocket decade tower gallery fit practice cart cherry giggle hair snack glance bulb farm"
|
||||
|
||||
// E2ETestSuite struct definition of asset suite
|
||||
type E2ETestSuite struct {
|
||||
suite.Suite
|
||||
@ -51,7 +46,7 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
kb := val.ClientCtx.Keyring
|
||||
account, err := kb.NewAccount("machine", mnemonic, keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1)
|
||||
account, err := kb.NewAccount(sample.Name, sample.Mnemonic, keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1)
|
||||
s.Require().NoError(err)
|
||||
pk, err := account.GetPubKey()
|
||||
pkHex := hex.EncodeToString(pk.Bytes())
|
||||
@ -61,31 +56,18 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
|
||||
// sending funds to machine to initialize account on chain
|
||||
args := []string{
|
||||
"node0",
|
||||
val.Moniker,
|
||||
addr.String(),
|
||||
"1000stake",
|
||||
sample.Amount,
|
||||
"--yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, "2stake"),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees),
|
||||
}
|
||||
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
machine := machinetypes.Machine{
|
||||
Name: "machine",
|
||||
Ticker: "machine_ticker",
|
||||
Reissue: true,
|
||||
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)
|
||||
|
||||
|
@ -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"
|
||||
@ -13,40 +14,26 @@ func (s *E2ETestSuite) TestAttestMachineREST() {
|
||||
baseURL := val.APIAddress
|
||||
|
||||
// Query Sequence Number
|
||||
k, err := val.ClientCtx.Keyring.Key("machine")
|
||||
k, err := val.ClientCtx.Keyring.Key(sample.Name)
|
||||
s.Require().NoError(err)
|
||||
|
||||
addr, err := k.GetAddress()
|
||||
s.Require().NoError(err)
|
||||
|
||||
// Create Attest Machine TX
|
||||
machine := machinetypes.Machine{
|
||||
Name: "machine",
|
||||
Ticker: "machine_ticker",
|
||||
Reissue: true,
|
||||
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(sample.Name, sample.PubKey)
|
||||
msg := machinetypes.MsgAttestMachine{
|
||||
Creator: addr.String(),
|
||||
Machine: &machine,
|
||||
}
|
||||
|
||||
txBytes, err := testutil.PrepareTx(val, &msg, "machine")
|
||||
txBytes, err := testutil.PrepareTx(val, &msg, sample.Name)
|
||||
s.Require().NoError(err)
|
||||
|
||||
broadcastTxResponse, err := testutil.BroadcastTx(val, txBytes)
|
||||
s.Require().NoError(err)
|
||||
|
||||
s.network.WaitForNextBlock()
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
tx, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/tx/v1beta1/txs/%s", val.APIAddress, broadcastTxResponse.TxResponse.TxHash))
|
||||
s.Require().NoError(err)
|
||||
|
||||
@ -55,7 +42,7 @@ func (s *E2ETestSuite) TestAttestMachineREST() {
|
||||
s.Require().NoError(err)
|
||||
s.Require().Equal(uint32(0), txRes.TxResponse.Code)
|
||||
|
||||
queryMachineUrl := fmt.Sprintf("%s/planetmint-go/machine/get_machine_by_public_key/%s", baseURL, pubKey)
|
||||
queryMachineUrl := fmt.Sprintf("%s/planetmint-go/machine/get_machine_by_public_key/%s", baseURL, sample.PubKey)
|
||||
queryMachineRes, err := testutil.GetRequest(queryMachineUrl)
|
||||
s.Require().NoError(err)
|
||||
|
||||
|
@ -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,16 +14,10 @@ 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"
|
||||
)
|
||||
|
||||
// Queryable pubkey for TestAttestMachine
|
||||
const pubKey = "AjKN6HiWucu1EBwzX0ACnkvomJiLRwq79oPxoLMY1zRw"
|
||||
const mnemonic = "helmet hedgehog lab actor weekend elbow pelican valid obtain hungry rocket decade tower gallery fit practice cart cherry giggle hair snack glance bulb farm"
|
||||
|
||||
// Struct definition of machine E2ETestSuite
|
||||
// E2ETestSuite struct definition of machine suite
|
||||
type E2ETestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
@ -30,12 +25,12 @@ type E2ETestSuite struct {
|
||||
network *network.Network
|
||||
}
|
||||
|
||||
// Returns new machine E2ETestSuite
|
||||
// NewE2ETestSuite returns configured machine E2ETestSuite
|
||||
func NewE2ETestSuite(cfg network.Config) *E2ETestSuite {
|
||||
return &E2ETestSuite{cfg: cfg}
|
||||
}
|
||||
|
||||
// Sets up new machine E2ETestSuite
|
||||
// SetupSuite initializes machine E2ETestSuite
|
||||
func (s *E2ETestSuite) SetupSuite() {
|
||||
s.T().Log("setting up e2e test suite")
|
||||
|
||||
@ -43,18 +38,18 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
kb := val.ClientCtx.Keyring
|
||||
account, err := kb.NewAccount("machine", mnemonic, keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1)
|
||||
account, err := kb.NewAccount(sample.Name, sample.Mnemonic, keyring.DefaultBIP39Passphrase, sdk.FullFundraiserPath, hd.Secp256k1)
|
||||
s.Require().NoError(err)
|
||||
|
||||
addr, _ := account.GetAddress()
|
||||
|
||||
// sending funds to machine to initialize account on chain
|
||||
args := []string{
|
||||
"node0",
|
||||
val.Moniker,
|
||||
addr.String(),
|
||||
"1000stake",
|
||||
sample.Amount,
|
||||
"--yes",
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, "2stake"),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees),
|
||||
}
|
||||
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, bank.NewSendTxCmd(), args)
|
||||
s.Require().NoError(err)
|
||||
@ -62,36 +57,23 @@ func (s *E2ETestSuite) SetupSuite() {
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
}
|
||||
|
||||
// Tear down machine E2ETestSuite
|
||||
// TearDownSuite clean up after testing
|
||||
func (s *E2ETestSuite) TearDownSuite() {
|
||||
s.T().Log("tearing down e2e test suite")
|
||||
}
|
||||
|
||||
// Attest machine and query attested machine from chain
|
||||
// TestAttestMachine attests machine and query attested machine from chain
|
||||
func (s *E2ETestSuite) TestAttestMachine() {
|
||||
val := s.network.Validators[0]
|
||||
|
||||
machine := machinetypes.Machine{
|
||||
Name: "machine",
|
||||
Ticker: "machine_ticker",
|
||||
Reissue: true,
|
||||
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(sample.Name, sample.PubKey)
|
||||
machineJSON, err := json.Marshal(&machine)
|
||||
s.Require().NoError(err)
|
||||
|
||||
args := []string{
|
||||
fmt.Sprintf("--%s=%s", flags.FlagChainID, s.network.Config.ChainID),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, "machine"),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, "2stake"),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFrom, sample.Name),
|
||||
fmt.Sprintf("--%s=%s", flags.FlagFees, sample.Fees),
|
||||
"--yes",
|
||||
string(machineJSON),
|
||||
}
|
||||
@ -102,7 +84,7 @@ func (s *E2ETestSuite) TestAttestMachine() {
|
||||
s.Require().NoError(s.network.WaitForNextBlock())
|
||||
|
||||
args = []string{
|
||||
pubKey,
|
||||
sample.PubKey,
|
||||
}
|
||||
|
||||
_, err = clitestutil.ExecTestCLICmd(val.ClientCtx, machinecli.CmdGetMachineByPublicKey(), args)
|
||||
|
@ -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,
|
||||
|
@ -80,7 +80,10 @@ func PrepareTx(val *network.Validator, msg sdk.Msg, signer string) ([]byte, erro
|
||||
}
|
||||
|
||||
txBuilder := val.ClientCtx.TxConfig.NewTxBuilder()
|
||||
txBuilder.SetMsgs(msg)
|
||||
err = txBuilder.SetMsgs(msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
txBuilder.SetGasLimit(200000)
|
||||
txBuilder.SetFeeAmount(sdk.Coins{sdk.NewInt64Coin("stake", 2)})
|
||||
txBuilder.SetTimeoutHeight(0)
|
||||
|
@ -11,6 +11,21 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Mnemonic sample mnemonic to use in tests
|
||||
const Mnemonic = "helmet hedgehog lab actor weekend elbow pelican valid obtain hungry rocket decade tower gallery fit practice cart cherry giggle hair snack glance bulb farm"
|
||||
|
||||
// PubKey corresponding public key to sample mnemonic
|
||||
const PubKey = "AjKN6HiWucu1EBwzX0ACnkvomJiLRwq79oPxoLMY1zRw"
|
||||
|
||||
// Name is the name of the sample machine to use in tests
|
||||
const Name = "machine"
|
||||
|
||||
// Amount is the amount to transfer to the machine account
|
||||
const Amount = "1000stake"
|
||||
|
||||
// Fees is the amount of fees to use in tests
|
||||
const Fees = "2stake"
|
||||
|
||||
// KeyPair returns a sample private / public keypair
|
||||
func KeyPair() (string, string) {
|
||||
secret := "Don't tell anybody"
|
||||
@ -26,25 +41,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",
|
||||
Reissue: true,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,6 +70,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
||||
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
//nolint:errcheck
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,9 @@ func (k Keeper) GetMachine(ctx sdk.Context, index types.MachineIndex) (val types
|
||||
if machine == nil {
|
||||
return val, false
|
||||
}
|
||||
k.cdc.Unmarshal(machine, &val)
|
||||
if err := k.cdc.Unmarshal(machine, &val); err != nil {
|
||||
return val, false
|
||||
}
|
||||
return val, true
|
||||
}
|
||||
|
||||
@ -53,19 +55,25 @@ func (k Keeper) GetMachineIndex(ctx sdk.Context, pubKey string) (val types.Machi
|
||||
|
||||
taIndex := taIndexStore.Get(keyBytes)
|
||||
if taIndex != nil {
|
||||
k.cdc.Unmarshal(taIndex, &val)
|
||||
if err := k.cdc.Unmarshal(taIndex, &val); err != nil {
|
||||
return val, false
|
||||
}
|
||||
return val, true
|
||||
}
|
||||
|
||||
ipIndex := issuerPlanetmintIndexStore.Get(keyBytes)
|
||||
if ipIndex != nil {
|
||||
k.cdc.Unmarshal(ipIndex, &val)
|
||||
if err := k.cdc.Unmarshal(ipIndex, &val); err != nil {
|
||||
return val, false
|
||||
}
|
||||
return val, true
|
||||
}
|
||||
|
||||
ilIndex := issuerLiquidIndexStore.Get(keyBytes)
|
||||
if ilIndex != nil {
|
||||
k.cdc.Unmarshal(ilIndex, &val)
|
||||
if err := k.cdc.Unmarshal(ilIndex, &val); err != nil {
|
||||
return val, false
|
||||
}
|
||||
return val, true
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -70,6 +70,7 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
||||
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
//nolint:errcheck
|
||||
types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user