Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions op-e2e/actions/helpers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (s *BasicUser[B]) ActResetTxOpts(t Testing) {
}

func (s *BasicUser[B]) ActRandomTxToAddr(t Testing) {
t.Helper()
i := s.rng.Intn(len(s.env.AddressCorpora))
var to *common.Address
if i > 0 { // 0 == nil
Expand Down Expand Up @@ -204,6 +205,7 @@ func (s *BasicUser[B]) ActSetTxValue(value *big.Int) Action {
}

func (s *BasicUser[B]) ActRandomTxData(t Testing) {
t.Helper()
dataLen := s.rng.Intn(128_000)
out := make([]byte, dataLen)
_, err := s.rng.Read(out[:])
Expand All @@ -212,6 +214,7 @@ func (s *BasicUser[B]) ActRandomTxData(t Testing) {
}

func (s *BasicUser[B]) PendingNonce(t Testing) uint64 {
t.Helper()
if s.txOpts.Nonce != nil {
return s.txOpts.Nonce.Uint64()
}
Expand All @@ -229,6 +232,7 @@ func (s *BasicUser[B]) TxValue() *big.Int {
}

func (s *BasicUser[B]) LastTxReceipt(t Testing) *types.Receipt {
t.Helper()
require.NotEqual(t, s.lastTxHash, common.Hash{}, "must send tx before getting last receipt")
receipt, err := s.env.EthCl.TransactionReceipt(t.Ctx(), s.lastTxHash)
require.NoError(t, err)
Expand Down Expand Up @@ -264,6 +268,7 @@ func (s *BasicUser[B]) MakeTransaction(t Testing) *types.Transaction {
// ActMakeTx makes a tx with the predetermined contents (see randomization and other actions)
// and sends it to the tx pool
func (s *BasicUser[B]) ActMakeTx(t Testing) {
t.Helper()
tx := s.MakeTransaction(t)
err := s.env.EthCl.SendTransaction(t.Ctx(), tx)
require.NoError(t, err, "must send tx")
Expand All @@ -279,6 +284,7 @@ func (s *BasicUser[B]) ActCheckReceiptStatusOfLastTx(success bool) func(t Testin
}

func (s *BasicUser[B]) CheckReceipt(t Testing, success bool, txHash common.Hash) *types.Receipt {
t.Helper()
receipt, err := s.env.EthCl.TransactionReceipt(t.Ctx(), txHash)
if receipt != nil && err == nil {
expected := types.ReceiptStatusFailed
Expand Down Expand Up @@ -391,6 +397,7 @@ func (s *CrossLayerUser) ActCheckDepositStatus(l1Success, l2Success bool) Action
}

func (s *CrossLayerUser) CheckDepositTx(t Testing, l1TxHash common.Hash, index int, l1Success, l2Success bool) {
t.Helper()
depositReceipt := s.L1.CheckReceipt(t, l1Success, l1TxHash)
if depositReceipt == nil {
require.False(t, l1Success)
Expand Down Expand Up @@ -427,7 +434,15 @@ func (s *CrossLayerUser) Address() common.Address {
return s.L1.address
}

func (s *CrossLayerUser) getLatestWithdrawalParams(t Testing) (*withdrawals.ProvenWithdrawalParameters, error) {
func (s *CrossLayerUser) GetLastDepositL2Receipt(t Testing) (*types.Receipt, error) {
depositL1Receipt := s.L1.CheckReceipt(t, true, s.lastL1DepositTxHash)
reconstructedDep, err := derive.UnmarshalDepositLogEvent(depositL1Receipt.Logs[0])
require.NoError(t, err, "Could not reconstruct L2 Deposit")
l2Tx := types.NewTx(reconstructedDep)
return s.L2.CheckReceipt(t, true, l2Tx.Hash()), nil
}

func (s *CrossLayerUser) getLastWithdrawalParams(t Testing) (*withdrawals.ProvenWithdrawalParameters, error) {
receipt := s.L2.CheckReceipt(t, true, s.lastL2WithdrawalTxHash)
l2WithdrawalBlock, err := s.L2.env.EthCl.BlockByNumber(t.Ctx(), receipt.BlockNumber)
require.NoError(t, err)
Expand Down Expand Up @@ -504,7 +519,7 @@ func (s *CrossLayerUser) ActProveWithdrawal(t Testing) {

// ProveWithdrawal creates a L1 proveWithdrawal tx for the given L2 withdrawal tx, returning the tx hash.
func (s *CrossLayerUser) ProveWithdrawal(t Testing, l2TxHash common.Hash) common.Hash {
params, err := s.getLatestWithdrawalParams(t)
params, err := s.getLastWithdrawalParams(t)
if err != nil {
t.InvalidAction("cannot prove withdrawal: %v", err)
return common.Hash{}
Expand Down Expand Up @@ -543,7 +558,7 @@ func (s *CrossLayerUser) ActCompleteWithdrawal(t Testing) {
// CompleteWithdrawal creates a L1 withdrawal finalization tx for the given L2 withdrawal tx, returning the tx hash.
// It's an invalid action to attempt to complete a withdrawal that has not passed the L1 finalization period yet
func (s *CrossLayerUser) CompleteWithdrawal(t Testing, l2TxHash common.Hash) common.Hash {
params, err := s.getLatestWithdrawalParams(t)
params, err := s.getLastWithdrawalParams(t)
if err != nil {
t.InvalidAction("cannot complete withdrawal: %v", err)
return common.Hash{}
Expand Down Expand Up @@ -576,7 +591,7 @@ func (s *CrossLayerUser) ActResolveClaim(t Testing) {

// ResolveClaim creates a L1 resolveClaim tx for the given L2 withdrawal tx, returning the tx hash.
func (s *CrossLayerUser) ResolveClaim(t Testing, l2TxHash common.Hash) common.Hash {
params, err := s.getLatestWithdrawalParams(t)
params, err := s.getLastWithdrawalParams(t)
if err != nil {
t.InvalidAction("cannot resolve claim: %v", err)
return common.Hash{}
Expand Down Expand Up @@ -614,7 +629,7 @@ func (s *CrossLayerUser) ActResolve(t Testing) {

// Resolve creates a L1 resolve tx for the given L2 withdrawal tx, returning the tx hash.
func (s *CrossLayerUser) Resolve(t Testing, l2TxHash common.Hash) common.Hash {
params, err := s.getLatestWithdrawalParams(t)
params, err := s.getLastWithdrawalParams(t)
if err != nil {
t.InvalidAction("cannot resolve game: %v", err)
return common.Hash{}
Expand Down
Loading