Skip to content

Commit

Permalink
avoid using array in emitlog
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhwarrier committed Dec 18, 2023
1 parent 674023e commit ae5508b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 59 deletions.
6 changes: 3 additions & 3 deletions contracts/src/v0.8/tests/LogEmitter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ contract LogEmitter {
}
}

function EmitLog4(uint256[] memory v, uint256 w) public {
for (uint256 i = 0; i < v.length; i++) {
emit Log4(v[i], w);
function EmitLog4(uint256 v, uint256 w, uint256 c) public {
for (uint256 i = 0; i < c; i++) {
emit Log4(v, w);
}
}
}
18 changes: 9 additions & 9 deletions core/gethwrappers/generated/log_emitter/log_emitter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ keeper_registry_wrapper1_3: ../../contracts/solc/v0.8.6/KeeperRegistry1_3/Keeper
keeper_registry_wrapper2_0: ../../contracts/solc/v0.8.6/KeeperRegistry2_0/KeeperRegistry2_0.abi ../../contracts/solc/v0.8.6/KeeperRegistry2_0/KeeperRegistry2_0.bin c32dea7d5ef66b7c58ddc84ddf69aa44df1b3ae8601fbc271c95be4ff5853056
keeper_registry_wrapper_2_1: ../../contracts/solc/v0.8.16/KeeperRegistry2_1/KeeperRegistry2_1.abi ../../contracts/solc/v0.8.16/KeeperRegistry2_1/KeeperRegistry2_1.bin 604e4a0cd980c713929b523b999462a3aa0ed06f96ff563a4c8566cf59c8445b
keepers_vrf_consumer: ../../contracts/solc/v0.8.6/KeepersVRFConsumer/KeepersVRFConsumer.abi ../../contracts/solc/v0.8.6/KeepersVRFConsumer/KeepersVRFConsumer.bin fa75572e689c9e84705c63e8dbe1b7b8aa1a8fe82d66356c4873d024bb9166e8
log_emitter: ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.abi ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.bin 343db77de2c67be230221c2139cc6a015aa9636242afd3d5fdcac17af0897d29
log_emitter: ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.abi ../../contracts/solc/v0.8.19/LogEmitter/LogEmitter.bin 4b129ab93432c95ff9143f0631323e189887668889e0b36ccccf18a571e41ccf
log_triggered_streams_lookup_wrapper: ../../contracts/solc/v0.8.16/LogTriggeredStreamsLookup/LogTriggeredStreamsLookup.abi ../../contracts/solc/v0.8.16/LogTriggeredStreamsLookup/LogTriggeredStreamsLookup.bin f8da43a927c1a66238a9f4fd5d5dd7e280e361daa0444da1f7f79498ace901e1
log_upkeep_counter_wrapper: ../../contracts/solc/v0.8.6/LogUpkeepCounter/LogUpkeepCounter.abi ../../contracts/solc/v0.8.6/LogUpkeepCounter/LogUpkeepCounter.bin 42426bbb83f96dfbe55fc576d6c65020eaeed690e2289cf99b0c4aa810a5f4ec
mock_aggregator_proxy: ../../contracts/solc/v0.8.6/MockAggregatorProxy/MockAggregatorProxy.abi ../../contracts/solc/v0.8.6/MockAggregatorProxy/MockAggregatorProxy.bin b16c108f3dd384c342ddff5e94da7c0a8d39d1be5e3d8f2cf61ecc7f0e50ff42
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/contracts/contract_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ type LogEmitter interface {
Address() common.Address
EmitLogInts(ints []int) (*types.Transaction, error)
EmitLogIntsIndexed(ints []int) (*types.Transaction, error)
EmitLogIntsMultiIndexed(ints []int, ints2 int) (*types.Transaction, error)
EmitLogIntMultiIndexed(ints int, ints2 int, count int) (*types.Transaction, error)
EmitLogStrings(strings []string) (*types.Transaction, error)
EmitLogInt(payload int) (*types.Transaction, error)
EmitLogIntIndexed(payload int) (*types.Transaction, error)
Expand Down
8 changes: 2 additions & 6 deletions integration-tests/contracts/test_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,12 @@ func (e *LogEmitterContract) EmitLogIntsIndexed(ints []int) (*types.Transaction,
return tx, e.client.ProcessTransaction(tx)
}

func (e *LogEmitterContract) EmitLogIntsMultiIndexed(ints []int, ints2 int) (*types.Transaction, error) {
func (e *LogEmitterContract) EmitLogIntMultiIndexed(ints int, ints2 int, count int) (*types.Transaction, error) {
opts, err := e.client.TransactionOpts(e.client.GetDefaultWallet())
if err != nil {
return nil, err
}
bigInts := make([]*big.Int, len(ints))
for i, v := range ints {
bigInts[i] = big.NewInt(int64(v))
}
tx, err := e.instance.EmitLog4(opts, bigInts, big.NewInt(int64(ints2)))
tx, err := e.instance.EmitLog4(opts, big.NewInt(int64(ints)), big.NewInt(int64(ints2)), big.NewInt(int64(count)))
if err != nil {
return nil, err
}
Expand Down
56 changes: 17 additions & 39 deletions integration-tests/load/automationv2_1/gun.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,71 +8,49 @@ import (
)

type LogTriggerGun struct {
triggerContract contracts.LogEmitter
logger zerolog.Logger
triggerPayload []int
spamPayload []int
spamNPayload []int
triggerContract contracts.LogEmitter
logger zerolog.Logger
numberOfEvents int
numberOfSpamMatchingEvents int
numberOfSpamNonMatchingEvents int
}

func NewLogTriggerUser(
triggerContract contracts.LogEmitter,
logger zerolog.Logger,
numberOfEvents int,
numberOfSpamEvents int,
numberOfSpamMatchingEvents int,
numberOfSpamNonMatchingEvents int,
) *LogTriggerGun {

triggerPayload := make([]int, 0)
spamPayload := make([]int, 0)
spamNPayload := make([]int, 0)

if numberOfEvents > 0 {
for i := 0; i < numberOfEvents; i++ {
triggerPayload = append(triggerPayload, 1)
}
}

if numberOfSpamEvents > 0 {
for i := 0; i < numberOfSpamEvents; i++ {
spamPayload = append(spamPayload, 1)
}
}

if numberOfSpamNonMatchingEvents > 0 {
for i := 0; i < numberOfSpamNonMatchingEvents; i++ {
spamNPayload = append(spamNPayload, 2)
}
}

return &LogTriggerGun{
triggerContract: triggerContract,
logger: logger,
triggerPayload: triggerPayload,
spamPayload: spamPayload,
spamNPayload: spamNPayload,
triggerContract: triggerContract,
logger: logger,
numberOfEvents: numberOfEvents,
numberOfSpamMatchingEvents: numberOfSpamMatchingEvents,
numberOfSpamNonMatchingEvents: numberOfSpamNonMatchingEvents,
}
}

func (m *LogTriggerGun) Call(_ *wasp.Generator) *wasp.Response {
m.logger.Debug().Str("Trigger address", m.triggerContract.Address().String()).Msg("Triggering upkeep")

if len(m.triggerPayload) > 0 {
_, err := m.triggerContract.EmitLogIntsMultiIndexed(m.triggerPayload, 1)
if m.numberOfEvents > 0 {
_, err := m.triggerContract.EmitLogIntMultiIndexed(1, 1, m.numberOfEvents)
if err != nil {
return &wasp.Response{Error: err.Error(), Failed: true}
}
}

if len(m.spamPayload) > 0 {
_, err := m.triggerContract.EmitLogIntsMultiIndexed(m.spamPayload, 2)
if m.numberOfSpamMatchingEvents > 0 {
_, err := m.triggerContract.EmitLogIntMultiIndexed(1, 2, m.numberOfSpamMatchingEvents)
if err != nil {
return &wasp.Response{Error: err.Error(), Failed: true}
}
}

if len(m.spamNPayload) > 0 {
_, err := m.triggerContract.EmitLogIntsMultiIndexed(m.spamNPayload, 2)
if m.numberOfSpamNonMatchingEvents > 0 {
_, err := m.triggerContract.EmitLogIntMultiIndexed(2, 2, m.numberOfSpamNonMatchingEvents)
if err != nil {
return &wasp.Response{Error: err.Error(), Failed: true}
}
Expand Down

0 comments on commit ae5508b

Please sign in to comment.