Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Miner] feat: add TxContext #118

Merged
merged 15 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions internal/testclient/common.go

This file was deleted.

28 changes: 28 additions & 0 deletions internal/testclient/keyring.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package testclient

import (
cosmoshd "github.com/cosmos/cosmos-sdk/crypto/hd"
cosmoskeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/stretchr/testify/require"
"testing"
)

func NewKey(
t *testing.T,
name string,
keyring cosmoskeyring.Keyring,
) (key *cosmoskeyring.Record, mnemonic string) {
t.Helper()

key, mnemonic, err := keyring.NewMnemonic(
name,
cosmoskeyring.English,
"m/44'/118'/0'/0/0",
cosmoskeyring.DefaultBIP39Passphrase,
cosmoshd.Secp256k1,
)
require.NoError(t, err)
require.NotNil(t, key)

return key, mnemonic
}
69 changes: 69 additions & 0 deletions internal/testclient/localnet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package testclient

import (
"testing"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/spf13/pflag"
"github.com/stretchr/testify/require"

"pocket/app"
"pocket/cmd/pocketd/cmd"
)

// CometLocalWebsocketURL provides a default URL pointing to the localnet websocket endpoint.
const CometLocalWebsocketURL = "ws://localhost:36657/websocket"

// EncodingConfig encapsulates encoding configurations for the Pocket application.
var EncodingConfig = app.MakeEncodingConfig()

// init initializes the SDK configuration upon package import.
func init() {
cmd.InitSDKConfig()
}

// NewLocalnetClientCtx creates a client context specifically tailored for localnet
// environments. The returned client context is initialized with encoding
// configurations, a default home directory, a default account retriever, and
// command flags.
//
// Parameters:
// - t: The testing.T instance used for the current test.
// - flagSet: The set of flags to be read for initializing the client context.
//
// Returns:
// - A pointer to a populated client.Context instance suitable for localnet usage.
func NewLocalnetClientCtx(t *testing.T, flagSet *pflag.FlagSet) *client.Context {
homedir := app.DefaultNodeHome
clientCtx := client.Context{}.
WithCodec(EncodingConfig.Marshaler).
WithTxConfig(EncodingConfig.TxConfig).
WithHomeDir(homedir).
WithAccountRetriever(authtypes.AccountRetriever{}).
WithInterfaceRegistry(EncodingConfig.InterfaceRegistry)

clientCtx, err := client.ReadPersistentCommandFlags(clientCtx, flagSet)
require.NoError(t, err)
return &clientCtx
}

// NewLocalnetFlagSet creates a set of predefined flags suitable for a localnet
// testing environment.
//
// Parameters:
// - t: The testing.T instance used for the current test.
//
// Returns:
// - A flag set populated with flags tailored for localnet environments.
func NewLocalnetFlagSet(t *testing.T) *pflag.FlagSet {
mockFlagSet := pflag.NewFlagSet("test", pflag.ContinueOnError)
mockFlagSet.String(flags.FlagNode, "tcp://127.0.0.1:36657", "use localnet poktrolld node")
mockFlagSet.String(flags.FlagHome, "", "use localnet poktrolld node")
mockFlagSet.String(flags.FlagKeyringBackend, "test", "use test keyring")
err := mockFlagSet.Parse([]string{})
require.NoError(t, err)

return mockFlagSet
}
Loading