Skip to content

Commit

Permalink
simplify loadgen Call
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhwarrier committed Dec 21, 2023
1 parent 428b650 commit 3516734
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions integration-tests/load/automationv2_1/gun.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type LogTriggerConfig struct {
}

type LogTriggerGun struct {
data [][][]byte
data [][]byte
addresses []string
multiCallAddress string
evmClient blockchain.EVMClient
Expand All @@ -46,32 +46,27 @@ func NewLogTriggerUser(
evmClient blockchain.EVMClient,
multicallAddress string,
) *LogTriggerGun {
var data1, data2, data3 [][]byte
var data [][]byte
var addresses []string

for _, c := range TriggerConfigs {
if c.NumberOfEvents > 0 {
d := generateCallData(1, 1, c.NumberOfEvents)
data1 = append(data1, d)
data = append(data, d)
addresses = append(addresses, c.Address)
}
if c.NumberOfSpamMatchingEvents > 0 {
d := generateCallData(1, 2, c.NumberOfSpamMatchingEvents)
data2 = append(data2, d)
data = append(data, d)
addresses = append(addresses, c.Address)
}
if c.NumberOfSpamNonMatchingEvents > 0 {
d := generateCallData(2, 2, c.NumberOfSpamNonMatchingEvents)
data3 = append(data3, d)
data = append(data, d)
addresses = append(addresses, c.Address)
}
}

var data [][][]byte
data = append(data, data1)
data = append(data, data2)
data = append(data, data3)

return &LogTriggerGun{
addresses: addresses,
data: data,
Expand All @@ -83,27 +78,26 @@ func NewLogTriggerUser(

func (m *LogTriggerGun) Call(_ *wasp.Generator) *wasp.Response {
var wg sync.WaitGroup
for _, d := range m.data {
var dividedData [][][]byte
chunkSize := 100
for i := 0; i < len(d); i += chunkSize {
end := i + chunkSize
if end > len(d) {
end = len(d)
}
dividedData = append(dividedData, d[i:end])
}
for _, a := range dividedData {
wg.Add(1)
go func(a [][]byte, m *LogTriggerGun) *wasp.Response {
defer wg.Done()
_, err := contracts.MultiCallLogTriggerLoadGen(m.evmClient, m.multiCallAddress, m.addresses, a)
if err != nil {
return &wasp.Response{Error: err.Error(), Failed: true}
}
return &wasp.Response{}
}(a, m)
var dividedData [][][]byte
d := m.data
chunkSize := 100
for i := 0; i < len(d); i += chunkSize {
end := i + chunkSize
if end > len(d) {
end = len(d)
}
dividedData = append(dividedData, d[i:end])
}
for _, a := range dividedData {
wg.Add(1)
go func(a [][]byte, m *LogTriggerGun) *wasp.Response {
defer wg.Done()
_, err := contracts.MultiCallLogTriggerLoadGen(m.evmClient, m.multiCallAddress, m.addresses, a)
if err != nil {
return &wasp.Response{Error: err.Error(), Failed: true}
}
return &wasp.Response{}
}(a, m)
}
wg.Wait()
return &wasp.Response{}
Expand Down

0 comments on commit 3516734

Please sign in to comment.