Skip to content

Commit

Permalink
Merge pull request #27 from datachainlab/fix-parallel-test
Browse files Browse the repository at this point in the history
Fix parallel test execution

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Nov 20, 2024
2 parents e7244ed + 5910e55 commit 129a912
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
12 changes: 6 additions & 6 deletions scripts/gencert.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/env bash
set -eu

out_certs_dir=./test/.tmp/testcerts
signing_rsa_bits=2048
signing_exponent=65537

Expand Down Expand Up @@ -41,23 +40,24 @@ function gen_ecdsa_signing_cert() {
}

function usage() {
echo "Usage: $0 {gen_rsa_root_cert|gen_rsa_signing_cert|gen_ecdsa_root_cert|gen_ecdsa_signing_cert}"
echo "Usage: $0 <out_certs_dir> {gen_rsa_root_cert|gen_rsa_signing_cert|gen_ecdsa_root_cert|gen_ecdsa_signing_cert}"
exit 1
}

if [ $# -eq 0 ]; then
if [ $# -lt 2 ]; then
usage
fi

out_certs_dir=$1
mkdir -p ${out_certs_dir}

case "$1" in
case "$2" in
"gen_rsa_root_cert")
gen_rsa_root_cert
;;
"gen_rsa_signing_cert")
signing_rsa_bits=$2
signing_exponent=$3
signing_rsa_bits=$3
signing_exponent=$4
gen_rsa_signing_cert
;;
"gen_ecdsa_root_cert")
Expand Down
55 changes: 31 additions & 24 deletions test/CertificateTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ contract CertificateTest is BasicTest {
);
}

string internal constant testCertsDir = "./test/.tmp/testcerts";
string internal constant testCertsBaseDir = "./test/.tmp/testcerts";
string internal constant genCertCmd = "./scripts/gencert.sh";

struct RSAParamsCase {
Expand All @@ -80,17 +80,18 @@ contract CertificateTest is BasicTest {
}

function testValidSigningCerts() public {
string memory testCertsDir = string(abi.encodePacked(testCertsBaseDir, "/", "valid_signing_certs"));
RSAParamsCase[4] memory cases = [
RSAParamsCase("2048", "65537"),
RSAParamsCase("2048", "3"),
RSAParamsCase("4096", "65537"),
RSAParamsCase("4096", "3")
];
vm.warp(1795167418);
cleanupTestCerts();
genRsaRootCert();
cleanupTestCerts(testCertsDir);
genRsaRootCert(testCertsDir);
for (uint256 i = 0; i < cases.length; i++) {
genRsaSigningCert(cases[i].bits, cases[i].exponent);
genRsaSigningCert(testCertsDir, cases[i].bits, cases[i].exponent);
AVRValidator.RSAParams memory rootParams = AVRValidator.verifyRootCACert(
vm.readFileBinary(string(abi.encodePacked(testCertsDir, "/root.crt.der")))
);
Expand All @@ -103,19 +104,21 @@ contract CertificateTest is BasicTest {
}

function testInvalidRootCerts() public {
string memory testCertsDir = string(abi.encodePacked(testCertsBaseDir, "/", "invalid_root_certs"));
vm.warp(1795167418);
cleanupTestCerts();
genEcdsaRootCert();
cleanupTestCerts(testCertsDir);
genEcdsaRootCert(testCertsDir);

vm.expectRevert();
AVRValidator.verifyRootCACert(vm.readFileBinary(string(abi.encodePacked(testCertsDir, "/root.crt.der"))));
}

function testInvalidSigningCerts() public {
string memory testCertsDir = string(abi.encodePacked(testCertsBaseDir, "/", "invalid_signing_certs"));
vm.warp(1795167418);
cleanupTestCerts();
genRsaRootCert();
genEcdsaSigningCert();
cleanupTestCerts(testCertsDir);
genRsaRootCert(testCertsDir);
genEcdsaSigningCert(testCertsDir);

AVRValidator.RSAParams memory rootParams =
AVRValidator.verifyRootCACert(vm.readFileBinary(string(abi.encodePacked(testCertsDir, "/root.crt.der"))));
Expand All @@ -127,41 +130,45 @@ contract CertificateTest is BasicTest {
);
}

function cleanupTestCerts() internal {
function cleanupTestCerts(string memory testCertsDir) internal {
string[] memory cmd = new string[](3);
cmd[0] = "rm";
cmd[1] = "-rf";
cmd[2] = testCertsDir;
runCmd(cmd);
}

function genRsaRootCert() internal {
string[] memory cmd = new string[](2);
function genRsaRootCert(string memory testCertsDir) internal {
string[] memory cmd = new string[](3);
cmd[0] = genCertCmd;
cmd[1] = "gen_rsa_root_cert";
cmd[1] = testCertsDir;
cmd[2] = "gen_rsa_root_cert";
runCmd(cmd);
}

function genRsaSigningCert(string memory bits, string memory exponent) internal {
string[] memory cmd = new string[](4);
function genRsaSigningCert(string memory testCertsDir, string memory bits, string memory exponent) internal {
string[] memory cmd = new string[](5);
cmd[0] = genCertCmd;
cmd[1] = "gen_rsa_signing_cert";
cmd[2] = bits;
cmd[3] = exponent;
cmd[1] = testCertsDir;
cmd[2] = "gen_rsa_signing_cert";
cmd[3] = bits;
cmd[4] = exponent;
runCmd(cmd);
}

function genEcdsaRootCert() internal {
string[] memory cmd = new string[](2);
function genEcdsaRootCert(string memory testCertsDir) internal {
string[] memory cmd = new string[](3);
cmd[0] = genCertCmd;
cmd[1] = "gen_ecdsa_root_cert";
cmd[1] = testCertsDir;
cmd[2] = "gen_ecdsa_root_cert";
runCmd(cmd);
}

function genEcdsaSigningCert() internal {
string[] memory cmd = new string[](2);
function genEcdsaSigningCert(string memory testCertsDir) internal {
string[] memory cmd = new string[](3);
cmd[0] = genCertCmd;
cmd[1] = "gen_ecdsa_signing_cert";
cmd[1] = testCertsDir;
cmd[2] = "gen_ecdsa_signing_cert";
runCmd(cmd);
}

Expand Down

0 comments on commit 129a912

Please sign in to comment.