Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xeroc committed Mar 14, 2019
2 parents ba2e6b8 + 7652135 commit 099d225
Show file tree
Hide file tree
Showing 18 changed files with 660 additions and 61 deletions.
1 change: 1 addition & 0 deletions .pyup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# see https://pyup.io/docs/configuration/ for all available options

update: all
branch: develop

# update schedule
# default: empty
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ clean-build:
rm -fr build/
rm -fr dist/
rm -fr *.egg-info
rm -fr __pycache__/ .eggs/ .cache/ .tox/
rm -fr __pycache__/ .eggs/ .cache/ .tox/ .pytest_cache/ .scannerwork/

clean-pyc:
find . -name '*.pyc' -exec rm -f {} +
Expand Down
2 changes: 1 addition & 1 deletion grapheneapi/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Http(Rpc):
""" RPC Calls
"""

def proxies(self):
def proxies(self): # pragma: no cover
proxy_url = self.get_proxy_url()
if proxy_url is None:
return None
Expand Down
4 changes: 2 additions & 2 deletions grapheneapi/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, url, **kwargs):

def setup_proxy(self, options):
proxy_url = options.pop("proxy", None)
if proxy_url:
if proxy_url: # pragma: no cover
url = urllib.parse.urlparse(proxy_url)
self.proxy_host = url.hostname
self.proxy_port = url.port
Expand All @@ -64,7 +64,7 @@ def setup_proxy(self, options):
"Using proxy %s:%d %s" % (self.proxy_host, self.proxy_port, self.proxy_type)
)

def get_proxy_url(self):
def get_proxy_url(self): # pragma: no cover
if not self.proxy_host:
return None
auth = ""
Expand Down
11 changes: 3 additions & 8 deletions graphenebase/memo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
import hashlib
import struct
import sys
Expand All @@ -13,9 +14,6 @@
except ImportError:
raise ImportError("Missing dependency: pyCryptodome")

" This class and the methods require python3 "
assert sys.version_info[0] == 3, "this library requires python3"


