Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Aug 30, 2024
1 parent db32f45 commit 6d4c5ed
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/compile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
branches:
- main
push:
branches:
- main

jobs:
build_and_run:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/op_proposer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ on:
- main
paths:
- 'op-proposer-go/**'
push:
branches:
- main
paths:
- 'op-proposer-go/**'

jobs:
test_op_proposer_go:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/pr_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
types:
- opened
- edited
push:
branches:
- main

permissions:
pull-requests: read
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ on:
pull_request:
branches:
- main
push:
branches:
- main
workflow_dispatch:

env:
Expand Down
127 changes: 127 additions & 0 deletions op-proposer-go/proposer/proposer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package proposer

import (
"context"
"flag"
"fmt"
"math/big"
"os"
"testing"

opsuccinctbindings "github.com/succinctlabs/op-succinct-go/bindings"
"github.com/ethereum-optimism/optimism/op-proposer/metrics"
opservice "github.com/ethereum-optimism/optimism/op-service"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/joho/godotenv"
"github.com/succinctlabs/op-succinct-go/proposer/flags"
"github.com/urfave/cli/v2"
)

// Tests checkpointing a block hash on an L2OO contract.
func TestCheckpointBlockHash(t *testing.T) {
app := cli.NewApp()
app.Flags = flags.Flags
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
for _, f := range app.Flags {
f.Apply(flagSet)
}
cliCtx := cli.NewContext(app, flagSet, nil)

err := godotenv.Load("../../.env.server")
if err != nil {
t.Fatalf("Error loading .env file: %v", err)
}

err = cliCtx.Set(flags.L1EthRpcFlag.Name, os.Getenv("L1_RPC"))
if err != nil {
t.Fatalf("failed to set L1EthRpcFlag: %v", err)
}
err = cliCtx.Set(flags.RollupRpcFlag.Name, os.Getenv("L2_NODE_RPC"))
if err != nil {
t.Fatalf("failed to set RollupRpcFlag: %v", err)
}
err = cliCtx.Set(flags.L2OOAddressFlag.Name, os.Getenv("L2OO_ADDRESS"))
if err != nil {
t.Fatalf("failed to set L2OOAddressFlag: %v", err)
}
err = cliCtx.Set(flags.PollIntervalFlag.Name, os.Getenv("POLL_INTERVAL"))
if err != nil {
t.Fatalf("failed to set PollIntervalFlag: %v", err)
}
err = cliCtx.Set(flags.BeaconRpcFlag.Name, os.Getenv("L1_BEACON_RPC"))
if err != nil {
t.Fatalf("failed to set BeaconRpcFlag: %v", err)
}
err = cliCtx.Set(flags.L2ChainIDFlag.Name, os.Getenv("L2_CHAIN_ID"))
if err != nil {
t.Fatalf("failed to set L2ChainIDFlag: %v", err)
}
err = cliCtx.Set(txmgr.PrivateKeyFlagName, os.Getenv("PRIVATE_KEY"))
if err != nil {
t.Fatalf("failed to set PrivateKeyFlag: %v", err)
}

if err := flags.CheckRequired(cliCtx); err != nil {
t.Fatalf("failed to check required flags: %v", err)
}
cfg := NewConfig(cliCtx)
if err := cfg.Check(); err != nil {
t.Fatalf("invalid CLI flags: %v", err)
}

l := oplog.NewLogger(oplog.AppOut(cliCtx), cfg.LogConfig)
oplog.SetGlobalLogHandler(l.Handler())
opservice.ValidateEnvVars(flags.EnvVarPrefix, flags.Flags, l)

txMgrConfig := txmgr.ReadCLIConfig(cliCtx)
procName := "default"
metrics := metrics.NewMetrics(procName)
txManager, err := txmgr.NewSimpleTxManager("proposer", l, metrics, txMgrConfig)
if err != nil {
t.Fatalf("failed to create tx manager: %v", err)
}

l2ooABI, err := opsuccinctbindings.ZKL2OutputOracleMetaData.GetAbi()
if err != nil {
t.Fatalf("failed to get L2OutputOracle ABI: %v", err)
}

var receipt *types.Receipt
blockNumber := big.NewInt(6601696)
blockHash := common.HexToHash("0x80958d9d5b18f4e189d12ae568576f5bb7d3b132f247bdc0475b9d7d00e638e0")
data, err := l2ooABI.Pack("checkpointBlockHash", blockNumber, blockHash)
if err != nil {
t.Fatalf("failed to pack checkpointBlockHash: %v", err)
}

ctx := context.Background()

// Get the Rollup Config
// chainId := uint64(11155420)
// rollupCfg, err := rollup.LoadOPStackRollupConfig(chainId)
// if err != nil {
// t.Fatalf("failed to load rollup config: %v", err)
// }

fmt.Println("txMgr RPC URL:", txMgrConfig.L1RPCURL)
fmt.Println("Private Key:", txMgrConfig.PrivateKey)

l2OutputOracleAddr := common.HexToAddress("0x7c1bb3c873f3c3f9d895ecafbb06ae3b93948447")
receipt, err = txManager.Send(ctx, txmgr.TxCandidate{
TxData: data,
To: &l2OutputOracleAddr,
GasLimit: 1000000,
})
if err != nil {
t.Fatalf("failed to send transaction: %v", err)
}

if receipt.Status == types.ReceiptStatusFailed {
t.Fatalf("checkpoint blockhash tx successfully published but reverted %v", receipt.TxHash)
} else {
t.Fatalf("checkpoint blockhash tx successfully published %v", receipt.TxHash)
}
}

0 comments on commit 6d4c5ed

Please sign in to comment.