Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
s4rv4d committed Nov 13, 2024
1 parent 66f4b56 commit ded5b96
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
5 changes: 2 additions & 3 deletions admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewAdminServer(log log.Logger, port uint64, networkConfig *config.NetworkCo
}

func (s *AdminServer) Start(ctx context.Context) error {
router := setupRouter(s)
router := s.setupRouter()

s.srv = &http.Server{Handler: router}

Expand Down Expand Up @@ -96,12 +96,11 @@ func filterByChainID(chains []config.ChainConfig, chainId uint64) *config.ChainC
return nil
}

func setupRouter(s *AdminServer) *gin.Engine {
func (s *AdminServer) setupRouter() *gin.Engine {
gin.SetMode(gin.ReleaseMode)
router := gin.New()
router.Use(gin.Recovery())

// Set up RPC server
rpcServer := rpc.NewServer()
rpcMethods := &RPCMethods{
Log: s.log,
Expand Down
56 changes: 39 additions & 17 deletions admin/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (

"github.com/ethereum-optimism/optimism/op-service/testlog"
"github.com/ethereum-optimism/supersim/config"
"github.com/ethereum-optimism/supersim/testutils"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rpc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -47,25 +49,45 @@ func TestAdminServerBasicFunctionality(t *testing.T) {
func TestGetL1AddressesRPC(t *testing.T) {
networkConfig := config.GetDefaultNetworkConfig(uint64(time.Now().Unix()), "")
testlog := testlog.Logger(t, log.LevelInfo)
server := NewAdminServer(testlog, 0, &networkConfig)
defer server.Stop(context.Background())

// Start the server
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go server.Start(ctx)
time.Sleep(1 * time.Second) // Allow time for the server to start

// Dial the RPC server
client, err := rpc.Dial(server.Endpoint())
require.NoError(t, err)

var addresses map[string]string
chainID := uint64(902)
err = client.CallContext(context.Background(), &addresses, "admin_getL1Addresses", chainID)
adminServer := NewAdminServer(testlog, 0, &networkConfig)
t.Cleanup(func() { cancel() })

require.NoError(t, err)
require.NoError(t, adminServer.Start(ctx))

require.Equal(t, "0xeCA0f912b4bd255f3851951caE5775CC9400aA3B", addresses["L2CrossDomainMessenger"])
require.Equal(t, "0x67B2aB287a32bB9ACe84F6a5A30A62597b10AdE9", addresses["L2StandardBridge"])
waitErr := testutils.WaitForWithTimeout(context.Background(), 500*time.Millisecond, 10*time.Second, func() (bool, error) {
// Dial the RPC server
client, err := rpc.Dial(adminServer.Endpoint())
require.NoError(t, err)

var addresses map[string]string
chainID := uint64(902)
err = client.CallContext(context.Background(), &addresses, "admin_getL1Addresses", chainID)

require.NoError(t, err)

expectedAddresses := map[string]string{
"AddressManager": "0x90D0B458313d3A207ccc688370eE76B75200EadA",
"L1CrossDomainMessengerProxy": "0xeCA0f912b4bd255f3851951caE5775CC9400aA3B",
"L1ERC721BridgeProxy": "0xdC0917C61A4CD589B29b6464257d564C0abeBB2a",
"L1StandardBridgeProxy": "0x67B2aB287a32bB9ACe84F6a5A30A62597b10AdE9",
"L2OutputOracleProxy": "0x0000000000000000000000000000000000000000",
"OptimismMintableERC20FactoryProxy": "0xd4E933aa1f37A755135d7623488a383f8208CC7c",
"OptimismPortalProxy": "0x35e67BC631C327b60C6A39Cff6b03a8adBB19c2D",
"ProxyAdmin": "0x0000000000000000000000000000000000000000",
"SuperchainConfig": "0x0000000000000000000000000000000000000000",
"SystemConfigProxy": "0xFb295Aa436F23BE2Bd17678Adf1232bdec02FED1",
}

for key, expectedValue := range expectedAddresses {
if addresses[key] != expectedValue {
return false, nil
}
}

return true, nil
})

assert.NoError(t, waitErr)
}
1 change: 0 additions & 1 deletion supersim.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func NewSupersim(log log.Logger, envPrefix string, closeApp context.CancelCauseF
return nil, fmt.Errorf("failed to create orchestrator")
}

// passing network config to admin server
adminServer := admin.NewAdminServer(log, cliConfig.AdminPort, &networkConfig)

return &Supersim{log, cliConfig, &networkConfig, o, adminServer}, nil
Expand Down

0 comments on commit ded5b96

Please sign in to comment.