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
6ce13f56
Unverified
Commit
6ce13f56
authored
Jan 21, 2022
by
Conner Fromknecht
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add BlockNumber method to interfaces
parent
c2f92c2f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
10 deletions
+66
-10
clear_pending_tx_test.go
go/batch-submitter/drivers/clear_pending_tx_test.go
+13
-6
l1client.go
go/batch-submitter/mock/l1client.go
+21
-0
txmgr.go
go/batch-submitter/txmgr/txmgr.go
+3
-0
txmgr_test.go
go/batch-submitter/txmgr/txmgr_test.go
+29
-4
No files found.
go/batch-submitter/drivers/clear_pending_tx_test.go
View file @
6ce13f56
...
...
@@ -32,12 +32,13 @@ func init() {
}
var
(
testPrivKey
*
ecdsa
.
PrivateKey
testWalletAddr
common
.
Address
testChainID
*
big
.
Int
// 1
testNonce
=
uint64
(
2
)
testGasPrice
*
big
.
Int
// 3
testGasLimit
=
uint64
(
4
)
testPrivKey
*
ecdsa
.
PrivateKey
testWalletAddr
common
.
Address
testChainID
=
big
.
NewInt
(
1
)
testNonce
=
uint64
(
2
)
testGasPrice
=
big
.
NewInt
(
3
)
testGasLimit
=
uint64
(
4
)
testBlockNumber
=
uint64
(
5
)
)
// TestCraftClearingTx asserts that CraftClearingTx produces the expected
...
...
@@ -107,6 +108,12 @@ type clearPendingTxHarness struct {
}
func
newClearPendingTxHarness
(
l1ClientConfig
mock
.
L1ClientConfig
)
*
clearPendingTxHarness
{
if
l1ClientConfig
.
BlockNumber
==
nil
{
l1ClientConfig
.
BlockNumber
=
func
(
_
context
.
Context
)
(
uint64
,
error
)
{
return
testBlockNumber
,
nil
}
}
if
l1ClientConfig
.
NonceAt
==
nil
{
l1ClientConfig
.
NonceAt
=
func
(
_
context
.
Context
,
_
common
.
Address
,
_
*
big
.
Int
)
(
uint64
,
error
)
{
return
testNonce
,
nil
...
...
go/batch-submitter/mock/l1client.go
View file @
6ce13f56
...
...
@@ -13,6 +13,9 @@ import (
// L1ClientConfig houses the internal methods that are executed by the mock
// L1Client. Any members left as nil will panic on execution.
type
L1ClientConfig
struct
{
// BlockNumber returns the most recent block number.
BlockNumber
func
(
context
.
Context
)
(
uint64
,
error
)
// EstimateGas tries to estimate the gas needed to execute a specific
// transaction based on the current pending state of the backend blockchain.
// There is no guarantee that this is the true gas limit requirement as
...
...
@@ -50,6 +53,14 @@ func NewL1Client(cfg L1ClientConfig) *L1Client {
}
}
// BlockNumber returns the most recent block number.
func
(
c
*
L1Client
)
BlockNumber
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
c
.
mu
.
RLock
()
defer
c
.
mu
.
RUnlock
()
return
c
.
cfg
.
BlockNumber
(
ctx
)
}
// EstimateGas executes the mock EstimateGas method.
func
(
c
*
L1Client
)
EstimateGas
(
ctx
context
.
Context
,
call
ethereum
.
CallMsg
)
(
uint64
,
error
)
{
c
.
mu
.
RLock
()
...
...
@@ -82,6 +93,16 @@ func (c *L1Client) TransactionReceipt(ctx context.Context, txHash common.Hash) (
return
c
.
cfg
.
TransactionReceipt
(
ctx
,
txHash
)
}
// SetBlockNumberFunc overwrites the mock BlockNumber method.
func
(
c
*
L1Client
)
SetBlockNumberFunc
(
f
func
(
context
.
Context
)
(
uint64
,
error
))
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
c
.
cfg
.
BlockNumber
=
f
}
// SetEstimateGasFunc overrwrites the mock EstimateGas method.
func
(
c
*
L1Client
)
SetEstimateGasFunc
(
f
func
(
context
.
Context
,
ethereum
.
CallMsg
)
(
uint64
,
error
))
{
...
...
go/batch-submitter/txmgr/txmgr.go
View file @
6ce13f56
...
...
@@ -71,6 +71,9 @@ type TxManager interface {
//
// NOTE: This is a subset of bind.DeployBackend.
type
ReceiptSource
interface
{
// BlockNumber returns the most recent block number.
BlockNumber
(
ctx
context
.
Context
)
(
uint64
,
error
)
// TransactionReceipt queries the backend for a receipt associated with
// txHash. If lookup does not fail, but the transaction is not found,
// nil should be returned for both values.
...
...
go/batch-submitter/txmgr/txmgr_test.go
View file @
6ce13f56
...
...
@@ -109,6 +109,9 @@ func newTestHarness() *testHarness {
type
mockBackend
struct
{
mu
sync
.
RWMutex
// blockHeight tracks the current height of the chain.
blockHeight
uint64
// txHashMinedWithGasPrice tracks the has of a mined transaction to its
// gas price.
txHashMinedWithGasPrice
map
[
common
.
Hash
]
*
big
.
Int
...
...
@@ -127,9 +130,18 @@ func (b *mockBackend) mine(txHash common.Hash, gasPrice *big.Int) {
b
.
mu
.
Lock
()
defer
b
.
mu
.
Unlock
()
b
.
blockHeight
++
b
.
txHashMinedWithGasPrice
[
txHash
]
=
gasPrice
}
// BlockNumber returns the most recent block number.
func
(
b
*
mockBackend
)
BlockNumber
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
b
.
mu
.
RLock
()
defer
b
.
mu
.
RUnlock
()
return
b
.
blockHeight
,
nil
}
// TransactionReceipt queries the mockBackend for a mined txHash. If none is
// found, nil is returned for both return values. Otherwise, it retruns a
// receipt containing the txHash and the gasPrice used in the GasUsed to make
...
...
@@ -392,7 +404,19 @@ func TestWaitMinedCanBeCanceled(t *testing.T) {
// first call but a success on the second call. This allows us to test that the
// inner loop of WaitMined properly handles this case.
type
failingBackend
struct
{
returnSuccess
bool
returnSuccessBlockNumber
bool
returnSuccessReceipt
bool
}
// BlockNumber for the failingBackend returns errRpcFailure on the first
// invocation and a fixed block height on subsequent calls.
func
(
b
*
failingBackend
)
BlockNumber
(
ctx
context
.
Context
)
(
uint64
,
error
)
{
if
!
b
.
returnSuccessBlockNumber
{
b
.
returnSuccessBlockNumber
=
true
return
0
,
errRpcFailure
}
return
1
,
nil
}
// TransactionReceipt for the failingBackend returns errRpcFailure on the first
...
...
@@ -400,13 +424,14 @@ type failingBackend struct {
func
(
b
*
failingBackend
)
TransactionReceipt
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
*
types
.
Receipt
,
error
)
{
if
!
b
.
returnSuccess
{
b
.
returnSuccess
=
true
if
!
b
.
returnSuccess
Receipt
{
b
.
returnSuccess
Receipt
=
true
return
nil
,
errRpcFailure
}
return
&
types
.
Receipt
{
TxHash
:
txHash
,
TxHash
:
txHash
,
BlockNumber
:
big
.
NewInt
(
1
),
},
nil
}
...
...
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