Skip to content

Commit

Permalink
fix: Data variants support in hash_type
Browse files Browse the repository at this point in the history
  • Loading branch information
xxuejie committed Nov 14, 2024
1 parent 0a499af commit df74aee
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/ckb-js-toolkit.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ckb-js-toolkit.node.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ckb-js-toolkit.node.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ckb-js-toolkit.umd.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export function ValidateScript(
assertHash(`${debugPath}.code_hash`, script.code_hash);
assertHexString(`${debugPath}.args`, script.args);

if (script.hash_type !== "data" && script.hash_type !== "type") {
const DATA_VARIANTS = /^data([1-9][0-9]*)?$/;
if (script.hash_type !== "type" && !DATA_VARIANTS.test(script.hash_type)) {
throw new Error(`${debugPath}.hash_type must be either data or type!`);
}
}
Expand Down
21 changes: 21 additions & 0 deletions tests/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ test("script with invalid hash type", t => {
});
});

test("script with data variants", t => {
validators.ValidateScript({
code_hash:
"0xa98c57135830e1b91345948df6c4b8870828199a786b26f09f7dec4bc27a73da",
args: "0x1234",
hash_type: "data2"
});
t.pass();
});

test("script with invalid data variants", t => {
t.throws(() => {
validators.ValidateScript({
code_hash:
"0xa98c57135830e1b91345948df6c4b8870828199a786b26f09f7dec4bc27a73da",
args: "0x1234",
hash_type: "dataf"
});
});
});

test("correct outpoint", t => {
validators.ValidateOutPoint({
tx_hash:
Expand Down

0 comments on commit df74aee

Please sign in to comment.