Documentation ¶
Overview ¶
Package rpcfuzz is meant to have some basic RPC fuzzing and conformance tests. Each test is meant to be self-contained i.e. the success or failure of a test should have no impact on other tests. The benefit here is that each test is an object and can be modified, decorated, fuzzed, etc.
The conformance test should also run successful on a network that is or isn't isolated. In some circumstances, it might be better to run the conformance test in once process while there is load being applied. The only consideration is that you shouldn't use the same key to load test as is used to run the conformance tests.
Index ¶
- Variables
- func ArgsBlockFilterID(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}
- func ArgsCoinbase(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}
- func ArgsCoinbaseTransaction(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs, ...) func() []interface{}
- func ArgsFilterID(ctx context.Context, rpcClient *rpc.Client, filterArgs RPCTestFilterArgs, ...) func() []interface{}
- func ArgsLatestBlockHash(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}
- func ArgsLatestBlockNumber(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}
- func ArgsRawBlock(ctx context.Context, rpcClient *rpc.Client, blockNumOrHash string, ...) func() []interface{}
- func ArgsSignTransaction(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs, ...) func() []interface{}
- func ArgsSignTransactionWithNonce(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs, ...) func() []interface{}
- func ArgsTransactionBlockHashAndIndex(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs) func() []interface{}
- func ArgsTransactionBlockNumberAndIndex(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs) func() []interface{}
- func ArgsTransactionHash(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs) func() []interface{}
- func CallRPCAndValidate(ctx context.Context, rpcClient *rpc.Client, ...) testreporter.TestResult
- func CallRPCWithFuzzAndValidate(ctx context.Context, rpcClient *rpc.Client, currTest RPCTest) testreporter.TestResult
- func GenericTransactionToDynamicFeeTx(tx *RPCTestTransactionArgs) ethtypes.DynamicFeeTx
- func GetCurrentChainID(ctx context.Context, rpcClient *rpc.Client) (*big.Int, error)
- func GetTestAccountNonce(ctx context.Context, rpcClient *rpc.Client) (uint64, error)
- func RequireAll(validators ...func(interface{}) error) func(result interface{}) error
- func RequireAny(validators ...func(interface{}) error) func(result interface{}) error
- func ValidateBlockHash() func(result interface{}) error
- func ValidateError(code int, errorMessageRegex string) func(result interface{}) error
- func ValidateErrorMsgString(errorMessageRegex string) func(result interface{}) error
- func ValidateExact(expected interface{}) func(result interface{}) error
- func ValidateExactJSON(expected string) func(result interface{}) error
- func ValidateHashedResponse(expectedHash string) func(result interface{}) error
- func ValidateJSONSchema(schema string) func(result interface{}) error
- func ValidateRegexString(regEx string) func(result interface{}) error
- func ValidateTransactionHash() func(result interface{}) error
- type RPCJSONError
- type RPCJSONResponse
- type RPCTest
- type RPCTestDynamicArgs
- type RPCTestFilterArgs
- type RPCTestFlag
- type RPCTestGeneric
- type RPCTestRawHTTP
- type RPCTestTransactionArgs
Constants ¶
This section is empty.
Variables ¶
var RPCFuzzCmd = &cobra.Command{ Use: "rpcfuzz", Short: "Continually run a variety of RPC calls and fuzzers.", Long: usage, Args: cobra.NoArgs, PreRunE: func(cmd *cobra.Command, args []string) error { return checkFlags() }, RunE: func(cmd *cobra.Command, args []string) error { return runRpcFuzz(cmd.Context()) }, }
Functions ¶
func ArgsBlockFilterID ¶
func ArgsBlockFilterID(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}
ArgsBlockFilterID will inject an argument that's a filter id corresponding to a block filte
func ArgsCoinbase ¶
func ArgsCoinbase(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}
ArgsCoinbase would return arguments where the first argument is now the coinbase
func ArgsCoinbaseTransaction ¶
func ArgsCoinbaseTransaction(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs, extraArgs ...interface{}) func() []interface{}
ArgsCoinbaseTransaction will return arguments where the from is replace with the current coinbase
func ArgsFilterID ¶
func ArgsFilterID(ctx context.Context, rpcClient *rpc.Client, filterArgs RPCTestFilterArgs, extraArgs ...interface{}) func() []interface{}
ArgsFilterID will inject an argument that's a filter id corresponding to the provide filter args
func ArgsLatestBlockHash ¶
func ArgsLatestBlockHash(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}
ArgsLatestBlockHash is meant to generate an argument with the latest block hash for testing
func ArgsLatestBlockNumber ¶
func ArgsLatestBlockNumber(ctx context.Context, rpcClient *rpc.Client, extraArgs ...interface{}) func() []interface{}
ArgsLatestBlockNumber will inject arguments that correspond to the most recent block's number
func ArgsRawBlock ¶
func ArgsRawBlock(ctx context.Context, rpcClient *rpc.Client, blockNumOrHash string, extraArgs ...interface{}) func() []interface{}
ArgsRawBlock will inject raw block RLP data into the arguments
func ArgsSignTransaction ¶
func ArgsSignTransaction(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs, extraArgs ...interface{}) func() []interface{}
ArgsSignTransaction will take the junk transaction type that we've created, convert it to a geth style dynamic fee transaction and sign it with the user provide key.
func ArgsSignTransactionWithNonce ¶
func ArgsSignTransactionWithNonce(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs, nonce uint64, extraArgs ...interface{}) func() []interface{}
ArgsSignTransactionWithNonce can be used to manipulate the nonce directly in order to create some error cases
func ArgsTransactionBlockHashAndIndex ¶
func ArgsTransactionBlockHashAndIndex(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs) func() []interface{}
ArgsTransactionBlockHashAndIndex will execute the provided transaction and return the block hash and index of the given transaction
func ArgsTransactionBlockNumberAndIndex ¶
func ArgsTransactionBlockNumberAndIndex(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs) func() []interface{}
ArgsTransactionBlockNumberAndIndex will execute the provided transaction and return the block number and index of the given transaction
func ArgsTransactionHash ¶
func ArgsTransactionHash(ctx context.Context, rpcClient *rpc.Client, tx *RPCTestTransactionArgs) func() []interface{}
ArgsTransactionHash will execute the provided transaction and return the transaction hash as an argument to be used in other tests.
func CallRPCAndValidate ¶
func CallRPCAndValidate(ctx context.Context, rpcClient *rpc.Client, wrappedHttpClient wrappedHttpClient, currTest RPCTest) testreporter.TestResult
func CallRPCWithFuzzAndValidate ¶
func CallRPCWithFuzzAndValidate(ctx context.Context, rpcClient *rpc.Client, currTest RPCTest) testreporter.TestResult
func GenericTransactionToDynamicFeeTx ¶
func GenericTransactionToDynamicFeeTx(tx *RPCTestTransactionArgs) ethtypes.DynamicFeeTx
GenericTransactionToDynamicFeeTx convert the simple tx representation that we have into a standard eth type
func GetCurrentChainID ¶
GetCurrentChainID will attempt to determine the chain for the current network
func GetTestAccountNonce ¶
GetTestAccountNonce will attempt to get the current nonce for the current test account
func RequireAll ¶
func RequireAny ¶
func ValidateBlockHash ¶
func ValidateBlockHash() func(result interface{}) error
ValidateBlockHash will convert the result into a block and compute the header in order to verify that the rpc header matches the computed header.
func ValidateError ¶
ValidateError will check the status code and error message text against the provide regular expression
func ValidateErrorMsgString ¶
ValidateErrorMsgString will check the error message text against the provide regular expression
func ValidateExact ¶
func ValidateExact(expected interface{}) func(result interface{}) error
ValidateExact will validate against the exact value expected.
func ValidateExactJSON ¶
func ValidateHashedResponse ¶
ValidateHashedResponse will take a hex encoded hash and return a function that will validate that a given result has the same hash. The expected hash does not start with 0x
func ValidateJSONSchema ¶
ValidateJSONSchema is used to validate the response against a JSON Schema
func ValidateRegexString ¶
ValidateRegexString will match a string from the json response against a regular expression
func ValidateTransactionHash ¶
func ValidateTransactionHash() func(result interface{}) error
ValidateTransactionHash will compare the rpc transaction hash to the computed transaction hash
Types ¶
type RPCJSONError ¶
type RPCJSONError struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` }
RPCJSONError can be used to unmarshal a raw error response.
func (*RPCJSONError) Error ¶
func (r *RPCJSONError) Error() string
type RPCJSONResponse ¶
type RPCJSONResponse struct { Version string `json:"jsonrpc"` Result any `json:"result,omitempty"` Error *RPCJSONError `json:"error,omitempty"` ID any `json:"id"` }
RPCJSONResponse can be used to unmarshal a raw response.
type RPCTest ¶
type RPCTest interface { // GetName returns a more descriptive name of the test being executed GetName() string // GetMethod returns the json rpc method name GetMethod() string // GetArgs will return the list of arguments that will be used when calling the rpc GetArgs() []interface{} // Validate will return an error of the result fails validation Validate(result interface{}) error // ExpectError is used by the validation code to understand of the test typically returns an error ExpectError() bool }
RPCTest is the common interface for a test. In the future we'll need some addition methods in particular if don't want to run tests that require unlocked accounts or if we want to skip certain namespaces
type RPCTestDynamicArgs ¶
type RPCTestDynamicArgs struct { Name string Method string Args func() []interface{} Validator func(result interface{}) error Flags RPCTestFlag }
RPCTestDynamicArgs is a simple implementation of the RPCTest that requires a function for Args which will be used to generate the args for testing.
func (*RPCTestDynamicArgs) ExpectError ¶
func (r *RPCTestDynamicArgs) ExpectError() bool
func (*RPCTestDynamicArgs) GetArgs ¶
func (r *RPCTestDynamicArgs) GetArgs() []interface{}
func (*RPCTestDynamicArgs) GetMethod ¶
func (r *RPCTestDynamicArgs) GetMethod() string
func (*RPCTestDynamicArgs) GetName ¶
func (r *RPCTestDynamicArgs) GetName() string
func (*RPCTestDynamicArgs) Validate ¶
func (r *RPCTestDynamicArgs) Validate(result interface{}) error
type RPCTestFilterArgs ¶
type RPCTestFilterArgs struct { FromBlock string `json:"fromBlock,omitempty"` ToBlock string `json:"toBlock,omitempty"` Address string `json:"address,omitempty"` Topics []interface{} `json:"topics,omitempty"` }
RPCTestFilterArgs is a simplified type to contain the flag needed to create a filter
type RPCTestFlag ¶
type RPCTestFlag uint64
RPCTestFlag is meant for bitmasking various flags to understand properties of the test
const ( FlagStrictValidation RPCTestFlag = 1 << iota // strict means the test is unsuitable for fuzzing / mutation because it most likely won't match FlagErrorValidation // error validation means the result is expected to be an error FlagRequiresUnlock // unlock means the test depends on unlocked accounts FlagEIP1559 // tests that would only exist with EIP-1559 enabled FlagOrderDependent // This flag indicates that the particular test might fail if shuffled )
type RPCTestGeneric ¶
type RPCTestGeneric struct { Name string Method string Args []interface{} Validator func(result interface{}) error Flags RPCTestFlag }
RPCTestGeneric is the simplest implementation of the RPCTest. Basically the implementation of the interface is managed by just returning hard coded values for method, args, validator, and error
func (*RPCTestGeneric) ExpectError ¶
func (r *RPCTestGeneric) ExpectError() bool
func (*RPCTestGeneric) GetArgs ¶
func (r *RPCTestGeneric) GetArgs() []interface{}
func (*RPCTestGeneric) GetMethod ¶
func (r *RPCTestGeneric) GetMethod() string
func (*RPCTestGeneric) GetName ¶
func (r *RPCTestGeneric) GetName() string
func (*RPCTestGeneric) Validate ¶
func (r *RPCTestGeneric) Validate(result interface{}) error
type RPCTestRawHTTP ¶
type RPCTestRawHTTP struct { Name string HTTPMethod string Args []interface{} Validator func(result interface{}) error Flags RPCTestFlag }
RPCTestRawHTTP is a raw RPCTest performed using HTTP requests. It does not leverage advanced HTTP libraries like `github.com/ethereum/go-ethereum/rpc`.
func (*RPCTestRawHTTP) ExpectError ¶
func (r *RPCTestRawHTTP) ExpectError() bool
func (*RPCTestRawHTTP) GetArgs ¶
func (r *RPCTestRawHTTP) GetArgs() []interface{}
func (*RPCTestRawHTTP) GetMethod ¶
func (r *RPCTestRawHTTP) GetMethod() string
func (*RPCTestRawHTTP) GetName ¶
func (r *RPCTestRawHTTP) GetName() string
func (*RPCTestRawHTTP) Validate ¶
func (r *RPCTestRawHTTP) Validate(result interface{}) error
type RPCTestTransactionArgs ¶
type RPCTestTransactionArgs struct { From string `json:"from,omitempty"` To string `json:"to,omitempty"` Gas string `json:"gas,omitempty"` GasPrice string `json:"gasPrice,omitempty"` MaxFeePerGas string `json:"maxFeePerGas,omitempty"` MaxPriorityFeePerGas string `json:"maxPriorityFeePerGas,omitempty"` Value string `json:"value,omitempty"` Nonce string `json:"nonce,omitempty"` Data string `json:"data"` }
RPCTestTransactionArgs is used to send transactions
Directories ¶
Path | Synopsis |
---|---|
Package argfuzz implements the randomizers, mutators, and fuzzers that can be utilized by gofuzz.
|
Package argfuzz implements the randomizers, mutators, and fuzzers that can be utilized by gofuzz. |
Package testreporter provides the utilities to capture, report, and log test results.
|
Package testreporter provides the utilities to capture, report, and log test results. |