Merge pull request #9 from dgcoffman/dgc/update-test-for-0-blobs-special-case
Update test for computeAggregateKzgProof empty blobs array special case
This commit is contained in:
commit
cf327db6e7
|
@ -5,10 +5,10 @@
|
|||
"cflags!": ["-fno-exceptions"],
|
||||
"cflags_cc!": ["-fno-exceptions"],
|
||||
"xcode_settings": {
|
||||
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
||||
"CLANG_CXX_LIBRARY": "libc++",
|
||||
"MACOSX_DEPLOYMENT_TARGET": "13.0"
|
||||
},
|
||||
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
|
||||
"sources": ["kzg.cxx"],
|
||||
"include_dirs": [
|
||||
"<(module_root_dir)/dist/deps/blst/bindings",
|
||||
|
@ -20,7 +20,6 @@
|
|||
"<(module_root_dir)/libblst.a"
|
||||
],
|
||||
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
|
||||
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
|
||||
"actions": [
|
||||
{
|
||||
"action_name": "build_blst",
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
"cflags!": ["-fno-exceptions"],
|
||||
"cflags_cc!": ["-fno-exceptions"],
|
||||
"xcode_settings": {
|
||||
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
||||
"CLANG_CXX_LIBRARY": "libc++",
|
||||
"MACOSX_DEPLOYMENT_TARGET": "13.0"
|
||||
},
|
||||
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
|
||||
"sources": ["kzg.cxx"],
|
||||
"include_dirs": [
|
||||
"../../inc",
|
||||
|
@ -19,8 +19,7 @@
|
|||
"<(module_root_dir)/c_kzg_4844.o",
|
||||
"<(module_root_dir)/../../lib/libblst.a"
|
||||
],
|
||||
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
|
||||
"defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"]
|
||||
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"]
|
||||
},
|
||||
{
|
||||
"target_name": "action_after_build",
|
||||
|
|
|
@ -26,7 +26,7 @@ Napi::Value throw_invalid_arguments_count(
|
|||
Napi::Value throw_invalid_argument_type(const Napi::Env env, std::string name, std::string expectedType) {
|
||||
Napi::TypeError::New(
|
||||
env,
|
||||
"Invalid parameter type: " + name + ". Expected " + expectedType
|
||||
"Invalid argument type: " + name + ". Expected " + expectedType
|
||||
).ThrowAsJavaScriptException();
|
||||
|
||||
return env.Null();
|
||||
|
@ -126,7 +126,7 @@ Napi::Value BlobToKzgCommitment(const Napi::CallbackInfo& info) {
|
|||
}
|
||||
|
||||
auto blob_param = info[0].As<Napi::TypedArray>();
|
||||
if (blob_param.TypedArrayType() != napi_uint8_array) {
|
||||
if (!blob_param.IsTypedArray() || blob_param.TypedArrayType() != napi_uint8_array) {
|
||||
return throw_invalid_argument_type(env, "blob", "UInt8Array");
|
||||
}
|
||||
auto blob = blob_param.As<Napi::Uint8Array>().Data();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "c-kzg",
|
||||
"version": "0.0.9",
|
||||
"version": "1.0.3",
|
||||
"description": "NodeJS bindings for C-KZG",
|
||||
"author": "Dan Coffman",
|
||||
"license": "MIT",
|
||||
|
|
|
@ -37,9 +37,13 @@ describe("C-KZG", () => {
|
|||
expect(verifyAggregateKzgProof(blobs, commitments, proof)).toBe(true);
|
||||
});
|
||||
|
||||
it("throws an error when blobs is an empty array", () => {
|
||||
expect(() => computeAggregateKzgProof([])).toThrowError(
|
||||
"Failed to compute proof",
|
||||
it("returns the identity (aka zero, aka neutral) element when blobs is an empty array", () => {
|
||||
expect(computeAggregateKzgProof([]).toString()).toEqual(
|
||||
[
|
||||
192, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0,
|
||||
].toString(),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -59,4 +63,13 @@ describe("C-KZG", () => {
|
|||
verifyAggregateKzgProof(blobs, commitments, proof),
|
||||
).toThrowError("Invalid commitment data");
|
||||
});
|
||||
|
||||
describe("computing commitment from blobs", () => {
|
||||
it("throws as expected when given an argument of invalid type", () => {
|
||||
// @ts-expect-error
|
||||
expect(() => blobToKzgCommitment("wrong type")).toThrowError(
|
||||
"Invalid argument type: blob. Expected UInt8Array",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue