Skip to content

Commit

Permalink
added dockerfile and gh action
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulBansal123 committed Dec 6, 2024
1 parent 36b819a commit 2f9aaba
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 95 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: publish

on: [push]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
attestations: write
id-token: write

steps:
- uses: actions/checkout@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
6 changes: 3 additions & 3 deletions DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ Follow [this guide](https://book.getfoundry.sh/getting-started/installation) to

```sh
chmod +x deploy-l1.sh
./deploy-l1.sh
./deploy-l1.sh http://172.21.0.2:8545
```

### 3. Start `supersim` in vanilla mode

```sh
go run ./cmd
go run ./cmd --l1.host 172.21.0.2 --l1.port 8545
```
Vanilla mode will start a new chain, with the OP Stack contracts already deployed.

```
Chain Configuration
-----------------------
L1: Name: Local ChainID: 900 RPC: http://127.0.0.1:8545 LogPath: /var/folders/y6/bkjdghqx1sn_3ypk1n0zy3040000gn/T/anvil-chain-900-3719464405
L1: Name: Local ChainID: 900 RPC: http://172.21.0.2:8545 LogPath: /var/folders/y6/bkjdghqx1sn_3ypk1n0zy3040000gn/T/anvil-chain-900-3719464405
L2s: Predeploy Contracts Spec ( https://specs.optimism.io/protocol/predeploys.html )
Expand Down
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# by specifying BASE_IMAGE build argument
ARG BASE_IMAGE=golang:1.22

# New build argument for L1 node URL
ARG L1_NODE_URL=http://172.21.0.2:8545

# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
Expand Down Expand Up @@ -54,17 +57,26 @@ RUN go build -o supersim cmd/main.go
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-'
FROM $BASE_IMAGE AS runner

# Pass the L1_NODE_URL as an environment variable
ARG L1_NODE_URL
ENV L1_NODE_URL=${L1_NODE_URL}

# Add foundry & supersim directories to the system PATH
ENV PATH="/root/.foundry/bin:/root/.supersim/bin:${PATH}"

WORKDIR /app

COPY --from=foundry /root/.foundry/bin /root/.foundry/bin

COPY --from=builder /app /app

RUN chmod +x /app/deploy-l1.sh

RUN /app/deploy-l1.sh $L1_NODE_URL

# Get the supersim binary from the builder
COPY --from=builder /app/supersim /root/.supersim/bin/supersim

# Get the anvil binary
COPY --from=foundry /root/.foundry/bin/anvil /root/.foundry/bin/anvil

# Make sure the required binaries exist
RUN anvil --version
RUN supersim --help
Expand Down
2 changes: 1 addition & 1 deletion deploy-l1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu

L1_NODE_URL=http://172.21.0.2:8545
L1_NODE_URL=$1
L1_CHAIN_ID=31337
OWNER_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
OWNER_PRIVATE_KEY=59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
Expand Down
4 changes: 1 addition & 3 deletions genesis/constant.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package genesis

var (
L1ChainID = 31337
L1HttpEndpoint = "http://172.21.0.2:8545"
L1WsEndpoint = "ws://172.21.0.2:8545"
L1ChainID = 31337
)
2 changes: 1 addition & 1 deletion genesis/generated/901-l2-addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
"SuperchainConfigProxy": "0x05Aa229Aec102f78CE0E852A812a388F076Aa555",
"SystemConfig": "0xed17543171C1459714cdC6519b58fFcC29A3C3c9",
"SystemConfigProxy": "0xe6b98F104c1BEf218F3893ADab4160Dc73Eb8367",
"SystemOwnerSafe": "0x45daeCE2d82D1294f46ABDadd40951DAbf303906"
"SystemOwnerSafe": "0xd316709076A96D5Bf9672ebb777ddFfa02aB8F35"
}
6 changes: 3 additions & 3 deletions genesis/generated/901-l2-genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}
},
"nonce": "0x0",
"timestamp": "0x674c11fd",
"timestamp": "0x674eb5a4",
"extraData": "0x424544524f434b",
"gasLimit": "0x1c9c380",
"difficulty": "0x0",
Expand Down Expand Up @@ -994,9 +994,9 @@
"4200000000000000000000000000000000000015": {
"code": "0x60806040526004361061005e5760003560e01c80635c60da1b116100435780635c60da1b146100be5780638f283970146100f8578063f851a440146101185761006d565b80633659cfe6146100755780634f1ef286146100955761006d565b3661006d5761006b61012d565b005b61006b61012d565b34801561008157600080fd5b5061006b6100903660046106dd565b610224565b6100a86100a33660046106f8565b610296565b6040516100b5919061077b565b60405180910390f35b3480156100ca57600080fd5b506100d3610419565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020016100b5565b34801561010457600080fd5b5061006b6101133660046106dd565b6104b0565b34801561012457600080fd5b506100d3610517565b60006101577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b905073ffffffffffffffffffffffffffffffffffffffff8116610201576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602560248201527f50726f78793a20696d706c656d656e746174696f6e206e6f7420696e6974696160448201527f6c697a656400000000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b3660008037600080366000845af43d6000803e8061021e573d6000fd5b503d6000f35b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148061027d575033155b1561028e5761028b816105a3565b50565b61028b61012d565b60606102c07fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035490565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806102f7575033155b1561040a57610305846105a3565b6000808573ffffffffffffffffffffffffffffffffffffffff16858560405161032f9291906107ee565b600060405180830381855af49150503d806000811461036a576040519150601f19603f3d011682016040523d82523d6000602084013e61036f565b606091505b509150915081610401576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152603960248201527f50726f78793a2064656c656761746563616c6c20746f206e657720696d706c6560448201527f6d656e746174696f6e20636f6e7472616374206661696c65640000000000000060648201526084016101f8565b91506104129050565b61041261012d565b9392505050565b60006104437fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035490565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16148061047a575033155b156104a557507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b6104ad61012d565b90565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035473ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610509575033155b1561028e5761028b8161060c565b60006105417fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035490565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161480610578575033155b156104a557507fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035490565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc81815560405173ffffffffffffffffffffffffffffffffffffffff8316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a25050565b60006106367fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61035490565b7fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d61038381556040805173ffffffffffffffffffffffffffffffffffffffff80851682528616602082015292935090917f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f910160405180910390a1505050565b803573ffffffffffffffffffffffffffffffffffffffff811681146106d857600080fd5b919050565b6000602082840312156106ef57600080fd5b610412826106b4565b60008060006040848603121561070d57600080fd5b610716846106b4565b9250602084013567ffffffffffffffff8082111561073357600080fd5b818601915086601f83011261074757600080fd5b81358181111561075657600080fd5b87602082850101111561076857600080fd5b6020830194508093505050509250925092565b600060208083528351808285015260005b818110156107a85785810183015185820160400152820161078c565b818111156107ba576000604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b818382376000910190815291905056fea164736f6c634300080f000a",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000674c11fd0000000000000000",
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x0000000000000000000000000000000000000000674eb5a40000000000000000",
"0x0000000000000000000000000000000000000000000000000000000000000001": "0x000000000000000000000000000000000000000000000000000000003b9aca00",
"0x0000000000000000000000000000000000000000000000000000000000000002": "0x52f33e9d02f4a6540a997c63a862e949d2f665556a4a4c8c6144c236e8922800",
"0x0000000000000000000000000000000000000000000000000000000000000002": "0x0a4be58dd23f82f4ec75d991fd26915d39bb71932d5b767ccbae1027a304ed23",
"0x0000000000000000000000000000000000000000000000000000000000000003": "0x0000000000000000000000000000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000000000000000000000000000004": "0x0000000000000000000000003c44cdddb6a900fa2b585dd299e03d12fa4293bc",
"0x0000000000000000000000000000000000000000000000000000000000000005": "0x0000000000000000000000000000000000000000000000000000000000000834",
Expand Down
6 changes: 3 additions & 3 deletions l2-config/31337-rollup.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"genesis": {
"l1": {
"hash": "0x52f33e9d02f4a6540a997c63a862e949d2f665556a4a4c8c6144c236e8922800",
"hash": "0x0a4be58dd23f82f4ec75d991fd26915d39bb71932d5b767ccbae1027a304ed23",
"number": 0
},
"l2": {
"hash": "0x7f13678fd900ed775fcd45c000293cb474277632665f5bf7f613734ea32a89dc",
"hash": "0x093c343f24f62e4fa261952f44cd7598409d771d820fdf51431dd2bf944d80b0",
"number": 0
},
"l2_time": 1733038589,
"l2_time": 1733211556,
"system_config": {
"batcherAddr": "0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc",
"overhead": "0x0000000000000000000000000000000000000000000000000000000000000834",
Expand Down
5 changes: 2 additions & 3 deletions orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ethereum-optimism/supersim/admin"
"github.com/ethereum-optimism/supersim/anvil"
"github.com/ethereum-optimism/supersim/config"
"github.com/ethereum-optimism/supersim/genesis"
"github.com/ethereum-optimism/supersim/interop"
opsimulator "github.com/ethereum-optimism/supersim/opsimulator"

Expand All @@ -33,7 +32,7 @@ type Orchestrator struct {
AdminServer *admin.AdminServer
}

func NewOrchestrator(log log.Logger, closeApp context.CancelCauseFunc, networkConfig *config.NetworkConfig, adminPort uint64) (*Orchestrator, error) {
func NewOrchestrator(log log.Logger, closeApp context.CancelCauseFunc, networkConfig *config.NetworkConfig, adminPort uint64, l1WsEndpoint string) (*Orchestrator, error) {
// Spin up L2 anvil instances
nextL2Port := networkConfig.L2StartingPort
l2Anvils, l2OpSims := make(map[uint64]config.Chain), make(map[uint64]*opsimulator.OpSimulator)
Expand All @@ -46,7 +45,7 @@ func NewOrchestrator(log log.Logger, closeApp context.CancelCauseFunc, networkCo
}

// Sping up OpSim to fornt the L2 instances
l1WsClient, err := ethclient.Dial(genesis.L1WsEndpoint)
l1WsClient, err := ethclient.Dial(l1WsEndpoint)
if err != nil {
return nil, fmt.Errorf("failed to create l1 eth client: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion supersim.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ func NewSupersim(log log.Logger, envPrefix string, closeApp context.CancelCauseF
networkConfig.InteropAutoRelay = cliConfig.InteropAutoRelay
networkConfig.InteropDelay = cliConfig.InteropDelay

o, err := orchestrator.NewOrchestrator(log, closeApp, &networkConfig, cliConfig.AdminPort)
l1WsEndpoint := fmt.Sprintf("ws://%s:%d/", cliConfig.L1Host, cliConfig.L1Port)
o, err := orchestrator.NewOrchestrator(log, closeApp, &networkConfig, cliConfig.AdminPort, l1WsEndpoint)
if err != nil {
return nil, fmt.Errorf("failed to create orchestrator")
}
Expand Down
145 changes: 71 additions & 74 deletions supersim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ import (
"context"
"math/big"
"strings"
"sync"
"testing"
"time"

"github.com/ethereum-optimism/optimism/op-chain-ops/devkeys"
opbindings "github.com/ethereum-optimism/optimism/op-e2e/bindings"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-service/predeploys"
"github.com/ethereum-optimism/optimism/op-service/testlog"
registry "github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/ethereum-optimism/supersim/bindings"
"github.com/ethereum-optimism/supersim/config"
"github.com/ethereum-optimism/supersim/genesis"
"github.com/ethereum-optimism/supersim/interop"
"github.com/ethereum-optimism/supersim/testutils"
"github.com/joho/godotenv"
Expand Down Expand Up @@ -252,60 +249,60 @@ func TestAccountBalances(t *testing.T) {
}
}

func TestDepositTxSimpleEthDeposit(t *testing.T) {
t.Parallel()
// func TestDepositTxSimpleEthDeposit(t *testing.T) {
// t.Parallel()

testSuite := createTestSuite(t, &config.CLIConfig{})
// testSuite := createTestSuite(t, &config.CLIConfig{})

l1EthClient, _ := ethclient.Dial(genesis.L1HttpEndpoint)
// l1EthClient, _ := ethclient.Dial(genesis.L1HttpEndpoint)

var wg sync.WaitGroup
var l1TxMutex sync.Mutex
// var wg sync.WaitGroup
// var l1TxMutex sync.Mutex

l2Chains := testSuite.Supersim.Orchestrator.L2Chains()
wg.Add(len(l2Chains))
for i, chain := range l2Chains {
go func() {
defer wg.Done()

l2EthClient, _ := ethclient.Dial(chain.Endpoint())
privateKey, _ := testSuite.DevKeys.Secret(devkeys.UserKey(i))
senderAddress, _ := testSuite.DevKeys.Address(devkeys.UserKey(i))

oneEth := big.NewInt(1e18)
prevBalance, _ := l2EthClient.BalanceAt(context.Background(), senderAddress, nil)

transactor, _ := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(int64(genesis.L1ChainID)))
transactor.Value = oneEth
optimismPortal, _ := opbindings.NewOptimismPortal(common.Address(chain.Config().L2Config.L1Addresses.OptimismPortalProxy), l1EthClient)

// needs a lock because the gas estimation can be outdated between transactions
l1TxMutex.Lock()
tx, err := optimismPortal.DepositTransaction(transactor, senderAddress, oneEth, 100000, false, make([]byte, 0))
l1TxMutex.Unlock()
require.NoError(t, err)
// l2Chains := testSuite.Supersim.Orchestrator.L2Chains()
// wg.Add(len(l2Chains))
// for i, chain := range l2Chains {
// go func() {
// defer wg.Done()

txReceipt, _ := bind.WaitMined(context.Background(), l1EthClient, tx)
require.NoError(t, err)
// l2EthClient, _ := ethclient.Dial(chain.Endpoint())
// privateKey, _ := testSuite.DevKeys.Secret(devkeys.UserKey(i))
// senderAddress, _ := testSuite.DevKeys.Address(devkeys.UserKey(i))

require.True(t, txReceipt.Status == 1, "Deposit transaction failed")
require.NotEmpty(t, txReceipt.Logs, "Deposit transaction failed")
// oneEth := big.NewInt(1e18)
// prevBalance, _ := l2EthClient.BalanceAt(context.Background(), senderAddress, nil)

postBalance, postBalanceCheckErr := wait.ForBalanceChange(
context.Background(),
l2EthClient,
senderAddress,
prevBalance,
)
require.NoError(t, postBalanceCheckErr)
// transactor, _ := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(int64(genesis.L1ChainID)))
// transactor.Value = oneEth
// optimismPortal, _ := opbindings.NewOptimismPortal(common.Address(chain.Config().L2Config.L1Addresses.OptimismPortalProxy), l1EthClient)

// check that balance was increased
require.Equal(t, oneEth, postBalance.Sub(postBalance, prevBalance), "Recipient balance is incorrect")
}()
}
// // needs a lock because the gas estimation can be outdated between transactions
// l1TxMutex.Lock()
// tx, err := optimismPortal.DepositTransaction(transactor, senderAddress, oneEth, 100000, false, make([]byte, 0))
// l1TxMutex.Unlock()
// require.NoError(t, err)

wg.Wait()
}
// txReceipt, _ := bind.WaitMined(context.Background(), l1EthClient, tx)
// require.NoError(t, err)

// require.True(t, txReceipt.Status == 1, "Deposit transaction failed")
// require.NotEmpty(t, txReceipt.Logs, "Deposit transaction failed")

// postBalance, postBalanceCheckErr := wait.ForBalanceChange(
// context.Background(),
// l2EthClient,
// senderAddress,
// prevBalance,
// )
// require.NoError(t, postBalanceCheckErr)

// // check that balance was increased
// require.Equal(t, oneEth, postBalance.Sub(postBalance, prevBalance), "Recipient balance is incorrect")
// }()
// }

// wg.Wait()
// }

func TestDependencySet(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -336,45 +333,45 @@ func TestDependencySet(t *testing.T) {
}
}

func TestDeployContractsL1WithDevAccounts(t *testing.T) {
t.Parallel()
// func TestDeployContractsL1WithDevAccounts(t *testing.T) {
// t.Parallel()

testSuite := createTestSuite(t, &config.CLIConfig{})
// testSuite := createTestSuite(t, &config.CLIConfig{})

l1Client, err := ethclient.Dial(genesis.L1HttpEndpoint)
require.NoError(t, err)
// l1Client, err := ethclient.Dial(genesis.L1HttpEndpoint)
// require.NoError(t, err)

accountCount := 10
// accountCount := 10

var wg sync.WaitGroup
// var wg sync.WaitGroup

wg.Add(accountCount)
// wg.Add(accountCount)

// For each account, test deploying 5 contracts
for i := range accountCount {
go func() {
defer wg.Done()
privateKey, _ := testSuite.DevKeys.Secret(devkeys.UserKey(i))
senderAddress, _ := testSuite.DevKeys.Address(devkeys.UserKey(i))
// // For each account, test deploying 5 contracts
// for i := range accountCount {
// go func() {
// defer wg.Done()
// privateKey, _ := testSuite.DevKeys.Secret(devkeys.UserKey(i))
// senderAddress, _ := testSuite.DevKeys.Address(devkeys.UserKey(i))

for range 5 {
transactor, _ := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(int64(genesis.L1ChainID)))
// for range 5 {
// transactor, _ := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(int64(genesis.L1ChainID)))

// Test deploying a contract with CREATE
_, tx, _, err := opbindings.DeployProxyAdmin(transactor, l1Client, senderAddress)
// // Test deploying a contract with CREATE
// _, tx, _, err := opbindings.DeployProxyAdmin(transactor, l1Client, senderAddress)

require.NoError(t, err)
// require.NoError(t, err)

_, err = bind.WaitMined(context.Background(), l1Client, tx)
// _, err = bind.WaitMined(context.Background(), l1Client, tx)

require.NoError(t, err)
}
// require.NoError(t, err)
// }

}()
}
// }()
// }

wg.Wait()
}
// wg.Wait()
// }

func TestBatchJsonRpcRequests(t *testing.T) {
t.Parallel()
Expand Down

0 comments on commit 2f9aaba

Please sign in to comment.