Commit cb3900fe authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-e2e: Migrate more bindings away from generated bindings (#10766)

parent 06011490
......@@ -129,8 +129,17 @@ func (c *PreimageOracleContract) AddGlobalDataTx(data *types.PreimageOracleData)
}
func (c *PreimageOracleContract) InitLargePreimage(uuid *big.Int, partOffset uint32, claimedSize uint32) (txmgr.TxCandidate, error) {
bond, err := c.GetMinBondLPP(context.Background())
if err != nil {
return txmgr.TxCandidate{}, fmt.Errorf("failed to get min bond for large preimage proposal: %w", err)
}
call := c.contract.Call(methodInitLPP, uuid, partOffset, claimedSize)
return call.ToTxCandidate()
candidate, err := call.ToTxCandidate()
if err != nil {
return txmgr.TxCandidate{}, fmt.Errorf("failed to create initLPP tx candidate: %w", err)
}
candidate.Value = bond
return candidate, nil
}
func (c *PreimageOracleContract) AddLeaves(uuid *big.Int, startingBlockIndex *big.Int, input []byte, commitments []common.Hash, finalize bool) (txmgr.TxCandidate, error) {
......
......@@ -164,6 +164,8 @@ func TestPreimageOracleContract_InitLargePreimage(t *testing.T) {
uuid := big.NewInt(123)
partOffset := uint32(1)
claimedSize := uint32(2)
bond := big.NewInt(42984)
stubRpc.SetResponse(oracleAddr, methodMinBondSizeLPP, rpcblock.Latest, nil, []interface{}{bond})
stubRpc.SetResponse(oracleAddr, methodInitLPP, rpcblock.Latest, []interface{}{
uuid,
partOffset,
......@@ -173,6 +175,7 @@ func TestPreimageOracleContract_InitLargePreimage(t *testing.T) {
tx, err := oracle.InitLargePreimage(uuid, partOffset, claimedSize)
require.NoError(t, err)
stubRpc.VerifyTxCandidate(tx)
require.Truef(t, bond.Cmp(tx.Value) == 0, "Expected bond %v got %v", bond, tx.Value)
}
func TestPreimageOracleContract_AddLeaves(t *testing.T) {
......
......@@ -164,11 +164,6 @@ func (p *LargePreimageUploader) initLargePreimage(uuid *big.Int, partOffset uint
if err != nil {
return fmt.Errorf("failed to create pre-image oracle tx: %w", err)
}
bond, err := p.contract.GetMinBondLPP(context.Background())
if err != nil {
return fmt.Errorf("failed to get min bond for large preimage proposal: %w", err)
}
candidate.Value = bond
if err := p.txSender.SendAndWaitSimple("init large preimage", candidate); err != nil {
return fmt.Errorf("failed to populate pre-image oracle: %w", err)
}
......
......@@ -124,15 +124,14 @@ func (h *FactoryHelper) PreimageHelper(ctx context.Context) *preimage.Helper {
opts := &bind.CallOpts{Context: ctx}
gameAddr, err := h.Factory.GameImpls(opts, cannonGameType)
h.Require.NoError(err)
game, err := bindings.NewFaultDisputeGameCaller(gameAddr, h.Client)
caller := batching.NewMultiCaller(h.Client.Client(), batching.DefaultBatchSize)
game, err := contracts.NewFaultDisputeGameContract(ctx, metrics.NoopContractMetrics, gameAddr, caller)
h.Require.NoError(err)
vmAddr, err := game.Vm(opts)
vm, err := game.Vm(ctx)
h.Require.NoError(err)
vm, err := bindings.NewMIPSCaller(vmAddr, h.Client)
oracle, err := vm.Oracle(ctx)
h.Require.NoError(err)
oracleAddr, err := vm.Oracle(opts)
h.Require.NoError(err)
return preimage.NewHelper(h.T, h.Opts, h.Client, oracleAddr)
return preimage.NewHelper(h.T, h.PrivKey, h.Client, oracle)
}
func NewGameCfg(opts ...GameOpt) *GameCfg {
......
......@@ -3,6 +3,7 @@ package preimage
import (
"bytes"
"context"
"crypto/ecdsa"
"errors"
"io"
"math/big"
......@@ -15,13 +16,12 @@ import (
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/preimages"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/matrix"
"github.com/ethereum-optimism/optimism/op-challenger/game/keccak/types"
"github.com/ethereum-optimism/optimism/op-e2e/bindings"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/transactions"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum-optimism/optimism/op-service/sources/batching/rpcblock"
"github.com/ethereum-optimism/optimism/op-service/testutils"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"
)
......@@ -29,28 +29,21 @@ import (
const MinPreimageSize = 10000
type Helper struct {
t *testing.T
require *require.Assertions
client *ethclient.Client
opts *bind.TransactOpts
oracleBindings *bindings.PreimageOracle
oracle *contracts.PreimageOracleContract
uuidProvider atomic.Int64
t *testing.T
require *require.Assertions
client *ethclient.Client
privKey *ecdsa.PrivateKey
oracle *contracts.PreimageOracleContract
uuidProvider atomic.Int64
}
func NewHelper(t *testing.T, opts *bind.TransactOpts, client *ethclient.Client, addr common.Address) *Helper {
require := require.New(t)
oracleBindings, err := bindings.NewPreimageOracle(addr, client)
require.NoError(err)
oracle := contracts.NewPreimageOracleContract(addr, batching.NewMultiCaller(client.Client(), batching.DefaultBatchSize))
func NewHelper(t *testing.T, privKey *ecdsa.PrivateKey, client *ethclient.Client, oracle *contracts.PreimageOracleContract) *Helper {
return &Helper{
t: t,
require: require,
client: client,
opts: opts,
oracleBindings: oracleBindings,
oracle: oracle,
t: t,
require: require.New(t),
client: client,
privKey: privKey,
oracle: oracle,
}
}
......@@ -82,14 +75,9 @@ func (h *Helper) UploadLargePreimage(ctx context.Context, dataSize int, modifier
data := testutils.RandomData(rand.New(rand.NewSource(1234)), dataSize)
s := matrix.NewStateMatrix()
uuid := big.NewInt(h.uuidProvider.Add(1))
bondValue, err := h.oracleBindings.MINBONDSIZE(&bind.CallOpts{})
h.require.NoError(err)
h.opts.Value = bondValue
tx, err := h.oracleBindings.InitLPP(h.opts, uuid, 32, uint32(len(data)))
h.require.NoError(err)
_, err = wait.ForReceiptOK(ctx, h.client, tx.Hash())
candidate, err := h.oracle.InitLargePreimage(uuid, 32, uint32(len(data)))
h.require.NoError(err)
h.opts.Value = big.NewInt(0)
transactions.RequireSendTx(h.t, ctx, h.client, candidate, h.privKey)
startBlock := big.NewInt(0)
totalBlocks := len(data) / types.BlockSize
......@@ -102,15 +90,10 @@ func (h *Helper) UploadLargePreimage(ctx context.Context, dataSize int, modifier
for _, modifier := range modifiers {
modifier(startBlock.Uint64(), &inputData)
}
commitments := make([][32]byte, len(inputData.Commitments))
for i, commitment := range inputData.Commitments {
commitments[i] = commitment
}
h.t.Logf("Uploading %v parts of preimage %v starting at block %v of about %v Finalize: %v", len(commitments), uuid.Uint64(), startBlock.Uint64(), totalBlocks, inputData.Finalize)
tx, err := h.oracleBindings.AddLeavesLPP(h.opts, uuid, startBlock, inputData.Input, commitments, inputData.Finalize)
h.require.NoError(err)
_, err = wait.ForReceiptOK(ctx, h.client, tx.Hash())
h.t.Logf("Uploading %v parts of preimage %v starting at block %v of about %v Finalize: %v", len(inputData.Commitments), uuid.Uint64(), startBlock.Uint64(), totalBlocks, inputData.Finalize)
tx, err := h.oracle.AddLeaves(uuid, startBlock, inputData.Input, inputData.Commitments, inputData.Finalize)
h.require.NoError(err)
transactions.RequireSendTx(h.t, ctx, h.client, tx, h.privKey)
startBlock = new(big.Int).Add(startBlock, big.NewInt(int64(len(inputData.Commitments))))
if inputData.Finalize {
break
......@@ -118,7 +101,7 @@ func (h *Helper) UploadLargePreimage(ctx context.Context, dataSize int, modifier
}
return types.LargePreimageIdent{
Claimant: h.opts.From,
Claimant: crypto.PubkeyToAddress(h.privKey.PublicKey),
UUID: uuid,
}
}
......
......@@ -44,9 +44,10 @@ func WithReceiptFail() SendTxOpt {
}
}
func RequireSendTx(t *testing.T, ctx context.Context, client *ethclient.Client, candidate txmgr.TxCandidate, privKey *ecdsa.PrivateKey, opts ...SendTxOpt) {
_, _, err := SendTx(ctx, client, candidate, privKey, opts...)
func RequireSendTx(t *testing.T, ctx context.Context, client *ethclient.Client, candidate txmgr.TxCandidate, privKey *ecdsa.PrivateKey, opts ...SendTxOpt) (*types.Transaction, *types.Receipt) {
tx, rcpt, err := SendTx(ctx, client, candidate, privKey, opts...)
require.NoError(t, err, "Failed to send transaction")
return tx, rcpt
}
func SendTx(ctx context.Context, client *ethclient.Client, candidate txmgr.TxCandidate, privKey *ecdsa.PrivateKey, opts ...SendTxOpt) (*types.Transaction, *types.Receipt, error) {
......
......@@ -11,6 +11,9 @@ import (
"testing"
"time"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
metrics2 "github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
"github.com/ethereum-optimism/optimism/op-service/sources/batching"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
......@@ -192,21 +195,21 @@ func TestL2OutputSubmitterFaultProofs(t *testing.T) {
require.Nil(t, err)
if latestGameCount.Cmp(initialGameCount) > 0 {
caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
committedL2Output, err := disputeGameFactory.GameAtIndex(&bind.CallOpts{}, new(big.Int).Sub(latestGameCount, common.Big1))
require.Nil(t, err)
proxy, err := bindings.NewFaultDisputeGameCaller(committedL2Output.Proxy, l1Client)
proxy, err := contracts.NewFaultDisputeGameContract(context.Background(), metrics2.NoopContractMetrics, committedL2Output.Proxy, caller)
require.Nil(t, err)
committedOutputRoot, err := proxy.RootClaim(&bind.CallOpts{})
claim, err := proxy.GetClaim(context.Background(), 0)
require.Nil(t, err)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
extradata, err := proxy.ExtraData(&bind.CallOpts{})
_, gameBlockNumber, err := proxy.GetBlockRange(ctx)
require.Nil(t, err)
gameBlockNumber := new(big.Int).SetBytes(extradata[0:32])
l2Output, err := rollupClient.OutputAtBlock(ctx, gameBlockNumber.Uint64())
l2Output, err := rollupClient.OutputAtBlock(ctx, gameBlockNumber)
require.Nil(t, err)
require.Equal(t, l2Output.OutputRoot[:], committedOutputRoot[:])
require.EqualValues(t, l2Output.OutputRoot, claim.Value)
break
}
......
......@@ -10,10 +10,10 @@ import (
"github.com/ethereum-optimism/optimism/op-chain-ops/crossdomain"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts"
"github.com/ethereum-optimism/optimism/op-challenger/game/fault/contracts/metrics"
legacybindings "github.com/ethereum-optimism/optimism/op-e2e/bindings"
"github.com/ethereum-optimism/optimism/op-e2e/config"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/geth"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/transactions"
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/wait"
"github.com/ethereum-optimism/optimism/op-node/bindings"
bindingspreview "github.com/ethereum-optimism/optimism/op-node/bindings/preview"
......@@ -201,9 +201,6 @@ func FinalizeWithdrawal(t *testing.T, cfg SystemConfig, l1Client *ethclient.Clie
require.Nil(t, err)
require.NotNil(t, game, "withdrawal should be proven")
proxy, err := legacybindings.NewFaultDisputeGame(game.DisputeGameProxy, l1Client)
require.Nil(t, err)
caller := batching.NewMultiCaller(l1Client.Client(), batching.DefaultBatchSize)
gameContract, err := contracts.NewFaultDisputeGameContract(context.Background(), metrics.NoopContractMetrics, game.DisputeGameProxy, caller)
require.Nil(t, err)
......@@ -216,19 +213,13 @@ func FinalizeWithdrawal(t *testing.T, cfg SystemConfig, l1Client *ethclient.Clie
return err == nil, nil
}))
resolveClaimTx, err := proxy.ResolveClaim(opts, common.Big0, common.Big0)
require.Nil(t, err)
resolveClaimReceipt, err = wait.ForReceiptOK(ctx, l1Client, resolveClaimTx.Hash())
require.Nil(t, err, "resolve claim")
require.Equal(t, types.ReceiptStatusSuccessful, resolveClaimReceipt.Status)
resolveTx, err := proxy.Resolve(opts)
require.Nil(t, err)
tx, err := gameContract.ResolveClaimTx(0)
require.NoError(t, err, "create resolveClaim tx")
_, resolveClaimReceipt = transactions.RequireSendTx(t, ctx, l1Client, tx, privKey)
resolveReceipt, err = wait.ForReceiptOK(ctx, l1Client, resolveTx.Hash())
require.Nil(t, err, "resolve")
require.Equal(t, types.ReceiptStatusSuccessful, resolveReceipt.Status)
tx, err = gameContract.ResolveTx()
require.NoError(t, err, "create resolve tx")
_, resolveReceipt = transactions.RequireSendTx(t, ctx, l1Client, tx, privKey)
}
if e2eutils.UseFaultProofs() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment