-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscenario.go
More file actions
50 lines (43 loc) · 1.11 KB
/
scenario.go
File metadata and controls
50 lines (43 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package generator
import (
"sync"
"github.com/sei-protocol/sei-load/generator/scenarios"
"github.com/sei-protocol/sei-load/types"
)
type scenarioGenerator struct {
scenario scenarios.TxGenerator
accountPool types.AccountPool
mu sync.RWMutex
}
func NewScenarioGenerator(accounts types.AccountPool,
txg scenarios.TxGenerator) Generator {
return &scenarioGenerator{
scenario: txg,
accountPool: accounts,
}
}
func (g *scenarioGenerator) GenerateN(n int) []*types.LoadTx {
result := make([]*types.LoadTx, 0, n)
for i := 0; i < n; i++ {
if tx, ok := g.Generate(); ok {
result = append(result, tx)
} else {
break // Generator is done
}
}
return result
}
func (g *scenarioGenerator) Generate() (*types.LoadTx, bool) {
sender := g.accountPool.NextAccount()
receiver := g.accountPool.NextAccount()
return g.scenario.Generate(&types.TxScenario{
Name: g.scenario.Name(),
Sender: sender,
Receiver: receiver.Address,
}), true
}
func (sg *scenarioGenerator) GetAccountPools() []types.AccountPool {
sg.mu.RLock()
defer sg.mu.RUnlock()
return []types.AccountPool{sg.accountPool}
}