def send_issuer_tokens(logger, dbsession, web3, private_key_hex, token_address, to_address, amount): """Send tokens to a receiver.""" global _ext_id_counter _ext_id_counter += 1 ext_id = str(_ext_id_counter) result = distribute_single(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, to_address=to_address, ext_id=ext_id, name=to_address[0:6], email="{}@example.com".format(to_address[0:6]), amount=amount) assert result broadcast( logger, dbsession, "testing", web3, ethereum_private_key=private_key_hex, ethereum_gas_limit=None, ethereum_gas_price=None, )
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 _execute(config, contract_name, contract_function_name, args): from sto.ethereum.txservice import EthereumStoredTXService from sto.models.implementation import BroadcastAccount, PreparedTransaction from sto.ethereum.utils import broadcast service = EthereumStoredTXService( config.network, config.dbsession, web3, config.ethereum_private_key, config.ethereum_gas_price, config.ethereum_gas_limit, BroadcastAccount, PreparedTransaction) abi = get_abi(None) tx = get_contract_deployed_tx(dbsession, contract_name) service.interact_with_contract(contract_name, abi, tx.contract_address, '', contract_function_name, args) broadcast(config)
def broadcast(config: BoardCommmadConfiguration): """Broadcast waiting transactions.""" assert is_ethereum_network(config.network) logger = config.logger from sto.ethereum.broadcast import broadcast dbsession = config.dbsession txs = broadcast(logger, dbsession, config.network, ethereum_node_url=config.ethereum_node_url, ethereum_private_key=config.ethereum_private_key, ethereum_gas_limit=config.ethereum_gas_limit, ethereum_gas_price=config.ethereum_gas_price) if txs: from sto.ethereum.txservice import EthereumStoredTXService EthereumStoredTXService.print_transactions(txs) logger.info( "Run %ssto tx-update%s to monitor your transaction propagation status", colorama.Fore.LIGHTCYAN_EX, colorama.Fore.RESET) # Write database dbsession.commit()
def scanned_distribution(logger, dbsession, web3, private_key_hex, sample_csv_file, sample_token): """Create some sample transactions so we can scan the token holder balances.""" token_address = sample_token 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, ) # 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 token_scan(logger, dbsession, "testing", web3, None, token_address) return token_address
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 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