def token_asset(dbsession, eth_network_id, deposit_address, eth_service: EthereumService) -> UUID: """Database asset referring to the token contract. deposit_address will hold 10000 tokens :return: Asset id """ with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) asset = network.create_asset(name="MyToken", symbol="MY", supply=Decimal(10000), asset_class=AssetClass.token) address = CryptoAddress.get_network_address( network, eth_address_to_bin(deposit_address)) op = address.create_token(asset) opid = op.id aid = asset.id # This gives op a txid success, fails = eth_service.run_waiting_operations() assert success == 1 wait_for_op_confirmations(eth_service, opid) with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) asset = dbsession.query(Asset).get(aid) address = CryptoAddress.get_network_address( network, eth_address_to_bin(deposit_address)) account = address.get_account(asset) assert account.account.get_balance() > 0 return aid
def token_asset(dbsession, eth_network_id, deposit_address, eth_service: EthereumService) -> UUID: """Database asset referring to the token contract. deposit_address will hold 10000 tokens :return: Asset id """ with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) asset = network.create_asset(name="MyToken", symbol="MY", supply=Decimal(10000), asset_class=AssetClass.token) address = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) op = address.create_token(asset) opid = op.id aid = asset.id # This gives op a txid success, fails = eth_service.run_waiting_operations() assert success == 1 wait_for_op_confirmations(eth_service, opid) with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) asset = dbsession.query(Asset).get(aid) address = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) account = address.get_account(asset) assert account.account.get_balance() > 0 return aid
def test_create_token(dbsession, eth_network_id, eth_service, coinbase, deposit_address): """Test user initiated token creation.""" # Initiate token creation operation with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) asset = network.create_asset(name="MyToken", symbol="MY", supply=Decimal(10000), asset_class=AssetClass.token) address = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) op = address.create_token(asset) opid = op.id aid = asset.id assert op.completed_at is None # Check asset is intact assert asset.symbol == "MY" assert asset.supply == 10000 assert asset.name == "MyToken" # This gives op a txid when smart contract creation tx is posted to geth success_count, failure_count = eth_service.run_waiting_operations() assert success_count == 1 assert failure_count == 0 # Check that initial asset data is in place with transaction.manager: op = dbsession.query(CryptoOperation).get(opid) network = dbsession.query(AssetNetwork).get(eth_network_id) address = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) asset = network.get_asset(aid) assert op.txid assert not op.block assert op.broadcasted_at is not None assert op.completed_at is None # Initial balance doesn't hit us until tx has been confirmed assert address.get_account(asset).account.get_balance() == 0 # Asset has received its smart contract address assert asset.external_id # Wait that the smart contract creation is confirmed wait_for_op_confirmations(eth_service, opid) # Initial balance doesn't hit us until op has enough confirmations with transaction.manager: op = dbsession.query(CryptoOperation).get(opid) network = dbsession.query(AssetNetwork).get(eth_network_id) address = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) asset = network.get_asset(aid) assert op.broadcasted_at is not None assert op.completed_at is not None assert address.get_account(asset).account.get_balance() == 10000
def test_create_token(dbsession, eth_network_id, eth_service, coinbase, deposit_address): """Test user initiated token creation.""" # Initiate token creation operation with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) asset = network.create_asset(name="MyToken", symbol="MY", supply=Decimal(10000), asset_class=AssetClass.token) address = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) op = address.create_token(asset) opid = op.id aid = asset.id assert op.completed_at is None # Check asset is intact assert asset.symbol == "MY" assert asset.supply == 10000 assert asset.name == "MyToken" # This gives op a txid when smart contract creation tx is posted to geth success_count, failure_count = eth_service.run_waiting_operations() assert success_count == 1 assert failure_count == 0 # Check that initial asset data is in place with transaction.manager: op = dbsession.query(CryptoOperation).get(opid) network = dbsession.query(AssetNetwork).get(eth_network_id) address = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) asset = network.get_asset(aid) assert op.txid assert not op.block assert op.broadcasted_at is not None assert op.completed_at is None # Initial balance doesn't hit us until tx has been confirmed assert address.get_account(asset).account.get_balance() == 0 # Asset has received its smart contract address assert asset.external_id # Wait that the smart contract creation is confirmed wait_for_op_confirmations(eth_service, opid) # Initial balance doesn't hit us until op has enough confirmations with transaction.manager: op = dbsession.query(CryptoOperation).get(opid) network = dbsession.query(AssetNetwork).get(eth_network_id) address = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) asset = network.get_asset(aid) assert op.broadcasted_at is not None assert op.completed_at is not None assert address.get_account(asset).account.get_balance() == 10000
def test_import_token(dbsession, eth_network_id, web3: Web3, eth_service: EthereumService, coinbase: str, deposit_address: str, token: Token): """Import an existing smart contract token to system.""" # Make sure we have an address that holds some of the tokens so it is cleared up during import txid = token.transfer(deposit_address, Decimal(4000)) confirm_transaction(web3, txid) with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) op = import_token(network, eth_address_to_bin(token.address)) opid = op.id # Let's create another address that doesn't hold tokens # and see that import doesn't fail for it addr = CryptoAddress(network=network, address=eth_address_to_bin("0x2f70d3d26829e412a602e83fe8eebf80255aeea5")) dbsession.add(addr) success_count, failure_count = eth_service.run_waiting_operations() assert success_count == 1 assert failure_count == 0 # Check that we created a new asset and its imports where fulfilled with transaction.manager: op = dbsession.query(CryptoOperation).get(opid) assert op.completed_at # We got account with tokens on it network = dbsession.query(AssetNetwork).get(eth_network_id) caddress = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) asset = network.assets.filter_by(external_id=eth_address_to_bin(token.address)).one() assert asset.name == "Mootoken" assert asset.symbol == "MOO" assert asset.supply == 10000 caccount = caddress.get_account_by_address(eth_address_to_bin(token.address)) assert caccount.account.get_balance() == 4000
def test_import_token(dbsession, eth_network_id, web3: Web3, eth_service: EthereumService, coinbase: str, deposit_address: str, token: Token): """Import an existing smart contract token to system.""" # Make sure we have an address that holds some of the tokens so it is cleared up during import txid = token.transfer(deposit_address, Decimal(4000)) confirm_transaction(web3, txid) with transaction.manager: network = dbsession.query(AssetNetwork).get(eth_network_id) op = import_token(network, eth_address_to_bin(token.address)) opid = op.id # Let's create another address that doesn't hold tokens # and see that import doesn't fail for it addr = CryptoAddress(network=network, address=eth_address_to_bin("0x2f70d3d26829e412a602e83fe8eebf80255aeea5")) dbsession.add(addr) success_count, failure_count = eth_service.run_waiting_operations() assert success_count == 1 assert failure_count == 0 # Check that we created a new asset and its imports where fulfilled with transaction.manager: op = dbsession.query(CryptoOperation).get(opid) assert op.completed_at # We got account with tokens on it network = dbsession.query(AssetNetwork).get(eth_network_id) caddress = CryptoAddress.get_network_address(network, eth_address_to_bin(deposit_address)) asset = network.assets.filter_by(external_id=eth_address_to_bin(token.address)).one() assert asset.name == "Mootoken" assert asset.symbol == "MOO" assert asset.supply == 10000 caccount = caddress.get_account_by_address(eth_address_to_bin(token.address)) assert caccount.account.get_balance() == 4000