Ejemplo n.º 1
0
def test_payout_deposit(private_key_hex, db_path, monkeypatch_create_web3,
                        monkeypatch_get_contract_deployed_tx,
                        get_contract_deployed_tx, click_runner, dbsession,
                        web3, security_token, kyc_contract, test_token,
                        test_token_name):
    abi = get_abi(None)

    # deploy contract
    result = click_runner.invoke(cli, [
        '--database-file', db_path, '--ethereum-private-key', private_key_hex,
        '--ethereum-gas-price', 9999999, 'payout-deploy', '--token-address',
        security_token, '--payout-token-address', test_token,
        '--payout-token-name', test_token_name, '--kyc-address', kyc_contract,
        '--payout-name', 'Pay X', '--uri', 'http://tokenmarket.net', '--type',
        0, '--options', [
            "Vested for dividend",
        ]
    ])
    assert result.exit_code == 0

    test_token_contract = web3.eth.contract(address=test_token,
                                            abi=abi[test_token_name]['abi'])

    result = click_runner.invoke(cli, [
        '--database-file', db_path, '--ethereum-private-key', private_key_hex,
        '--ethereum-gas-price', 9999999, 'payout-approve',
        '--payout-token-name', test_token_name
    ])
    assert result.exit_code == 0
    payout_contract_address = get_contract_deployed_tx(
        dbsession, 'PayoutContract').contract_address
    payout_contract = web3.eth.contract(address=payout_contract_address,
                                        abi=abi['PayoutContract']['abi'])
    initial_balance = test_token_contract.call().balanceOf(
        payout_contract_address)
    result = click_runner.invoke(cli, [
        '--database-file', db_path, '--ethereum-private-key', private_key_hex,
        '--ethereum-gas-price', 9999999, 'payout-deposit'
    ])
    assert result.exit_code == 0
    assert test_token_contract.functions.balanceOf(
        payout_contract.address).call() > initial_balance
    # check if payouts happen
    initial_balance = test_token_contract.call().balanceOf(
        priv_key_to_address(private_key_hex))
    payout_contract.functions.act(123).transact(
        {"from": priv_key_to_address(private_key_hex)})
    # 0x0000000000000000000000000000000000000064 is the default address 100
    assert payout_contract.functions.balanceOf(
        '0x0000000000000000000000000000000000000064').call() == 123
    assert test_token_contract.call().balanceOf(
        priv_key_to_address(private_key_hex)) > initial_balance
Ejemplo n.º 2
0
def kyc_contract(
        click_runner,
        dbsession,
        db_path,
        private_key_hex,
        monkeypatch_get_contract_deployed_tx,
        monkeypatch_create_web3,
        get_contract_deployed_tx,
        customer_private_key
):
    result = click_runner.invoke(
        cli,
        [
            '--database-file', db_path,
            '--ethereum-private-key', private_key_hex,
            'kyc-deploy'
        ]
    )
    assert result.exit_code == 0
    tx = get_contract_deployed_tx(dbsession, 'BasicKYC')

    # whitelist customer
    result = click_runner.invoke(
        cli,
        [
            '--database-file', db_path,
            '--ethereum-private-key', private_key_hex,
            '--ethereum-gas-limit', 80000,
            'kyc-manage',
            '--whitelist-address', priv_key_to_address(private_key_hex)
        ]
    )
    assert result.exit_code == 0
    result = click_runner.invoke(
        cli,
        [
            '--database-file', db_path,
            '--ethereum-private-key', private_key_hex,
            '--ethereum-gas-limit', 80000,
            'kyc-manage',
            '--whitelist-address', priv_key_to_address(customer_private_key)
        ]
    )
    assert result.exit_code == 0
    return tx.contract_address
