Ejemplo n.º 1
0
    def test_checksum_failed_raises_error(self):
        wallet = HDWallet()

        # https://github.com/trezor/python-mnemonic/blob/master/test_mnemonic.py
        wallet.shards = FakeShards("bless cloud wheel regular tiny venue" +
                                   "bird web grief security dignity zoo")
        with pytest.raises(hermit.errors.HermitError) as e_info1:
            wallet.unlock()

        # https://github.com/kristovatlas/bip39_gym/blob/master/test_bip39.py
        wallet.shards = FakeShards("town iron abandon")
        with pytest.raises(hermit.errors.HermitError) as e_info2:
            wallet.unlock()

        #https://github.com/tyler-smith/go-bip39/blob/master/bip39_test.go
        wallet.shards = FakeShards("abandon abandon abandon abandon abandon" +
                                   "abandon abandon abandon abandon abandon" +
                                   "abandon yellow")
        with pytest.raises(hermit.errors.HermitError) as e_info3:
            wallet.unlock()

        expected = "Wallet words failed checksum."
        assert str(e_info1.value) == expected
        assert str(e_info2.value) == expected
        assert str(e_info3.value) == expected
    def test_opensouce_bitcoin_vector_0(self,
                                        mock_request,
                                        mock_input,
                                        mock_display_qr_code,
                                        fixture_opensource_shard_set,
                                        fixture_opensource_bitcoin_vectors,
                                        capsys):
        # TODO: use an actual shard_file
        # TODO: move to all opensource vectors
        test_vector = fixture_opensource_bitcoin_vectors
        wallet = HDWallet()
        wallet.shards = fixture_opensource_shard_set
        mock_request.return_value = test_vector['request_json']
        mock_input.return_value = 'y'

        signer = BitcoinSigner(wallet)
        signer.sign(testnet=True)
        captured = capsys.readouterr()

        expected_display = test_vector['expected_display']
        expected_return = test_vector['expected_signature']

        mock_display_qr_code.assert_called_once()
        mock_display_qr_code.assert_called_with(json.dumps(expected_return),
                                                name='Signature')
Ejemplo n.º 3
0
 def test_root_priv_from_trezor_vectors(self, trezor_bip39_vectors):
     # With Passphrase
     for v in trezor_bip39_vectors['english']:
         wallet = HDWallet()
         wallet.shards = FakeShards(v[1])
         wallet.unlock(passphrase="TREZOR")
         xprv = wallet.root_priv
         assert xprv == v[3]
Ejemplo n.º 4
0
 def test_root_priv_from_unchained_vectors(self, unchained_vectors):
     # Without Passphrase
     for words in unchained_vectors:
         wallet = HDWallet()
         wallet.shards = FakeShards(words)
         wallet.unlock()
         xprv = wallet.root_priv
         expected_xprv = unchained_vectors[words]['m']['xprv']
         assert xprv == expected_xprv
Ejemplo n.º 5
0
    def test_can_create_valid_signature(self, mock_request, mock_input,
                                        mock_display_qr_code,
                                        fixture_opensource_bitcoin_vectors,
                                        fixture_opensource_shard_set, capsys):
        request_json = fixture_opensource_bitcoin_vectors['request_json']
        wallet = HDWallet()
        wallet.shards = fixture_opensource_shard_set
        mock_request.return_value = request_json
        mock_input.return_value = 'y'
        EchoSigner(wallet).sign(testnet=True)
        mock_display_qr_code.assert_called_once()
        captured = capsys.readouterr()
        expected_return = json.loads(request_json)
        expected_display = """QR Code:
        {}
        """.format(expected_return)

        mock_display_qr_code.assert_called_with(request_json, name='Request')
Ejemplo n.º 6
0
 def test_locked_wallet_is_not_unlocked(self, opensource_wallet_words):
     wallet = HDWallet()
     wallet.shards = FakeShards(opensource_wallet_words)
     wallet.unlock()
     wallet.lock()
     assert wallet.unlocked() == False