def issue(config: BoardCommmadConfiguration, symbol, name, amount, transfer_restriction): """Issue out a new security token.""" logger = config.logger assert is_ethereum_network(config.network) # Nothing else implemented yet from sto.ethereum.issuance import deploy_token_contracts from sto.ethereum.txservice import EthereumStoredTXService dbsession = config.dbsession txs = deploy_token_contracts( logger, dbsession, config.network, ethereum_node_url=config.ethereum_node_url, ethereum_abi_file=config.ethereum_abi_file, ethereum_private_key=config.ethereum_private_key, ethereum_gas_limit=config.ethereum_gas_limit, ethereum_gas_price=config.ethereum_gas_price, name=name, symbol=symbol, amount=amount, transfer_restriction=transfer_restriction) EthereumStoredTXService.print_transactions(txs) # Write database dbsession.commit() logger.info("Run %ssto tx-broadcast%s to write this to blockchain", colorama.Fore.LIGHTCYAN_EX, colorama.Fore.RESET)
def test_issuance(logger, dbsession, web3, private_key_hex): """Walk through issuance process from top to bottom""" # Creating transactions txs = deploy_token_contracts(logger, dbsession, "testing", web3, ethereum_abi_file=None, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, name="Moo Corp", symbol="MOO", amount=9999, transfer_restriction="unrestricted") assert len(txs) == 5 # Send transactions to emphmereal test chain txs = broadcast(logger, dbsession, "testing", web3, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, ) assert len(txs) == 5 # Check they got mined txs = update_status(logger, dbsession, "testing", web3, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, ) assert len(txs) == 5 for tx in txs: # type: PreparedTransaction assert tx.result_transaction_success token_address = txs[0].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
def sample_token(logger, dbsession, web3, private_key_hex, sample_csv_file): """Create a security token used in these tests.""" # Creating transactions txs = deploy_token_contracts( logger, dbsession, "testing", web3, ethereum_abi_file=None, ethereum_private_key=private_key_hex, ethereum_gas_limit=9999999, ethereum_gas_price=None, name="Moo Corp", symbol="MOO", url="https://tokenmarket.net", amount=9999, transfer_restriction="unrestricted" ) token_address = txs[0].contract_address # Deploy contract transactions to emphmereal test chain broadcast(logger, dbsession, "testing", web3, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, ) # 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 return token_address
def test_distribute(logger, dbsession, web3, private_key_hex, sample_csv_file): """Distribute tokens.""" # Creating transactions txs = deploy_token_contracts( logger, dbsession, "testing", web3, ethereum_abi_file=None, ethereum_private_key=private_key_hex, ethereum_gas_limit=99999999, ethereum_gas_price=None, name="Moo Corp", symbol="MOO", url="https://tokenmarket.net", amount=9999, transfer_restriction="unrestricted" ) token_address = txs[0].contract_address # Deploy contract transactions to emphmereal test chain broadcast( logger, dbsession, "testing", web3, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, ) # 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 entries = read_csv(logger, sample_csv_file) new_distributes, old_distributes = distribute_tokens( logger, dbsession, "testing", web3, ethereum_abi_file=None, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, token_address=token_address, dists=entries ) assert new_distributes == 2 assert old_distributes == 0 # Check they got mined # Send transactions to emphmereal test chain txs = broadcast( logger, dbsession, "testing", web3, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, ) # Check they got mined txs = update_status( logger, dbsession, "testing", web3, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, ) assert len(txs) == 6 for tx in txs: # type: PreparedTransaction assert tx.result_transaction_success # Check that rerun does not recreate txs new_distributes, old_distributes = distribute_tokens( logger, dbsession, "testing", web3, ethereum_abi_file=None, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, token_address=token_address, dists=entries ) assert new_distributes == 0 assert old_distributes == 2