def get_shared_secret(priv, pub):
""" Derive the share secret between ``priv`` and ``pub``
Expand Down Expand Up @@ -115,12 +113,9 @@ def decode_memo(priv, pub, nonce, message):
" Checksum "
checksum = cleartext[0:4]
message = cleartext[4:]
try:
message = _unpad(message, 16)
except Exception as e:
raise ValueError(message)
message = _unpad(message, 16)
" Verify checksum "
check = hashlib.sha256(message).digest()[0:4]
if check != checksum:
if check != checksum: # pragma: no cover
raise ValueError("checksum verification failure")
return message.decode("utf8")
29 changes: 11 additions & 18 deletions graphenebase/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def klass(self):

@property
def ops(self):
if callable(self.operations):
if callable(self.operations): # pragma: no cover
# Legacy support
return self.operations()
else:
Expand Down Expand Up @@ -180,7 +180,7 @@ def __init__(self, *args, **kwargs):
super().__init__(self.detail(*args, **kwargs))

def __bytes__(self):
if len(self) is 0:
if len(self) == 0:
return bytes()
b = b""
for name, value in self.items():
Expand All @@ -191,11 +191,11 @@ def __bytes__(self):
return b

def __json__(self):
if len(self) is 0:
if len(self) == 0:
return {}
d = {} # JSON output is *not* ordered
for name, value in self.items():
if isinstance(value, Optional) and value.isempty():
if isinstance(value, Optional) and value.isempty(): # pragma: no cover
continue

if isinstance(value, String):
Expand Down Expand Up @@ -234,17 +234,10 @@ def isArgsThisClass(self, args):

# Common Objects
class Asset(GrapheneObject):
def __init__(self, *args, **kwargs):
if isArgsThisClass(self, args):
self.data = args[0].data
else:
if len(args) == 1 and len(kwargs) == 0:
kwargs = args[0]
super().__init__(
OrderedDict(
[
("amount", Int64(kwargs["amount"])),
("asset_id", ObjectId(kwargs["asset_id"], "asset")),
]
)
)
def detail(self, *args, **kwargs):
return OrderedDict(
[
("amount", Int64(kwargs["amount"])),
("asset_id", ObjectId(kwargs["asset_id"], "asset")),
]
)
13 changes: 2 additions & 11 deletions graphenebase/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
VoteId,
ObjectId,
)
from .objects import GrapheneObject, isArgsThisClass
from .objects import GrapheneObject, isArgsThisClass, Asset
from .account import PublicKey
from .chains import default_prefix
from .operationids import getOperationNameForId


# Old style of defining an operation
Expand Down Expand Up @@ -56,16 +57,6 @@ def detail(self, *args, **kwargs):
)


class Asset(GrapheneObject):
def detail(self, *args, **kwargs):
return OrderedDict(
[
("amount", Int64(kwargs["amount"])),
("asset_id", ObjectId(kwargs["asset_id"], "asset")),
]
)


class Permission(GrapheneObject):
def detail(self, *args, **kwargs):
prefix = kwargs.pop("prefix", default_prefix)
Expand Down
2 changes: 1 addition & 1 deletion graphenebase/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def __str__(self):
def isempty(self):
if self.data is None:
return True
if not bool(str(self.data)):
if not bool(str(self.data)): # pragma: no cover
return True
return not bool(bytes(self.data))

Expand Down
16 changes: 8 additions & 8 deletions graphenecommon/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def refresh(self):
raise AccountDoesNotExistsException(self.identifier)
self.store(account, "name")

if self.full:
if self.full: # pragma: no cover
accounts = self.blockchain.rpc.get_full_accounts([account["id"]], False)
if accounts and isinstance(accounts, list):
account = accounts[0][1]
Expand All @@ -81,12 +81,12 @@ def name(self):
return self["name"]

@property
def is_fully_loaded(self):
def is_fully_loaded(self): # pragma: no cover
""" Is this instance fully loaded / e.g. all data available?
"""
return self.full and "votes" in self

def ensure_full(self):
def ensure_full(self): # pragma: no cover
if not self.is_fully_loaded:
self.full = True
self.refresh()
Expand Down Expand Up @@ -170,7 +170,7 @@ def history(self, first=0, last=0, limit=-1, only_ops=[], exclude_ops=[]):
):
cnt += 1
yield i
if limit >= 0 and cnt >= limit:
if limit >= 0 and cnt >= limit: # pragma: no cover
return

if not txs:
Expand All @@ -181,25 +181,25 @@ def history(self, first=0, last=0, limit=-1, only_ops=[], exclude_ops=[]):
break
first = int(txs[-1]["id"].split(".")[2])

def upgrade(self):
def upgrade(self): # pragma: no cover
""" Upgrade account to life time member
"""
assert callable(self.blockchain.upgrade_account)
return self.blockchain.upgrade_account(account=self)

def whitelist(self, account):
def whitelist(self, account): # pragma: no cover
""" Add an other account to the whitelist of this account
"""
assert callable(self.blockchain.account_whitelist)
return self.blockchain.account_whitelist(account, lists=["white"], account=self)

def blacklist(self, account):
def blacklist(self, account): # pragma: no cover
""" Add an other account to the blacklist of this account
"""
assert callable(self.blockchain.account_whitelist)
return self.blockchain.account_whitelist(account, lists=["black"], account=self)

def nolist(self, account):
def nolist(self, account): # pragma: no cover
""" Remove an other account from any list of this account
"""
assert callable(self.blockchain.account_whitelist)
Expand Down
4 changes: 4 additions & 0 deletions graphenecommon/genesisbalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def claim(self, account=None, **kwargs):
pubkeys = self.blockchain.wallet.getPublicKeys()
addresses = dict()
for p in pubkeys:
if p[: len(self.blockchain.prefix)] != self.blockchain.prefix:
continue
pubkey = self.publickey_class(p)
addresses[
str(
Expand Down Expand Up @@ -131,6 +133,8 @@ def __init__(self, **kwargs):
pubkeys = self.blockchain.wallet.getPublicKeys()
addresses = list()
for p in pubkeys:
if p[: len(self.blockchain.prefix)] != self.blockchain.prefix:
continue
pubkey = self.publickey_class(p)
addresses.append(
str(
Expand Down
2 changes: 1 addition & 1 deletion graphenestorage/masterpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def encrypt(self, wif):
raise WalletLocked
return format(bip38.encrypt(str(wif), self.masterkey), "encwif")

def changePassword(self, newpassword):
def changePassword(self, newpassword): # pragma: no cover
warnings.warn(
"changePassword will be replaced by change_password in the future",
PendingDeprecationWarning,
Expand Down
59 changes: 50 additions & 9 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import mock
import yaml
import json

# Graphene API
from grapheneapi import exceptions
Expand All @@ -24,7 +25,6 @@
)
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,
Expand All @@ -36,8 +36,14 @@
BitcoinAddress,
)
from graphenebase.objects import Operation, GrapheneObject
from graphenebase.operations import Newdemooepration, Newdemooepration2, Demooepration
from graphenebase.operationids import ops, operations, getOperationNameForId
from graphenebase.operations import (
Newdemooepration,
Newdemooepration2,
Demooepration,
Account_create,
)
from graphenebase import operations as operations_module
from graphenebase.operationids import ops, getOperationNameForId, operations

from graphenebase import bip38
from graphenebase.bip38 import encrypt, decrypt
Expand Down Expand Up @@ -78,6 +84,18 @@
from graphenecommon.witness import Witness as GWitness, Witnesses as GWitnesss
from graphenecommon.chain import AbstractGrapheneChain

objects_cache = dict()


def store_test_object(o):
global objects_cache
if o.get("id"):
objects_cache[o["id"]] = o


def get_object(id):
return objects_cache.get(id, {})


class SharedInstance(GSharedInstance):
pass
Expand Down Expand Up @@ -131,14 +149,23 @@ def _load(self, name):
d = yaml.safe_load(fid)
return d.get(name)

def get_objects(self, *args, **kwargs):
return []
def get_objects(self, ids, *args, **kwargs):
return [self.get_object(x) for x in ids]

def get_object(self, *args, **kwargs):
return {}
def get_object(self, id, *args, **kwargs):
return get_object(id)

def get_account_history(self, *args, **kwargs):
return []
with open(
os.path.join(
os.path.dirname(__file__), "vector_get_account_history.yaml"
)
) as fid:
history = yaml.safe_load(fid)
return history

def get_account_balances(self, account, *args, **kwargs):
return [{"asset_id": "1.3.0", "amount": 132442}]

def lookup_account_names(self, name, **kwargs):
return [None]
Expand All @@ -149,6 +176,12 @@ def get_all_workers(self):
def get_workers_by_account(self, name):
return [self._load("workers")[0]]

def get_dynamic_global_properties(self):
return {
"head_block_id": "021dcf4a9af758e508364f16e3ab5ac928b7f76c",
"head_block_number": 35508042,
}

def __getattr__(self, name):
def fun(self, *args, **kwargs):
return {}
Expand Down Expand Up @@ -184,7 +217,7 @@ class Account(GAccount):
def define_classes(self):
self.type_id = 2
self.amount_class = Amount
self.operations = operations
self.operations = operations_module


@BlockchainInstance.inject
Expand Down Expand Up @@ -265,24 +298,32 @@ def fixture_data():
with open(os.path.join(os.path.dirname(__file__), "fixtures.yaml")) as fid:
data = yaml.safe_load(fid)

for o in data.get("objects"):
store_test_object(o)

# Feed our objects into the caches!
for account in data.get("accounts"):
store_test_object(account)
Account._cache[account["id"]] = account
Account._cache[account["name"]] = account

for asset in data.get("assets"):
store_test_object(asset)
Asset._cache[asset["symbol"]] = asset
Asset._cache[asset["id"]] = asset

for committee in data.get("committees"):
store_test_object(committee)
Committee._cache[committee["id"]] = committee

for blocknum, block in data.get("blocks").items():
block["id"] = blocknum
Block._cache[str(blocknum)] = block

for worker in data.get("workers"):
store_test_object(worker)
Worker._cache[worker["id"]] = worker

for witness in data.get("witnesses"):
store_test_object(witness)
Witness._cache[witness["id"]] = witness
Loading

0 comments on commit 099d225

Please sign in to comment.