Skip to content

Commit

Permalink
add address "#" before each address value
Browse files Browse the repository at this point in the history
  • Loading branch information
billbsing committed May 24, 2021
1 parent ee2e61d commit a11a8e9
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Change log

### 0.1.4
+ Add address '#' ident before each address number.

### 0.1.3
+ Add transfer_account, the ability to change your account public key for a given account address
+ Remove eth-utils library dependency
Expand Down
16 changes: 8 additions & 8 deletions convex_api/convex_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def request_funds(self, amount, account):
"""
faucet_url = urljoin(self._url, '/api/v1/faucet')
faucet_data = {
'address': account.address,
'address': f'#{account.address}',
'amount': amount
}
logger.debug(f'request_funds {faucet_url} {faucet_data}')
Expand Down Expand Up @@ -497,9 +497,9 @@ def get_balance(self, address_account, account_from=None):
address_from = to_address(account_from)
else:
address_from = account_from.address
line = f'(balance {address})'
line = f'(balance #{address})'
if self._language == ConvexAPI.LANGUAGE_SCRYPT:
line = f'balance({address})'
line = f'balance(#{address})'
try:

result = self._transaction_query(address_from, line)
Expand Down Expand Up @@ -550,9 +550,9 @@ def transfer(self, to_address_account, amount, account):
if not to_address:
raise ValueError(f'You must provide a valid to account/address ({transfer_to_address}) to transfer funds too')

line = f'(transfer {transfer_to_address} {amount})'
line = f'(transfer #{transfer_to_address} {amount})'
if self._language == ConvexAPI.LANGUAGE_SCRYPT:
line = f'transfer({transfer_to_address}, {amount})'
line = f'transfer(#{transfer_to_address}, {amount})'

result = self.send(line, account)
if result and 'value' in result:
Expand Down Expand Up @@ -689,7 +689,7 @@ def _transaction_prepare(self, address, transaction, language=None, sequence_num
language = self._language
prepare_url = urljoin(self._url, '/api/v1/transaction/prepare')
data = {
'address': address,
'address': f'#{address}',
'lang': language,
'source': transaction,
}
Expand All @@ -713,7 +713,7 @@ def _transaction_submit(self, address, public_key, hash_data, signed_data):
"""
submit_url = urljoin(self._url, '/api/v1/transaction/submit')
data = {
'address': to_address(address),
'address': f'#{to_address(address)}',
'accountKey': public_key,
'hash': hash_data,
'sig': remove_0x_prefix(signed_data)
Expand All @@ -738,7 +738,7 @@ def _transaction_query(self, address, transaction, language=None):

prepare_url = urljoin(self._url, '/api/v1/query')
data = {
'address': address,
'address': f'#{address}',
'lang': language,
'source': transaction,
}
Expand Down
4 changes: 2 additions & 2 deletions convex_api/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ def clear(self):
self._address = None

def register(self, name, contract_address, account):
result = self._convex.send(f'(call {self.address} (register {{:name "{name}"}}))', account)
result = self._convex.send(f'(call #{self.address} (register {{:name "{name}"}}))', account)
logger.debug(f'register result: {result}')
if result and 'value' in result:
try:
result = self._convex.send(f'(call {self.address} (cns-update "{name}" {contract_address}))', account)
result = self._convex.send(f'(call #{self.address} (cns-update "{name}" {contract_address}))', account)
logger.debug(f'cns-update result: {result}')
if result and 'value' in result:
items = result['value']
Expand Down
6 changes: 4 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

PRIVATE_TEST_KEY = 0x973f69bcd654b264759170724e1e30ccd2e75fc46b7993fd24ce755f0a8c24d0
PUBLIC_KEY = '0x5288Fec4153b702430771DFAC8AeD0B21CAFca4344daE0d47B97F0bf532b3306'

PRIVATE_KEY_MNEMONIC = 'now win hundred protect enroll cram stone come inch ill method often common quiz balance hundred negative truck crime turkey vague ecology nation balcony'

PRIVATE_TEST_KEY_TEXT = """
-----BEGIN ENCRYPTED PRIVATE KEY-----
Expand All @@ -39,12 +39,14 @@ def test_account_info():
'private_bytes': to_bytes(PRIVATE_TEST_KEY),
'private_text': PRIVATE_TEST_KEY_TEXT,
'private_password': PRIVATE_TEST_KEY_PASSWORD,
'private_mnemonic': PRIVATE_KEY_MNEMONIC,
'public_key': PUBLIC_KEY
}

@pytest.fixture(scope='module')
def import_account(test_account_info):
return Account.import_from_bytes(test_account_info['private_bytes'])
account = Account.import_from_bytes(test_account_info['private_bytes'])
return account

@pytest.fixture(scope='module')
def test_account(convex, import_account):
Expand Down
14 changes: 7 additions & 7 deletions tests/intergration/test_basic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_account(convex_url, public_address):

def request_funds(convex_url, address):
faucet_data = {
'address': address,
'address': f'#{address}',
'amount': 10000000
}
print('faucet send', faucet_data)
Expand All @@ -64,7 +64,7 @@ def test_submit_transaction(convex_url):

# prepare
prepare_data = {
'address': address,
'address': f'#{address}',
'source': '(map inc [1 2 3])'
}
url = f'{convex_url}/api/v1/transaction/prepare'
Expand All @@ -82,7 +82,7 @@ def test_submit_transaction(convex_url):
signed_hash_bytes = private_key.sign(hash_data)
signed_hash = to_hex(signed_hash_bytes)
submit_data = {
'address': address,
'address': f'#{address}',
'accountKey': public_address,
'hash': result['hash'],
'sig': remove_0x_prefix(signed_hash)
Expand All @@ -103,9 +103,9 @@ def test_query_lisp(convex_url):
address = create_account(convex_url, public_address)
request_funds(convex_url, address)
query_data = {
'address': address,
'address': f'#{address}',
'lang': 'convex-lisp',
'source': f'(balance {address})'
'source': f'(balance #{address})'
}
url = f'{convex_url}/api/v1/query'
print('query send', query_data)
Expand All @@ -123,9 +123,9 @@ def test_query_scrypt(convex_url):
address = create_account(convex_url, public_address)
request_funds(convex_url, address)
query_data = {
'address': address,
'address': f'#{address}',
'lang': 'convex-scrypt',
'source': f'balance({address})'
'source': f'balance(#{address})'
}
url = f'{convex_url}/api/v1/query'
print('query send', query_data)
Expand Down
4 changes: 2 additions & 2 deletions tests/intergration/test_convex_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ def test_convex_api_call(convex_url):
call_get_result = convex.query('call storage_example get()', account)
assert(call_get_result['value'] == test_number)

call_get_result = convex.query(f'call {contract_address} get()', account)
call_get_result = convex.query(f'call #{contract_address} get()', account)
assert(call_get_result['value'] == test_number)

with pytest.raises(ConvexRequestError, match='400'):
call_set_result = convex.send(f'call {contract_address}.set({test_number})', account)
call_set_result = convex.send(f'call #{contract_address}.set({test_number})', account)

address = convex.get_address('storage_example', account)
assert(address == contract_address)
Expand Down
6 changes: 3 additions & 3 deletions tests/intergration/test_convex_break.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_convex_recursion(convex, test_account):
if next_index == chain_length:
next_index = 0
call_address = address_list[next_index]
result = convex.send(f'(call chain-{index} (set-chain-address {call_address}))', test_account)
result = convex.send(f'(call chain-{index} (set-chain-address #{call_address}))', test_account)
test_number = secrets.randbelow(1000)
if index == chain_length - 1:
with pytest.raises(ConvexAPIError, match='DEPTH'):
Expand Down Expand Up @@ -87,7 +87,7 @@ def test_schedule_transfer(convex, test_account, other_account):
contract_address = to_address(result['value'])
convex.transfer(contract_address, 800000, other_account)
convex.topup_account(test_account)
result = convex.send(f'(call {contract_address} (tx-delay {other_account.address} 1000))', test_account)
result = convex.send(f'(call #{contract_address} (tx-delay #{other_account.address} 1000))', test_account)
print(result)
result = convex.send(f'(call {contract_address} (show-schedule))', test_account)
result = convex.send(f'(call #{contract_address} (show-schedule))', test_account)
print(result)

0 comments on commit a11a8e9

Please sign in to comment.