Merge branch 'master' of gitlab.com:grassrootseconomics/cic-internal-integration into philip/management-integration-tests

This commit is contained in:
PhilipWafula 2021-05-19 20:46:01 +03:00
commit f39468d41f
Signed by untrusted user: mango-habanero
GPG Key ID: B00CE9034DA19FB7
18 changed files with 75 additions and 27 deletions

View File

@ -72,7 +72,9 @@ class CallbackFilter(SyncFilter):
#transfer_data['token_address'] = tx.inputs[0] #transfer_data['token_address'] = tx.inputs[0]
faucet_contract = tx.inputs[0] faucet_contract = tx.inputs[0]
o = Faucet.token(faucet_contract, sender_address=self.caller_address) c = Faucet(self.chain_spec)
o = c.token(faucet_contract, sender_address=self.caller_address)
r = conn.do(o) r = conn.do(o)
transfer_data['token_address'] = add_0x(c.parse_token(r)) transfer_data['token_address'] = add_0x(c.parse_token(r))

View File

@ -4,7 +4,7 @@ import sys
import logging import logging
# external imports # external imports
from chainlib.eth.erc20 import ERC20 from eth_erc20 import ERC20
# local imports # local imports
from cic_eth.api import Api from cic_eth.api import Api

View File

@ -14,9 +14,9 @@ from chainlib.eth.tx import (
Tx, Tx,
) )
from chainlib.eth.block import Block from chainlib.eth.block import Block
from chainlib.eth.erc20 import ERC20 from eth_erc20 import ERC20
from sarafu_faucet import MinterFaucet from sarafu_faucet import MinterFaucet
from eth_accounts_index import AccountRegistry from eth_accounts_index.registry import AccountRegistry
from potaahto.symbols import snake_and_camel from potaahto.symbols import snake_and_camel
from hexathon import add_0x from hexathon import add_0x
@ -26,7 +26,6 @@ from cic_eth.runnable.daemons.filters.callback import CallbackFilter
logg = logging.getLogger() logg = logging.getLogger()
@pytest.mark.skip()
def test_transfer_tx( def test_transfer_tx(
default_chain_spec, default_chain_spec,
init_database, init_database,
@ -66,7 +65,6 @@ def test_transfer_tx(
assert transfer_type == 'transfer' assert transfer_type == 'transfer'
@pytest.mark.skip()
def test_transfer_from_tx( def test_transfer_from_tx(
default_chain_spec, default_chain_spec,
init_database, init_database,

View File

@ -4,7 +4,7 @@ import logging
# external imports # external imports
import pytest import pytest
from chainlib.eth.nonce import RPCNonceOracle from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.erc20 import ERC20 from eth_erc20 import ERC20
from chainlib.eth.tx import receipt from chainlib.eth.tx import receipt
# local imports # local imports

View File

@ -9,7 +9,7 @@ import celery
from chainlib.connection import RPCConnection from chainlib.connection import RPCConnection
from chainlib.eth.nonce import RPCNonceOracle from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import receipt from chainlib.eth.tx import receipt
from eth_accounts_index import AccountRegistry from eth_accounts_index.registry import AccountRegistry
from hexathon import strip_0x from hexathon import strip_0x
from chainqueue.db.enum import StatusEnum from chainqueue.db.enum import StatusEnum
from chainqueue.db.models.otx import Otx from chainqueue.db.models.otx import Otx

View File

@ -4,7 +4,7 @@ import logging
# external imports # external imports
import pytest import pytest
import celery import celery
from chainlib.eth.erc20 import ERC20 from eth_erc20 import ERC20
from chainlib.eth.nonce import RPCNonceOracle from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import ( from chainlib.eth.tx import (
receipt, receipt,

View File

@ -3,7 +3,7 @@ from chainlib.eth.nonce import RPCNonceOracle
from chainlib.eth.tx import ( from chainlib.eth.tx import (
receipt, receipt,
) )
from eth_address_declarator import AddressDeclarator from eth_address_declarator import Declarator
from hexathon import add_0x from hexathon import add_0x
# local imports # local imports
@ -23,7 +23,7 @@ def test_translate(
nonce_oracle = RPCNonceOracle(contract_roles['CONTRACT_DEPLOYER'], eth_rpc) nonce_oracle = RPCNonceOracle(contract_roles['CONTRACT_DEPLOYER'], eth_rpc)
c = AddressDeclarator(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle) c = Declarator(default_chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
description = 'alice'.encode('utf-8').ljust(32, b'\x00').hex() description = 'alice'.encode('utf-8').ljust(32, b'\x00').hex()
(tx_hash_hex, o) = c.add_declaration(address_declarator, contract_roles['CONTRACT_DEPLOYER'], agent_roles['ALICE'], add_0x(description)) (tx_hash_hex, o) = c.add_declaration(address_declarator, contract_roles['CONTRACT_DEPLOYER'], agent_roles['ALICE'], add_0x(description))

View File

@ -8,7 +8,7 @@ from chainlib.eth.tx import (
count, count,
receipt, receipt,
) )
from chainlib.eth.erc20 import ERC20 from eth_erc20 import ERC20
from chainlib.eth.nonce import RPCNonceOracle from chainlib.eth.nonce import RPCNonceOracle
# local imports # local imports

View File

@ -9,3 +9,7 @@ class AlreadyInitializedError(Exception):
class PleaseCommitFirstError(Exception): class PleaseCommitFirstError(Exception):
"""Raised when there exists uncommitted changes in the code while trying to build out the package.""" """Raised when there exists uncommitted changes in the code while trying to build out the package."""
pass pass
class NotificationSendError(Exception):
"""Raised when a notification failed to due to some error as per the service responsible for dispatching the notification."""

View File

@ -0,0 +1,19 @@
# standard imports
from enum import IntEnum
class AfricasTalkingStatusCodes(IntEnum):
PROCESSED = 100
SENT = 101
QUEUED = 102
RISK_HOLD = 401
INVALID_SENDER_ID = 402
INVALID_PHONE_NUMBER = 403
UNSUPPORTED_NUMBER_TYPE = 404
INSUFFICIENT_BALANCE = 405
USER_IN_BLACKLIST = 406
COULD_NOT_ROUTE = 407
INTERNAL_SERVER_ERROR = 500
GATEWAY_ERROR = 501
REJECTED_BY_GATEWAY = 502

View File

@ -6,7 +6,8 @@ import celery
import africastalking import africastalking
# local imports # local imports
from cic_notify.error import NotInitializedError, AlreadyInitializedError from cic_notify.error import NotInitializedError, AlreadyInitializedError, NotificationSendError
from cic_notify.ext.enums import AfricasTalkingStatusCodes
logg = logging.getLogger() logg = logging.getLogger()
celery_app = celery.current_app celery_app = celery.current_app
@ -50,10 +51,27 @@ class AfricasTalkingNotifier:
if self.sender_id: if self.sender_id:
response = self.api_client.send(message=message, recipients=[recipient], sender_id=self.sender_id) response = self.api_client.send(message=message, recipients=[recipient], sender_id=self.sender_id)
logg.debug(f'Africastalking response sender-id {response}') logg.debug(f'Africastalking response sender-id {response}')
else: else:
response = self.api_client.send(message=message, recipients=[recipient]) response = self.api_client.send(message=message, recipients=[recipient])
logg.debug(f'africastalking response no-sender-id {response}') logg.debug(f'africastalking response no-sender-id {response}')
recipients = response.get('Recipients')
if len(recipients) != 1:
status = response.get('SMSMessageData').get('Message')
raise NotificationSendError(f'Unexpected number of recipients: {len(recipients)}. Status: {status}')
status_code = recipients[0].get('statusCode')
status = recipients[0].get('status')
if status_code not in [
AfricasTalkingStatusCodes.PROCESSED.value,
AfricasTalkingStatusCodes.SENT.value,
AfricasTalkingStatusCodes.QUEUED.value
]:
raise NotificationSendError(f'Sending notification failed due to: {status}')
@celery_app.task @celery_app.task
def send(message, recipient): def send(message, recipient):

View File

@ -9,7 +9,7 @@ import semver
logg = logging.getLogger() logg = logging.getLogger()
version = (0, 4, 0, 'alpha.4') version = (0, 4, 0, 'alpha.5')
version_object = semver.VersionInfo( version_object = semver.VersionInfo(
major=version[0], major=version[0],

View File

@ -102,7 +102,7 @@ class MetadataRequestsHandler(Metadata):
'digest': json.loads(data).get('digest'), 'digest': json.loads(data).get('digest'),
} }
} }
formatted_data = json.dumps(formatted_data).encode('utf-8') formatted_data = json.dumps(formatted_data)
result = make_request(method='PUT', url=self.url, data=formatted_data, headers=self.headers) result = make_request(method='PUT', url=self.url, data=formatted_data, headers=self.headers)
logg.info(f'signed metadata submission status: {result.status_code}.') logg.info(f'signed metadata submission status: {result.status_code}.')
metadata_http_error_handler(result=result) metadata_http_error_handler(result=result)
@ -116,8 +116,10 @@ class MetadataRequestsHandler(Metadata):
"""This function is responsible for querying the metadata server for data corresponding to a unique pointer.""" """This function is responsible for querying the metadata server for data corresponding to a unique pointer."""
result = make_request(method='GET', url=self.url) result = make_request(method='GET', url=self.url)
metadata_http_error_handler(result=result) metadata_http_error_handler(result=result)
response_data = result.content response_data = result.json()
data = json.loads(response_data.decode('utf-8')) data = json.loads(response_data)
if not isinstance(data, dict):
raise ValueError(f'Invalid data object: {data}.')
if result.status_code == 200 and self.cic_type == ':cic.person': if result.status_code == 200 and self.cic_type == ':cic.person':
person = Person() person = Person()
deserialized_person = person.deserialize(person_data=data) deserialized_person = person.deserialize(person_data=data)

View File

@ -1,12 +1,12 @@
sw: sw:
kenya: kenya:
initial_language_selection: |- initial_language_selection: |-
CON Welcome to Sarafu CON Karibu Sarafu Network
1. English 1. English
2. Kiswahili 2. Kiswahili
3. Help 3. Help
initial_pin_entry: |- initial_pin_entry: |-
CON Tafadhali weka PIN ili kudhibiti akaunti yako. CON Tafadhali weka pin mpya yenye nambari nne kwa akaunti yako
0. Nyuma 0. Nyuma
initial_pin_confirmation: |- initial_pin_confirmation: |-
CON Weka PIN yako tena CON Weka PIN yako tena
@ -21,12 +21,13 @@ sw:
CON Weka jinsia yako CON Weka jinsia yako
1. Mwanaume 1. Mwanaume
2. Mwanamke 2. Mwanamke
3. Nyngine
0. Nyuma 0. Nyuma
enter_location: |- enter_location: |-
CON Weka eneo lako CON Weka eneo lako
0. Nyuma 0. Nyuma
enter_products: |- enter_products: |-
CON Tafadhali weka bidhaa ama huduma unauza CON Weka bidhaa ama huduma unauza
0. Nyuma 0. Nyuma
start: |- start: |-
CON Salio %{account_balance} %{account_token_name} CON Salio %{account_balance} %{account_token_name}
@ -155,7 +156,7 @@ sw:
99. Ondoka 99. Ondoka
exit_insufficient_balance: |- exit_insufficient_balance: |-
CON Malipo ya %{amount} %{token_symbol} kwa %{recipient_information} halijakamilika kwa sababu salio lako haitoshi. CON Malipo ya %{amount} %{token_symbol} kwa %{recipient_information} halijakamilika kwa sababu salio lako haitoshi.
Akaunti yako ya Sarafu-Network ina salio ifuatayo: %{token_balance} Akaunti yako ya Sarafu ina salio ifuatayo: %{token_balance}
00. Nyuma 00. Nyuma
99. Ondoka 99. Ondoka
invalid_service_code: |- invalid_service_code: |-

View File

@ -171,6 +171,7 @@ if __name__ == '__main__':
logg.error('load error for {}: {}'.format(y, e)) logg.error('load error for {}: {}'.format(y, e))
continue continue
f.close() f.close()
logg.debug('deserializing {} {}'.format(filepath, o))
u = Person.deserialize(o) u = Person.deserialize(o)
new_address = register_eth(i, u) new_address = register_eth(i, u)

View File

@ -105,7 +105,7 @@ def genId(addr, typ):
def genDate(): def genDate():
ts = random.randint(ts_then, ts_now) ts = random.randint(ts_then, ts_now)
return datetime.datetime.fromtimestamp(ts).timestamp() return int(datetime.datetime.fromtimestamp(ts).timestamp())
def genPhone(): def genPhone():
@ -193,6 +193,7 @@ def prepareLocalFilePath(datadir, address):
if __name__ == '__main__': if __name__ == '__main__':
base_dir = os.path.join(user_dir, 'old') base_dir = os.path.join(user_dir, 'old')
ussd_dir = os.path.join(user_dir, 'ussd')
os.makedirs(base_dir, exist_ok=True) os.makedirs(base_dir, exist_ok=True)
fa = open(os.path.join(user_dir, 'balances.csv'), 'w') fa = open(os.path.join(user_dir, 'balances.csv'), 'w')
@ -223,6 +224,8 @@ if __name__ == '__main__':
f = open('{}/{}'.format(d, uid + '.json'), 'w') f = open('{}/{}'.format(d, uid + '.json'), 'w')
json.dump(o.serialize(), f) json.dump(o.serialize(), f)
f.close() f.close()
d = prepareLocalFilePath(ussd_dir, uid)
x = open('{}/{}'.format(d, uid + '_ussd_data.json'), 'w') x = open('{}/{}'.format(d, uid + '_ussd_data.json'), 'w')
json.dump(ussd_data, x) json.dump(ussd_data, x)
x.close() x.close()

View File

@ -23,7 +23,7 @@ from chainlib.eth.connection import EthHTTPConnection
from chainlib.eth.gas import RPCGasOracle from chainlib.eth.gas import RPCGasOracle
from chainlib.eth.nonce import RPCNonceOracle from chainlib.eth.nonce import RPCNonceOracle
from cic_types.processor import generate_metadata_pointer from cic_types.processor import generate_metadata_pointer
from eth_accounts_index import AccountRegistry from eth_accounts_index.registry import AccountRegistry
from eth_contract_registry import Registry from eth_contract_registry import Registry
from crypto_dev_signer.keystore.dict import DictKeystore from crypto_dev_signer.keystore.dict import DictKeystore
from crypto_dev_signer.eth.signer.defaultsigner import ReferenceSigner as EIP155Signer from crypto_dev_signer.eth.signer.defaultsigner import ReferenceSigner as EIP155Signer

View File

@ -446,9 +446,9 @@ services:
PGPASSWORD: ${DATABASE_PASSWORD:-tralala} PGPASSWORD: ${DATABASE_PASSWORD:-tralala}
CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis} CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
CELERY_RESULT_URL: ${CELERY_BROKER_URL:-redis://redis} CELERY_RESULT_URL: ${CELERY_BROKER_URL:-redis://redis}
TASKS_AFRICASTALKING: $TASKS_AFRICASTALKING AFRICASTALKING_API_USERNAME: $AFRICASTALKING_API_USERNAME
TASKS_SMS_DB: $TASKS_SMS_DB AFRICASTALKING_API_KEY: $AFRICASTALKING_API_KEY
TASKS_LOG: $TASKS_LOG AFRICASTALKING_API_SENDER_ID: $AFRICASTALKING_API_SENDER_ID
depends_on: depends_on:
- postgres - postgres
- redis - redis