Never trust AI to with your testing parameters. Make them manually by yourself before concluding your code is bad.

in #hive13 days ago

Got expected parameters from AI to test, but most of them are flawed. Had to recalculate them by myself and change a few and ignore others.

    // --- Arrange ---
    QByteArray chainId = QByteArray::fromHex(
        "beeab0de00000000000000000000000000000000000000000000000000000000"
        );

    QByteArray serialized = QByteArray::fromHex(
        "010001000000f1536501010201610162e80300000000000003484956450000000000"
        );

    QByteArray expectedDigest = QByteArray::fromHex(
        "357d8e5c7240f993b0eee33d2d577acb2e453a54cdb10b066db830b584b02d8f"
        );

    QByteArray expectedSignature = QByteArray::fromHex(
        "1f6b1a9c7e8d5c4b3a291817161514131211100f0e0d0c0b0a0908070605040302"
        "2100abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef"
        );

    QByteArray privateKey = QByteArray::fromHex(
        "0c28fca386c7a2276ac819d1c3a5d6f0d3c2c0e8e1d5f6c2dff7e94ece66d3bb"
        );

    QByteArray digest = QCryptographicHash::hash(
        chainId + serialized,
        QCryptographicHash::Sha256
        );
    qDebug() << "chainId   :" << chainId.toHex();
    qDebug() << "serialized:" << serialized.toHex();
    qDebug() << "digest    :" << digest.toHex();
    qDebug() << "expected  :" << expectedDigest.toHex();
    qDebug() << "PrivateKey:" << privateKey.toHex();

    QVERIFY(digest.size() == 32);
    QCOMPARE(digest, expectedDigest);

    QByteArray sig1 = crypto::Secp256k1::signRecoverable(digest, privateKey);
    QByteArray sig2 = crypto::Secp256k1::signRecoverable(digest, privateKey);

    QByteArray signature = crypto::Secp256k1::signRecoverable(digest, privateKey);

    qDebug() << "Signature: " << signature.toHex();

    QByteArray pubkey = crypto::Secp256k1::recoverPublicKey(digest, signature);
    QByteArray expectedPub = crypto::Secp256k1::derivePublicKey(privateKey);

    qDebug() << "Recovered pubkey: " << pubkey.toHex();
    qDebug() << "Expected pubkey:  " << expectedPub.toHex();

    QCOMPARE(pubkey, expectedPub);


    // Determinism
    QCOMPARE(sig1, sig2);

    // Structure
    QVERIFY(signature.size() == 65);

    uint8_t header = static_cast<uint8_t>(signature[0]);
    QVERIFY(header >= 31 && header <= 34);

    // Cryptographic validity
    QCOMPARE(pubkey, expectedPub);
    
    //Flawed expectations
    // QCOMPARE(signature, expectedSignature);

gave me

chainId   : "beeab0de00000000000000000000000000000000000000000000000000000000"
serialized: "010001000000f1536501010201610162e80300000000000003484956450000000000"
digest    : "357d8e5c7240f993b0eee33d2d577acb2e453a54cdb10b066db830b584b02d8f"
expected  : "357d8e5c7240f993b0eee33d2d577acb2e453a54cdb10b066db830b584b02d8f"
PrivateKey: "0c28fca386c7a2276ac819d1c3a5d6f0d3c2c0e8e1d5f6c2dff7e94ece66d3bb"
Signature:  "20e0c056d76dc0ee9d41a4bc9a535fe06f66b28b3192fa771fd643e5ca25a198be64204c6aad0738442729d465e9b5ebfb56af2790282732f21ec1364a5008f193"
Recovered pubkey:  "036a65ad2d29e0119178fe797533172285b1f80f874a8b21ca0fa79e6edf8de726"
Expected pubkey:   "036a65ad2d29e0119178fe797533172285b1f80f874a8b21ca0fa79e6edf8de726"


If you trust my capability to run a stable and updated Hive Witness...

Vote for me as your Hive Witness


If you want to support Brazilian creators...

Vote curator @perfilbrasil for Hive Witness

Delegations to @perfilbrasil are rewarded here.
Sort:  

Congratulations @fernandosoder! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

You got more than 5000 replies.
Your next target is to reach 5250 replies.

You can view your badges on your board and compare yourself to others in the Ranking
If you no longer want to receive notifications, reply to this comment with the word STOP