-
Notifications
You must be signed in to change notification settings - Fork 772
feat(load2): add contract tests #4071
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting for context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR migrates contract tests from the original load framework to load 2.0, replacing the simple ZeroTransferTest
with a comprehensive RandomTest
that can execute multiple test types with configurable weights.
- Introduces a new
RandomTest
struct that uses weighted sampling to select from multiple test types - Adds 10 new contract test implementations (ReadTest, WriteTest, StateModificationTest, etc.)
- Updates the main load generator to deploy a contract and use the new random test selection
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
File | Description |
---|---|
tests/load2/tests.go | Adds RandomTest implementation and 10 contract test types with shared utility functions |
tests/load2/main/main.go | Updates main function to deploy contract and configure RandomTest with equal weights |
) { | ||
require := require.New(tc) | ||
|
||
index, ok := r.weighted.Sample(rand.Uint64N(r.totalWeight)) //#nosec G404 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this reflect load testing reproducibility, should we consider using a seeded random source?
) | ||
|
||
var _ Test = (*ZeroTransferTest)(nil) | ||
var ( | ||
maxFeeCap = big.NewInt(300000000000) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a config structure for example
type LoadTestConfig struct {
MaxFeeCap *big.Int
DefaultTimeout time.Duration
GasTipMultiplier int64
}
} | ||
|
||
type WriteTest struct { | ||
Contract *contracts.EVMLoadSimulator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed we're repeating the same setup in pretty much every test:
Contract *contracts.EVMLoadSimulator // in every struct
// and this exact block everywhere:
txOpts, err := newTxOpts(wallet.privKey, wallet.chainID, maxFeeCap, wallet.nonce)
require.NoError(err)
Could probably clean this up with a base struct or something. Here's one way that might work:
type BaseContractTest struct {
Contract *contracts.EVMLoadSimulator
}
func (b *BaseContractTest) executeContractTx(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
txFunc func(*bind.TransactOpts) (*types.Transaction, error),
) {
require := require.New(tc)
txOpts, err := newTxOpts(wallet.privKey, wallet.chainID, maxFeeCap, wallet.nonce)
require.NoError(err)
tx, err := txFunc(txOpts)
require.NoError(err)
require.NoError(wallet.SendTx(ctx, tx, time.Millisecond))
}
// Then tests become much simpler:
type ReadTest struct {
BaseContractTest
Count *big.Int
}
func (r ReadTest) Run(tc tests.TestContext, ctx context.Context, wallet *Wallet) {
r.executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return r.Contract.SimulateReads(txOpts, r.Count)
})
}
Would cut down the boilerplate quite a bit. Though there's probably other ways to approach this too this is just what came to mind first. What do you think?
Why this should be merged
This PR migrates over the existing contract tests from the original load framework into load 2.0. This PR also replaces the type of test used in load 2.0 testing (
ZeroTransferTest
=>RandomTest
).How this works
Migration with the following caveats:
How this was tested
CI
Need to be documented in RELEASES.md?
N/A