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
e2998e8f
Unverified
Commit
e2998e8f
authored
Feb 29, 2024
by
Roberto Bayardo
Committed by
GitHub
Feb 29, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more blob test vectors (#9685)
parent
7f16d0b9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
2 deletions
+63
-2
blob_test.go
op-service/eth/blob_test.go
+63
-2
No files found.
op-service/eth/blob_test.go
View file @
e2998e8f
...
...
@@ -44,6 +44,7 @@ func TestSmallBlobEncoding(t *testing.T) {
require
.
Equal
(
t
,
data
,
decoded
)
// only 10 bytes of data
data
=
Data
(
make
([]
byte
,
10
))
data
[
9
]
=
0xFF
err
=
b
.
FromData
(
data
)
require
.
NoError
(
t
,
err
)
...
...
@@ -157,8 +158,6 @@ func FuzzDetectNonBijectivity(f *testing.F) {
})
}
// TODO(optimism#8872): Create more test vectors to implement one-way tests confirming that
// specific inputs yield desired outputs.
func
TestDecodeTestVectors
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
input
,
output
string
...
...
@@ -185,6 +184,21 @@ func TestDecodeTestVectors(t *testing.T) {
input
:
"
\x00\x00\x01\xFB\xFD
"
,
err
:
ErrBlobInvalidLength
,
},
{
// encode len=10
input
:
"
\x00\x00\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff
"
,
output
:
"
\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff
"
,
},
{
// decode what should be 27 0xFF bytes
input
:
"
\x00\x00\x00\x00\x1b\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff
"
,
output
:
"
\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff
"
,
},
{
// decode what should be 32 0xFF bytes
input
:
"
\x3f\x00\x00\x00\x20\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x30\xff\xff\xff\xff
"
,
output
:
"
\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff
"
,
},
}
var
b
Blob
...
...
@@ -202,6 +216,53 @@ func TestDecodeTestVectors(t *testing.T) {
}
}
func
TestEncodeTestVectors
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
input
,
output
string
err
error
}{
{
// empty (all zeros) blob should decode as empty string
input
:
""
,
output
:
""
,
},
{
// max input data
input
:
string
(
make
([]
byte
,
MaxBlobDataSize
)),
output
:
"
\x00\x00\x01\xfb\xfc
"
,
},
{
// input data too big
input
:
string
(
make
([]
byte
,
MaxBlobDataSize
+
1
)),
output
:
""
,
err
:
ErrBlobInputTooLarge
,
},
{
// 27 bytes each with high order bits set (should cleanly fit in the first FE along with the version+length)
input
:
"
\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff
"
,
output
:
"
\x00\x00\x00\x00\x1b\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff
"
,
},
{
// 28 bytes each with high order bits set, requires high bits spilling into byte 0 and last byte
input
:
"
\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff
"
,
output
:
"
\x3f\x00\x00\x00\x1c\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x30
"
,
},
}
var
b
,
testBlob
Blob
for
_
,
c
:=
range
cases
{
err
:=
b
.
FromData
(
Data
(
c
.
input
))
if
c
.
err
!=
nil
{
require
.
ErrorIs
(
t
,
err
,
c
.
err
)
}
else
{
require
.
NoError
(
t
,
err
)
testBlob
.
Clear
()
copy
(
testBlob
[
:
],
[]
byte
(
c
.
output
))
require
.
Equal
(
t
,
testBlob
,
b
)
}
}
}
func
TestExtraneousData
(
t
*
testing
.
T
)
{
var
b
Blob
// make sure 0 length blob with non-zero bits in upper byte are detected & rejected
...
...
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