Skip to content

Commit

Permalink
coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Aug 22, 2018
1 parent 301a8f1 commit ec5f10e
Show file tree
Hide file tree
Showing 26 changed files with 416 additions and 56 deletions.
Empty file removed graphene/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion grapheneapi/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def parse_response(self, query):
ret = {}
try:
ret = json.loads(query, strict=False)
except ValueError: # pragma: nocover
except ValueError: # pragma: no cover pragma: no branch
raise ValueError("Client returned invalid format. Expected JSON!")

log.debug(json.dumps(query))
Expand Down
2 changes: 0 additions & 2 deletions graphenebase/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,6 @@ def uncompressed(self):
""" Derive uncompressed key """
public_key = repr(self._pk)
prefix = public_key[0:2]
if prefix == "04":
return public_key
assert prefix == "02" or prefix == "03"
x = int(public_key[2:], 16)
y = self._derive_y_from_x(x, (prefix == "02"))
Expand Down
14 changes: 7 additions & 7 deletions graphenebase/bip38.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
raise ImportError("Missing dependency: pyCryptodome")

SCRYPT_MODULE = None
if not SCRYPT_MODULE: # pragma: no branch
if not SCRYPT_MODULE: # pragma: no cover
try:
import scrypt
SCRYPT_MODULE = "scrypt"
Expand Down Expand Up @@ -68,12 +68,12 @@ def encrypt(privkey, passphrase):
"""
a = _bytes(addr)
salt = hashlib.sha256(hashlib.sha256(a).digest()).digest()[0:4]
if SCRYPT_MODULE == "scrypt": # pragma: no branch
if SCRYPT_MODULE == "scrypt": # pragma: no cover
key = scrypt.hash(passphrase, salt, 16384, 8, 8)
elif SCRYPT_MODULE == "pylibscrypt": # pragma: no branch
elif SCRYPT_MODULE == "pylibscrypt": # pragma: no cover
key = scrypt.scrypt(bytes(passphrase, "utf-8"), salt, 16384, 8, 8)
else: # pragma: no cover
raise ValueError("No scrypt module loaded")
raise ValueError("No scrypt module loaded") # pragma: no cover
(derived_half1, derived_half2) = (key[:32], key[32:])
aes = AES.new(derived_half2, AES.MODE_ECB)
encrypted_half1 = _encrypt_xor(privkeyhex[:32], derived_half1[:16], aes)
Expand Down Expand Up @@ -106,12 +106,12 @@ def decrypt(encrypted_privkey, passphrase):
assert flagbyte == b'\xc0', "Flagbyte has to be 0xc0"
salt = d[0:4]
d = d[4:-4]
if SCRYPT_MODULE == "scrypt": # pragma: no branch
if SCRYPT_MODULE == "scrypt": # pragma: no cover
key = scrypt.hash(passphrase, salt, 16384, 8, 8)
elif SCRYPT_MODULE == "pylibscrypt": # pragma: no branch
elif SCRYPT_MODULE == "pylibscrypt": # pragma: no cover
key = scrypt.scrypt(bytes(passphrase, "utf-8"), salt, 16384, 8, 8)
else:
raise ValueError("No scrypt module loaded")
raise ValueError("No scrypt module loaded") # pragma: no cover
derivedhalf1 = key[0:32]
derivedhalf2 = key[32:64]
encryptedhalf1 = d[0:16]
Expand Down
6 changes: 3 additions & 3 deletions graphenebase/ecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def compressedPubkey(pk):
order = ecdsa.SECP256k1.order
x = pk.public_numbers().x
y = pk.public_numbers().y
else:
else: # pragma: no cover
order = pk.curve.generator.order()
p = pk.pubkey.point
x = p.x()
Expand Down Expand Up @@ -129,7 +129,7 @@ def recoverPubkeyParameter(message, digest, signature, pubkey):
pubkey_comp = hexlify(compressedPubkey(pubkey))
if (p_comp == pubkey_comp):
return i
else:
else: # pragma: no cover
p = recover_public_key(digest, signature, i)
p_comp = hexlify(compressedPubkey(p))
p_string = hexlify(p.to_string())
Expand Down Expand Up @@ -313,7 +313,7 @@ def verify_message(message, signature, hashfn=hashlib.sha256):
return phex


def pointToPubkey(x, y, order=None):
def pointToPubkey(x, y, order=None): # pragma: no cover
order = order or ecdsa.SECP256k1.order
x_str = ecdsa.util.number_to_string(x, order)
"""
Expand Down
39 changes: 39 additions & 0 deletions graphenebase/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import sys
import time
from datetime import datetime, timezone
timeFormat = '%Y-%m-%dT%H:%M:%S'


