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
0745c50e
Commit
0745c50e
authored
Dec 01, 2023
by
Sebastian Stammler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-service: Test EthClient receipts validation
parent
6e9e3451
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
0 deletions
+44
-0
eth_client_test.go
op-service/sources/eth_client_test.go
+44
-0
No files found.
op-service/sources/eth_client_test.go
View file @
0745c50e
...
...
@@ -4,6 +4,7 @@ import (
"context"
crand
"crypto/rand"
"math/big"
"math/rand"
"testing"
"github.com/stretchr/testify/mock"
...
...
@@ -18,6 +19,7 @@ import (
"github.com/ethereum-optimism/optimism/op-node/rollup"
"github.com/ethereum-optimism/optimism/op-service/client"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum-optimism/optimism/op-service/sources/caching"
)
type
mockRPC
struct
{
...
...
@@ -177,3 +179,45 @@ func TestEthClient_WrongInfoByHash(t *testing.T) {
require
.
Error
(
t
,
err
,
"cannot accept the wrong block"
)
m
.
Mock
.
AssertExpectations
(
t
)
}
func
TestEthClient_validateReceipts
(
t
*
testing
.
T
)
{
require
:=
require
.
New
(
t
)
mrpc
:=
new
(
mockRPC
)
mrp
:=
new
(
mockReceiptsProvider
)
const
numTxs
=
4
block
,
receipts
:=
randomRpcBlockAndReceipts
(
rand
.
New
(
rand
.
NewSource
(
420
)),
numTxs
)
txHashes
:=
receiptTxHashes
(
receipts
)
ctx
:=
context
.
Background
()
// mutate a field to make validation fail.
receipts
[
2
]
.
Bloom
[
0
]
=
1
mrpc
.
On
(
"CallContext"
,
ctx
,
mock
.
AnythingOfType
(
"**sources.rpcBlock"
),
"eth_getBlockByHash"
,
[]
any
{
block
.
Hash
,
true
})
.
Run
(
func
(
args
mock
.
Arguments
)
{
*
(
args
[
1
]
.
(
**
rpcBlock
))
=
block
})
.
Return
([]
error
{
nil
})
.
Once
()
mrp
.
On
(
"FetchReceipts"
,
ctx
,
block
.
BlockID
(),
txHashes
)
.
Return
(
types
.
Receipts
(
receipts
),
error
(
nil
))
.
Once
()
ethcl
:=
newEthClientWithCaches
(
nil
,
numTxs
)
ethcl
.
client
=
mrpc
ethcl
.
recProvider
=
mrp
ethcl
.
trustRPC
=
false
_
,
_
,
err
:=
ethcl
.
FetchReceipts
(
ctx
,
block
.
Hash
)
require
.
ErrorContains
(
err
,
"invalid receipts"
)
mrpc
.
AssertExpectations
(
t
)
mrp
.
AssertExpectations
(
t
)
}
func
newEthClientWithCaches
(
metrics
caching
.
Metrics
,
cacheSize
int
)
*
EthClient
{
return
&
EthClient
{
transactionsCache
:
caching
.
NewLRUCache
[
common
.
Hash
,
types
.
Transactions
](
metrics
,
"txs"
,
cacheSize
),
headersCache
:
caching
.
NewLRUCache
[
common
.
Hash
,
eth
.
BlockInfo
](
metrics
,
"headers"
,
cacheSize
),
payloadsCache
:
caching
.
NewLRUCache
[
common
.
Hash
,
*
eth
.
ExecutionPayload
](
metrics
,
"payloads"
,
cacheSize
),
}
}
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