Add test harness for building and running NodeJS tests on Linux
This commit is contained in:
parent
72f696e119
commit
0e474e6ec4
|
@ -15,3 +15,4 @@ rollup.config.js
|
||||||
tsconfig.json
|
tsconfig.json
|
||||||
babel.config.js
|
babel.config.js
|
||||||
*.bak
|
*.bak
|
||||||
|
Dockerfile
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Exists as a test harness for building and running tests in Linux
|
||||||
|
|
||||||
|
FROM node:16
|
||||||
|
|
||||||
|
COPY ./dist/ /app/dist/
|
||||||
|
COPY test.ts /app
|
||||||
|
COPY trusted_setup.txt /app
|
||||||
|
COPY kzg.ts /app
|
||||||
|
COPY kzg.cxx /app
|
||||||
|
COPY package.json /app
|
||||||
|
COPY tsconfig.json /app
|
||||||
|
COPY babel.config.js /app
|
||||||
|
COPY jest.config.js /app
|
||||||
|
COPY binding.dist.gyp /app/binding.gyp
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
RUN yarn install
|
||||||
|
|
||||||
|
CMD ["yarn", "jest"]
|
|
@ -29,3 +29,10 @@ publish: bundle
|
||||||
mv binding.gyp binding.gyp.bak
|
mv binding.gyp binding.gyp.bak
|
||||||
cp binding.dist.gyp binding.gyp
|
cp binding.dist.gyp binding.gyp
|
||||||
npm publish && mv binding.gyp.bak binding.gyp || mv binding.gyp.bak binding.gyp
|
npm publish && mv binding.gyp.bak binding.gyp || mv binding.gyp.bak binding.gyp
|
||||||
|
|
||||||
|
|
||||||
|
linux-test: bundle
|
||||||
|
cp ../../src/trusted_setup.txt .
|
||||||
|
docker build -t "linux-test" .
|
||||||
|
rm trusted_setup.txt
|
||||||
|
docker logs --follow `docker run -d linux-test`
|
||||||
|
|
|
@ -53,6 +53,10 @@
|
||||||
{
|
{
|
||||||
"files": ["./build/Release/kzg.node"],
|
"files": ["./build/Release/kzg.node"],
|
||||||
"destination": "./dist"
|
"destination": "./dist"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"files": ["./build/Release/kzg.node"],
|
||||||
|
"destination": "./"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,6 +155,7 @@ Napi::Value ComputeAggregateKzgProof(const Napi::CallbackInfo& info) {
|
||||||
auto kzg_settings = info[1].As<Napi::External<KZGSettings>>().Data();
|
auto kzg_settings = info[1].As<Napi::External<KZGSettings>>().Data();
|
||||||
|
|
||||||
auto blobs_count = blobs_param.Length();
|
auto blobs_count = blobs_param.Length();
|
||||||
|
|
||||||
auto blobs = (Blob*)calloc(blobs_count, sizeof(Blob));
|
auto blobs = (Blob*)calloc(blobs_count, sizeof(Blob));
|
||||||
|
|
||||||
for (uint32_t blob_index = 0; blob_index < blobs_count; blob_index++) {
|
for (uint32_t blob_index = 0; blob_index < blobs_count; blob_index++) {
|
||||||
|
|
|
@ -12,12 +12,14 @@
|
||||||
"@rollup/plugin-typescript": "^9.0.2",
|
"@rollup/plugin-typescript": "^9.0.2",
|
||||||
"@types/jest": "^29.2.1",
|
"@types/jest": "^29.2.1",
|
||||||
"jest": "^29.2.2",
|
"jest": "^29.2.2",
|
||||||
"node-addon-api": "^5.0.0",
|
|
||||||
"node-gyp": "^9.3.0",
|
"node-gyp": "^9.3.0",
|
||||||
"prettier": "2.7.1",
|
"prettier": "2.7.1",
|
||||||
"rollup": "^3.2.5",
|
"rollup": "^3.2.5",
|
||||||
"ts-jest": "^29.0.3",
|
"ts-jest": "^29.0.3",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "^4.8.4"
|
"typescript": "^4.8.4"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"node-addon-api": "^5.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import { randomBytes } from "crypto";
|
import { randomBytes } from "crypto";
|
||||||
|
import { existsSync } from "fs";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
loadTrustedSetup,
|
loadTrustedSetup,
|
||||||
freeTrustedSetup,
|
freeTrustedSetup,
|
||||||
|
@ -9,7 +11,12 @@ import {
|
||||||
FIELD_ELEMENTS_PER_BLOB,
|
FIELD_ELEMENTS_PER_BLOB,
|
||||||
} from "./kzg";
|
} from "./kzg";
|
||||||
|
|
||||||
const SETUP_FILE_PATH = "../../src/trusted_setup.txt";
|
const setupFileName = "trusted_setup.txt";
|
||||||
|
|
||||||
|
const SETUP_FILE_PATH = existsSync(setupFileName)
|
||||||
|
? setupFileName
|
||||||
|
: `../../src/${setupFileName}`;
|
||||||
|
|
||||||
const BLOB_BYTE_COUNT = FIELD_ELEMENTS_PER_BLOB * BYTES_PER_FIELD_ELEMENT;
|
const BLOB_BYTE_COUNT = FIELD_ELEMENTS_PER_BLOB * BYTES_PER_FIELD_ELEMENT;
|
||||||
|
|
||||||
const generateRandomBlob = () => new Uint8Array(randomBytes(BLOB_BYTE_COUNT));
|
const generateRandomBlob = () => new Uint8Array(randomBytes(BLOB_BYTE_COUNT));
|
||||||
|
@ -23,13 +30,26 @@ describe("C-KZG", () => {
|
||||||
freeTrustedSetup();
|
freeTrustedSetup();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("computes the correct commitments and aggregate proofs from blobs", () => {
|
it("computes the correct commitments and aggregate proof from blobs", () => {
|
||||||
const blobs = new Array(2).fill(0).map(generateRandomBlob);
|
let blobs = new Array(2).fill(0).map(generateRandomBlob);
|
||||||
const commitments = blobs.map(blobToKzgCommitment);
|
let commitments = blobs.map(blobToKzgCommitment);
|
||||||
const proof = computeAggregateKzgProof(blobs);
|
let proof = computeAggregateKzgProof(blobs);
|
||||||
expect(verifyAggregateKzgProof(blobs, commitments, proof)).toBe(true);
|
expect(verifyAggregateKzgProof(blobs, commitments, proof)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("computes the aggregate proof when blobs is an empty array", () => {
|
||||||
|
const proof = computeAggregateKzgProof([]);
|
||||||
|
|
||||||
|
// Is this actually what the aggregate proof for an empty array should be?
|
||||||
|
expect(proof.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(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("fails when given incorrect commitments", () => {
|
it("fails when given incorrect commitments", () => {
|
||||||
const blobs = new Array(2).fill(0).map(generateRandomBlob);
|
const blobs = new Array(2).fill(0).map(generateRandomBlob);
|
||||||
const commitments = blobs.map(blobToKzgCommitment);
|
const commitments = blobs.map(blobToKzgCommitment);
|
||||||
|
|
Loading…
Reference in New Issue