-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from 0xPolygonHermez/feature/add-compute-gi
add compute global index
- Loading branch information
Showing
5 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ on: | |
branches: | ||
- main | ||
- develop | ||
- feature/fork-etrog | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
test/helpers/test-vectors/merkle-tree-bridge/global-index.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"indexLocal": "0", | ||
"indexRollup": "0", | ||
"isMainnet": false, | ||
"expectedGlobalIndex": "0" | ||
}, | ||
{ | ||
"indexLocal": "0", | ||
"indexRollup": "0", | ||
"isMainnet": true, | ||
"expectedGlobalIndex": "18446744073709551616" | ||
}, | ||
{ | ||
"indexLocal": "1", | ||
"indexRollup": "0", | ||
"isMainnet": false, | ||
"expectedGlobalIndex": "1" | ||
}, | ||
{ | ||
"indexLocal": "1", | ||
"indexRollup": "0", | ||
"isMainnet": true, | ||
"expectedGlobalIndex": "18446744073709551617" | ||
}, | ||
{ | ||
"indexLocal": "0", | ||
"indexRollup": "1", | ||
"isMainnet": false, | ||
"expectedGlobalIndex": "4294967296" | ||
}, | ||
{ | ||
"indexLocal": "0", | ||
"indexRollup": "1", | ||
"isMainnet": true, | ||
"expectedGlobalIndex": "18446744073709551616" | ||
}, | ||
{ | ||
"indexLocal": "18446744073709551615", | ||
"indexRollup": "18446744073709551615", | ||
"isMainnet": false, | ||
"expectedGlobalIndex": "79228162532711081662958534655" | ||
}, | ||
{ | ||
"indexLocal": "18446744073709551615", | ||
"indexRollup": "18446744073709551615", | ||
"isMainnet": true, | ||
"expectedGlobalIndex": "36893488147419103231" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { Scalar } = require('ffjavascript'); | ||
const { expect } = require('chai'); | ||
const { argv } = require('yargs'); | ||
const { | ||
computeGlobalIndex, | ||
} = require('../index').mtBridgeUtils; | ||
const { pathTestVectors } = require('./helpers/test-utils'); | ||
|
||
describe('Merkle Bridge Utils', () => { | ||
const pathTests = path.join(pathTestVectors, 'merkle-tree-bridge/global-index.json'); | ||
|
||
let update; | ||
let testVectors; | ||
|
||
before(async () => { | ||
testVectors = JSON.parse(fs.readFileSync(pathTests)); | ||
update = argv.update === true; | ||
}); | ||
|
||
it('computeGlobalIndex', async () => { | ||
for (let i = 0; i < testVectors.length; i++) { | ||
const { | ||
indexLocal, indexRollup, isMainnet, expectedGlobalIndex, | ||
} = testVectors[i]; | ||
|
||
const computedGlobalIndex = computeGlobalIndex( | ||
Scalar.e(indexLocal), | ||
Scalar.e(indexRollup), | ||
isMainnet, | ||
); | ||
|
||
if (update) { | ||
testVectors[i].expectedGlobalIndex = computedGlobalIndex.toString(); | ||
} else { | ||
expect(computedGlobalIndex.toString()).to.be.equal(expectedGlobalIndex); | ||
} | ||
} | ||
|
||
if (update) { | ||
fs.writeFileSync(pathTests, JSON.stringify(testVectors, null, 2)); | ||
} | ||
}); | ||
}); |