Exemplo n.º 1
0
Arquivo: test.py Projeto: anklee/pyeos
def test_rent3():
    balance_test1 = eosapi.get_account('test')
    balance_currency1 = eosapi.get_account('currency')
    amount = 1

    show_rent_result(b'test', b'currency')

    with producer:
        stake = {'from':'test','to':'currency','amount':amount}
        r = eosapi.push_message('eos', 'stake', stake, ['eos', 'test', 'currency'], {'test':'active'})
        assert r

    show_rent_result(b'test', b'currency')

    amount = 1
    #try to unstake 1000 eos from test
    with producer:
        stake = {'from':'test','to':'currency','amount':amount}
        r = eosapi.push_message('eos', 'unstake', stake, ['eos', 'test', 'currency'], {'test':'active'})
        assert r

    show_rent_result(b'test', b'currency')

    amount = 1
    with producer:
        stake = {'from':'test','to':'currency','amount':amount}
        r = eosapi.push_message('eos', 'release', stake, ['eos', 'test', 'currency'], {'test':'active'})
        assert r

    show_rent_result(b'test', b'currency')
Exemplo n.º 2
0
def test_bs():

    with producer:
        args = {
            "buyer": {
                "name": "inita",
                "number": 1
            },
            "at_price": "2",
            "quantity": 4,
            "expiration": "2018-11-11T13:12:28",
            "fill_or_kill": 0
        }
        scopes = ['exchange', 'inita']
        permissions = {'inita': 'active'}

        r = eosapi.push_message('exchange', 'buy', args, scopes, permissions)

        args = {
            "seller": {
                "name": "initb",
                "number": 1
            },
            "at_price": "2",
            "quantity": 2,
            "expiration": "2018-11-11T13:12:28",
            "fill_or_kill": 0
        }
        scopes = ['exchange', 'inita']
        permissions = {'initb': 'active'}
        r = eosapi.push_message('exchange', 'sell', args, scopes, permissions)

    r = eosapi.get_table('exchange', 'exchange', 'account')
    print(r)
Exemplo n.º 3
0
def test_deadlock():
# raise a "tx_missing_scope: missing required scope" exception
    r = eosapi.push_message('currency', 'transfer', {"from":"currency", "to":"inita", "quantity":1, "memo":"hello"}, ['inita'], {'currency':'active'})

# raise a "tx_missing_auth: missing required authority" exception
    r = eosapi.push_message('currency', 'transfer', {"from":"currency", "to":"inita", "quantity":1, "memo":"hello"}, ['currency', 'inita'], {})
    producer()
Exemplo n.º 4
0
def test_withdraw():
    messages = [
                [   
                    {"from":"exchange", "to":"inita", "amount":1, "memo":"hello"},
                    ['exchange', 'inita'],
                    {'exchange':'active', 'inita':'active'}
                 ],
                [
                    {"from":"exchange", "to":"initb", "amount":1, "memo":"hello"},
                    ['exchange', 'initb'],
                    {'exchange':'active', 'initb':'active'}
                 ],
                ]
    for msg in messages:
        args, scopes, permissions = msg
        r = eosapi.push_message('eos', 'transfer', args, scopes, permissions)
        

    messages = [
                [{"from":"exchange", "to":"inita", "quantity":1, "memo":"hello"}, ['exchange', 'inita'], {'exchange':'active', 'inita':'active'}],
                [{"from":"exchange", "to":"initb", "quantity":1, "memo":"hello"}, ['exchange', 'initb'], {'exchange':'active', 'initb':'active'}]
               ]

# r = eosapi.push_message('currency','transfer',{"from":"exchange","to":"initb","amount":1,"memo":"hello"},['exchange','initb'],{'exchange':'active','initb':'active'})

    for msg in messages:
        args, scopes, permissions = msg
        r = eosapi.push_message('currency', 'transfer', args, scopes, permissions)
    
    producer()
Exemplo n.º 5
0
Arquivo: test.py Projeto: anklee/pyeos
def init():
    psw = 'PW5Kd5tv4var9XCzvQWHZVyBMPjHEXwMjH1V19X67kixwxRpPNM4J'
    wallet.open('mywallet')
    wallet.unlock('mywallet', psw)
    
    key1 = 'EOS61MgZLN7Frbc2J7giU7JdYjy2TqnfWFjZuLXvpHJoKzWAj7Nst'
    key2 = 'EOS5JuNfuZPATy8oPz9KMZV2asKf9m8fb2bSzftvhW55FKQFakzFL'
    
    with producer:
        if not eosapi.get_account('currency'):
            r = eosapi.create_account('inita', 'currency', key1, key2)

        if not eosapi.get_account('test'):
            r = eosapi.create_account('inita', 'test', key1, key2)
            assert r

    with producer:
        r = eosapi.set_contract('currency', '../../programs/pyeos/contracts/currency/currency.py', '../../contracts/currency/currency.abi', eosapi.py_vm_type)
        assert r
        r = eosapi.set_contract('test','../../programs/pyeos/contracts/test/code.py','../../programs/pyeos/contracts/test/test.abi', eosapi.py_vm_type)
        assert r

    #transfer some "money" to test account for test
    with producer:
        r = eosapi.push_message('currency','transfer','{"from":"currency","to":"test","quantity":1000}',['currency','test'],{'currency':'active'})
        assert r

    #transfer some "money" to test account for test
    with producer:
        r = eosapi.push_message('eos','transfer',{"from":"inita","to":"test","amount":1000,"memo":"hello"},['inita','test'],{'inita':'active'})
        assert r
Exemplo n.º 6
0
def test_rent2():
    balance_test1 = eosapi.get_account('test')
    balance_currency1 = eosapi.get_account('currency')
    amount = 1
    with producer:
        stake = {'from': 'test', 'to': 'currency', 'amount': amount}
        r = eosapi.push_message('eos', 'stake', stake,
                                ['eos', 'test', 'currency'],
                                {'test': 'active'})
        assert r

    amount = 2
    with producer:
        stake = {'from': 'inita', 'to': 'currency', 'amount': amount}
        r = eosapi.push_message('eos', 'stake', stake,
                                ['eos', 'inita', 'currency'],
                                {'inita': 'active'})
        assert r

    #try to unstake 1000 eos from test
    amount = 1000
    with producer:
        stake = {'from': 'test', 'to': 'currency', 'amount': amount}
        r = eosapi.push_message('eos', 'unstake', stake,
                                ['eos', 'test', 'currency'],
                                {'test': 'active'})
        assert not r
Exemplo n.º 7
0
Arquivo: test.py Projeto: eos21/pyeos
def test_deposit():
    messages = [
        [{
            "from": "currency",
            "to": "inita",
            "amount": 1000
        }, ['currency', 'inita'], {
            'currency': 'active'
        }],
        [{
            "from": "currency",
            "to": "initb",
            "amount": 1000
        }, ['currency', 'initb'], {
            'currency': 'active'
        }],
        [{
            "from": "inita",
            "to": "exchange",
            "amount": 1000
        }, ['exchange', 'inita'], {
            'inita': 'active'
        }],
        [{
            "from": "initb",
            "to": "exchange",
            "amount": 1000
        }, ['exchange', 'initb'], {
            'initb': 'active'
        }],
    ]
    for msg in messages:
        args, scopes, permissions = msg
        r = eosapi.push_message('currency', 'transfer', args, scopes,
                                permissions)

    messages = [
        [{
            "from": "inita",
            "to": "exchange",
            "amount": 1000,
            "memo": "hello"
        }, ['exchange', 'inita'], {
            'inita': 'active'
        }],
        [{
            "from": "initb",
            "to": "exchange",
            "amount": 1000,
            "memo": "hello"
        }, ['exchange', 'initb'], {
            'initb': 'active'
        }],
    ]
    for msg in messages:
        args, scopes, permissions = msg
        r = eosapi.push_message('eos', 'transfer', args, scopes, permissions)
    producer()
Exemplo n.º 8
0
def test_rent():
    balance_test1 = eosapi.get_account('test')
    balance_currency1 = eosapi.get_account('currency')
    amount = 1
    with producer:
        stake = {'from': 'test', 'to': 'currency', 'amount': amount}
        r = eosapi.push_message('eos', 'stake', stake,
                                ['eos', 'test', 'currency'],
                                {'test': 'active'})
        assert r

    balance_test2 = eosapi.get_account('test')
    balance_currency2 = eosapi.get_account('currency')

    assert balance_test1.balance == balance_test2.balance + amount
    assert balance_currency1.balance == balance_currency2.balance
    assert balance_currency1.stakedBalance + amount == balance_currency2.stakedBalance

    balance_test1 = balance_test2
    balance_currency1 = balance_currency2

    with producer:
        stake = {'from': 'test', 'to': 'currency', 'amount': amount}
        r = eosapi.push_message('eos', 'unstake', stake,
                                ['eos', 'test', 'currency'],
                                {'test': 'active'})
        assert r

    balance_test2 = eosapi.get_account('test')
    balance_currency2 = eosapi.get_account('currency')

    assert balance_test1.balance == balance_test2.balance
    assert balance_currency1.balance == balance_currency2.balance
    assert balance_currency1.stakedBalance == balance_currency2.stakedBalance + amount
    assert balance_currency1.unstakingBalance == balance_currency2.unstakingBalance - amount

    balance_test1 = balance_test2
    balance_currency1 = balance_currency2

    with producer:
        stake = {'from': 'test', 'to': 'currency', 'amount': amount}
        r = eosapi.push_message('eos', 'release', stake,
                                ['eos', 'test', 'currency'],
                                {'test': 'active'})
        assert r

    balance_test2 = eosapi.get_account('test')
    balance_currency2 = eosapi.get_account('currency')

    print(balance_test1.balance, balance_test2.balance)

    assert balance_test1.balance + amount == balance_test2.balance
    assert balance_currency1.balance == balance_currency2.balance
    assert balance_currency1.stakedBalance == balance_currency2.stakedBalance
    assert balance_currency1.unstakingBalance == balance_currency2.unstakingBalance + amount
Exemplo n.º 9
0
def test(name=None):
    with producer:
        if not name:
            name = 'mike'
        r = eosapi.push_message('greeter', 'setgreeting', name,
                                {'greeter': 'active'})
        assert r

    with producer:
        r = eosapi.push_message('greeter', 'greeting', '',
                                {'greeter': 'active'})
        assert r
Exemplo n.º 10
0
def test(msg='hello,world'):
    '''
    with producer:
        r = eosapi.push_message('twitbot', 'sayhello', msg, {'twitbot':'active'})
        assert r
    '''
    msg = {"from":"eosio", "to":"hello", "quantity":"100.0000 EOS", "memo":"m"}
    r = eosapi.push_message('eosio.token', 'transfer', msg, {'eosio':'active'})

    with producer:
        msg = {"from":"hello", "to":"twitbot", "quantity":"1.0000 EOS", "memo":"m"}
        r = eosapi.push_message('eosio.token', 'transfer', msg, {'hello':'active'})
Exemplo n.º 11
0
Arquivo: test.py Projeto: anklee/pyeos
def test_memory():
    with producer:
        size = 2024*1025 
        print(size)
        #should throw an exception
        r = eosapi.push_message('test', 'testmem', {'data':size}, ['test','inita'], {'test':'active'})
        assert not r

    with producer:
        size = 1024
        print(size)
        r = eosapi.push_message('test', 'testmem', {'data':size}, ['test','inita'], {'test':'active'})
        assert r
Exemplo n.º 12
0
    def deploy(self, src_file, _dir=None):
        _abs_file_path = None
        if _dir:
            _abs_file_path = os.path.join(_dir, src_file)
        else:
            _abs_file_path = os.path.join(self.src_dir, src_file)

        if self.check(_abs_file_path):
            print('++++++++++:', src_file, "up to date")
            return

        src_code = open(_abs_file_path, 'rb').read()
        mod_name = src_file  #os.path.basename(src_file)
        msg = int.to_bytes(len(mod_name), 1, 'little')
        msg += mod_name.encode('utf8')
        msg += int.to_bytes(0, 1, 'little')  # source code
        msg += src_code
        with producer:
            print('++++++++++++++++deply:', mod_name)
            r = eosapi.push_message('kitties',
                                    'deploy',
                                    msg, {'kitties': 'active'},
                                    rawargs=True)
            assert r
        self.save()
Exemplo n.º 13
0
def send_transaction():
    r = eosapi.get_table('test', 'currency', 'account')
    print(r)
    r = eosapi.get_table('inita', 'currency', 'account')
    print(r)

    with producer:
        r = eosapi.push_message('test',
                                'testts',
                                '', [
                                    'test',
                                ], {'test': 'active'},
                                rawargs=True)
        assert r

    r = eosapi.get_table('test', 'currency', 'account')
    print(r)
    r = eosapi.get_table('inita', 'currency', 'account')
    print(r)

    producer()

    r = eosapi.get_table('test', 'currency', 'account')
    print(r)
    r = eosapi.get_table('inita', 'currency', 'account')
    print(r)
Exemplo n.º 14
0
def test(name=None):
    with producer:
        if not name:
            name = 'mike'
        r = eosapi.push_message('kitties', 'sayhello', name,
                                {'kitties': 'active'})
        assert r
Exemplo n.º 15
0
def test(name=None):
    with producer:
        r = eosapi.push_message('rpctest',
                                'sayhello',
                                'hello,world', {'rpctest': 'active'},
                                rawargs=True)
        assert r
Exemplo n.º 16
0
def test():
    producer()
    p = os.path.join(os.getcwd(), '../../programs/pyeos/contracts/mnist')
    sys.path.insert(0, p)
    import mnist_loader
    training_data, validation_data, test_data = mnist_loader.load_data_wrapper(
    )
    print('load done!')
    training_data = list(training_data)
    txids = []
    counter = 0
    for d in training_data[:1]:
        data = pickle.dumps([
            d,
        ])
        data = zlib.compress(data)
        #    print(data)
        r = eosapi.push_message('mnist',
                                'train',
                                data, ['mnist'], {'mnist': 'active'},
                                rawargs=True)
        assert r
        print(r.transaction_id)
        if r.transaction_id in txids:
            raise 'dumplicate ts id'
        txids.append(r.transaction_id)
        counter += 1
        if counter % 50 == 0:
            print(counter)
            with producer:
                pass
    producer()
Exemplo n.º 17
0
Arquivo: test.py Projeto: anklee/pyeos
def test():
    with producer:
        r = eosapi.push_message('hello',
                                'sayhello',
                                'hello,world', ['hello'], {},
                                rawargs=True)
        assert r
Exemplo n.º 18
0
def giveRightToVote(name=None):
    with producer:
        if not name:
            name = 'mike'
        msg = struct.pack('QQ', eosapi.N('vote'), eosapi.N('hello'))
        r = eosapi.push_message('vote', 'giveright', msg, {'vote': 'active'})
        assert r
Exemplo n.º 19
0
def delegate(name=None):
    with producer:
        if not name:
            name = 'hello'
        msg = struct.pack('QQ', eosapi.N('vote'), eosapi.N(name))
        r = eosapi.push_message('vote', 'delegate', msg, {'vote': 'active'})
        assert r
Exemplo n.º 20
0
def send_eos_inline():
    args = {"from": "inita", "to": "test", "amount": 1000, "memo": "hello"}
    scopes = ['test', 'inita']
    permissions = {'inita': 'active'}

    with producer:
        r = eosapi.push_message('eos', 'transfer', args, scopes, permissions)
Exemplo n.º 21
0
def inline_send():
    with producer:
        r = eosapi.push_message('apitest', 'inlinesend', '', {
            'hello': 'active',
            'apitest': 'active'
        })
        assert r
Exemplo n.º 22
0
def deploy_mpy():
    src_dir = os.path.dirname(os.path.abspath(__file__))
    code = eosapi.N('backyard')
    for file_name in libs:
        print('deploy ', file_name)
        src_code = eosapi.mp_compile(os.path.join(src_dir, file_name))
        file_name = file_name.replace('.py', '.mpy')
        src_id = eosapi.hash64(file_name, 0)
        itr = eoslib.db_find_i64(code, code, code, src_id)
        if itr >= 0:
            old_src = eoslib.db_get_i64(itr)
            if old_src[1:] == src_code:
                continue
        mod_name = file_name
        msg = int.to_bytes(len(mod_name), 1, 'little')
        msg += mod_name.encode('utf8')
        msg += int.to_bytes(1, 1, 'little')  # compiled code
        msg += src_code

        print('++++++++++++++++deply:', file_name)
        r = eosapi.push_message('backyard', 'deploy', msg,
                                {'backyard': 'active'})
        assert r

    producer.produce_block()
Exemplo n.º 23
0
def deffer_send():
    with producer:
        r = eosapi.push_message('apitest', 'deffersend', '', {
            'apitest': 'active',
            'hello': 'active'
        })
        assert r
Exemplo n.º 24
0
def t2():
    args = {"buyer" : {"name":"inita", "number":1}, "at_price" : "2", "quantity" : 1, "expiration" : "2018-11-11T13:12:28", "fill_or_kill":1}
    scopes = ['exchange', 'inita']
    permissions = {'inita':'active'}
    with producer:
        r = eosapi.push_message('exchange', 'buy', args, scopes, permissions)
        assert r
Exemplo n.º 25
0
def call(name=None):
    with producer:
        r = eosapi.push_message('kitties',
                                'call',
                                'hello,world', {'kitties': 'active'},
                                rawargs=True)
        assert r
Exemplo n.º 26
0
def test(name='abc'):
    with producer:
        r = eosapi.push_message('storage',
                                'storagetest',
                                name, {'storage': 'active'},
                                rawargs=True)
        assert r
Exemplo n.º 27
0
def start(beneficiary='hello', auctionEnd=10000):
    with producer:
        beneficiary = eosapi.N(beneficiary)
        msg = int.to_bytes(beneficiary, 8, 'little')
        msg += int.to_bytes(auctionEnd, 8, 'little')
        r = eosapi.push_message('auction1', 'start', msg,
                                {'auction1': 'active'})
        assert r
Exemplo n.º 28
0
def issue():
    with producer:
        r = eosapi.push_message('eosio.token', 'issue', {
            "to": "hello",
            "quantity": "1000.0000 EOS",
            "memo": ""
        }, {'eosio': 'active'})
        assert r
Exemplo n.º 29
0
def play():
    with producer:
        if not eosapi.get_account('hello').permissions:
            r = eosapi.create_account('eosio', 'hello', initeos.key1, initeos.key2)
            assert r
    with producer:
        r = eosapi.push_message('hello','play','',{'hello':'active'},rawargs=True)
        assert r
Exemplo n.º 30
0
def test_release():
    with producer:
        stake = {'from': 'test', 'to': 'currency', 'amount': 1}
        r = eosapi.push_message('eos', 'release', stake,
                                ['eos', 'test', 'currency'],
                                {'test': 'active'})
        assert r
    show_result()