Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion tests/load/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Each test must satisfy the following interface for compatibility with the load g
```go
type Test interface {
// Run should create a signed transaction and broadcast it to the network via wallet.
Run(tc tests.TestContext, ctx context.Context, wallet *Wallet)
Run(tc tests.TestContext, wallet *Wallet)
}
```

Expand Down
5 changes: 3 additions & 2 deletions tests/load/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

type Test interface {
Run(tc tests.TestContext, ctx context.Context, wallet *Wallet)
Run(tc tests.TestContext, wallet *Wallet)
}

type Worker struct {
Expand Down Expand Up @@ -99,5 +99,6 @@ func execTestWithRecovery(ctx context.Context, log logging.Logger, test Test, wa
defer tc.Recover()
contextWithTimeout, cancel := context.WithTimeout(ctx, testTimeout)
defer cancel()
test.Run(tc, contextWithTimeout, wallet)
tc.SetDefaultContextParent(contextWithTimeout)
test.Run(tc, wallet)
}
107 changes: 27 additions & 80 deletions tests/load/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,7 @@ func NewRandomWeightedTest(
}, nil
}

func (r *RandomWeightedTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
func (r *RandomWeightedTest) Run(tc tests.TestContext, wallet *Wallet) {
require := require.New(tc)

r.mu.Lock()
Expand All @@ -221,7 +217,7 @@ func (r *RandomWeightedTest) Run(
index, ok := r.weighted.Sample(uint64(sampleValue))
require.True(ok)

r.tests[index].Run(tc, ctx, wallet)
r.tests[index].Run(tc, wallet)
}

type WeightedTest struct {
Expand All @@ -233,11 +229,7 @@ type TransferTest struct {
Value *big.Int
}

func (t TransferTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
func (t TransferTest) Run(tc tests.TestContext, wallet *Wallet) {
require := require.New(tc)

maxValue := int64(100 * 1_000_000_000 / params.TxGas)
Expand All @@ -263,20 +255,16 @@ func (t TransferTest) Run(
})
require.NoError(err)

require.NoError(wallet.SendTx(ctx, tx))
require.NoError(wallet.SendTx(tc.GetDefaultContextParent(), tx))
}

type ReadTest struct {
Contract *contracts.EVMLoadSimulator
Count *big.Int
}

func (r ReadTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
func (r ReadTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return r.Contract.SimulateReads(txOpts, r.Count)
})
}
Expand All @@ -286,12 +274,8 @@ type WriteTest struct {
Count *big.Int
}

func (w WriteTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
func (w WriteTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return w.Contract.SimulateRandomWrite(txOpts, w.Count)
})
}
Expand All @@ -301,12 +285,8 @@ type StateModificationTest struct {
Count *big.Int
}

func (s StateModificationTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
func (s StateModificationTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return s.Contract.SimulateModification(txOpts, s.Count)
})
}
Expand All @@ -316,12 +296,8 @@ type HashingTest struct {
Count *big.Int
}

func (h HashingTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
func (h HashingTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return h.Contract.SimulateHashing(txOpts, h.Count)
})
}
Expand All @@ -331,12 +307,8 @@ type MemoryTest struct {
Count *big.Int
}

func (m MemoryTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
func (m MemoryTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return m.Contract.SimulateMemory(txOpts, m.Count)
})
}
Expand All @@ -346,12 +318,8 @@ type CallDepthTest struct {
Count *big.Int
}

func (c CallDepthTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
func (c CallDepthTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return c.Contract.SimulateCallDepth(txOpts, c.Count)
})
}
Expand All @@ -360,25 +328,17 @@ type ContractCreationTest struct {
Contract *contracts.EVMLoadSimulator
}

func (c ContractCreationTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, c.Contract.SimulateContractCreation)
func (c ContractCreationTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, c.Contract.SimulateContractCreation)
}

type PureComputeTest struct {
Contract *contracts.EVMLoadSimulator
NumIterations *big.Int
}

func (p PureComputeTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
func (p PureComputeTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return p.Contract.SimulatePureCompute(txOpts, p.NumIterations)
})
}
Expand All @@ -388,12 +348,8 @@ type LargeEventTest struct {
NumEvents *big.Int
}

func (l LargeEventTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
func (l LargeEventTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return l.Contract.SimulateLargeEvent(txOpts, l.NumEvents)
})
}
Expand All @@ -402,32 +358,23 @@ type ExternalCallTest struct {
Contract *contracts.EVMLoadSimulator
}

func (e ExternalCallTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, e.Contract.SimulateExternalCall)
func (e ExternalCallTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, e.Contract.SimulateExternalCall)
}

type TrieStressTest struct {
Contract *contracts.TrieStressTest
NumValues *big.Int
}

func (t TrieStressTest) Run(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
) {
executeContractTx(tc, ctx, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
func (t TrieStressTest) Run(tc tests.TestContext, wallet *Wallet) {
executeContractTx(tc, wallet, func(txOpts *bind.TransactOpts) (*types.Transaction, error) {
return t.Contract.WriteValues(txOpts, t.NumValues)
})
}

func executeContractTx(
tc tests.TestContext,
ctx context.Context,
wallet *Wallet,
txFunc func(*bind.TransactOpts) (*types.Transaction, error),
) {
Expand All @@ -439,7 +386,7 @@ func executeContractTx(
tx, err := txFunc(txOpts)
require.NoError(err)

require.NoError(wallet.SendTx(ctx, tx))
require.NoError(wallet.SendTx(tc.GetDefaultContextParent(), tx))
}

// newTxOpts returns transactions options for contract calls, with sending disabled
Expand Down