def test_key_pair_is_equal(test_key_pair):
    key_pair = KeyPair()
    assert (test_key_pair.is_equal(test_key_pair))
    assert (test_key_pair.is_equal(test_key_pair.public_key_api))
    assert (test_key_pair.is_equal(test_key_pair.public_key))
    assert (not key_pair.is_equal(test_key_pair.public_key_checksum))
    assert (not key_pair.is_equal(test_key_pair))
    with pytest.raises(TypeError):
        assert (not key_pair.is_equal(test_key_pair.public_key_bytes))
Exemple #2
0
def process_convex_depoly(convex, result_value):
    deploy_storage = """
(def storage-example
    (deploy
        '(do
            (def stored-data nil)
            (defn get [] stored-data)
            (defn set [x] (def stored-data x))
            (export get set)
        )
    )
)
"""
    key_pair = KeyPair()
    account = convex.create_account(key_pair)
    for index in range(0, 10):
        convex.topup_account(account)
        try:
            result = convex.send(deploy_storage, account)
        except ConvexAPIError as e:
            balance = convex.get_balance(account)
            print('*' * 132)
            print('failed send', e, balance)
            print('*' * 132)
            result_value.value = balance
            return
        assert (result)
        assert (result['value'])
        contract_address = to_address(result['value'])
        assert (contract_address)
    result_value.value = 1