Ejemplo n.º 3
0
Archivo: main.py Proyecto: uivlis/sto
def payout_approve(
    config: BoardCommmadConfiguration,
    payout_token_address: str,
    payout_token_name: str,
):
    """
    approve tokens to the payout contract
    """
    from sto.ethereum.utils import (get_contract_deployed_tx, create_web3,
                                    get_abi, broadcast as _broadcast,
                                    priv_key_to_address)
    from sto.ethereum.txservice import EthereumStoredTXService
    from sto.models.implementation import BroadcastAccount, PreparedTransaction

    tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract')
    if not tx:
        raise Exception(
            'PayoutContract not found. Call payout-deploy to deploy PayoutContract'
        )
    if payout_token_name:
        tx = get_contract_deployed_tx(config.dbsession, payout_token_name)
        payout_token_address = tx.contract_address
    if payout_token_address is None:
        raise Exception('''
            Either payout token is not deployed or --payout-token-address not provided
            ''')
    tx = get_contract_deployed_tx(config.dbsession, 'PayoutContract')
    if not tx:
        raise Exception(
            'PayoutContract not found. Call payout-deploy to deploy PayoutContract'
        )
    payout_contract_address = tx.contract_address

    web3 = create_web3(config.ethereum_node_url)
    service = EthereumStoredTXService(config.network, config.dbsession, web3,
                                      config.ethereum_private_key,
                                      config.ethereum_gas_price,
                                      config.ethereum_gas_limit,
                                      BroadcastAccount, PreparedTransaction)
    abi = get_abi(config.ethereum_abi_file)
    payout_token_contract = web3.eth.contract(
        address=payout_token_address, abi=abi[payout_token_name]['abi'])
    service.interact_with_contract(
        payout_token_name,
        abi,
        payout_token_address,
        'approving tokens',
        'approve',
        args={
            '_spender':
            payout_contract_address,
            '_value':
            payout_token_contract.functions.balanceOf(
                priv_key_to_address(config.ethereum_private_key)).call()
        },
        use_bytecode=False)
    _broadcast(config)
Ejemplo n.º 4
0
def sample_token(logger, dbsession, web3, private_key_hex, sample_csv_file,
                 db_path, click_runner, get_contract_deployed_tx, kyc_contract,
                 monkeypatch_get_contract_deployed_tx, request):
    """Create a security token used in these tests."""
    if request.param == 'restricted':
        from sto.ethereum.utils import priv_key_to_address
        # whitelist owner
        result = click_runner.invoke(cli, [
            '--database-file', db_path, '--ethereum-private-key',
            private_key_hex, '--ethereum-gas-limit', 999999999, 'kyc-manage',
            '--whitelist-address',
            priv_key_to_address(private_key_hex)
        ])
        assert result.exit_code == 0

    result = click_runner.invoke(cli, [
        '--database-file', db_path, '--ethereum-private-key', private_key_hex,
        '--ethereum-gas-limit', 999999999, 'issue', '--name', "Moo Corp",
        '--symbol', "MOO", '--url', "https://tokenmarket.net", '--amount',
        9999, '--transfer-restriction', request.param
    ])

    assert result.exit_code == 0
    result = click_runner.invoke(cli, [
        '--database-file',
        db_path,
        '--ethereum-private-key',
        private_key_hex,
        '--ethereum-gas-limit',
        999999999,
        'tx-broadcast',
    ])
    assert result.exit_code == 0

    token_address = get_contract_deployed_tx(dbsession,
                                             "SecurityToken").contract_address

    # Check that we can view the token status
    status = contract_status(
        logger,
        dbsession,
        "testing",
        web3,
        ethereum_abi_file=None,
        ethereum_private_key=private_key_hex,
        ethereum_gas_limit=None,
        ethereum_gas_price=None,
        token_contract=token_address,
    )

    assert status["name"] == "Moo Corp"
    assert status["totalSupply"] == 9999 * 10**18
    dbsession.commit()

    return token_address
Ejemplo n.º 5
0
def test_token(deploy, dbsession, monkeypatch_get_contract_deployed_tx,
               get_contract_deployed_tx, test_token_name, web3,
               private_key_hex, execute_contract_function):
    args = {
        "_name": 'test_token',
        "_symbol": 'TEST',
        "_initialSupply":
        9999000000000000000000,  # make sure this is greater tan or equal security token supply
        "_decimals": 18,
        "_mintable": True
    }
    deploy(test_token_name, args)
    tx = get_contract_deployed_tx(dbsession, test_token_name)
    execute_contract_function(test_token_name, 'setReleaseAgent',
                              {'addr': priv_key_to_address(private_key_hex)})
    execute_contract_function(test_token_name, 'releaseTokenTransfer', {})
    return tx.contract_address