diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a9ef46..c13aa97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/convex_api/convex_api.py b/convex_api/convex_api.py index 73ba8f2..bf6bef3 100644 --- a/convex_api/convex_api.py +++ b/convex_api/convex_api.py @@ -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}') @@ -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) @@ -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: @@ -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, } @@ -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) @@ -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, } diff --git a/convex_api/registry.py b/convex_api/registry.py index c9a8ccb..8b1aa8d 100644 --- a/convex_api/registry.py +++ b/convex_api/registry.py @@ -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'] diff --git a/tests/conftest.py b/tests/conftest.py index f1e32c9..17119dd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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----- @@ -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): diff --git a/tests/intergration/test_basic_api.py b/tests/intergration/test_basic_api.py index 1d86c58..171ea8e 100644 --- a/tests/intergration/test_basic_api.py +++ b/tests/intergration/test_basic_api.py @@ -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) @@ -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' @@ -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) @@ -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) @@ -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) diff --git a/tests/intergration/test_convex_api.py b/tests/intergration/test_convex_api.py index e38b847..2f15c10 100644 --- a/tests/intergration/test_convex_api.py +++ b/tests/intergration/test_convex_api.py @@ -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) diff --git a/tests/intergration/test_convex_break.py b/tests/intergration/test_convex_break.py index 6be46b5..412413e 100644 --- a/tests/intergration/test_convex_break.py +++ b/tests/intergration/test_convex_break.py @@ -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'): @@ -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)