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
43412820
Unverified
Commit
43412820
authored
Jul 25, 2023
by
inphi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve test coverage
parent
58ad9ccf
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
5 deletions
+75
-5
random.go
op-node/testutils/random.go
+8
-0
cache_test.go
op-program/client/l2/cache_test.go
+20
-0
oracle_test.go
op-program/client/l2/oracle_test.go
+18
-0
retry_test.go
op-program/host/prefetcher/retry_test.go
+29
-5
No files found.
op-node/testutils/random.go
View file @
43412820
...
...
@@ -269,3 +269,11 @@ func RandomOutputResponse(rng *rand.Rand) *eth.OutputResponse {
},
}
}
func
RandomOutputV0
(
rng
*
rand
.
Rand
)
*
eth
.
OutputV0
{
return
&
eth
.
OutputV0
{
StateRoot
:
eth
.
Bytes32
(
RandomHash
(
rng
)),
MessagePasserStorageRoot
:
eth
.
Bytes32
(
RandomHash
(
rng
)),
BlockHash
:
RandomHash
(
rng
),
}
}
op-program/client/l2/cache_test.go
View file @
43412820
...
...
@@ -4,6 +4,7 @@ import (
"math/rand"
"testing"
"github.com/ethereum-optimism/optimism/op-node/eth"
"github.com/ethereum-optimism/optimism/op-node/testutils"
"github.com/ethereum-optimism/optimism/op-program/client/l2/test"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -66,3 +67,22 @@ func TestCodeByHash(t *testing.T) {
actual
=
oracle
.
CodeByHash
(
hash
)
require
.
Equal
(
t
,
node
,
actual
)
}
func
TestOutputByRoot
(
t
*
testing
.
T
)
{
stub
,
_
:=
test
.
NewStubOracle
(
t
)
oracle
:=
NewCachingOracle
(
stub
)
rng
:=
rand
.
New
(
rand
.
NewSource
(
1
))
output
:=
testutils
.
RandomOutputV0
(
rng
)
// Initial call retrieves from the stub
root
:=
common
.
Hash
(
eth
.
OutputRoot
(
output
))
stub
.
Outputs
[
root
]
=
output
actual
:=
oracle
.
OutputByRoot
(
root
)
require
.
Equal
(
t
,
output
,
actual
)
// Later calls should retrieve from cache
delete
(
stub
.
Outputs
,
root
)
actual
=
oracle
.
OutputByRoot
(
root
)
require
.
Equal
(
t
,
output
,
actual
)
}
op-program/client/l2/oracle_test.go
View file @
43412820
...
...
@@ -122,3 +122,21 @@ func TestPreimageOracleCodeByHash(t *testing.T) {
})
}
}
func
TestPreimageOracleOutputByRoot
(
t
*
testing
.
T
)
{
rng
:=
rand
.
New
(
rand
.
NewSource
(
123
))
for
i
:=
0
;
i
<
10
;
i
++
{
t
.
Run
(
fmt
.
Sprintf
(
"output_%d"
,
i
),
func
(
t
*
testing
.
T
)
{
po
,
hints
,
preimages
:=
mockPreimageOracle
(
t
)
output
:=
testutils
.
RandomOutputV0
(
rng
)
h
:=
common
.
Hash
(
eth
.
OutputRoot
(
output
))
preimages
[
preimage
.
Keccak256Key
(
h
)
.
PreimageKey
()]
=
output
.
Marshal
()
hints
.
On
(
"hint"
,
L2OutputHint
(
h
)
.
Hint
())
.
Once
()
.
Return
()
gotOutput
:=
po
.
OutputByRoot
(
h
)
hints
.
AssertExpectations
(
t
)
require
.
Equal
(
t
,
hexutil
.
Bytes
(
output
.
Marshal
()),
hexutil
.
Bytes
(
gotOutput
.
Marshal
()),
"output matches"
)
})
}
}
op-program/host/prefetcher/retry_test.go
View file @
43412820
...
...
@@ -119,6 +119,8 @@ func TestRetryingL2Source(t *testing.T) {
&
types
.
Transaction
{},
}
data
:=
[]
byte
{
1
,
2
,
3
,
4
,
5
}
output
:=
&
eth
.
OutputV0
{}
wrongOutput
:=
&
eth
.
OutputV0
{
BlockHash
:
common
.
Hash
{
0x99
}}
t
.
Run
(
"InfoAndTxsByHash Success"
,
func
(
t
*
testing
.
T
)
{
source
,
mock
:=
createL2Source
(
t
)
...
...
@@ -187,6 +189,28 @@ func TestRetryingL2Source(t *testing.T) {
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
data
,
actual
)
})
t
.
Run
(
"OutputByRoot Success"
,
func
(
t
*
testing
.
T
)
{
source
,
mock
:=
createL2Source
(
t
)
defer
mock
.
AssertExpectations
(
t
)
mock
.
ExpectOutputByRoot
(
hash
,
output
,
nil
)
actualOutput
,
err
:=
source
.
OutputByRoot
(
ctx
,
hash
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
output
,
actualOutput
)
})
t
.
Run
(
"OutputByRoot Error"
,
func
(
t
*
testing
.
T
)
{
source
,
mock
:=
createL2Source
(
t
)
defer
mock
.
AssertExpectations
(
t
)
expectedErr
:=
errors
.
New
(
"boom"
)
mock
.
ExpectOutputByRoot
(
hash
,
wrongOutput
,
expectedErr
)
mock
.
ExpectOutputByRoot
(
hash
,
output
,
nil
)
actualOutput
,
err
:=
source
.
OutputByRoot
(
ctx
,
hash
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
output
,
actualOutput
)
})
}
func
createL2Source
(
t
*
testing
.
T
)
(
*
RetryingL2Source
,
*
MockL2Source
)
{
...
...
@@ -217,6 +241,11 @@ func (m *MockL2Source) CodeByHash(ctx context.Context, hash common.Hash) ([]byte
return
out
[
0
]
.
([]
byte
),
*
out
[
1
]
.
(
*
error
)
}
func
(
m
*
MockL2Source
)
OutputByRoot
(
ctx
context
.
Context
,
root
common
.
Hash
)
(
eth
.
Output
,
error
)
{
out
:=
m
.
Mock
.
MethodCalled
(
"OutputByRoot"
,
root
)
return
out
[
0
]
.
(
eth
.
Output
),
*
out
[
1
]
.
(
*
error
)
}
func
(
m
*
MockL2Source
)
ExpectInfoAndTxsByHash
(
blockHash
common
.
Hash
,
info
eth
.
BlockInfo
,
txs
types
.
Transactions
,
err
error
)
{
m
.
Mock
.
On
(
"InfoAndTxsByHash"
,
blockHash
)
.
Once
()
.
Return
(
info
,
txs
,
&
err
)
}
...
...
@@ -229,11 +258,6 @@ func (m *MockL2Source) ExpectCodeByHash(hash common.Hash, code []byte, err error
m
.
Mock
.
On
(
"CodeByHash"
,
hash
)
.
Once
()
.
Return
(
code
,
&
err
)
}
func
(
m
*
MockL2Source
)
OutputByRoot
(
ctx
context
.
Context
,
root
common
.
Hash
)
(
eth
.
Output
,
error
)
{
out
:=
m
.
Mock
.
MethodCalled
(
"OutputByRoot"
,
root
)
return
out
[
0
]
.
(
eth
.
Output
),
*
out
[
1
]
.
(
*
error
)
}
func
(
m
*
MockL2Source
)
ExpectOutputByRoot
(
root
common
.
Hash
,
output
eth
.
Output
,
err
error
)
{
m
.
Mock
.
On
(
"OutputByRoot"
,
root
)
.
Once
()
.
Return
(
output
,
&
err
)
}
...
...
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