cltest

package
v1.13.3 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 100 Imported by: 0

Documentation

Overview

Importing cltest should only be for top level black box (X_test package) integration tests, for example testing against the Application object itself. Consider using a smaller scoped package: utils or testutils/* if possible.

Index

Constants

View Source
const (
	// APIKey of the fixture API user
	APIKey = "2d25e62eaf9143e993acaf48691564b2"
	// APISecret of the fixture API user.
	APISecret = "1eCP/w0llVkchejFaoBpfIGaLRxZK54lTXBCT22YLW+pdzE4Fafy/XO5LoJ2uwHi"
	// Collection of test fixture DB user emails per role
	APIEmailAdmin    = "apiuser@chainlink.test"
	APIEmailEdit     = "apiuser-edit@chainlink.test"
	APIEmailRun      = "apiuser-run@chainlink.test"
	APIEmailViewOnly = "apiuser-view-only@chainlink.test"
	// Password just a password we use everywhere for testing
	Password = testutils.Password
	// SessionSecret is the hardcoded secret solely used for test
	SessionSecret = "clsession_test_secret"
	// DefaultPeerID is the peer ID of the default p2p key
	DefaultPeerID = "12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X"
	// DefaultOCRKeyBundleID is the ID of the default ocr key bundle
	DefaultOCRKeyBundleID = "f5bf259689b26f1374efb3c9a9868796953a0f814bb2d39b968d0e61b58620a5"
	// DefaultOCR2KeyBundleID is the ID of the fixture ocr2 key bundle
	DefaultOCR2KeyBundleID = "92be59c45d0d7b192ef88d391f444ea7c78644f8607f567aab11d53668c27a4d"
	// Private key seed of test keys created with `big.NewInt(1)`, representations of value present in `scrub_logs` script
	KeyBigIntSeed = 1
)
View Source
const (
	// DBPollingInterval can't be too short to avoid DOSing the test database
	DBPollingInterval = 100 * time.Millisecond
	// AssertNoActionTimeout shouldn't be too long, or it will slow down tests
	AssertNoActionTimeout = 3 * time.Second
)
View Source
const (
	UseRealExternalInitiatorManager = "UseRealExternalInitiatorManager"
)

Variables

Functions

func AllExternalInitiators added in v0.6.6

func AllExternalInitiators(t testing.TB, db *sqlx.DB) []bridges.ExternalInitiator

func AssertCount added in v0.10.3

func AssertCount(t *testing.T, db *sqlx.DB, tableName string, expected int64)

func AssertCountStays added in v0.10.3

func AssertCountStays(t testing.TB, db *sqlx.DB, tableName string, want int64)

func AssertError

func AssertError(t testing.TB, want bool, err error)

func AssertEthTxAttemptCountStays added in v0.9.6

func AssertEthTxAttemptCountStays(t testing.TB, db *sqlx.DB, want int) []txmgr.EthTxAttempt

AssertEthTxAttemptCountStays asserts that the number of tx attempts remains at the provided value

func AssertPipelineRunsStays added in v0.10.4

func AssertPipelineRunsStays(t testing.TB, pipelineSpecID int32, db *sqlx.DB, want int) []pipeline.Run

AssertPipelineRunsStays asserts that the number of pipeline runs for a particular job remains at the provided values

func AssertPipelineTaskRunsErrored added in v1.5.0

func AssertPipelineTaskRunsErrored(t testing.TB, runs []pipeline.TaskRun)

func AssertPipelineTaskRunsSuccessful added in v0.10.11

func AssertPipelineTaskRunsSuccessful(t testing.TB, runs []pipeline.TaskRun)

func AssertRecordEventually added in v0.10.4

func AssertRecordEventually(t *testing.T, db *sqlx.DB, model interface{}, stmt string, check func() bool)

func AssertServerResponse

func AssertServerResponse(t testing.TB, resp *http.Response, expectedStatusCode int)

AssertServerResponse is used to match against a client response, will print any errors returned if the request fails.

func AwaitJobActive added in v0.10.8

func AwaitJobActive(t testing.TB, jobSpawner job.Spawner, jobID int32, waitFor time.Duration)

func BatchElemMatchesParams added in v1.3.0

func BatchElemMatchesParams(req rpc.BatchElem, arg interface{}, method string) bool

func BatchElemMustMatchParams added in v1.3.0

func BatchElemMustMatchParams(t *testing.T, req rpc.BatchElem, hash common.Hash, method string)

func CallbackOrTimeout

func CallbackOrTimeout(t testing.TB, msg string, callback func(), durationParams ...time.Duration)

func ClearDBTables added in v1.2.0

func ClearDBTables(t *testing.T, db *sqlx.DB, tables ...string)

ClearDBTables deletes all rows from the given tables

func CreateExternalInitiatorViaWeb added in v0.6.6

func CreateExternalInitiatorViaWeb(
	t testing.TB,
	app *TestApplication,
	payload string,
) *webpresenters.ExternalInitiatorAuthentication

CreateExternalInitiatorViaWeb creates a bridgetype via web using /v2/bridge_types

func CreateJobRunViaExternalInitiatorV2 added in v0.10.8

func CreateJobRunViaExternalInitiatorV2(
	t testing.TB,
	app *TestApplication,
	jobID uuid.UUID,
	eia auth.Token,
	body string,
) webpresenters.PipelineRunResource

func CreateJobRunViaUser added in v1.5.0

func CreateJobRunViaUser(
	t testing.TB,
	app *TestApplication,
	jobID uuid.UUID,
	body string,
) webpresenters.PipelineRunResource

func CreateJobViaWeb added in v0.9.9

func CreateJobViaWeb(t testing.TB, app *TestApplication, request []byte) job.Job

func CreateJobViaWeb2 added in v0.10.4

func CreateJobViaWeb2(t testing.TB, app *TestApplication, spec string) webpresenters.JobResource

func CreateUserWithRole added in v1.7.0

func CreateUserWithRole(t testing.TB, role sessions.UserRole) sessions.User

CreateUserWithRole inserts a new user with specified role and associated test DB email into the test DB

func DecodeSessionCookie

func DecodeSessionCookie(value string) (string, error)

func DeleteJobViaWeb added in v0.10.8

func DeleteJobViaWeb(t testing.TB, app *TestApplication, jobID int32)

func DynamicFeeTransactionsFromTipCaps added in v1.1.0

func DynamicFeeTransactionsFromTipCaps(tipCaps ...int64) []evmtypes.Transaction

DynamicFeeTransactionsFromTipCaps returns EIP-1559 transactions with the given TipCaps (FeeCap is arbitrary)

func DynamicFeeTransactionsFromTipCapsTxType added in v1.10.0

func DynamicFeeTransactionsFromTipCapsTxType(code evmtypes.TxType, tipCaps ...int64) []evmtypes.Transaction

func EmptyCLIContext

func EmptyCLIContext() *cli.Context

func EventuallyExpectationsMet added in v0.10.3

func EventuallyExpectationsMet(t *testing.T, mock testifyExpectationsAsserter, timeout time.Duration, interval time.Duration)

func FlagSetApplyFromAction added in v1.12.0

func FlagSetApplyFromAction(action interface{}, flagSet *flag.FlagSet, parentCommand string)

FlagSetApplyFromAction applies the flags from action to the flagSet. `parentCommand` will filter the app commands and only applies the flags if the command/subcommand has a parent with that name, if left empty no filtering is done

func GetLogs added in v0.8.4

func GetLogs(t *testing.T, rv interface{}, logs EthereumLogIterator) []interface{}

GetLogs drains logs of EVM log representations. Since those log representations don't fit into a type hierarchy, this API is a bit awkward. It returns the logs as a slice of blank interface{}s, and if rv is non-nil, it must be a pointer to a slice for elements of the same type as the logs, in which case GetLogs will append the logs to it.

func Head(val interface{}) *evmtypes.Head

Head given the value convert it into an Head

func JSONFromBytes

func JSONFromBytes(t testing.TB, body []byte) models.JSON

JSONFromBytes creates JSON from a given byte array

func JSONFromFixture

func JSONFromFixture(t *testing.T, path string) models.JSON

JSONFromFixture create models.JSON from file path

func JSONFromString

func JSONFromString(t testing.TB, body string, args ...interface{}) models.JSON

JSONFromString create JSON from given body and arguments

func LegacyTransactionsFromGasPrices added in v1.1.0

func LegacyTransactionsFromGasPrices(gasPrices ...int64) []evmtypes.Transaction

LegacyTransactionsFromGasPrices returns transactions matching the given gas prices

func LegacyTransactionsFromGasPricesTxType added in v1.10.0

func LegacyTransactionsFromGasPricesTxType(code evmtypes.TxType, gasPrices ...int64) []evmtypes.Transaction

func LogFromFixture

func LogFromFixture(t *testing.T, path string) types.Log

LogFromFixture create ethtypes.log from file path

func MakeConfigDigest added in v0.9.7

func MakeConfigDigest(t *testing.T) ocrtypes.ConfigDigest

func MakeDirectRequestJobSpec added in v0.10.6

func MakeDirectRequestJobSpec(t *testing.T) *job.Job

func Mine added in v0.10.3

func Mine(backend *backends.SimulatedBackend, blockTime time.Duration) (stopMining func())

Mine forces the simulated backend to produce a new block every 2 seconds

func MinimalOCRNonBootstrapSpec added in v0.9.6

func MinimalOCRNonBootstrapSpec(contractAddress, transmitterAddress ethkey.EIP55Address, peerID p2pkey.PeerID, keyBundleID string) string

func MockApplicationEthCalls added in v0.9.9

func MockApplicationEthCalls(t *testing.T, app *TestApplication, ethClient *evmMocks.Client, sub *evmMocks.Subscription)

MockApplicationEthCalls mocks all calls made by the chainlink application as standard when starting and stopping

func MustAddKeyToKeystore added in v0.9.9

func MustAddKeyToKeystore(t testing.TB, key ethkey.KeyV2, chainID *big.Int, ethKeyStore keystore.Eth)

func MustAddRandomKeyToKeystore added in v0.9.9

func MustAddRandomKeyToKeystore(t testing.TB, ethKeyStore keystore.Eth) (ethkey.KeyV2, common.Address)

func MustBytesToConfigDigest added in v0.9.7

func MustBytesToConfigDigest(t *testing.T, b []byte) ocrtypes.ConfigDigest

func MustCreateBridge added in v1.1.0

func MustCreateBridge(t testing.TB, db *sqlx.DB, opts BridgeOpts, cfg pg.QConfig) (bta *bridges.BridgeTypeAuthentication, bt *bridges.BridgeType)

MustCreateBridge creates a bridge Be careful not to specify a name here unless you ABSOLUTELY need to This is because name is a unique index and identical names used across transactional tests will lock/deadlock

func MustGenerateRandomKey added in v0.9.9

func MustGenerateRandomKey(t testing.TB) ethkey.KeyV2

func MustGenerateRandomKeyState added in v1.1.0

func MustGenerateRandomKeyState(t testing.TB) ethkey.State

func MustGenerateSessionCookie

func MustGenerateSessionCookie(t testing.TB, value string) *http.Cookie

func MustGetStateForKey added in v1.1.0

func MustGetStateForKey(t testing.TB, kst keystore.Eth, key ethkey.KeyV2) ethkey.State

func MustInsertConfirmedEthTxBySaveFetchedReceipts added in v1.13.0

func MustInsertConfirmedEthTxBySaveFetchedReceipts(t *testing.T, borm txmgr.ORM, fromAddress common.Address, nonce int64, blockNum int64, chainID big.Int) (etx txmgr.EthTx)

func MustInsertConfirmedEthTxWithLegacyAttempt added in v1.1.0

func MustInsertConfirmedEthTxWithLegacyAttempt(t *testing.T, borm txmgr.ORM, nonce int64, broadcastBeforeBlockNum int64, fromAddress common.Address) txmgr.EthTx

func MustInsertConfirmedEthTxWithReceipt added in v0.10.7

func MustInsertConfirmedEthTxWithReceipt(t *testing.T, borm txmgr.ORM, fromAddress common.Address, nonce, blockNum int64) (etx txmgr.EthTx)

Inserts into eth_receipts but does not update eth_txes or eth_tx_attempts

func MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt added in v1.3.0

func MustInsertConfirmedMissingReceiptEthTxWithLegacyAttempt(
	t *testing.T, borm txmgr.ORM, nonce int64, broadcastBeforeBlockNum int64,
	broadcastAt time.Time, fromAddress common.Address) txmgr.EthTx

func MustInsertEthReceipt added in v0.8.7

func MustInsertEthReceipt(t *testing.T, borm txmgr.ORM, blockNumber int64, blockHash common.Hash, txHash common.Hash) txmgr.EthReceipt

func MustInsertExternalInitiator added in v0.10.11

func MustInsertExternalInitiator(t *testing.T, orm bridges.ORM) (ei bridges.ExternalInitiator)

func MustInsertExternalInitiatorWithOpts added in v0.10.11

func MustInsertExternalInitiatorWithOpts(t *testing.T, orm bridges.ORM, opts ExternalInitiatorOpts) (ei bridges.ExternalInitiator)

func MustInsertFatalErrorEthTx added in v0.8.7

func MustInsertFatalErrorEthTx(t *testing.T, borm txmgr.ORM, fromAddress common.Address) txmgr.EthTx

func MustInsertHead added in v0.10.4

func MustInsertHead(t *testing.T, db *sqlx.DB, cfg pg.QConfig, number int64) evmtypes.Head

func MustInsertInProgressEthTxWithAttempt added in v0.9.6

func MustInsertInProgressEthTxWithAttempt(t *testing.T, borm txmgr.ORM, nonce int64, fromAddress common.Address) txmgr.EthTx

func MustInsertKeeperJob added in v0.10.3

func MustInsertKeeperJob(t *testing.T, db *sqlx.DB, korm keeper.ORM, from ethkey.EIP55Address, contract ethkey.EIP55Address) job.Job

func MustInsertKeeperRegistry added in v0.10.3

func MustInsertKeeperRegistry(t *testing.T, db *sqlx.DB, korm keeper.ORM, ethKeyStore keystore.Eth, keeperIndex, numKeepers, blockCountPerTurn int32) (keeper.Registry, job.Job)

func MustInsertOffchainreportingOracleSpec added in v0.9.0

func MustInsertOffchainreportingOracleSpec(t *testing.T, db *sqlx.DB, transmitterAddress ethkey.EIP55Address) job.OCROracleSpec

func MustInsertPipelineRun added in v0.9.10

func MustInsertPipelineRun(t *testing.T, db *sqlx.DB) (run pipeline.Run)

func MustInsertPipelineRunWithStatus added in v1.12.0

func MustInsertPipelineRunWithStatus(t *testing.T, db *sqlx.DB, pipelineSpecID int32, status pipeline.RunStatus) (run pipeline.Run)

func MustInsertPipelineSpec added in v1.11.0

func MustInsertPipelineSpec(t *testing.T, db *sqlx.DB) (spec pipeline.Spec)

func MustInsertRandomKey added in v0.8.11

func MustInsertRandomKey(
	t testing.TB,
	keystore keystore.Eth,
	opts ...interface{},
) (ethkey.KeyV2, common.Address)

MustInsertRandomKey inserts a randomly generated (not cryptographically secure) key for testing By default it is enabled for the fixture chain

func MustInsertRandomKeyReturningState added in v1.1.0

func MustInsertRandomKeyReturningState(t testing.TB,
	keystore keystore.Eth,
	opts ...interface{},
) (ethkey.State, common.Address)

func MustInsertRevertedEthReceipt added in v1.5.0

func MustInsertRevertedEthReceipt(t *testing.T, borm txmgr.ORM, blockNumber int64, blockHash common.Hash, txHash common.Hash) txmgr.EthReceipt

func MustInsertUnconfirmedEthTx added in v0.10.6

func MustInsertUnconfirmedEthTx(t *testing.T, borm txmgr.ORM, nonce int64, fromAddress common.Address, opts ...interface{}) txmgr.EthTx

func MustInsertUnconfirmedEthTxWithAttemptState added in v1.5.0

func MustInsertUnconfirmedEthTxWithAttemptState(t *testing.T, borm txmgr.ORM, nonce int64, fromAddress common.Address, txAttemptState txmgr.EthTxAttemptState, opts ...interface{}) txmgr.EthTx

func MustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt added in v1.1.0

func MustInsertUnconfirmedEthTxWithBroadcastDynamicFeeAttempt(t *testing.T, borm txmgr.ORM, nonce int64, fromAddress common.Address, opts ...interface{}) txmgr.EthTx

func MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt added in v1.1.0

func MustInsertUnconfirmedEthTxWithBroadcastLegacyAttempt(t *testing.T, borm txmgr.ORM, nonce int64, fromAddress common.Address, opts ...interface{}) txmgr.EthTx

func MustInsertUnconfirmedEthTxWithInsufficientEthAttempt added in v0.9.9

func MustInsertUnconfirmedEthTxWithInsufficientEthAttempt(t *testing.T, borm txmgr.ORM, nonce int64, fromAddress common.Address) txmgr.EthTx

func MustInsertUnfinishedPipelineTaskRun added in v0.9.7

func MustInsertUnfinishedPipelineTaskRun(t *testing.T, db *sqlx.DB, pipelineRunID int64) (tr pipeline.TaskRun)

func MustInsertUnstartedEthTx added in v0.10.5

func MustInsertUnstartedEthTx(t *testing.T, borm txmgr.ORM, fromAddress common.Address, opts ...interface{}) txmgr.EthTx

func MustInsertUpkeepForRegistry added in v0.10.3

func MustInsertUpkeepForRegistry(t *testing.T, db *sqlx.DB, cfg keeper.Config, registry keeper.Registry) keeper.UpkeepRegistration

func MustInsertV2JobSpec added in v0.10.3

func MustInsertV2JobSpec(t *testing.T, db *sqlx.DB, transmitterAddress common.Address) job.Job

func MustInsertWebhookSpec added in v0.10.11

func MustInsertWebhookSpec(t *testing.T, db *sqlx.DB) (job.Job, job.WebhookSpec)

func MustJSONMarshal added in v0.10.8

func MustJSONMarshal(t *testing.T, val interface{}) string

func MustNewUser added in v0.8.4

func MustNewUser(t *testing.T, email, password string) sessions.User

func MustParseDuration

func MustParseDuration(t testing.TB, durationStr string) time.Duration

func MustParseURL

func MustParseURL(t testing.TB, input string) *url.URL

func MustRandomBytes added in v0.9.9

func MustRandomBytes(t *testing.T, l int) (b []byte)

func MustRandomP2PPeerID added in v0.10.10

func MustRandomP2PPeerID(t *testing.T) p2ppeer.ID

func MustRandomUser added in v0.8.4

func MustRandomUser(t testing.TB) sessions.User

MustRandomUser inserts a new admin user with a random email into the test DB

func MustReadFile

func MustReadFile(t testing.TB, file string) []byte

MustReadFile loads a file but should never fail

func MustSendingKeyStates added in v1.1.0

func MustSendingKeyStates(t *testing.T, ethKeyStore keystore.Eth, chainID *big.Int) []ethkey.State

func MustWebURL added in v0.10.11

func MustWebURL(t *testing.T, s string) *models.WebURL

func NewBridgeType

NewBridgeType create new bridge type given info slice

func NewChainSetMockWithOneChain added in v1.1.0

func NewChainSetMockWithOneChain(t testing.TB, ethClient evmclient.Client, cfg evmconfig.ChainScopedConfig) evm.ChainSet

func NewContractMockReceiver added in v0.10.3

func NewContractMockReceiver(t *testing.T, ethMock *evmmocks.Client, abi abi.ABI, address common.Address) contractMockReceiver

func NewDynamicFeeEthTxAttempt added in v1.1.0

func NewDynamicFeeEthTxAttempt(t *testing.T, etxID int64) txmgr.EthTxAttempt

func NewEIP55Address added in v0.9.3

func NewEIP55Address() ethkey.EIP55Address

func NewEthBroadcaster added in v0.9.3

func NewEthBroadcaster(t testing.TB, db *sqlx.DB, ethClient evmclient.Client, keyStore txmgr.KeyStore, config evmconfig.ChainScopedConfig, keyStates []ethkey.State, checkerFactory txmgr.TransmitCheckerFactory, nonceAutoSync bool) *txmgr.EthBroadcaster

NewEthBroadcaster creates a new txmgr.EthBroadcaster for use in testing.

func NewEthConfirmer added in v0.10.10

func NewEthConfirmer(t testing.TB, orm txmgr.ORM, ethClient evmclient.Client, config evmconfig.ChainScopedConfig, ks keystore.Eth, keyStates []ethkey.State, fn txmgr.ResumeCallback) *txmgr.EthConfirmer

func NewEthMocks added in v0.9.9

func NewEthMocks(t testing.TB) *evmMocks.Client

func NewEthMocksWithDefaultChain added in v1.1.0

func NewEthMocksWithDefaultChain(t testing.TB) (c *evmMocks.Client)

func NewEthMocksWithStartupAssertions added in v0.9.9

func NewEthMocksWithStartupAssertions(t testing.TB) *evmMocks.Client

func NewEthMocksWithTransactionsOnBlocksAssertions added in v1.2.0

func NewEthMocksWithTransactionsOnBlocksAssertions(t testing.TB) *evmMocks.Client

NewEthMocksWithTransactionsOnBlocksAssertions sets an Eth mock with transactions on blocks

func NewEthReceipt added in v1.1.0

func NewEthReceipt(t *testing.T, blockNumber int64, blockHash common.Hash, txHash common.Hash, status uint64) txmgr.EthReceipt

func NewEthTx added in v0.8.7

func NewEthTx(t *testing.T, fromAddress common.Address) txmgr.EthTx

func NewEventBroadcaster added in v1.1.0

func NewEventBroadcaster(t testing.TB, dbURL url.URL) pg.EventBroadcaster

func NewHTTPMockServer

func NewHTTPMockServer(
	t *testing.T,
	status int,
	wantMethod string,
	response string,
	callback ...func(http.Header, string),
) *httptest.Server

NewHTTPMockServer create http test server with passed in parameters

func NewHTTPMockServerWithAlterableResponse added in v0.8.4

func NewHTTPMockServerWithAlterableResponse(
	t *testing.T, response func() string) (server *httptest.Server)

func NewHTTPMockServerWithAlterableResponseAndRequest added in v0.10.5

func NewHTTPMockServerWithAlterableResponseAndRequest(t *testing.T, response func() string, callback func(r *http.Request)) (server *httptest.Server)

func NewHTTPMockServerWithRequest added in v0.9.10

func NewHTTPMockServerWithRequest(
	t *testing.T,
	status int,
	response string,
	callback func(r *http.Request),
) *httptest.Server

NewHTTPMockServerWithRequest creates http test server that makes the request available in the callback

func NewKeyStore added in v0.10.8

func NewKeyStore(t testing.TB, db *sqlx.DB, cfg pg.QConfig) keystore.Master

NewKeyStore returns a new, unlocked keystore

func NewLegacyEthTxAttempt added in v1.1.0

func NewLegacyEthTxAttempt(t *testing.T, etxID int64) txmgr.EthTxAttempt

func NewMockAuthenticatedHTTPClient

func NewMockAuthenticatedHTTPClient(lggr logger.Logger, cfg cmd.ClientOpts, sessionID string) cmd.HTTPClient

func NewPeerID added in v0.9.3

func NewPeerID() p2ppeer.ID

func NewRandomPositiveInt64 added in v1.8.0

func NewRandomPositiveInt64() int64

func NewSession

func NewSession(optionalSessionID ...string) clsessions.Session

func NewSimulatedBackend added in v1.1.0

func NewSimulatedBackend(t *testing.T, alloc core.GenesisAlloc, gasLimit uint32) *backends.SimulatedBackend

func NewTestChainScopedConfig added in v1.1.0

func NewTestChainScopedConfig(t testing.TB) evmconfig.ChainScopedConfig

func NewTestGeneralConfig deprecated added in v1.1.0

func NewTestGeneralConfig(t testing.TB) *configtest.TestGeneralConfig

Deprecated: use configtest/v2.NewTestGeneralConfig https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config

func NewTxmORM added in v1.3.0

func NewTxmORM(t *testing.T, db *sqlx.DB, cfg pg.QConfig) txmgr.ORM

func NewWSServer

func NewWSServer(t *testing.T, chainID *big.Int, callback testutils.JSONRPCHandler) string

NewWSServer starts a websocket server which invokes callback for each message received. If chainID is set, then eth_chainId calls will be automatically handled.

func ParseJSON

func ParseJSON(t testing.TB, body io.Reader) models.JSON

func ParseJSONAPIErrors

func ParseJSONAPIErrors(t testing.TB, body io.Reader) *models.JSONAPIErrors

func ParseJSONAPIResponse

func ParseJSONAPIResponse(t testing.TB, resp *http.Response, resource interface{}) error

ParseJSONAPIResponse parses the response and returns the JSONAPI resource.

func ParseJSONAPIResponseMeta

func ParseJSONAPIResponseMeta(input []byte) (map[string]*json.RawMessage, error)

ParseJSONAPIResponseMeta parses the bytes of the root document and returns a map of *json.RawMessage's within the 'meta' key.

func ParseJSONAPIResponseMetaCount

func ParseJSONAPIResponseMetaCount(input []byte) (int, error)

ParseJSONAPIResponseMetaCount parses the bytes of the root document and returns the value of the 'count' key from the 'meta' section.

func ParseResponseBody

func ParseResponseBody(t testing.TB, resp *http.Response) []byte

ParseResponseBody will parse the given response into a byte slice

func RandomLog added in v0.10.3

func RandomLog(t *testing.T) types.Log

func RawNewRoundLog added in v0.10.3

func RawNewRoundLog(t *testing.T, contractAddr common.Address, blockHash common.Hash, blockNumber uint64, logIndex uint, removed bool) types.Log

func RawNewRoundLogWithTopics added in v0.10.6

func RawNewRoundLogWithTopics(t *testing.T, contractAddr common.Address, blockHash common.Hash, blockNumber uint64, logIndex uint, removed bool, topics []common.Hash) types.Log

func RequireTxSuccessful added in v0.10.11

func RequireTxSuccessful(t testing.TB, client TransactionReceipter, txHash common.Hash) *types.Receipt

func SimulateIncomingHeads added in v0.10.3

func SimulateIncomingHeads(t *testing.T, args SimulateIncomingHeadsArgs) (done chan struct{})

SimulateIncomingHeads spawns a goroutine which sends a stream of heads and closes the returned channel when finished.

func TxReceiptFromFixture

func TxReceiptFromFixture(t *testing.T, path string) *types.Receipt

TxReceiptFromFixture create ethtypes.log from file path

func UnauthenticatedGet added in v1.10.0

func UnauthenticatedGet(t testing.TB, url string, headers map[string]string) (*http.Response, func())

func UnauthenticatedPost added in v0.6.7

func UnauthenticatedPost(t testing.TB, url string, body io.Reader, headers map[string]string) (*http.Response, func())

func WaitForCount added in v0.10.3

func WaitForCount(t *testing.T, db *sqlx.DB, tableName string, want int64)

func WaitForPipeline added in v1.1.0

func WaitForPipeline(t testing.TB, nodeID int, jobID int32, expectedPipelineRuns int, expectedTaskRuns int, jo job.ORM, timeout, poll time.Duration, state pipeline.RunStatus) []pipeline.Run

func WaitForPipelineComplete added in v0.9.9

func WaitForPipelineComplete(t testing.TB, nodeID int, jobID int32, expectedPipelineRuns int, expectedTaskRuns int, jo job.ORM, timeout, poll time.Duration) []pipeline.Run

func WaitForPipelineError added in v1.1.0

func WaitForPipelineError(t testing.TB, nodeID int, jobID int32, expectedPipelineRuns int, expectedTaskRuns int, jo job.ORM, timeout, poll time.Duration) []pipeline.Run

func WaitForSpecErrorV2 added in v0.10.4

func WaitForSpecErrorV2(t *testing.T, db *sqlx.DB, jobID int32, count int) []job.SpecError

WaitForSpecErrorV2 polls until the passed in jobID has count number of job spec errors.

func WebURL

func WebURL(t testing.TB, unparsed string) models.WebURL

WebURL parses a url into a models.WebURL

Types

type Awaiter added in v0.9.3

type Awaiter chan struct{}

func NewAwaiter added in v0.9.3

func NewAwaiter() Awaiter

func (Awaiter) AssertHappened added in v0.10.9

func (a Awaiter) AssertHappened(t *testing.T, expected bool)

func (Awaiter) AwaitOrFail added in v0.9.3

func (a Awaiter) AwaitOrFail(t testing.TB, durationParams ...time.Duration)

func (Awaiter) ItHappened added in v0.9.3

func (a Awaiter) ItHappened()

type BlockedRunner

type BlockedRunner struct {
	Done chan struct{}
}

BlockedRunner is a Runner that blocks until its channel is posted to

func (BlockedRunner) Run

Run runs the blocked runner, doesn't return until the channel is signalled

type Blocks added in v0.10.10

type Blocks struct {
	Hashes []common.Hash

	Heads map[int64]*evmtypes.Head
	// contains filtered or unexported fields
}

Blocks - a helper logic to construct a range of linked heads and an ability to fork and create logs from them

func NewBlocks added in v0.10.10

func NewBlocks(t *testing.T, numHashes int) *Blocks

func (*Blocks) ForkAt added in v0.10.10

func (b *Blocks) ForkAt(t *testing.T, blockNum int64, numHashes int) *Blocks

func (*Blocks) HashesMap added in v0.10.10

func (b *Blocks) HashesMap() map[int64]common.Hash

func (*Blocks) Head added in v0.10.10

func (b *Blocks) Head(number uint64) *evmtypes.Head

func (*Blocks) LogOnBlockNum added in v0.10.10

func (b *Blocks) LogOnBlockNum(i uint64, addr common.Address) types.Log

func (*Blocks) LogOnBlockNumRemoved added in v0.10.10

func (b *Blocks) LogOnBlockNumRemoved(i uint64, addr common.Address) types.Log

func (*Blocks) LogOnBlockNumWithIndex added in v0.10.10

func (b *Blocks) LogOnBlockNumWithIndex(i uint64, logIndex uint, addr common.Address) types.Log

func (*Blocks) LogOnBlockNumWithIndexRemoved added in v0.10.10

func (b *Blocks) LogOnBlockNumWithIndexRemoved(i uint64, logIndex uint, addr common.Address) types.Log

func (*Blocks) LogOnBlockNumWithTopics added in v0.10.10

func (b *Blocks) LogOnBlockNumWithTopics(i uint64, logIndex uint, addr common.Address, topics []common.Hash) types.Log

func (*Blocks) NewHead added in v1.0.0

func (b *Blocks) NewHead(number uint64) *evmtypes.Head

type BridgeOpts added in v1.1.0

type BridgeOpts struct {
	Name string
	URL  string
}

type EmptyRunner

type EmptyRunner struct{}

EmptyRunner is an EmptyRunner

func (EmptyRunner) Run

Run runs the empty runner

type EthereumLogIterator added in v0.8.4

type EthereumLogIterator interface{ Next() bool }

EthereumLogIterator is the interface provided by gethwrapper representations of EVM logs.

type EventWebSocketServer

type EventWebSocketServer struct {
	*httptest.Server

	Connected      chan struct{}
	Disconnected   chan struct{}
	ReceivedText   chan string
	ReceivedBinary chan []byte
	URL            *url.URL
	// contains filtered or unexported fields
}

EventWebSocketServer is a web socket server designed specifically for testing

func NewEventWebSocketServer

func NewEventWebSocketServer(t *testing.T) (*EventWebSocketServer, func())

NewEventWebSocketServer returns a new EventWebSocketServer

func (*EventWebSocketServer) Broadcast

func (wss *EventWebSocketServer) Broadcast(message string) error

Broadcast sends a message to every web socket client connected to the EventWebSocketServer

func (EventWebSocketServer) ConnectionsCount added in v1.4.0

func (wss EventWebSocketServer) ConnectionsCount() int

func (*EventWebSocketServer) WriteCloseMessage

func (wss *EventWebSocketServer) WriteCloseMessage()

WriteCloseMessage tells connected clients to disconnect. Useful to emulate that the websocket server is shutting down without actually shutting down. This overcomes httptest.Server's inability to restart on the same URL:port.

type ExternalInitiatorOpts added in v0.10.11

type ExternalInitiatorOpts struct {
	NamePrefix     string
	URL            *models.WebURL
	OutgoingSecret string
	OutgoingToken  string
}

type HTTPClientCleaner

type HTTPClientCleaner struct {
	HTTPClient cmd.HTTPClient
	// contains filtered or unexported fields
}

func (*HTTPClientCleaner) Delete

func (r *HTTPClientCleaner) Delete(path string) (*http.Response, func())

func (*HTTPClientCleaner) Get

func (r *HTTPClientCleaner) Get(path string, headers ...map[string]string) (*http.Response, func())

func (*HTTPClientCleaner) Patch

func (r *HTTPClientCleaner) Patch(path string, body io.Reader, headers ...map[string]string) (*http.Response, func())

func (*HTTPClientCleaner) Post

func (r *HTTPClientCleaner) Post(path string, body io.Reader) (*http.Response, func())

func (*HTTPClientCleaner) Put added in v0.8.2

func (r *HTTPClientCleaner) Put(path string, body io.Reader) (*http.Response, func())

type HeadBuffer added in v1.0.0

type HeadBuffer struct {
	Heads []*evmtypes.Head
	// contains filtered or unexported fields
}

HeadBuffer - stores heads in sequence, with increasing timestamps

func NewHeadBuffer added in v1.0.0

func NewHeadBuffer(t *testing.T) *HeadBuffer

func (*HeadBuffer) Append added in v1.0.0

func (hb *HeadBuffer) Append(head *evmtypes.Head)

type HeadTrackableFunc added in v0.10.3

type HeadTrackableFunc func(context.Context, *evmtypes.Head)

func (HeadTrackableFunc) OnNewLongestChain added in v0.10.3

func (fn HeadTrackableFunc) OnNewLongestChain(ctx context.Context, head *evmtypes.Head)

type InstanceAppFactory

type InstanceAppFactory struct {
	App chainlink.Application
}

InstanceAppFactory is an InstanceAppFactory

func (InstanceAppFactory) NewApplication

NewApplication creates a new application with specified config

type InstantClock

type InstantClock struct{}

InstantClock an InstantClock

func (InstantClock) After

func (InstantClock) After(_ time.Duration) <-chan time.Time

After return channel of time

func (InstantClock) Now

func (InstantClock) Now() time.Time

Now returns the current local time

type JobPipelineV2TestHelper added in v0.10.5

type JobPipelineV2TestHelper struct {
	Prm pipeline.ORM
	Jrm job.ORM
	Pr  pipeline.Runner
}

func NewJobPipelineV2 added in v0.10.5

func NewJobPipelineV2(t testing.TB, cfg config.BasicConfig, cc evm.ChainSet, db *sqlx.DB, keyStore keystore.Master, restrictedHTTPClient, unrestrictedHTTPClient *http.Client) JobPipelineV2TestHelper

type MockAPIInitializer

type MockAPIInitializer struct {
	Count int
	// contains filtered or unexported fields
}

func NewMockAPIInitializer added in v1.1.0

func NewMockAPIInitializer(t testing.TB) *MockAPIInitializer

func (*MockAPIInitializer) Initialize

func (m *MockAPIInitializer) Initialize(orm sessions.ORM, lggr logger.Logger) (sessions.User, error)

type MockChangePasswordPrompter

type MockChangePasswordPrompter struct {
	web.UpdatePasswordRequest
	// contains filtered or unexported fields
}

func (MockChangePasswordPrompter) Prompt

type MockCookieAuthenticator

type MockCookieAuthenticator struct {
	SessionID string
	Error     error
	// contains filtered or unexported fields
}

func (MockCookieAuthenticator) Authenticate

func (MockCookieAuthenticator) Cookie

func (m MockCookieAuthenticator) Cookie() (*http.Cookie, error)

func (MockCookieAuthenticator) Logout added in v1.3.0

func (m MockCookieAuthenticator) Logout() error

type MockCountingPrompter

type MockCountingPrompter struct {
	T              *testing.T
	EnteredStrings []string
	Count          int
	NotTerminal    bool
}

MockCountingPrompter is a mock counting prompt

func (*MockCountingPrompter) IsTerminal

func (p *MockCountingPrompter) IsTerminal() bool

IsTerminal always returns true in tests

func (*MockCountingPrompter) PasswordPrompt

func (p *MockCountingPrompter) PasswordPrompt(string) string

PasswordPrompt returns an entered string

func (*MockCountingPrompter) Prompt

func (p *MockCountingPrompter) Prompt(string) string

Prompt returns an entered string

type MockCron

type MockCron struct {
	Entries []MockCronEntry
	// contains filtered or unexported fields
}

MockCron represents a mock cron

func (*MockCron) AddFunc

func (mc *MockCron) AddFunc(schd string, fn func()) (cron.EntryID, error)

AddFunc appends a schedule to mockcron entries

func (*MockCron) RunEntries

func (mc *MockCron) RunEntries()

RunEntries run every function for each mockcron entry

func (*MockCron) Start

func (*MockCron) Start()

Start starts the mockcron

func (*MockCron) Stop

func (*MockCron) Stop() context.Context

Stop stops the mockcron

type MockCronEntry

type MockCronEntry struct {
	Schedule string
	Function func()
}

MockCronEntry a cron schedule and function

type MockHeadTrackable

type MockHeadTrackable struct {
	// contains filtered or unexported fields
}

MockHeadTrackable allows you to mock HeadTrackable

func (*MockHeadTrackable) OnNewLongestChain added in v0.8.5

func (m *MockHeadTrackable) OnNewLongestChain(context.Context, *evmtypes.Head)

OnNewLongestChain increases the OnNewLongestChainCount count by one

func (*MockHeadTrackable) OnNewLongestChainCount added in v0.8.5

func (m *MockHeadTrackable) OnNewLongestChainCount() int32

OnNewLongestChainCount returns the count of new heads, safely.

type MockPasswordPrompter

type MockPasswordPrompter struct {
	Password string
}

func (MockPasswordPrompter) Prompt

func (m MockPasswordPrompter) Prompt() string

type MockSecretGenerator added in v1.0.0

type MockSecretGenerator struct{}

func (MockSecretGenerator) Generate added in v1.0.0

func (m MockSecretGenerator) Generate(string) ([]byte, error)

type MockSessionRequestBuilder

type MockSessionRequestBuilder struct {
	Count int
	Error error
}

func (*MockSessionRequestBuilder) Build

type MockSubscription

type MockSubscription struct {
	Errors chan error
	// contains filtered or unexported fields
}

MockSubscription a mock subscription

func EmptyMockSubscription

func EmptyMockSubscription(t testing.TB) *MockSubscription

EmptyMockSubscription return empty MockSubscription

func (*MockSubscription) Err

func (mes *MockSubscription) Err() <-chan error

Err returns error channel from mes

func (*MockSubscription) Unsubscribe

func (mes *MockSubscription) Unsubscribe()

Unsubscribe closes the subscription

type NeverSleeper

type NeverSleeper struct{}

NeverSleeper is a struct that never sleeps

func (NeverSleeper) After

func (ns NeverSleeper) After() time.Duration

After returns a duration

func (NeverSleeper) Duration

func (ns NeverSleeper) Duration() time.Duration

Duration returns a duration

func (NeverSleeper) Reset

func (ns NeverSleeper) Reset()

Reset resets the never sleeper

func (NeverSleeper) Sleep

func (ns NeverSleeper) Sleep()

Sleep puts the never sleeper to sleep

type RendererMock

type RendererMock struct {
	Renders []interface{}
}

RendererMock a mock renderer

func (*RendererMock) Render

func (rm *RendererMock) Render(v interface{}, headers ...string) error

Render appends values to renderer mock

type SimulateIncomingHeadsArgs added in v0.10.3

type SimulateIncomingHeadsArgs struct {
	StartBlock, EndBlock int64
	HeadTrackables       []httypes.HeadTrackable
	Blocks               *Blocks
}

type TestApplication

type TestApplication struct {
	*chainlink.ChainlinkApplication
	Logger  logger.Logger
	Server  *httptest.Server
	Started bool
	Backend *backends.SimulatedBackend
	Keys    []ethkey.KeyV2
	// contains filtered or unexported fields
}

TestApplication holds the test application and test servers

func NewApplication

func NewApplication(t testing.TB, flagsAndDeps ...interface{}) *TestApplication

NewApplication creates a New TestApplication along with a NewConfig It mocks the keystore with no keys or accounts by default

func NewApplicationEVMDisabled added in v1.1.0

func NewApplicationEVMDisabled(t *testing.T) *TestApplication

NewApplicationEVMDisabled creates a new application with default config but EVM disabled Useful for testing controllers

func NewApplicationWithConfig

func NewApplicationWithConfig(t testing.TB, cfg config.GeneralConfig, flagsAndDeps ...interface{}) *TestApplication

NewApplicationWithConfig creates a New TestApplication with specified test config. This should only be used in full integration tests. For controller tests, see NewApplicationEVMDisabled.

func NewApplicationWithConfigAndKey

func NewApplicationWithConfigAndKey(t testing.TB, c config.GeneralConfig, flagsAndDeps ...interface{}) *TestApplication

NewApplicationWithConfigAndKey creates a new TestApplication with the given testorm it will also provide an unlocked account on the keystore

func NewApplicationWithConfigV2AndKeyOnSimulatedBlockchain added in v1.10.0

func NewApplicationWithConfigV2AndKeyOnSimulatedBlockchain(
	t testing.TB,
	cfg coreconfig.GeneralConfig,
	backend *backends.SimulatedBackend,
	flagsAndDeps ...interface{},
) *TestApplication

NewApplicationWithConfigV2AndKeyOnSimulatedBlockchain is like NewApplicationWithConfigAndKeyOnSimulatedBlockchain but cfg should be v2, and configtest.NewGeneralConfigSimulated used to include the simulated chain (testutils.SimulatedChainID).

func NewApplicationWithKey

func NewApplicationWithKey(t *testing.T, flagsAndDeps ...interface{}) *TestApplication

NewApplicationWithKey creates a new TestApplication along with a new config It uses the native keystore and will load any keys that are in the database

func NewLegacyApplicationEVMDisabled deprecated added in v1.10.0

func NewLegacyApplicationEVMDisabled(t *testing.T) *TestApplication

Deprecated: use NewApplicationEVMDisabled https://app.shortcut.com/chainlinklabs/story/33622/remove-legacy-config

func (*TestApplication) Import added in v1.0.0

func (ta *TestApplication) Import(content string)

ImportKey adds private key to the application keystore and database

func (*TestApplication) MustSeedNewSession added in v0.8.4

func (ta *TestApplication) MustSeedNewSession(roleFixtureUserAPIEmail string) (id string)

func (*TestApplication) NewAuthenticatingClient

func (ta *TestApplication) NewAuthenticatingClient(prompter cmd.Prompter) *cmd.Client

func (*TestApplication) NewClientAndRenderer

func (ta *TestApplication) NewClientAndRenderer() (*cmd.Client, *RendererMock)

NewClientAndRenderer creates a new cmd.Client for the test application

func (*TestApplication) NewClientOpts added in v1.5.0

func (ta *TestApplication) NewClientOpts() cmd.ClientOpts

func (*TestApplication) NewHTTPClient

func (ta *TestApplication) NewHTTPClient(roleFixtureUserAPIEmail string) HTTPClientCleaner

func (*TestApplication) Start added in v0.8.2

func (ta *TestApplication) Start(ctx context.Context) error

Start starts the chainlink app and registers Stop to clean up at end of test.

func (*TestApplication) Stop

func (ta *TestApplication) Stop() error

Stop will stop the test application and perform cleanup

type TransactionReceipter added in v0.10.11

type TransactionReceipter interface {
	TransactionReceipt(context.Context, common.Hash) (*types.Receipt, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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