-
-
Notifications
You must be signed in to change notification settings - Fork 478
Hex encode graffiti in transit when calling produce block APIs #5109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2623842
6354308
4eadd1b
2243338
f77d09c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ import {GenericServerTestCases} from "../../../utils/genericServerTest.js"; | |
| const ZERO_HASH = Buffer.alloc(32, 0); | ||
| const ZERO_HASH_HEX = "0x" + ZERO_HASH.toString("hex"); | ||
| const randaoReveal = Buffer.alloc(96, 1); | ||
| const graffiti = "0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2"; | ||
| const graffiti = "a".repeat(32); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this changed?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The The problem is that |
||
|
|
||
| export const testData: GenericServerTestCases<Api> = { | ||
| getAttesterDuties: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import {expect} from "chai"; | ||
| import {fromGraffitiHex, toGraffitiHex} from "../../../src/utils/serdes.js"; | ||
|
|
||
| describe("utils / serdes", () => { | ||
| describe("toGraffitiHex", () => { | ||
| it("should convert a UTF-8 graffiti to hex", () => { | ||
| expect(toGraffitiHex("a".repeat(32))).to.equal( | ||
| "0x6161616161616161616161616161616161616161616161616161616161616161" | ||
| ); | ||
| }); | ||
|
|
||
| it("should convert a graffiti with Unicode symbols to hex", () => { | ||
| expect(toGraffitiHex("🦇🔊".repeat(4))).to.equal( | ||
| "0xf09fa687f09f948af09fa687f09f948af09fa687f09f948af09fa687f09f948a" | ||
| ); | ||
| }); | ||
|
|
||
| it("should trim the hex graffiti if it is too long", () => { | ||
| expect(toGraffitiHex("a".repeat(50))).to.equal(toGraffitiHex("a".repeat(32))); | ||
| }); | ||
|
|
||
| it("should trim the hex graffiti if the last character is a Unicode symbol", () => { | ||
| expect(toGraffitiHex("a".repeat(31) + "🐼")).to.equal( | ||
| "0x61616161616161616161616161616161616161616161616161616161616161f0" | ||
| ); | ||
| }); | ||
|
|
||
| it("should right-pad the hex graffiti with zeros if it is too short", () => { | ||
| expect(toGraffitiHex("a")).to.equal("0x6100000000000000000000000000000000000000000000000000000000000000"); | ||
| expect(toGraffitiHex("ab")).to.equal("0x6162000000000000000000000000000000000000000000000000000000000000"); | ||
| expect(toGraffitiHex("abc")).to.equal("0x6162630000000000000000000000000000000000000000000000000000000000"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("fromGraffitiHex", () => { | ||
| it("should convert a hex graffiti to UTF-8", () => { | ||
| expect(fromGraffitiHex("0x6161616161616161616161616161616161616161616161616161616161616161")).to.equal( | ||
| "a".repeat(32) | ||
| ); | ||
| }); | ||
|
|
||
| it("should convert a hex graffiti with Unicode symbols to UTF-8", () => { | ||
| expect(fromGraffitiHex("0xf09fa687f09f948af09fa687f09f948af09fa687f09f948af09fa687f09f948a")).to.equal( | ||
| "🦇🔊".repeat(4) | ||
| ); | ||
| }); | ||
|
|
||
| it("should convert a padded hex graffiti to UTF-8", () => { | ||
| expect(fromGraffitiHex("0x6100000000000000000000000000000000000000000000000000000000000000")).to.equal( | ||
| // null bytes will not be displayed/ignored later on | ||
| "a" + "\u0000".repeat(31) | ||
| ); | ||
| }); | ||
|
|
||
| it("should decode a hex graffiti with a cut off Unicode character at the end", () => { | ||
| expect(fromGraffitiHex("0x61616161616161616161616161616161616161616161616161616161616161f0")).to.equal( | ||
| // last character will be displayed as � | ||
| "a".repeat(31) + "\ufffd" | ||
| ); | ||
| }); | ||
|
|
||
| it("should not throw an error if an invalid hex graffiti is provided", () => { | ||
| expect(() => fromGraffitiHex("a")).to.not.throw(); | ||
| }); | ||
|
|
||
| it("should return the provided graffiti string if decoding fails", () => { | ||
| expect(fromGraffitiHex("a")).to.equal("a"); | ||
| }); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.