<commit_before><?php

namespace BitWasp\Secp256k1Tests;

use Symfony\Component\Yaml\Yaml;

class Secp256k1PubkeyTweakAddTest extends TestCase
{

    /**
     * @return array
     */
    public function getVectors()
    {
        $stop = 0;
        $parser = new Yaml();
        $data = $parser->parse(__DIR__ . '/data/secp256k1_pubkey_tweak_add.yml');

        $context = TestCase::getContext();
        $fixtures = array();
        foreach ($data['vectors'] as $c => $vector) {
            if ($stop && $c >= 2) {
                break;
            }
            $fixtures[] = array(
                $context,
                $vector['publicKey'],
                $vector['tweak'],
                $vector['tweaked']
            );
        }
        return $fixtures;
    }

    /**
     * @dataProvider getVectors
     */
    public function testAddsToPubkey($context, $publicKey, $tweak, $expectedPublicKey)
    {
        $this->genericTest(
            $context,
            $publicKey,
            $tweak,
            $expectedPublicKey,
            1
        );
    }

    /**
     * @param $publicKey
     * @param $tweak
     * @param $expectedPublicKey
     * @param $eAdd
     */
    private function genericTest($context, $publicKey, $tweak, $expectedPublicKey, $eAdd)
    {
        $publicKey = $this->toBinary32($publicKey);
        $tweak = $this->toBinary32($tweak);
        $result = secp256k1_ec_pubkey_tweak_add($context, $publicKey, $tweak);
        $this->assertEquals($eAdd, $result);
        $this->assertEquals(bin2hex($publicKey), $expectedPublicKey);
    }


    public function getErroneousTypeVectors()
    {
        $context = TestCase::getContext();
        $publicKey = $this->pack('<KEY>');

        $array = array();
        $class = new self;
        $resource = openssl_pkey_new();

        return array(
            // Only test second value, first is zVal to tested elsewhere
            array($context, $publicKey, $array),
            array($context, $publicKey, $resource),
            array($context, $publicKey, $class)
        );
    }

    /**
     * @dataProvider getErroneousTypeVectors
     * @expectedException \PHPUnit_Framework_Error_Warning
     */
    public function testErroneousTypes($context, $pubkey, $tweak)
    {
        \secp256k1_ec_pubkey_tweak_add($context, $pubkey, $tweak);
    }

    /**
     * @expectedException \Exception
     */
    public function testEnforceZvalString()
    {
        $tweak = $this->pack('<KEY>');
        $pubkey = array();
        \secp256k1_ec_pubkey_tweak_add(TestCase::getContext(), $pubkey, $tweak);
    }
}<commit_msg>Update PubkeyTweakAddTest<commit_after><?php

namespace BitWasp\Secp256k1Tests;

use Symfony\Component\Yaml\Yaml;

class Secp256k1PubkeyTweakAddTest extends TestCase
{

    /**
     * @return array
     */
    public function getVectors()
    {
        $stop = 0;
        $parser = new Yaml();
        $data = $parser->parse(__DIR__ . '/data/secp256k1_pubkey_tweak_add.yml');

        $compressed = 0;
        $context = TestCase::getContext();
        $fixtures = array();
        foreach ($data['vectors'] as $c => $vector) {
            if ($stop && $c >= 2) {
                break;
            }
            $fixtures[] = array(
                $context,
                $vector['publicKey'],
                $vector['tweak'],
                $vector['tweaked'],
                $compressed
            );
        }
        return $fixtures;
    }

    /**
     * @dataProvider getVectors
     */
    public function testAddsToPubkey($context, $publicKey, $tweak, $expectedPublicKey, $compressed)
    {
        $this->genericTest(
            $context,
            $publicKey,
            $tweak,
            $expectedPublicKey,
            1,
            $compressed
        );
    }

    /**
     * @param $publicKey
     * @param $tweak
     * @param $expectedPublicKey
     * @param $eAdd
     */
    private function genericTest($context, $publicKey, $tweak, $expectedPublicKey, $eAdd, $compressed)
    {
        $publicKey = $this->toBinary32($publicKey);
        $p = '';
        secp256k1_ec_pubkey_parse($context, $publicKey, $p);
        $tweak = $this->toBinary32($tweak);
        $result = secp256k1_ec_pubkey_tweak_add($context, $p, $tweak);
        $this->assertEquals($eAdd, $result);

        $pSer = '';
        secp256k1_ec_pubkey_serialize($context, $p, $compressed, $pSer);
        $this->assertEquals(bin2hex($pSer), $expectedPublicKey);
    }


    public function getErroneousTypeVectors()
    {
        $context = TestCase::getContext();
        $publicKey = $this->pack('<KEY>');

        $array = array();
        $class = new self;
        $resource = openssl_pkey_new();

        return array(
            // Only test second value, first is zVal to tested elsewhere
            array($context, $publicKey, $array),
            array($context, $publicKey, $resource),
            array($context, $publicKey, $class)
        );
    }

    /**
     * @dataProvider getErroneousTypeVectors
     * @expectedException \PHPUnit_Framework_Error_Warning
     */
    public function testErroneousTypes($context, $pubkey, $tweak)
    {
        \secp256k1_ec_pubkey_tweak_add($context, $pubkey, $tweak);
    }

    /**
     * @expectedException \PHPUnit_Framework_Error_Warning
     */
    public function testEnforceZvalString()
    {
        $tweak = $this->pack('<KEY>');
        $pubkey = array();
        \secp256k1_ec_pubkey_tweak_add(TestCase::getContext(), $pubkey, $tweak);
    }
}
{'fraction_non_alphanumeric': 0.13517915309446255, 'fraction_numerical': 0.013210278682591387, 'mean_word_length': 2.0688506385341476, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3503662', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1705, 'n_words': 304}