upgrade bls tests to 0.8.3
This commit is contained in:
parent
72fc3219e2
commit
45e687f25e
|
@ -52,7 +52,7 @@
|
||||||
"@babel/register": "^7.0.0",
|
"@babel/register": "^7.0.0",
|
||||||
"@babel/runtime": "^7.4.4",
|
"@babel/runtime": "^7.4.4",
|
||||||
"@chainsafe/benchmark-utils": "^0.1.0",
|
"@chainsafe/benchmark-utils": "^0.1.0",
|
||||||
"@chainsafe/eth2.0-spec-test-util": "^0.2.3",
|
"@chainsafe/eth2.0-spec-test-util": "0.4.1",
|
||||||
"@types/assert": "^1.4.2",
|
"@types/assert": "^1.4.2",
|
||||||
"@types/chai": "^4.1.7",
|
"@types/chai": "^4.1.7",
|
||||||
"@types/mocha": "^5.2.5",
|
"@types/mocha": "^5.2.5",
|
||||||
|
|
|
@ -1,21 +1,27 @@
|
||||||
import {join} from "path";
|
import bls, {PublicKey} from "../../src";
|
||||||
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
||||||
import bls from "../../src";
|
import path from "path";
|
||||||
import {BLSSignature} from "@chainsafe/eth2.0-types";
|
|
||||||
|
|
||||||
describeSpecTest(
|
interface AggregatePubKeysTestCase {
|
||||||
join(__dirname, "../../../spec-test-cases/tests/bls/aggregate_pubkeys/aggregate_pubkeys.yaml"),
|
data: {
|
||||||
bls.aggregatePubkeys,
|
input: string[];
|
||||||
({input}) => {
|
output: string;
|
||||||
const sigs: BLSSignature[] = [];
|
};
|
||||||
input.forEach((sig: string) => {
|
}
|
||||||
sigs.push(Buffer.from(sig.replace('0x', ''), 'hex'));
|
|
||||||
});
|
describeDirectorySpecTest<AggregatePubKeysTestCase, string>(
|
||||||
return [
|
"aggregate pubkeys",
|
||||||
sigs
|
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/aggregate_pubkeys/small"),
|
||||||
];
|
(testCase => {
|
||||||
},
|
const result = bls.aggregatePubkeys(testCase.data.input.map(pubKey => {
|
||||||
({output}) => output,
|
return Buffer.from(pubKey.replace("0x", ""), "hex");
|
||||||
(result) => `0x${result.toString('hex')}`,
|
}));
|
||||||
() => false,
|
return `0x${result.toString('hex')}`;
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
inputTypes: {
|
||||||
|
data: InputType.YAML,
|
||||||
|
},
|
||||||
|
getExpected: (testCase => testCase.data.output)
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,21 +1,27 @@
|
||||||
import {join} from "path";
|
import path from "path";
|
||||||
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
|
||||||
import bls from "../../src";
|
import bls from "../../src";
|
||||||
import {BLSPubkey} from "../../src/types";
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
||||||
|
|
||||||
describeSpecTest(
|
interface AggregateSigsTestCase {
|
||||||
join(__dirname, "../../../spec-test-cases/tests/bls/aggregate_sigs/aggregate_sigs.yaml"),
|
data: {
|
||||||
bls.aggregateSignatures,
|
input: string[];
|
||||||
({input}) => {
|
output: string;
|
||||||
const pubKeys: BLSPubkey[] = [];
|
};
|
||||||
input.forEach((pubKey: string) => {
|
}
|
||||||
pubKeys.push(Buffer.from(pubKey.replace('0x', ''), 'hex'));
|
|
||||||
});
|
describeDirectorySpecTest<AggregateSigsTestCase, string>(
|
||||||
return [
|
"aggregate sigs",
|
||||||
pubKeys
|
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/aggregate_sigs/small"),
|
||||||
];
|
(testCase => {
|
||||||
},
|
const result = bls.aggregateSignatures(testCase.data.input.map(pubKey => {
|
||||||
({output}) => output,
|
return Buffer.from(pubKey.replace("0x", ""), "hex");
|
||||||
(result) => `0x${result.toString('hex')}`,
|
}));
|
||||||
() => false,
|
return `0x${result.toString('hex')}`;
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
inputTypes: {
|
||||||
|
data: InputType.YAML,
|
||||||
|
},
|
||||||
|
getExpected: (testCase => testCase.data.output)
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
import {join} from "path";
|
|
||||||
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
|
||||||
import {padLeft} from "../../src/helpers/utils";
|
|
||||||
import {G2point} from "../../src/helpers/g2point";
|
|
||||||
|
|
||||||
describeSpecTest(
|
|
||||||
join(__dirname, "../../../spec-test-cases/tests/bls/msg_hash_g2_compressed/g2_compressed.yaml"),
|
|
||||||
G2point.hashToG2,
|
|
||||||
({input}) => {
|
|
||||||
const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8);
|
|
||||||
return [
|
|
||||||
Buffer.from(input.message.replace('0x', ''), 'hex'),
|
|
||||||
domain
|
|
||||||
];
|
|
||||||
},
|
|
||||||
({output}) => {
|
|
||||||
const xReExpected = padLeft(Buffer.from(output[0].replace('0x', ''), 'hex'), 48);
|
|
||||||
const xImExpected = padLeft(Buffer.from(output[1].replace('0x', ''), 'hex'), 48);
|
|
||||||
return '0x' + Buffer.concat([xReExpected, xImExpected]).toString('hex');
|
|
||||||
},
|
|
||||||
(result: G2point) => `0x${result.toBytesCompressed().toString('hex')}`,
|
|
||||||
() => false,
|
|
||||||
);
|
|
|
@ -1,28 +0,0 @@
|
||||||
import {join} from "path";
|
|
||||||
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
|
||||||
import {padLeft} from "../../src/helpers/utils";
|
|
||||||
import {G2point} from "../../src/helpers/g2point";
|
|
||||||
|
|
||||||
describeSpecTest(
|
|
||||||
join(__dirname, "../../../spec-test-cases/tests/bls/msg_hash_g2_uncompressed/g2_uncompressed.yaml"),
|
|
||||||
G2point.hashToG2,
|
|
||||||
({input}) => {
|
|
||||||
const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8);
|
|
||||||
return [
|
|
||||||
Buffer.from(input.message.replace('0x', ''), 'hex'),
|
|
||||||
domain
|
|
||||||
];
|
|
||||||
},
|
|
||||||
({output}) => {
|
|
||||||
return '0x' + G2point.fromUncompressedInput(
|
|
||||||
Buffer.from(output[0][0].replace('0x', ''), 'hex'),
|
|
||||||
Buffer.from(output[0][1].replace('0x', ''), 'hex'),
|
|
||||||
Buffer.from(output[1][0].replace('0x', ''), 'hex'),
|
|
||||||
Buffer.from(output[1][1].replace('0x', ''), 'hex'),
|
|
||||||
Buffer.from(output[2][0].replace('0x', ''), 'hex'),
|
|
||||||
Buffer.from(output[2][1].replace('0x', ''), 'hex'),
|
|
||||||
).toBytesCompressed().toString('hex');
|
|
||||||
},
|
|
||||||
(result: G2point) => `0x${result.toBytesCompressed().toString('hex')}`,
|
|
||||||
() => false,
|
|
||||||
);
|
|
|
@ -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, "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');
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
|
@ -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, "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');
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
|
@ -1,14 +1,25 @@
|
||||||
import {join} from "path";
|
|
||||||
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
|
||||||
import bls from "../../src";
|
import bls from "../../src";
|
||||||
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
||||||
|
import path from "path";
|
||||||
|
|
||||||
describeSpecTest(
|
interface PrivToPubTestCase {
|
||||||
join(__dirname, "../../../spec-test-cases/tests/bls/priv_to_pub/priv_to_pub.yaml"),
|
data: {
|
||||||
bls.generatePublicKey,
|
input: string;
|
||||||
({input}) => {
|
output: string;
|
||||||
return [Buffer.from(input.replace('0x', ''), 'hex')];
|
};
|
||||||
},
|
}
|
||||||
({output}) => output,
|
|
||||||
(result) => `0x${result.toString('hex')}`,
|
describeDirectorySpecTest<PrivToPubTestCase, string>(
|
||||||
() => false,
|
"priv_to_pub",
|
||||||
|
path.join(__dirname, "../../../spec-test-cases/tests/general/phase0/bls/priv_to_pub/small"),
|
||||||
|
(testCase => {
|
||||||
|
const result = bls.generatePublicKey(Buffer.from(testCase.data.input.replace('0x', ''), 'hex'));
|
||||||
|
return `0x${result.toString('hex')}`;
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
inputTypes: {
|
||||||
|
data: InputType.YAML,
|
||||||
|
},
|
||||||
|
getExpected: (testCase => testCase.data.output)
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,20 +1,34 @@
|
||||||
import {join} from "path";
|
import path from "path";
|
||||||
import {describeSpecTest} from "@chainsafe/eth2.0-spec-test-util";
|
|
||||||
import bls from "../../src";
|
import bls from "../../src";
|
||||||
import {padLeft} from "../../src/helpers/utils";
|
import {padLeft} from "../../src/helpers/utils";
|
||||||
|
import {describeDirectorySpecTest, InputType} from "@chainsafe/eth2.0-spec-test-util/lib/single";
|
||||||
|
|
||||||
describeSpecTest(
|
interface SignMessageTestCase {
|
||||||
join(__dirname, "../../../spec-test-cases/tests/bls/sign_msg/sign_msg.yaml"),
|
data: {
|
||||||
bls.sign,
|
input: {
|
||||||
({input}) => {
|
privkey: string,
|
||||||
const domain = padLeft(Buffer.from(input.domain.replace('0x', ''), 'hex'), 8);
|
message: string,
|
||||||
return [
|
domain: string
|
||||||
Buffer.from(input.privkey.replace('0x', ''), 'hex'),
|
};
|
||||||
Buffer.from(input.message.replace('0x', ''), 'hex'),
|
output: string;
|
||||||
domain
|
};
|
||||||
];
|
}
|
||||||
},
|
|
||||||
({output}) => output,
|
describeDirectorySpecTest<SignMessageTestCase, string>(
|
||||||
(result) => `0x${result.toString('hex')}`,
|
"priv_to_pub",
|
||||||
() => false,
|
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)
|
||||||
|
}
|
||||||
);
|
);
|
Reference in New Issue