Exemplo n.º 1
0
def test_lib_init():
    web3 = init_web3(ENDPOINT)
    wallet = Web3Wallet(ETH_PRIVATE_KEY, web3)
    skale = Skale(ENDPOINT, TEST_ABI_FILEPATH, wallet)

    lib_contracts_info = skale._Skale__contracts_info
    for contract_info in CONTRACTS_INFO:
        assert isinstance(lib_contracts_info[contract_info.name], ContractInfo)

    lib_contracts = skale._Skale__contracts
    assert len(lib_contracts) == len(CONTRACTS_INFO)

    for lib_contract in lib_contracts.values():
        assert issubclass(type(lib_contract), BaseContract)
        assert lib_contract.address is not None
        assert int(lib_contract.address, 16) != 0
        assert web3.eth.getCode(lib_contract.address)
        assert lib_contract.abi is not None

    assert skale.abi is not None

    provider = skale.web3.provider
    assert isinstance(provider, WebsocketProvider)

    http_endpoint = 'http://localhost:8080'
    with mock.patch.object(Skale, '_Skale__init_contracts'):
        skale = Skale(http_endpoint, TEST_ABI_FILEPATH, wallet)
        provider = skale.web3.provider
        assert isinstance(provider, HTTPProvider)

    file_endpoint = 'file://local_file:1001'
    with pytest.raises(Exception):
        Skale(file_endpoint, TEST_ABI_FILEPATH, wallet)
Exemplo n.º 2
0
def init_skale(endpoint, wallet=None, spin=True):
    """Init read-only instance of SKALE library"""
    if not spin:
        return Skale(endpoint, SKALE_VAL_ABI_FILE, wallet)
    with yaspin(text="Loading", color=SPIN_COLOR) as sp:
        sp.text = 'Connecting to SKALE Manager contracts'
        skale = Skale(endpoint, SKALE_VAL_ABI_FILE, wallet)
        return skale
def create_nodes():
    skale = Skale(ENDPOINT, ABI_FILEPATH, wallet)
    print(f'Creating {amount} nodes...')
    for i in range(int(amount)):
        print(LONG_LINE)
        print(f'Creating {i+1}/{amount} node...')
        create_node(skale, wallet)
Exemplo n.º 4
0
def init_skale(node_id=None):
    if node_id is None:
        wallet = RPCWallet(os.environ['TM_URL']) if ENV != 'DEV' else None
    else:
        ETH_PRIVATE_KEY = os.environ['ETH_PRIVATE_KEY']
        web3 = init_web3(ENDPOINT)
        wallet = Web3Wallet(ETH_PRIVATE_KEY, web3)
    return Skale(ENDPOINT, ABI_FILEPATH, wallet)
Exemplo n.º 5
0
def create(ctx, amount, save_to, skale_amount, eth_amount):
    """ Command that creates new accounts with schains """
    skale = ctx.obj['skale']
    for i in range(amount):
        wallet, private_key = create_account(skale, skale_amount, eth_amount)
        skale_acc = Skale(skale._endpoint, skale._abi_filepath, wallet)
        schain_info = create_schain(skale_acc)
        save_info(i, schain_info, wallet, private_key, save_to)
        logger.info(LONG_LINE)
    show_all_schain_ids(skale)
Exemplo n.º 6
0
def get_node_data():
    skale = Skale(ENDPOINT, TEST_ABI_FILEPATH)
    for _ in range(0, 30):
        skale.nodes_data.get_by_name(DEFAULT_NODE_NAME)
Exemplo n.º 7
0
import threading
import os
from skale import Skale
from skale.wallets import RPCWallet
from config import ENDPOINT, ABI_FILEPATH
from utils import generate_random_node_data
from skale.utils.web3_utils import wait_receipt

TM_URL = os.environ['TM_URL']

wallet = RPCWallet(TM_URL)
skale = Skale(ENDPOINT, ABI_FILEPATH, wallet)

print('Address: ', wallet.address)


def main():
    monitors = []
    for _ in range(0, 5):
        monitor = threading.Thread(target=create_nodes, daemon=True)
        monitor.start()
        monitors.append(monitor)
    for monitor in monitors:
        monitor.join()


def create_nodes():
    for _ in range(0, 100):
        create_node()

Exemplo n.º 8
0
def main(ctx, endpoint, abi_filepath):
    ctx.ensure_object(dict)
    wallet = init_wallet(endpoint)
    ctx.obj['skale'] = Skale(endpoint, abi_filepath, wallet)
Exemplo n.º 9
0
def skale():
    web3 = init_web3(ENDPOINT)
    wallet = Web3Wallet(ETH_PRIVATE_KEY, web3)
    return Skale(ENDPOINT, TEST_ABI_FILEPATH, wallet)
Exemplo n.º 10
0
def skale():
    '''Returns a SKALE instance with provider from config'''
    web3 = init_web3(ENDPOINT)
    wallet = Web3Wallet(ETH_PRIVATE_KEY, web3)
    return Skale(ENDPOINT, TEST_ABI_FILEPATH, wallet)