Skip to content

Commit

Permalink
fix: data2 should be serialized to 4
Browse files Browse the repository at this point in the history
  • Loading branch information
homura committed Nov 23, 2023
1 parent d4356fe commit 9d8b881
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/toolkit/src/normalizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function normalizeObject(debugPath, object, keys) {

for (const [key, f] of Object.entries(keys)) {
const value = object[key];
if (!value) {
if (value == null) {
throw new Error(`${debugPath} is missing ${key}!`);
}
result[key] = f(`${debugPath}.${key}`, value);
Expand All @@ -88,14 +88,14 @@ export function NormalizeScript(script, { debugPath = "script" } = {}) {
case "data1":
return 2;
case "data2":
return 3;
return 4;
case 0:
return value;
case 1:
return value;
case 2:
return value;
case 3:
case 4:
return value;
default:
throw new Error(`${debugPath}.hashType has invalid value: ${value}`);
Expand Down
20 changes: 20 additions & 0 deletions packages/toolkit/tests/normailizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,23 @@ test("error outPoint should not pass validation", (t) => {
});
});
});

test("normalizeScript should work", (t) => {
["type", "data", "data1", "data2", 0, 1, 2, 4].forEach((hashType) => {
normalizers.NormalizeScript({
codeHash: `0x${"00".repeat(32)}`,
args: "0x",
hashType,
});
});

t.pass();

t.throws(() => {
normalizers.NormalizeScript({
codeHash: `0x${"00".repeat(32)}`,
args: "0x",
hashType: "unknown",
});
});
});

1 comment on commit 9d8b881

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 New canary release: 0.0.0-ckb2023-9d8b881-20231123114111

npm install @ckb-lumos/[email protected]

Please sign in to comment.