testproxy

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const JSONRPCInternalErrorCode = -32000

JSONRPCInternalErrorCode is the default JSON-RPC error code to be used when generating a JSON-RPC error reply. JSON-RPC specification uses -32000 to -32099 as implementation-defined server-errors. See: https://www.jsonrpc.org/specification#error_object

Variables

This section is empty.

Functions

func GenerateRelayRequest

func GenerateRelayRequest(
	test *TestBehavior,
	privKey *secp256k1.PrivKey,
	serviceId string,
	blockHeight int64,
	supplierKeyName string,
	payload []byte,
) *servicetypes.RelayRequest

GenerateRelayRequest generates a relay request with the provided parameters

func GetApplicationRingSignature

func GetApplicationRingSignature(
	t *testing.T,
	req *servicetypes.RelayRequest,
	appPrivateKey *secp256k1.PrivKey,
) []byte

GetApplicationRingSignature crafts a ring signer for test purposes and uses it to sign the relay request

func GetRelayResponseError

func GetRelayResponseError(t *testing.T, res *http.Response) (errCode int32, errMsg string)

GetRelayResponseError returns the error code and message from the relay response. If the response is not an error, it returns `0, ""`.

func MarshalAndSend

func MarshalAndSend(
	test *TestBehavior,
	servicesConfigMap map[string]*config.RelayMinerServerConfig,
	serviceEndpoint string,
	serviceId string,
	request *servicetypes.RelayRequest,
) (errCode int32, errorMessage string)

MarshalAndSend marshals the request and sends it to the provided service.

func PrepareJSONRPCRequest added in v0.0.3

func PrepareJSONRPCRequest(t *testing.T) []byte

PrepareJSONRPCRequest constructs a hard-coded JSON-RPC http.Request and returns the corresponding sdk serialized POKTHTTPRequest.

It uses the default POST method and "application/json" content type, along with the provided hard-coded body bytes. The function then serializes the entire generated http.Request into an sdk serialized POKTHTTPRequest to be embedded in a RelayRequest.Payload.

Unlike sendJSONRPCResponse, this function IS EXPORTED to be used in the pkg/relayer/proxy/proxy_test testing code.

IMPORTANT: This function is intended solely for testing purposes and SHOULD NOT be used in production code.

func WithDefaultApplication

func WithDefaultApplication(appPrivateKey *secp256k1.PrivKey) func(*TestBehavior)

WithDefaultApplication creates the default staked application actor for the test

func WithDefaultSessionSupplier

func WithDefaultSessionSupplier(
	supplierKeyName string,
	serviceId string,
	appPrivateKey *secp256k1.PrivKey,
) func(*TestBehavior)

WithDefaultSessionSupplier adds the default staked supplier to the application's current session If the supplierKeyName is empty, the supplier will not be staked so we can test the case where the supplier is not in the application's session's supplier list.

func WithDefaultSupplier

func WithDefaultSupplier(
	supplierKeyName string,
	supplierEndpoints map[string][]*sharedtypes.SupplierEndpoint,
) func(*TestBehavior)

WithDefaultSupplier creates the default staked supplier for the test

func WithRelayerProxyDependenciesForBlockHeight

func WithRelayerProxyDependenciesForBlockHeight(
	keyName string,
	blockHeight int64,
) func(*TestBehavior)

WithRelayerProxyDependenciesForBlockHeight creates the dependencies for the relayer proxy from the TestBehavior.mocks so they have the right interface and can be used by the dependency injection framework. blockHeight being the block height that will be returned by the block client's LastNBlock method

func WithServicesConfigMap

func WithServicesConfigMap(
	servicesConfigMap map[string]*config.RelayMinerServerConfig,
) func(*TestBehavior)

WithServicesConfigMap creates the services that the relayer proxy will proxy requests to. It creates an HTTP server for each service and starts listening on the provided host.

func WithSuccessiveSessions

func WithSuccessiveSessions(
	supplierKeyName string,
	serviceId string,
	appPrivateKey *secp256k1.PrivKey,
	sessionsCount int,
) func(*TestBehavior)

WithSuccessiveSessions creates sessions with SessionNumber 0 through SessionCount -1 and adds all of them to the sessionMap. Each session is configured for the same serviceId and application provided.

Types

type JSONRPCError added in v0.0.3

type JSONRPCError struct {
	Code    int32  `json:"code"`
	Message string `json:"message"`
}

JSONRPCError is the error struct for the JSONRPC response payload.

type JSONRPCErrorReply added in v0.0.3

type JSONRPCErrorReply struct {
	Id      int32  `json:"id"`
	Jsonrpc string `json:"jsonrpc"`
	Error   *JSONRPCError
}

JSONRPCErrorReply is the error reply struct for the JSON-RPC response payload.

type TestBehavior

type TestBehavior struct {

	// Deps is exported so it can be used by the dependency injection framework
	// from the pkg/relayer/proxy/proxy_test.go
	Deps depinject.Config
	// contains filtered or unexported fields
}

TestBehavior is a struct that holds the test context and mocks for the relayer proxy tests. It is used to provide the context needed by the instrumentation functions in order to isolate specific execution paths of the subject under test.

func NewRelayerProxyTestBehavior

func NewRelayerProxyTestBehavior(
	ctx context.Context,
	t *testing.T,
	behaviors ...func(*TestBehavior),
) *TestBehavior

NewRelayerProxyTestBehavior creates a TestBehavior with the provided set of behavior function that are used to instrument the tested subject's dependencies and isolate specific execution pathways.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL