from time import sleep

from client.client import Client
from dependency_config import container
from utils.utils import increaseTime

alice = Client(container.get_root('alice'), container.get_token('alice'))
bob = Client(container.get_root('bob'), container.get_token('bob'))

# Operator
authority = Client(container.get_root('authority'),
                   container.get_token('authority'))
w3 = alice.root_chain.w3  # get w3 instance

# Give alice 5 tokens
alice.register()

aliceTokensStart = alice.token_contract.balance_of()
print('Alice has {} tokens'.format(aliceTokensStart))
assert aliceTokensStart == 5, "START: Alice has incorrect number of tokens"
bobTokensStart = bob.token_contract.balance_of()
print('Bob has {} tokens'.format(bobTokensStart))
assert bobTokensStart == 0, "START: Bob has incorrect number of tokens"

# Alice deposits 3 of her coins to the plasma contract and gets 3 plasma nft
# utxos in return
tokenId = 1
tx_hash, gas_used = alice.deposit(tokenId)
event_data = alice.root_chain.get_event_data('Deposit', tx_hash)
print('ALICE EVENT DATA1', event_data[0]['args'])
Example #2
0
import collections

from client.client import Client
from dependency_config import container
from utils.utils import increaseTime

authority = Client(
    container.get_root("authority"), container.get_token("authority")
)
w3 = authority.root_chain.w3  # get w3 instance

child_block_interval = 1000
block_iterations = 8
coins_per_register = 5
num_deposited_coins = 2
coin_indices = range(0, num_deposited_coins)
number_of_players = 5
players_indices = range(0, number_of_players)

gas_costs = collections.defaultdict(dict)

players = list(
    map(
        lambda index: Client(
            container.get_root("players", index),
            container.get_token("players", index),
        ),
        players_indices,
    )
)
Example #3
0
import time

from client.client import Client
from dependency_config import container
from utils.utils import increaseTime

dan = Client(container.get_root('dan'), container.get_token('dan'))
mallory = Client(container.get_root('mallory'), container.get_token('mallory'))
authority = Client(container.get_root('authority'),
                   container.get_token('authority'))

# Give Mallory 5 tokens
mallory.register()

danTokensStart = dan.token_contract.balance_of()
print('Dan has {} tokens'.format(danTokensStart))
assert danTokensStart == 0, "START: Dan has incorrect number of tokens"
malloryTokensStart = mallory.token_contract.balance_of()
print('Mallory has {} tokens'.format(malloryTokensStart))
assert malloryTokensStart == 5, "START: Mallory has incorrect number of tokens"
current_block = authority.get_block_number()
print('current block: {}'.format(current_block))

# Mallory deposits one of her coins to the plasma contract
tx_hash, gas_used = mallory.deposit(6)
event_data = mallory.root_chain.get_event_data('Deposit', tx_hash)
deposit1_utxo = event_data[0]['args']['slot']
mallory.deposit(7)
# wait to make sure that events get fired correctly
time.sleep(2)
registered_deposits = mallory.get_all_deposits()
import time

from client.client import Client
from dependency_config import container
from utils.utils import increaseTime

dan = Client(container.get_root('dan'), container.get_token('dan'))
trudy = Client(container.get_root('trudy'), container.get_token('trudy'))
authority = Client(
    container.get_root('authority'), container.get_token('authority')
)

# Give Trudy 5 tokens
trudy.register()

danTokensStart = dan.token_contract.balance_of()

# Trudy deposits a coin
tx_hash, gas_used = trudy.deposit(21)
event_data = trudy.root_chain.get_event_data('Deposit', tx_hash)
deposit1_utxo = event_data[0]['args']['slot']

# wait to make sure that events get fired correctly
time.sleep(2)

trudy_submit_block = authority.get_block_number()
trudyTokensStart = trudy.token_contract.balance_of()

coin = trudy.get_plasma_coin(deposit1_utxo)
authority.submit_block()
trudy.watch_exits(deposit1_utxo)