working bls on 0.8.3 tests

This commit is contained in:
Marin Petrunić 2019-09-05 18:51:27 -04:00
parent 45e687f25e
commit 8ef2ac2ac0
7 changed files with 101 additions and 101 deletions

View File

@ -28,7 +28,7 @@
"pretest": "yarn check-types",
"prepublishOnly": "yarn build",
"test:unit": "nyc --cache-dir .nyc_output/.cache -r lcov -e .ts mocha --colors -r ./.babel-register 'test/unit/**/*.test.ts' && nyc report",
"test:spec": "mocha --colors -r ./.babel-register 'test/spec/**/*.test.ts'",
"test:spec": "mocha --colors -r ts-node/register 'test/spec/**/*.test.ts'",
"test:spec-min": "yarn run test:spec",
"test": "yarn test:unit && yarn test:spec",
"coverage": "codecov -F bls",
@ -64,7 +64,7 @@
"codecov": "^3.1.0",
"eslint": "^5.14.1",
"js-yaml": "^3.13.1",
"mocha": "^5.2.0",
"mocha": "^6.2.0",
"nyc": "^13.3.0",
"sinon": "^7.2.7",
"supertest": "^4.0.2",

View File

@ -1,4 +1,4 @@
import bls, {PublicKey} from "../../src";
import bls from "../../src";
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
import path from "path";

View File

@ -0,0 +1,35 @@
import path from "path";
import {padLeft} from "../../src/helpers/utils";
import {G2point} from "../../src/helpers/g2point";
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
interface MsgHHashCOmpressed {
data: {
input: {
message: string;
domain: string;
};
output: string[];
};
}
describeDirectorySpecTest<MsgHHashCOmpressed, string>(
"msg_hash_compressed",
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/msg_hash_compressed/small"),
(testCase => {
const domain = padLeft(Buffer.from(testCase.data.input.domain.replace('0x', ''), 'hex'), 8);
const input = Buffer.from(testCase.data.input.message.replace('0x', ''), "hex");
const result = G2point.hashToG2(input, domain);
return `0x${result.toBytesCompressed().toString('hex')}`;
}),
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase => {
const xReExpected = padLeft(Buffer.from(testCase.data.output[0].replace('0x', ''), 'hex'), 48);
const xImExpected = padLeft(Buffer.from(testCase.data.output[1].replace('0x', ''), 'hex'), 48);
return '0x' + Buffer.concat([xReExpected, xImExpected]).toString('hex');
})
}
);

View File

@ -1,40 +0,0 @@
import path from "path";
import {padLeft} from "../../src/helpers/utils";
import {G2point} from "../../src/helpers/g2point";
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
interface MsgHHashUnCompressed {
data: {
input: {
message: string,
domain: string
};
output: string[][];
};
}
describeDirectorySpecTest<MsgHHashUnCompressed, string>(
"msg_hash_uncompressed",
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/msg_hash_uncompressed/small"),
(testCase => {
const domain = padLeft(Buffer.from(testCase.data.input.domain.replace('0x', ''), 'hex'), 8);
const input = Buffer.from(testCase.data.input.message, "hex");
const result = G2point.hashToG2(input, domain);
return `0x${result.toBytesCompressed().toString('hex')}`
}),
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase => {
return '0x' + G2point.fromUncompressedInput(
Buffer.from(testCase.data.output[0][0].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[0][1].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[1][0].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[1][1].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[2][0].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[2][1].replace('0x', ''), 'hex'),
).toBytesCompressed().toString('hex');
})
}
);

View File

@ -0,0 +1,40 @@
import path from "path";
import {padLeft} from "../../src/helpers/utils";
import {G2point} from "../../src/helpers/g2point";
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
interface MsgHHashUnCompressed {
data: {
input: {
message: string;
domain: string;
};
output: string[][];
};
}
describeDirectorySpecTest<MsgHHashUnCompressed, string>(
"msg_hash_uncompressed",
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/msg_hash_uncompressed/small"),
(testCase => {
const domain = padLeft(Buffer.from(testCase.data.input.domain.replace('0x', ''), 'hex'), 8);
const input = Buffer.from(testCase.data.input.message.replace("0x", ""), "hex");
const result = G2point.hashToG2(input, domain);
return `0x${result.toBytesCompressed().toString('hex')}`;
}),
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase => {
return '0x' + G2point.fromUncompressedInput(
Buffer.from(testCase.data.output[0][0].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[0][1].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[1][0].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[1][1].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[2][0].replace('0x', ''), 'hex'),
Buffer.from(testCase.data.output[2][1].replace('0x', ''), 'hex'),
).toBytesCompressed().toString('hex');
})
}
);

View File

@ -1,35 +0,0 @@
import path from "path";
import {padLeft} from "../../src/helpers/utils";
import {G2point} from "../../src/helpers/g2point";
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
interface MsgHHashCOmpressed {
data: {
input: {
message: string,
domain: string
};
output: string[];
};
}
describeDirectorySpecTest<MsgHHashCOmpressed, string>(
"msg_hash_compressed",
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/msg_hash_compressed/small"),
(testCase => {
const domain = padLeft(Buffer.from(testCase.data.input.domain.replace('0x', ''), 'hex'), 8);
const input = Buffer.from(testCase.data.input.message, "hex");
const result = G2point.hashToG2(input, domain);
return `0x${result.toBytesCompressed().toString('hex')}`
}),
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase => {
const xReExpected = padLeft(Buffer.from(testCase.data.output[0].replace('0x', ''), 'hex'), 48);
const xImExpected = padLeft(Buffer.from(testCase.data.output[1].replace('0x', ''), 'hex'), 48);
return '0x' + Buffer.concat([xReExpected, xImExpected]).toString('hex');
})
}
);

View File

@ -4,31 +4,31 @@ import {padLeft} from "../../src/helpers/utils";
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
interface SignMessageTestCase {
data: {
input: {
privkey: string,
message: string,
domain: string
};
output: string;
data: {
input: {
privkey: string;
message: string;
domain: string;
};
output: string;
};
}
describeDirectorySpecTest<SignMessageTestCase, string>(
"priv_to_pub",
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/sign_msg/small"),
(testCase => {
const signature = bls.sign(
Buffer.from(testCase.data.input.privkey.replace("0x", ""), "hex"),
Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"),
padLeft(Buffer.from(testCase.data.input.domain.replace('0x', ''), 'hex'), 8)
);
return `0x${signature.toString("hex")}`;
}),
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase => testCase.data.output)
}
"priv_to_pub",
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/sign_msg/small"),
(testCase => {
const signature = bls.sign(
Buffer.from(testCase.data.input.privkey.replace("0x", ""), "hex"),
Buffer.from(testCase.data.input.message.replace("0x", ""), "hex"),
padLeft(Buffer.from(testCase.data.input.domain.replace('0x', ''), 'hex'), 8)
);
return `0x${signature.toString("hex")}`;
}),
{
inputTypes: {
data: InputType.YAML,
},
getExpected: (testCase => testCase.data.output)
}
);