def _bytes(x): # pragma: no branch
Expand Down Expand Up @@ -34,3 +37,39 @@ def unicodify(data):
else:
r.append(s)
return bytes("".join(r), "utf-8")


def formatTime(t):
""" Properly Format Time for permlinks
"""
if isinstance(t, (float, int)):
return datetime.utcfromtimestamp(t).strftime(timeFormat)
elif isinstance(t, datetime):
return t.strftime(timeFormat)
else:
raise ValueError("formatTime expects float/int, or datetime")


def formatTimeFromNow(secs=0):
""" Properly Format Time that is `x` seconds in the future
:param int secs: Seconds to go in the future (`x>0`) or the
past (`x<0`)
:return: Properly formated time for Graphene (`%Y-%m-%dT%H:%M:%S`)
:rtype: str
"""
return datetime.utcfromtimestamp(
time.time() + int(secs)).strftime(timeFormat)


def parse_time(block_time):
"""Take a string representation of time from the blockchain, and parse it
into datetime object.
"""
return datetime.strptime(block_time, timeFormat).replace(
tzinfo=timezone.utc)


# Legacy names
formatTimeString = formatTime
2 changes: 0 additions & 2 deletions graphenestorage/masterpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ def getEncryptedMaster(self):
figure out that a provided password is correct or not. The
checksum is only 4 bytes long!
"""
if not self.masterkey:
raise WalletLocked
if not self.unlocked():
raise WalletLocked
aes = AESCipher(self.password)
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ max-complexity = 15
# cover-xml=1
# cover-inclusive=1
# detailed-errors=1
# cover-package=graphenebase,grapheneapi,graphenestorage,graphene
# cover-package=graphenebase,grapheneapi,graphenestorage
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
'secp256k1'
],
packages=[
"graphene",
"grapheneapi",
"graphenebase",
"graphenestorage",
Expand Down
74 changes: 74 additions & 0 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import os
import yaml

# Graphene API
from grapheneapi import exceptions
from grapheneapi.api import Api, Websocket, Http

# Graphenebase
import graphenebase.ecdsa as ecdsa
from graphenebase.aes import AESCipher
from graphenebase.base58 import (
Base58,
base58decode,
base58encode,
ripemd160,
base58CheckEncode,
base58CheckDecode,
gphBase58CheckEncode,
gphBase58CheckDecode,
b58decode,
b58encode
)
from graphenebase import types, utils
from graphenebase.transactions import (
formatTimeFromNow,
timeformat
)
from graphenebase.operations import Account_create
from graphenebase.signedtransactions import (
Signed_Transaction,
MissingSignatureForKey
)
from graphenebase.account import (
BrainKey,
Address,
PublicKey,
PrivateKey,
PasswordKey,
GrapheneAddress,
BitcoinAddress
)
from graphenebase.objects import (
Operation,
GrapheneObject
)
from graphenebase.operations import (
Newdemooepration,
Newdemooepration2,
Demooepration
)
from graphenebase.operationids import (
ops,
operations,
getOperationNameForId
)

from graphenebase import bip38
from graphenebase.bip38 import encrypt, decrypt
from graphenebase.transactions import getBlockParams

# Graphenestorage
from graphenestorage.exceptions import (
WrongMasterPasswordException,
KeyAlreadyInStoreException,
WalletLocked
)
import graphenestorage as storage
from graphenestorage.interfaces import (
StoreInterface,
KeyInterface,
ConfigInterface,
EncryptedKeyInterface,
)
from graphenestorage.sqlite import SQLiteStore
144 changes: 144 additions & 0 deletions tests/fixtures.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
accounts:

- name: init0
id: '1.2.100'
registrar: '1.2.0'
lifetime_referrer: '1.2.0'
top_n_control_flags: 0
blacklisting_accounts: []
referrer: '1.2.0'
whitelisted_accounts: []
owner:
address_auths: []
key_auths:
- - BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
- 1
account_auths: []
weight_threshold: 1
active:
address_auths: []
key_auths:
- - BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
- 1
- - BTS5i8bEmtnN4fP4jAsBe17z9CCuQcHLkRyTuRZXYZeN2kVCL1sXa
- 1
account_auths: []
weight_threshold: 1
referrer_rewards_percentage: 0
membership_expiration_date: 1969-12-31T23:59:59
statistics: '2.6.1888'
network_fee_percentage: 2000
options:
extensions: []
voting_account: '1.2.5'
votes: []
num_committee: 0
memo_key: BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
num_witness: 0
whitelisting_accounts: []
lifetime_referrer_fee_percentage: 8000
blacklisted_accounts: []
owner_special_authority:
- 0
- {}
active_special_authority:
- 0
- {}

- name: init1
id: '1.2.101'
registrar: '1.2.0'
lifetime_referrer: '1.2.0'
top_n_control_flags: 0
blacklisting_accounts: []
referrer: '1.2.0'
whitelisted_accounts: []
owner:
address_auths: []
key_auths:
- - BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
- 1
account_auths: []
weight_threshold: 1
active:
address_auths: []
key_auths:
- - BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
- 1
account_auths: []
weight_threshold: 1
referrer_rewards_percentage: 0
membership_expiration_date: 1969-12-31T23:59:59
statistics: '2.6.1888'
network_fee_percentage: 2000
options:
extensions: []
voting_account: '1.2.5'
votes: []
num_committee: 0
memo_key: BTS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV
num_witness: 0
whitelisting_accounts: []
lifetime_referrer_fee_percentage: 8000
blacklisted_accounts: []
owner_special_authority:
- 0
- {}
active_special_authority:
- 0
- {}

assets:
- dynamic_asset_data_id: '2.3.121'
precision: 4
symbol: USD
bitasset_data_id: '2.4.21'
id: '1.3.121'
options:
issuer_permissions: 511
flags: 129
extensions: []
core_exchange_rate:
base:
amount: 221
asset_id: '1.3.121'
quote:
amount: 11564
asset_id: '1.3.0'
whitelist_authorities: []
whitelist_markets: []
max_market_fee: '1000000000000000'
market_fee_percent: 10
blacklist_markets: []
blacklist_authorities: []
max_supply: '1000000000000000'
description: ! '{"main":"1 United States dollar","market":""}'
issuer: '1.2.0'

- dynamic_asset_data_id: '2.3.120'
precision: 4
symbol: EUR
bitasset_data_id: '2.4.20'
id: '1.3.120'
options:
issuer_permissions: 511
flags: 128
extensions: []
core_exchange_rate:
base:
amount: 1229
asset_id: '1.3.120'
quote:
amount: 74364
asset_id: '1.3.0'
whitelist_authorities: []
whitelist_markets: []
max_market_fee: '1000000000000000'
market_fee_percent: 0
blacklist_markets: []
blacklist_authorities: []
max_supply: '1000000000000000'
description: 1 euro
issuer: '1.2.0'


Loading

0 comments on commit ec5f10e

Please sign in to comment.