Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
3c6f4345
Commit
3c6f4345
authored
Mar 20, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-batcher driver send tx tests :test_tube:
parent
a2252447
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
166 additions
and
0 deletions
+166
-0
driver_test.go
op-batcher/batcher/driver_test.go
+80
-0
TxManager.go
op-service/txmgr/mocks/TxManager.go
+84
-0
txmgr.go
op-service/txmgr/txmgr.go
+2
-0
No files found.
op-batcher/batcher/driver_test.go
0 → 100644
View file @
3c6f4345
package
batcher
import
(
"context"
"math/big"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-node/testlog"
"github.com/ethereum-optimism/optimism/op-service/txmgr"
"github.com/ethereum-optimism/optimism/op-service/txmgr/mocks"
)
// TestSendTransaction tests that the driver can send a transaction
// through the txmgr.
func
TestSendTransaction
(
t
*
testing
.
T
)
{
log
:=
testlog
.
Logger
(
t
,
log
.
LvlCrit
)
txMgr
:=
mocks
.
TxManager
{}
batcherInboxAddress
:=
common
.
HexToAddress
(
"0x42000000000000000000000000000000000000ff"
)
chainID
:=
big
.
NewInt
(
1
)
sender
:=
common
.
HexToAddress
(
"0xdeadbeef"
)
bs
:=
BatchSubmitter
{
Config
:
Config
{
log
:
log
,
From
:
sender
,
OfflineGasEstimation
:
false
,
Rollup
:
&
rollup
.
Config
{
L1ChainID
:
chainID
,
BatchInboxAddress
:
batcherInboxAddress
,
},
},
txMgr
:
&
txMgr
,
}
txData
:=
[]
byte
{
0x00
,
0x01
,
0x02
}
gasTipCap
:=
big
.
NewInt
(
136
)
gasFeeCap
:=
big
.
NewInt
(
137
)
gas
:=
uint64
(
1337
)
candidate
:=
txmgr
.
TxCandidate
{
Recipient
:
batcherInboxAddress
,
TxData
:
txData
,
From
:
sender
,
ChainID
:
chainID
,
GasLimit
:
uint64
(
0
),
}
tx
:=
types
.
NewTx
(
&
types
.
DynamicFeeTx
{
ChainID
:
chainID
,
Nonce
:
0
,
GasTipCap
:
gasTipCap
,
GasFeeCap
:
gasFeeCap
,
Gas
:
gas
,
To
:
&
batcherInboxAddress
,
Data
:
txData
,
})
txHash
:=
tx
.
Hash
()
expectedReceipt
:=
types
.
Receipt
{
Type
:
1
,
PostState
:
[]
byte
{},
Status
:
uint64
(
1
),
CumulativeGasUsed
:
gas
,
TxHash
:
txHash
,
GasUsed
:
gas
,
}
txMgr
.
On
(
"CraftTx"
,
mock
.
Anything
,
candidate
)
.
Return
(
tx
,
nil
)
txMgr
.
On
(
"Send"
,
mock
.
Anything
,
tx
)
.
Return
(
&
expectedReceipt
,
nil
)
receipt
,
err
:=
bs
.
SendTransaction
(
context
.
Background
(),
tx
.
Data
())
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
receipt
,
&
expectedReceipt
)
}
op-service/txmgr/mocks/TxManager.go
0 → 100644
View file @
3c6f4345
// Code generated by mockery v2.22.1. DO NOT EDIT.
package
mocks
import
(
context
"context"
txmgr
"github.com/ethereum-optimism/optimism/op-service/txmgr"
mock
"github.com/stretchr/testify/mock"
types
"github.com/ethereum/go-ethereum/core/types"
)
// TxManager is an autogenerated mock type for the TxManager type
type
TxManager
struct
{
mock
.
Mock
}
// CraftTx provides a mock function with given fields: ctx, candidate
func
(
_m
*
TxManager
)
CraftTx
(
ctx
context
.
Context
,
candidate
txmgr
.
TxCandidate
)
(
*
types
.
Transaction
,
error
)
{
ret
:=
_m
.
Called
(
ctx
,
candidate
)
var
r0
*
types
.
Transaction
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
txmgr
.
TxCandidate
)
(
*
types
.
Transaction
,
error
));
ok
{
return
rf
(
ctx
,
candidate
)
}
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
txmgr
.
TxCandidate
)
*
types
.
Transaction
);
ok
{
r0
=
rf
(
ctx
,
candidate
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Transaction
)
}
}
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
context
.
Context
,
txmgr
.
TxCandidate
)
error
);
ok
{
r1
=
rf
(
ctx
,
candidate
)
}
else
{
r1
=
ret
.
Error
(
1
)
}
return
r0
,
r1
}
// Send provides a mock function with given fields: ctx, tx
func
(
_m
*
TxManager
)
Send
(
ctx
context
.
Context
,
tx
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
)
{
ret
:=
_m
.
Called
(
ctx
,
tx
)
var
r0
*
types
.
Receipt
var
r1
error
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
Transaction
)
(
*
types
.
Receipt
,
error
));
ok
{
return
rf
(
ctx
,
tx
)
}
if
rf
,
ok
:=
ret
.
Get
(
0
)
.
(
func
(
context
.
Context
,
*
types
.
Transaction
)
*
types
.
Receipt
);
ok
{
r0
=
rf
(
ctx
,
tx
)
}
else
{
if
ret
.
Get
(
0
)
!=
nil
{
r0
=
ret
.
Get
(
0
)
.
(
*
types
.
Receipt
)
}
}
if
rf
,
ok
:=
ret
.
Get
(
1
)
.
(
func
(
context
.
Context
,
*
types
.
Transaction
)
error
);
ok
{
r1
=
rf
(
ctx
,
tx
)
}
else
{
r1
=
ret
.
Error
(
1
)
}
return
r0
,
r1
}
type
mockConstructorTestingTNewTxManager
interface
{
mock
.
TestingT
Cleanup
(
func
())
}
// NewTxManager creates a new instance of TxManager. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
func
NewTxManager
(
t
mockConstructorTestingTNewTxManager
)
*
TxManager
{
mock
:=
&
TxManager
{}
mock
.
Mock
.
Test
(
t
)
t
.
Cleanup
(
func
()
{
mock
.
AssertExpectations
(
t
)
})
return
mock
}
op-service/txmgr/txmgr.go
View file @
3c6f4345
...
@@ -68,6 +68,8 @@ type Config struct {
...
@@ -68,6 +68,8 @@ type Config struct {
// TxManager is an interface that allows callers to reliably publish txs,
// TxManager is an interface that allows callers to reliably publish txs,
// bumping the gas price if needed, and obtain the receipt of the resulting tx.
// bumping the gas price if needed, and obtain the receipt of the resulting tx.
//
//go:generate mockery --name TxManager --output ./mocks
type
TxManager
interface
{
type
TxManager
interface
{
// Send is used to publish a transaction with incrementally higher gas
// Send is used to publish a transaction with incrementally higher gas
// prices until the transaction eventually confirms. This method blocks
// prices until the transaction eventually confirms. This method blocks
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment