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
e563f956
Unverified
Commit
e563f956
authored
Sep 27, 2021
by
Mark Tyneway
Committed by
GitHub
Sep 27, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1470 from rajivpo/rajiv/message-relayer-coverage
[added] coverage for getMerkleTreeProof
parents
c891827e
e504bb47
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
1 deletion
+44
-1
sharp-dancers-clap.md
.changeset/sharp-dancers-clap.md
+5
-0
relay-tx.ts
packages/message-relayer/src/relay-tx.ts
+4
-1
relay-tx.spec.ts
packages/message-relayer/test/unit-tests/relay-tx.spec.ts
+35
-0
No files found.
.changeset/sharp-dancers-clap.md
0 → 100644
View file @
e563f956
---
'
@eth-optimism/message-relayer'
:
patch
---
added coverage for getMerkleTreeProof
packages/message-relayer/src/relay-tx.ts
View file @
e563f956
...
...
@@ -258,7 +258,10 @@ export const getStateRootBatchByTransactionIndex = async (
* @param index Index to generate a proof for.
* @returns Merkle proof sibling leaves, as hex strings.
*/
const
getMerkleTreeProof
=
(
leaves
:
string
[],
index
:
number
):
string
[]
=>
{
export
const
getMerkleTreeProof
=
(
leaves
:
string
[],
index
:
number
):
string
[]
=>
{
// Our specific Merkle tree implementation requires that the number of leaves is a power of 2.
// If the number of given leaves is less than a power of 2, we need to round up to the next
// available power of 2. We fill the remaining space with the hash of bytes32(0).
...
...
packages/message-relayer/test/unit-tests/relay-tx.spec.ts
View file @
e563f956
...
...
@@ -9,6 +9,7 @@ import { toPlainObject } from 'lodash'
/* Imports: Internal */
import
{
getMerkleTreeProof
,
getMessagesAndProofsForL2Transaction
,
getStateRootBatchByTransactionIndex
,
getStateBatchAppendedEventByTransactionIndex
,
...
...
@@ -375,3 +376,37 @@ describe('relay transaction generation functions', () => {
})
})
})
describe
(
'
getMerkleTreeProof
'
,
()
=>
{
let
leaves
:
string
[]
=
[
'
the
'
,
'
quick
'
,
'
brown
'
,
'
fox
'
,
'
jumps
'
,
'
over
'
,
'
the
'
,
'
lazy
'
,
'
dog
'
,
]
const
index
:
number
=
4
it
(
'
should generate a merkle tree proof from an odd number of leaves at the correct index
'
,
()
=>
{
const
expectedProof
=
[
'
0x6f766572
'
,
'
0x123268ec1a3f9aac2bc68e899fe4329eefef783c76265722508b8abbfbf11440
'
,
'
0x12aaa1b2e09f26e14d86aa3b157b94cfeabe815e44b6742d00c47441a576b12d
'
,
'
0x297d90df3f77f93eefdeab4e9f6e9a074b41a3508f9d265e92e9b5449c7b11c8
'
,
]
expect
(
getMerkleTreeProof
(
leaves
,
index
)).
to
.
deep
.
equal
(
expectedProof
)
})
it
(
'
should generate a merkle tree proof from an even number of leaves at the correct index
'
,
()
=>
{
const
expectedProof
=
[
'
0x6f766572
'
,
'
0x09e430fa7b513203dd9c74afd734267a73f64299d9dac61ef09e96c3b3b3fe96
'
,
'
0x12aaa1b2e09f26e14d86aa3b157b94cfeabe815e44b6742d00c47441a576b12d
'
,
]
leaves
=
leaves
.
slice
(
0
,
leaves
.
length
-
2
)
expect
(
getMerkleTreeProof
(
leaves
,
index
)).
to
.
deep
.
equal
(
expectedProof
)
})
})
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