-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from ethereum-optimism/06-25-feat_spin_up_mult…
…iple_chains feat: spin up multiple chains
- Loading branch information
Showing
2 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,77 @@ | ||
package supersim | ||
|
||
import ( | ||
"fmt" | ||
|
||
"context" | ||
|
||
"github.com/ethereum-optimism/supersim/anvil" | ||
|
||
"github.com/ethereum/go-ethereum/log" | ||
) | ||
|
||
|
||
|
||
type Config struct { | ||
l1Chain anvil.Config | ||
l2Chains []anvil.Config | ||
} | ||
|
||
var DefaultConfig = Config{ | ||
l1Chain: anvil.Config{ChainId: 1, Port: 8545}, | ||
l2Chains: []anvil.Config{{ChainId: 10, Port: 9545}, {ChainId: 30, Port: 9555}}, | ||
} | ||
|
||
type Supersim struct { | ||
log log.Logger | ||
|
||
anvil *anvil.Anvil | ||
l1Chain *anvil.Anvil | ||
l2Chains map[uint64]*anvil.Anvil | ||
|
||
} | ||
|
||
func NewSupersim(log log.Logger) *Supersim { | ||
anvil := anvil.New(log, &anvil.Config{ChainId: 10, Port: 9545}) | ||
return &Supersim{log, anvil} | ||
func NewSupersim(log log.Logger, config *Config) *Supersim { | ||
l1Chain := anvil.New(log, &config.l1Chain) | ||
|
||
l2Chains := make(map[uint64]*anvil.Anvil) | ||
for _, l2Chain := range config.l2Chains { | ||
l2Chains[l2Chain.ChainId] = anvil.New(log, &l2Chain) | ||
} | ||
|
||
return &Supersim{log, l1Chain, l2Chains} | ||
} | ||
|
||
func (s *Supersim) Start(ctx context.Context) error { | ||
s.log.Info("starting supersim") | ||
return s.anvil.Start(ctx) | ||
|
||
if err := s.l1Chain.Start(ctx); err != nil { | ||
return fmt.Errorf("l1 chain failed to start: %w", err) | ||
} | ||
|
||
for _, l2Chain := range s.l2Chains { | ||
if err := l2Chain.Start(ctx); err!= nil { | ||
return fmt.Errorf("l2 chain failed to start: %w", err) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *Supersim) Stop(_ context.Context) error { | ||
s.log.Info("stopping supersim") | ||
return s.anvil.Stop() | ||
} | ||
|
||
for _, l2Chain := range s.l2Chains { | ||
if err := l2Chain.Stop(); err!= nil { | ||
return fmt.Errorf("l2 chain failed to stop: %w", err) | ||
} | ||
} | ||
|
||
if err := s.l1Chain.Stop(); err != nil { | ||
return fmt.Errorf("l1 chain failed to stop: %w", err) | ||
} | ||
|
||
return nil} | ||
|
||
func (s *Supersim) Stopped() bool { | ||
return s.anvil.Stopped() | ||
return s.l1Chain.Stopped() | ||
} |