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
6e9e3451
Commit
6e9e3451
authored
Dec 01, 2023
by
Sebastian Stammler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
op-service: Test CachingReceiptsProvider
parent
db5eacbe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
receipts_caching_test.go
op-service/sources/receipts_caching_test.go
+62
-0
No files found.
op-service/sources/receipts_caching_test.go
0 → 100644
View file @
6e9e3451
package
sources
import
(
"context"
"math/rand"
"testing"
"time"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
)
type
mockReceiptsProvider
struct
{
mock
.
Mock
}
func
(
m
*
mockReceiptsProvider
)
FetchReceipts
(
ctx
context
.
Context
,
block
eth
.
BlockID
,
txHashes
[]
common
.
Hash
)
(
types
.
Receipts
,
error
)
{
args
:=
m
.
Called
(
ctx
,
block
,
txHashes
)
return
args
.
Get
(
0
)
.
(
types
.
Receipts
),
args
.
Error
(
1
)
}
func
TestCachingReceiptsProvider_Caching
(
t
*
testing
.
T
)
{
block
,
receipts
:=
randomRpcBlockAndReceipts
(
rand
.
New
(
rand
.
NewSource
(
69
)),
4
)
txHashes
:=
receiptTxHashes
(
receipts
)
blockid
:=
block
.
BlockID
()
mrp
:=
new
(
mockReceiptsProvider
)
rp
:=
NewCachingReceiptsProvider
(
mrp
,
nil
,
1
)
ctx
,
done
:=
context
.
WithTimeout
(
context
.
Background
(),
10
*
time
.
Second
)
defer
done
()
mrp
.
On
(
"FetchReceipts"
,
ctx
,
blockid
,
txHashes
)
.
Return
(
types
.
Receipts
(
receipts
),
error
(
nil
))
.
Once
()
// receipts should be cached after first fetch
for
i
:=
0
;
i
<
4
;
i
++
{
gotRecs
,
err
:=
rp
.
FetchReceipts
(
ctx
,
blockid
,
txHashes
)
require
.
NoError
(
t
,
err
)
for
i
,
gotRec
:=
range
gotRecs
{
requireEqualReceipt
(
t
,
receipts
[
i
],
gotRec
)
}
}
mrp
.
AssertExpectations
(
t
)
}
func
TestCachingReceiptsProvider_Concurrency
(
t
*
testing
.
T
)
{
block
,
receipts
:=
randomRpcBlockAndReceipts
(
rand
.
New
(
rand
.
NewSource
(
69
)),
4
)
txHashes
:=
receiptTxHashes
(
receipts
)
blockid
:=
block
.
BlockID
()
mrp
:=
new
(
mockReceiptsProvider
)
rp
:=
NewCachingReceiptsProvider
(
mrp
,
nil
,
1
)
mrp
.
On
(
"FetchReceipts"
,
mock
.
Anything
,
blockid
,
txHashes
)
.
Return
(
types
.
Receipts
(
receipts
),
error
(
nil
))
.
Once
()
// receipts should be cached after first fetch
runConcurrentFetchingTest
(
t
,
rp
,
32
,
receipts
,
block
)
mrp
.
AssertExpectations
(
t
)
}
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