def test_convex_api_call(convex_url):

    deploy_storage = """
(def storage-example
    (deploy
        '(do
            (def stored-data nil)
            (defn get [] stored-data)
            (defn set [x] (def stored-data x))
            (export get set)
        )
    )
)
"""
    convex = API(convex_url)
    key_pair = KeyPair()
    account = convex.create_account(key_pair)
    amount = TEST_FUNDING_AMOUNT
    request_amount = convex.request_funds(amount, account)
    result = convex.send(deploy_storage, account)
    assert(result['value'])
    contract_address = to_address(result['value'])
    test_number = secrets.randbelow(1000)
    call_set_result = convex.send(f'(call storage-example(set {test_number}))', account)
    assert(call_set_result['value'] == test_number)
    call_get_result = convex.query('(call storage-example(get))', account)
    assert(call_get_result['value'] == test_number)

    # now api calls using language scrypt
    """
def test_key_pair_export_to_mnemonic(test_key_pair):
    words = test_key_pair.export_to_mnemonic
    assert (words)
    new_key_pair = KeyPair.import_from_mnemonic(words)
    assert (new_key_pair)
    assert (test_key_pair.public_key == new_key_pair.public_key)
    assert (
        test_key_pair.export_to_mnemonic == new_key_pair.export_to_mnemonic)
def test_convex_api_get_balance_small_funds(convex_url, test_account):
    convex = API(convex_url)
    key_pair = KeyPair()
    account = convex.create_account(key_pair)
    amount = 100
    request_amount = convex.request_funds(amount, account)
    new_balance = convex.get_balance(account)
    assert(new_balance == amount)
def test_convex_api_get_balance_new_account(convex_url):
    convex = API(convex_url)
    key_pair = KeyPair()
    account = convex.create_account(key_pair)
    amount = TEST_FUNDING_AMOUNT
    request_amount = convex.request_funds(amount, account)
    assert(request_amount == amount)
    new_balance = convex.get_balance(account)
    assert(new_balance == TEST_FUNDING_AMOUNT)
def test_convex_api_topup_account(convex_url):
    convex = API(convex_url)
    key_pair = KeyPair()
    account = convex.create_account(key_pair)
    topup_amount = TEST_FUNDING_AMOUNT
    amount = convex.topup_account(account, topup_amount)
    assert(amount >= topup_amount)

    account = convex.create_account(key_pair)
    amount = convex.topup_account(account)
    assert(amount >= 0)
def test_key_pair_import_export_to_file(test_key_pair):
    filename = '/tmp/private_key.pem'
    password = '******'
    if os.path.exists(filename):
        os.remove(filename)

    text = test_key_pair.export_to_file(filename, password)
    assert (os.path.exists(filename))
    import_key_pair = KeyPair.import_from_file(filename, password)
    assert (import_key_pair)
    assert (import_key_pair.public_key == test_key_pair.public_key)
    os.remove(filename)
def test_convex_api_transfer(convex_url):
    convex = API(convex_url)
    key_pair = KeyPair()
    account_from = convex.create_account(key_pair)
    account_to = convex.create_account(key_pair)
    amount = TEST_FUNDING_AMOUNT
    request_amount = convex.request_funds(amount, account_from)
    assert(request_amount == amount)

    transfer_amount = int(amount / 2)
    result = convex.transfer(account_to, transfer_amount, account_from)
    assert(result)
    assert(result == transfer_amount)
    balance_from = convex.get_balance(account_from)
    balance_to = convex.get_balance(account_to)
    assert(balance_to == transfer_amount)
Exemple #10
0
def test_convex_get_account_info(convex_url, test_account):
    convex = API(convex_url)
    info = convex.get_account_info(test_account)
    assert(info)
    assert(info['type']== 'user')
    assert(info['balance'] > 0)
    assert(info['sequence'] >= 0)

    with pytest.raises(ConvexRequestError, match='INCORRECT'):
        info = convex.get_account_info(pow(2, 100))

    with pytest.raises(ConvexRequestError, match='INCORRECT'):
        info = convex.get_account_info(pow(2, 1024))

    key_pair = KeyPair()
    account = convex.create_account(key_pair)
    request_amount = convex.request_funds(TEST_FUNDING_AMOUNT, account)
    info = convex.get_account_info(account)
    assert(info)
    assert(info['balance'] == TEST_FUNDING_AMOUNT)
Exemple #11
0
def test_convex_transfer_account(convex_url, test_account):
    convex = API(convex_url)

    # create a new account with a random keys
    key_pair = KeyPair()
    account_1 = convex.create_account(key_pair)
    convex.topup_account(account_1)
    result = convex.send('(map inc [1 2 3 4 5])', account_1)
    assert 'value' in result
    assert(result['value'] == [2, 3, 4, 5, 6])

    # transfer the new account_1 to use the same keys as the test_account
    account_1_change = convex.transfer_account(test_account, account_1)
    assert(account_1_change)
    # public key should be the same as the test_account
    assert(account_1_change.key_pair.is_equal(test_account.key_pair))
    # adress still the same
    assert(account_1_change.address == account_1.address )

    # test out new key
    result = convex.send('(map inc [1 2 3 4 5])', account_1_change)
    assert 'value' in result
    assert(result['value'] == [2, 3, 4, 5, 6])
Exemple #12
0
def test_account_create_new():
    key_pair = KeyPair()
    account = Account(key_pair, 99)
    assert (account)
    assert (account.public_key)
def test_key_pair_address_bytes(test_key_pair_info):
    key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
    assert (key_pair)
    assert (key_pair.public_key_bytes == to_bytes(
        hexstr=test_key_pair_info['public_key']))
def test_key_pair_address_api(test_key_pair_info):
    key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
    assert (key_pair)
    assert (key_pair.public_key_api == remove_0x_prefix(
        test_key_pair_info['public_key']))
def test_key_pair_address_checksum(test_key_pair_info):
    key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
    assert (key_pair)
    assert (key_pair.public_key_checksum == test_key_pair_info['public_key'])
Exemple #16
0
def test_convex_api_get_balance_no_funds(convex_url):
    convex = API(convex_url)
    key_pair = KeyPair()
    account = convex.create_account(key_pair)
    new_balance = convex.get_balance(account)
    assert(new_balance == 0)
def process_convex_account_creation(convex, result_value):
    key_pair = KeyPair()
    account = convex.create_account(key_pair)
    assert(account)
    assert(account.address)
    result_value.value = 1
Exemple #18
0
def other_account(convex):
    key_pair = KeyPair()
    account = convex.create_account(key_pair)
    convex.topup_account(account)
    return account
def test_key_pair_create_from_bytes(test_key_pair_info):
    key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
    assert (key_pair)
    assert (key_pair.public_key == test_key_pair_info['public_key'].lower())
def test_key_pair_sign(test_key_pair_info):
    hash_text = SIGN_HASH_TEXT
    key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
    sign_data = key_pair.sign(hash_text)
    assert (sign_data == SIGN_TEXT)
def test_key_pair_import_export_to_text(test_key_pair):
    password = '******'
    text = test_key_pair.export_to_text(password)
    import_key_pair = KeyPair.import_from_text(text, password)
    assert (import_key_pair)
    assert (import_key_pair.public_key == test_key_pair.public_key)
Exemple #22
0
def test_key_pair(test_key_pair_info):
    key_pair = KeyPair.import_from_bytes(test_key_pair_info['private_bytes'])
    return key_pair
def test_key_pair_create_new():
    key_pair = KeyPair()
    assert (key_pair)
    assert (key_pair.public_key)