-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(protocol-parser): allow arbitrary key order when encoding values (#…
- Loading branch information
Showing
4 changed files
with
81 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@latticexyz/protocol-parser": patch | ||
--- | ||
|
||
Allow arbitrary key order when encoding values |
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,53 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { encodeValueArgs } from "./encodeValueArgs"; | ||
import { stringToHex } from "viem"; | ||
|
||
describe("encodeValueArgs", () => { | ||
it("can encode record value to hex", () => { | ||
const valueSchema = { | ||
entityId: "bytes32", | ||
exists: "bool", | ||
playerName: "string", | ||
badges: "uint256[]", | ||
} as const; | ||
|
||
const result = encodeValueArgs(valueSchema, { | ||
entityId: stringToHex("hello", { size: 32 }), | ||
exists: true, | ||
playerName: "henry", | ||
badges: [42n], | ||
}); | ||
|
||
expect(result).toMatchInlineSnapshot(` | ||
{ | ||
"dynamicData": "0x68656e7279000000000000000000000000000000000000000000000000000000000000002a", | ||
"encodedLengths": "0x0000000000000000000000000000000000000020000000000500000000000025", | ||
"staticData": "0x68656c6c6f00000000000000000000000000000000000000000000000000000001", | ||
} | ||
`); | ||
}); | ||
|
||
it("encodes record when key order of value and valueSchema do not match", () => { | ||
const valueSchema = { | ||
entityId: "bytes32", | ||
playerName: "string", | ||
exists: "bool", | ||
badges: "uint256[]", | ||
} as const; | ||
|
||
const result = encodeValueArgs(valueSchema, { | ||
exists: true, | ||
playerName: "henry", | ||
entityId: stringToHex("hello", { size: 32 }), | ||
badges: [42n], | ||
}); | ||
|
||
expect(result).toMatchInlineSnapshot(` | ||
{ | ||
"dynamicData": "0x68656e7279000000000000000000000000000000000000000000000000000000000000002a", | ||
"encodedLengths": "0x0000000000000000000000000000000000000020000000000500000000000025", | ||
"staticData": "0x68656c6c6f00000000000000000000000000000000000000000000000000000001", | ||
} | ||
`); | ||
}); | ||
}); |
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
a2f41ad
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
mud-docs – ./
v2.mud.dev
mud-docs.vercel.app
mud-docs-git-main-latticexyz.vercel.app
mud.dev
mud-docs-latticexyz.vercel.app
www.mud.dev