-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: body hash as buffer in TS + minor cleanup (#4012)
When the block gets submitted on chain the body hash has to be represented as normal buffer. Since we represent as 2 fields just because of Noir I decided to do the conversion in `type_conversion.ts`.
- Loading branch information
Showing
13 changed files
with
86 additions
and
42 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { makeHeader } from '../tests/factories.js'; | ||
import { Header } from './header.js'; | ||
|
||
describe('Header', () => { | ||
it(`serializes to buffer and deserializes it back`, () => { | ||
const randomInt = Math.floor(Math.random() * 1000); | ||
const expected = makeHeader(randomInt, undefined); | ||
const buffer = expected.toBuffer(); | ||
const res = Header.fromBuffer(buffer); | ||
expect(res).toEqual(expected); | ||
}); | ||
}); |
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
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
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,18 @@ | ||
import { randomBytes } from '../crypto/index.js'; | ||
import { from2Fields, to2Fields } from './free_funcs.js'; | ||
|
||
describe('buffer to fields and back', () => { | ||
it('should correctly serialize and deserialize a buffer', () => { | ||
// Generate a random 32-byte buffer | ||
const originalBuffer = randomBytes(32); | ||
|
||
// Serialize the buffer to two fields | ||
const [field1, field2] = to2Fields(originalBuffer); | ||
|
||
// Deserialize the fields back to a buffer | ||
const reconstructedBuffer = from2Fields(field1, field2); | ||
|
||
// Check if the original buffer and reconstructed buffer are identical | ||
expect(reconstructedBuffer).toEqual(originalBuffer); | ||
}); | ||
}); |
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
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
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