Skip to content

Commit 0d665fd

Browse files
committed
upgrade to remove export, and add address symbol
1 parent 193c0ab commit 0d665fd

File tree

8 files changed

+96
-41
lines changed

8 files changed

+96
-41
lines changed

convex_api/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def request_funds(self, amount, account):
350350
"""
351351
faucet_url = urljoin(self._url, '/api/v1/faucet')
352352
faucet_data = {
353-
'address': f'#{account.address}',
353+
'address': account.address,
354354
'amount': amount
355355
}
356356
logger.debug(f'request_funds {faucet_url} {faucet_data}')
@@ -689,7 +689,7 @@ def _transaction_prepare(self, transaction, address, language=None, sequence_num
689689
language = self._language
690690
prepare_url = urljoin(self._url, '/api/v1/transaction/prepare')
691691
data = {
692-
'address': f'#{address}',
692+
'address': to_address(address),
693693
'lang': language,
694694
'source': transaction,
695695
}
@@ -711,7 +711,7 @@ def _transaction_submit(self, address, public_key, hash_data, signed_data):
711711
"""
712712
submit_url = urljoin(self._url, '/api/v1/transaction/submit')
713713
data = {
714-
'address': f'#{to_address(address)}',
714+
'address': to_address(address),
715715
'accountKey': public_key,
716716
'hash': hash_data,
717717
'sig': remove_0x_prefix(signed_data)
@@ -732,7 +732,7 @@ def _transaction_query(self, address, transaction, language=None):
732732

733733
query_url = urljoin(self._url, '/api/v1/query')
734734
query_data = {
735-
'address': f'#{address}',
735+
'address': address,
736736
'lang': language,
737737
'source': transaction,
738738
}

convex_api/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def clear(self):
3838
self._address = None
3939

4040
def register(self, name, contract_address, account):
41-
result = self._convex.send(f'(call #{self.address} (register {{:name "{name}"}}))', account)
41+
result = self._convex.send(f'(call #{self.address} (register {{:name (symbol "{name}")}}))', account)
4242
logger.debug(f'register result: {result}')
4343
if result and 'value' in result:
4444
try:
45-
result = self._convex.send(f'(call #{self.address} (cns-update "{name}" {contract_address}))', account)
45+
result = self._convex.send(f'(call #{self.address} (cns-update (symbol "{name}") #{contract_address}))', account)
4646
logger.debug(f'cns-update result: {result}')
4747
if result and 'value' in result:
4848
items = result['value']

tests/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import logging
88
import pytest
9+
import secrets
910

1011
from convex_api.account import Account
1112
from convex_api.api import API
@@ -51,7 +52,8 @@ def test_key_pair(test_key_pair_info):
5152

5253
@pytest.fixture(scope='module')
5354
def test_account(convex, test_key_pair):
54-
account = convex.setup_account(TEST_ACCOUNT_NAME, test_key_pair)
55+
test_account_name = f'{TEST_ACCOUNT_NAME}.{secrets.token_hex(8)}'
56+
account = convex.setup_account(test_account_name, test_key_pair)
5557
convex.topup_account(account)
5658
return account
5759

tests/intergration/test_account_api.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
44
"""
55

6+
import pytest
7+
import secrets
8+
69
from convex_api import (
710
Account,
811
API,
@@ -11,6 +14,10 @@
1114

1215
TEST_ACCOUNT_NAME = 'test.convex-api'
1316

17+
@pytest.fixture
18+
def account_name():
19+
return f'{TEST_ACCOUNT_NAME}-{secrets.token_hex(8)}'
20+
1421
def test_account_api_create_account(convex_url):
1522

1623
convex = API(convex_url)
@@ -33,26 +40,26 @@ def test_account_api_multi_create_account(convex_url):
3340
assert(account_1.address != account_2.address)
3441

3542

36-
def test_account_name(convex_url, test_key_pair_info):
43+
def test_account_name(convex_url, test_key_pair_info, account_name):
3744
convex = API(convex_url)
3845
import_key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
39-
if convex.resolve_account_name(TEST_ACCOUNT_NAME):
40-
account = convex.load_account(TEST_ACCOUNT_NAME, import_key_pair)
46+
if convex.resolve_account_name(account_name):
47+
account = convex.load_account(account_name, import_key_pair)
4148
else:
4249
account = convex.create_account(import_key_pair)
4350
convex.topup_account(account)
44-
account = convex.register_account_name(TEST_ACCOUNT_NAME, account)
51+
account = convex.register_account_name(account_name, account)
4552
assert(account.address)
4653
assert(account.name)
47-
assert(account.name == TEST_ACCOUNT_NAME)
48-
assert(convex.resolve_account_name(TEST_ACCOUNT_NAME) == account.address)
54+
assert(account.name == account_name)
55+
assert(convex.resolve_account_name(account_name) == account.address)
4956

5057

51-
def test_account_setup_account(convex_url, test_key_pair_info):
58+
def test_account_setup_account(convex_url, test_key_pair_info, account_name):
5259
convex = API(convex_url)
5360
import_key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
54-
account = convex.setup_account(TEST_ACCOUNT_NAME, import_key_pair)
61+
account = convex.setup_account(account_name, import_key_pair)
5562
assert(account.address)
5663
assert(account.name)
57-
assert(account.name == TEST_ACCOUNT_NAME)
58-
assert(convex.resolve_account_name(TEST_ACCOUNT_NAME) == account.address)
64+
assert(account.name == account_name)
65+
assert(convex.resolve_account_name(account_name) == account.address)

tests/intergration/test_api.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_convex_account_name_registry(convex_url, test_account, test_key_pair):
9999

100100
def test_convex_resolve_name(convex_url):
101101
convex = API(convex_url)
102-
address = convex.resolve_name('convex.nft-tokens')
102+
address = convex.resolve_name('convex.trust')
103103
assert(address)
104104

105105

@@ -175,10 +175,20 @@ def test_convex_api_call(convex_url):
175175
(def storage-example
176176
(deploy
177177
'(do
178-
(def stored-data nil)
179-
(defn get [] stored-data)
180-
(defn set [x] (def stored-data x))
181-
(export get set)
178+
(def stored-data
179+
^{:private? true}
180+
nil
181+
)
182+
(defn get
183+
^{:callable? true}
184+
[]
185+
stored-data
186+
)
187+
(defn set
188+
^{:callable? true}
189+
[x]
190+
( def stored-data x)
191+
)
182192
)
183193
)
184194
)
@@ -207,11 +217,11 @@ def test_convex_api_call(convex_url):
207217
call_get_result = convex.query('call storage_example get()', account)
208218
assert(call_get_result['value'] == test_number)
209219
210-
call_get_result = convex.query(f'call #{contract_address} get()', account)
220+
call_get_result = convex.query(f'call {contract_address} get()', account)
211221
assert(call_get_result['value'] == test_number)
212222
213223
with pytest.raises(ConvexRequestError, match='400'):
214-
call_set_result = convex.send(f'call #{contract_address}.set({test_number})', account)
224+
call_set_result = convex.send(f'call {contract_address}.set({test_number})', account)
215225
216226
address = convex.get_address('storage_example', account)
217227
assert(address == contract_address)

tests/intergration/test_convex_break.py

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,29 @@ def test_convex_recursion(convex, test_account):
2525
(def chain-{index}
2626
(deploy
2727
'(do
28-
(def stored-data nil)
29-
(def chain-address nil)
30-
(defn get [] (call chain-address (get)))
31-
(defn set [x] (if chain-address (call chain-address(set x)) (def stored-data x)) )
32-
(defn set-chain-address [x] (def chain-address x))
33-
(export get set set-chain-address)
28+
(def stored-data
29+
^{{:private? true}}
30+
nil
31+
)
32+
(def chain-address
33+
^{{:private? true}}
34+
nil
35+
)
36+
(defn get
37+
^{{:callable? true}}
38+
[]
39+
(call chain-address (get))
40+
)
41+
(defn set
42+
^{{:callable? true}}
43+
[x]
44+
( if chain-address (call chain-address(set x)) (def stored-data x))
45+
)
46+
(defn set-chain-address
47+
^{{:callable? true}}
48+
[x]
49+
(def chain-address x)
50+
)
3451
)
3552
)
3653
)
@@ -62,19 +79,28 @@ def test_schedule_transfer(convex, test_account, other_account):
6279
(def transfer-for-ever
6380
(deploy
6481
'(do
65-
(defn tx-delay [to-address amount]
82+
(defn tx-delay
83+
^{:callable? true}
84+
[to-address amount]
6685
(transfer to-address amount)
6786
(def call-address *address*)
6887
(schedule (+ *timestamp* 1000) (call call-address (tx-delay to-address amount)))
6988
)
70-
(defn tx-now [to-address amount]
89+
(defn tx-now
90+
^{:callable? true}
91+
[to-address amount]
7192
(transfer to-address amount)
7293
)
73-
(defn show-schedule []
94+
(defn show-schedule
95+
^{:callable? true}
96+
[]
7497
[(get *state* :schedule) *address*]
7598
)
76-
(defn receive-coin [sender amount data] (accept amount))
77-
(export show-schedule tx-delay tx-now, receive-coin)
99+
(defn receive-coin
100+
^{:callable? true}
101+
[sender amount data]
102+
(accept amount)
103+
)
78104
)
79105
)
80106
)

tests/intergration/test_convex_multi_thread.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,20 @@ def process_convex_depoly(convex, result_value):
8585
(def storage-example
8686
(deploy
8787
'(do
88-
(def stored-data nil)
89-
(defn get [] stored-data)
90-
(defn set [x] (def stored-data x))
91-
(export get set)
88+
(def stored-data
89+
^{:private? true}
90+
nil
91+
)
92+
(defn get
93+
^{:callable? true}
94+
[]
95+
stored-data
96+
)
97+
(defn set
98+
^{:callable? true}
99+
[x]
100+
(def stored-data x)
101+
)
92102
)
93103
)
94104
)

tests/intergration/tool/test_account_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def test_account_info_command(convex_url, test_account):
6868
output = Output()
6969
command.execute(args, output)
7070
assert(output.values['balance'])
71-
assert(output.values['memorySize'])
71+
assert(output.values['address'])
7272
assert(output.values['sequence'])
7373
assert(output.values['type'])
7474

@@ -80,7 +80,7 @@ def test_account_info_command(convex_url, test_account):
8080
output = Output()
8181
command.execute(args, output)
8282
assert(output.values['balance'])
83-
assert(output.values['memorySize'])
83+
assert(output.values['address'])
8484
assert(output.values['sequence'])
8585
assert(output.values['type'])
8686

0 commit comments

Comments
 (0)