Example #1
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_action('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_action('exchange', 'sell', args, scopes, permissions)

    r = eosapi.get_table('exchange', 'exchange', 'account')
    print(r)
Example #2
0
def update_auth3():
    account = 'hello'
    permission = 'active'
    parent = 'owner'
    keys = [
        'EOS8TK6xU7M86WqRupHDUzAwwem4gzzDSXWA1byfD2KC1H8WWC9Dk',
        'EOS6X5BmJUB95F6Tac5t87gTEZUcNGcJpW22MhTzbvMHfMXjiDAMu'
    ]
    keys.sort()
    a = {
        "account": account,
        "permission": permission,
        "parent": parent,
        "auth": {
            "threshold": 2,
            "keys": [{
                "key": keys[0],
                "weight": 1
            }, {
                "key": keys[1],
                "weight": 1
            }],
            "accounts": [],
            "waits": []
        }
    }
    eosapi.push_action('eosio', 'updateauth', a, {'hello': 'owner'})
Example #3
0
def update_auth2():
    account = 'hello'
    permission = 'active'
    parent = 'owner'
    a = {
        "account": account,
        "permission": permission,
        "parent": parent,
        "auth": {
            "threshold":
            2,
            "keys": [{
                "key": "EOS61MgZLN7Frbc2J7giU7JdYjy2TqnfWFjZuLXvpHJoKzWAj7Nst",
                "weight": 1
            }],
            "accounts": [{
                'permission': {
                    'actor': 'hello',
                    'permission': 'owner'
                },
                'weight': 1
            }],
            "waits": []
        }
    }
    eosapi.push_action('eosio', 'updateauth', a, {'hello': 'owner'})
Example #4
0
def test_deposit():
    messages = [
        [{
            "from": "currency",
            "to": "inita",
            "quantity": 1000
        }, ['currency', 'inita'], {
            'currency': 'active'
        }],
        [{
            "from": "currency",
            "to": "initb",
            "quantity": 1000
        }, ['currency', 'initb'], {
            'currency': 'active'
        }],
        [{
            "from": "inita",
            "to": "exchange",
            "quantity": 1000
        }, ['exchange', 'inita'], {
            'inita': 'active'
        }],
        [{
            "from": "initb",
            "to": "exchange",
            "quantity": 1000
        }, ['exchange', 'initb'], {
            'initb': 'active'
        }],
    ]
    for msg in messages:
        args, scopes, permissions = msg
        r = eosapi.push_action('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_action('eos', 'transfer', args, scopes, permissions)
    producer()
Example #5
0
 def func_wrapper(wasm=True, *args, **kwargs):
     eosapi.push_action('eosio', 'setpriv', {
         'account': 'eosio.prods',
         'is_priv': 1
     }, {'eosio': 'active'})
     r = eosapi.set_contract(
         'eosio.prods', '../contracts/eosio.prods/eosio.prods.wast',
         '../contracts/eosio.prods/eosio.prods.abi', 0)
     return func(*args, **kwargs)
Example #6
0
def undlbw(_from, _to, net, cpu):
    args = {
        'from': _from,
        'receiver': _to,
        'unstake_net_quantity': '%.4f EOS' % (net, ),
        'unstake_cpu_quantity': '%.4f EOS' % (cpu, ),
        'transfer': False
    }
    eosapi.push_action('eosio', 'undelegatebw', args, {_from: 'active'})
Example #7
0
def t3(count=100, sign=True):
#    tracemalloc.start()
#    snapshot1 = tracemalloc.take_snapshot()
    wast = '../../build/contracts/eosio.token/eosio.token.wast'
    key_words = b"hello,world"
    r = eosapi.set_contract('bugs', wast, '../../build/contracts/eosio.token/eosio.token.abi', 0)

    msg = {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS","can_freeze":0,"can_recall":0, "can_whitelist":0}
    r = eosapi.push_action('bugs', 'create', msg, {'bugs':'active'})

    r = eosapi.push_action('bugs','issue',{"to":"bugs","quantity":"1000000.0000 EOS","memo":""},{'eosio':'active'})

    _src_dir = os.path.dirname(__file__)
    for i in range(count):
        actions = []
        #break the wasm cache
        key_words = b"hello,world"
        wast_file = os.path.join(_src_dir, '/Users/newworld/dev/pyeos/build/contracts/eosio.token/eosio.token.wast')
        with open(wast_file, 'rb') as f:
            data = f.read()
            replace_str = b"%d"%(int(time.time()),)
            replace_str.zfill(len(key_words))
            data = data.replace(key_words, replace_str)
            wasm = eosapi.wast2wasm(data)
            raw_code = eosapi.pack_bytes(wasm)

        code = struct.pack('QBB', N('bugs'), 0, 0)
        code += raw_code
        
        act = [N('eosio'), N('setcode'), [[N('bugs'), N('active')]], code]
        setabi = eosapi.pack_setabi('../../build/contracts/eosio.token/eosio.token.abi', eosapi.N('bugs'))
        setabi_action = [N('eosio'), N('setabi'), [[N('bugs'), N('active')]], setabi]
        actions.append([act, setabi_action])


        code = struct.pack('QBB', N('eosio.token'), 0, 0)
        code += raw_code
        act = [N('eosio'), N('setcode'), [[N('eosio.token'), N('active')]], code]
        setabi = eosapi.pack_setabi('../../build/contracts/eosio.token/eosio.token.abi', eosapi.N('eosio.token'))
        setabi_action = [N('eosio'), N('setabi'), [[N('eosio.token'), N('active')]], setabi]
        actions.append([act, setabi_action])

        print('&'*50)
        cost_time = eosapi.push_transactions2(actions, sign)
        
        print('*'*50)
        msg = {"from":"bugs", "to":"eosio", "quantity":"0.0001 EOS", "memo":"%d"%(i,)}
        r = eosapi.push_action('bugs', 'transfer', msg, {'bugs':'active'})

        print('='*20, 'cached module should be decreased by 1 as eosio.token load the same code as bugs')
        msg = {"from":"bugs", "to":"eosio", "quantity":"0.0001 EOS", "memo":"%d"%(i,)}
        r = eosapi.push_action('eosio.token', 'transfer', msg, {'bugs':'active'})

        if i % 50 == 0:
            cost_time = eosapi.produce_block()
    eosapi.produce_block()
Example #8
0
def test(name=None):
    with producer:
        if not name:
            name = 'mike'
        r = eosapi.push_action('greeter', 'setgreeting', name, {'greeter':'active'})
        assert r

    with producer:
        r = eosapi.push_action('greeter', 'greeting', '' , {'greeter':'active'})
        assert r
Example #9
0
def create_tokens():

    msg = {"issuer":"eosio","maximum_supply":"10000000000.0000 EOS"}
    r, cost = eosapi.push_action('eosio.token', 'create', msg, {'eosio.token':'active'})
    assert r

    total_allocation = allocate_funds()

    r = eosapi.push_action('eosio.token','issue',{"to":"eosio","quantity":int_to_currency(total_allocation),"memo":""},{'eosio':'active'})
    assert r
Example #10
0
File: t.py Project: shuke0327/pyeos
def test(msg='hello,world'):
    '''
    with producer:
        r = eosapi.push_action('twitbot', 'sayhello', msg, {'twitbot':'active'})
        assert r
    '''
    msg = {"from":"eosio", "to":"hello", "quantity":"100.0000 EOS", "memo":"m"}
    r = eosapi.push_action('eosio.token', 'transfer', msg, {'eosio':'active'})

    with producer:
        msg = {"from":"hello", "to":"twitbot", "quantity":"1.0000 EOS", "memo":"m"}
        r = eosapi.push_action('eosio.token', 'transfer', msg, {'hello':'active'})
Example #11
0
def publish_system_contract():
    contracts_path = os.path.join(os.getcwd(), '..', 'contracts')
    sys.path.append(os.getcwd())
    for account in ['eosio.bios', 'eosio.msig', 'eosio.system', 'eosio.token']:
        print('account', account)
        if not eosapi.get_account(account):
            with producer:
                r = eosapi.create_account('eosio', account, key1, key2)
                assert r

        old_code = eosapi.get_code(account)
        if old_code:
            old_code = old_code[0]
        need_update = not old_code
        if old_code:
            print('+++++++++old_code[:4]', old_code[:4])
            if old_code[:4] != b'\x00asm':
                old_code = eosapi.wast2wasm(old_code)

            wast = os.path.join(contracts_path, account, account + '.wast')
            code = open(wast, 'rb').read()
            code = eosapi.wast2wasm(code)

            print(len(code), len(old_code), old_code[:20])
            if code == old_code:
                need_update = False
        if need_update:
            print('+++++++++code update', account)
            wast = os.path.join(contracts_path, account, account + '.wast')
            abi = os.path.join(contracts_path, account, account + '.abi')
            with producer:
                r = eosapi.set_contract(account, wast, abi, 0)

            if account == 'eosio.token':
                #                msg = {"issuer":"eosio","maximum_supply":"1000000000.0000 EOS","can_freeze":0,"can_recall":0, "can_whitelist":0}
                with producer:
                    msg = {
                        "issuer": "eosio",
                        "maximum_supply": "10000000000.0000 EOS"
                    }
                    r = eosapi.push_action('eosio.token', 'create', msg,
                                           {'eosio.token': 'active'})
                    assert r
                    r = eosapi.push_action('eosio.token', 'issue', {
                        "to": "eosio",
                        "quantity": "1000.0000 EOS",
                        "memo": ""
                    }, {'eosio': 'active'})
                    assert r
Example #12
0
def test(msg='hello,world'):
    msg = {"producer": "prod.aa", "account": "eosio"}
    r = eosapi.push_action('eosio.prods', 'votejit', {
        "producer": "prod.aa",
        "account": "eosio",
        'last_code_update': 0
    }, {'prod.aa': 'active'})
Example #13
0
def t3():
    r = eosapi.push_action('eosio.token', 'issue', {
        "to": "eosio",
        "quantity": "1000.0000 EOS",
        "memo": ""
    }, {'eosio': 'active'})
    assert r
Example #14
0
def call(func_name, args = (), amount=0):
    print(func_name, args)
    data =generate_call_params(func_name, args)
    print('+++call parameters:', data)
    args = {'from':'eosio', 'to':'evm', 'amount':amount, 'data':data}
    r = eosapi.push_action('evm', 'transfer', args, {'eosio':'active'})
    print(r['elapsed'])
Example #15
0
File: t.py Project: shuke0327/pyeos
def delegate(name=None):
    with producer:
        if not name:
            name = 'hello'
        msg = struct.pack('QQ', eosapi.N('vote'), eosapi.N(name))
        r = eosapi.push_action('vote', 'delegate', msg, {'vote': 'active'})
        assert r
Example #16
0
File: t.py Project: beaquant/pyeos
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 = db.find_i64(code, code, code, src_id)
        if itr >= 0:
            #Something went wrong in mp_compile.
            #Generating different bytecode each time with the same source code, walkaround this problem for now
            continue 
            old_src = 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 python bytecode
        msg += src_code

        print('++++++++++++++++deply:', file_name)
        r = eosapi.push_action('backyard','deploy',msg,{'backyard':'active'})
        assert r
Example #17
0
def deffer_send():
    with producer:
        r = eosapi.push_action('apitest', 'deffersend', '', {
            'apitest': 'active',
            'hello': 'active'
        })
        assert r
Example #18
0
File: t.py Project: shuke0327/pyeos
def test(name=None):
    with producer:
        if not name:
            name = 'mike'
        r = eosapi.push_action('kitties', 'sayhello', name,
                               {'kitties': 'active'})
        assert r
Example #19
0
File: t.py Project: shuke0327/pyeos
def unlock(msg='hello,world', wasm=False):
    with producer:
        r = eosapi.push_action('eosio', 'unlockcode', {
            'unlocker': 'eosio',
            'account': 'lockunlock'
        }, {'eosio': 'active'})
        assert r
Example #20
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_action('vote', 'giveright', msg, {'vote':'active'})
        assert r
Example #21
0
def start(beneficiary='hello', auctionEnd=None):
    if not auctionEnd:
        auctionEnd = int(time.time()+60)
    beneficiary = eosapi.N(beneficiary)
    msg = struct.pack('QQ', beneficiary, auctionEnd)
    r = eosapi.push_action('auction1','start', msg, {'auction1':'active'})
    assert r
Example #22
0
def issue2():
    r = eosapi.push_action('tokentest', 'issue', {
        "to": "hello",
        "quantity": "10000000000.0000 EOS",
        "memo": ""
    }, {'eosio': 'active'})
    assert r
Example #23
0
def deploy_wast():
    src_dir = os.path.dirname(os.path.abspath(__file__))
    code = eosapi.N('backyard')
    for file_name in ('math.wast', ):
        print('deploy ', file_name)
        bin_code = None
        with open(os.path.join(src_dir, file_name), 'rb') as f:
            bin_code = eosapi.wast2wasm(f.read())

        src_id = eosapi.hash64(file_name, 0)
        itr = db.find_i64(code, code, code, src_id)
        if itr >= 0:
            old_src = db.get_i64(itr)
            if old_src[1:] == bin_code:
                continue
        mod_name = file_name
        msg = int.to_bytes(len(mod_name), 1, 'little')
        msg += mod_name.encode('utf8')
        msg += int.to_bytes(3, 1, 'little')  # compiled cpp bytecode
        msg += bin_code
        print(msg)
        print('++++++++++++++++deply:', file_name)
        r = eosapi.push_action('backyard', 'deploy', msg,
                               {'backyard': 'active'})
        assert r
Example #24
0
File: t.py Project: shuke0327/pyeos
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_action('backyard', 'deploy', msg,
                               {'backyard': 'active'})
        assert r

    producer.produce_block()
Example #25
0
def getValue():
    main_class = '<stdin>:Greeter'
    greeter = os.path.join(os.path.dirname(__file__), 'greeter.sol')
    with open(greeter, 'r') as f:
        contract_source_code = f.read()
        contract_interface = compile(contract_source_code, main_class)
        #        deploy(contract_interface)
        contract_abi = contract_interface['abi']

    fn_identifier = 'getValue'

    for abi in contract_abi:
        if 'name' in abi and abi['name'] == fn_identifier:
            fn_abi = abi
            break
    args = ()
    kwargs = {}

    data = web3.utils.contracts.encode_transaction_data(
        web3, fn_identifier, contract_abi, fn_abi, args, kwargs)
    print(data)
    data = data[2:]
    args = {'from': 'eosio', 'to': 'evm', 'amount': 1234567, 'data': data}
    #    args = eosapi.pack_args('evm', 'transfer', args)
    #    print(args)
    r = eosapi.push_action('evm', 'ethtransfer', args, {'eosio': 'active'})
    print(r['elapsed'])
Example #26
0
def test4():
    with producer:
        msg = {"issuer": "eosio", "maximum_supply": "10000000000.0000 EOS"}
        r = eosapi.push_action('eosio.token', 'create', msg,
                               {'eosio.token': 'active'})
        print(r)
        assert r
Example #27
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_action('mnist', 'train', data, ['mnist'],
                               {'mnist': 'active'})
        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()
Example #28
0
File: t.py Project: hi-noikiy/pyeos
def delete(vm='vm.py.1'):
    debug.mp_set_max_execution_time(10000_000)
    
    account = 'vmstore' #eosapi.N('vmstore')
    msg = int.to_bytes(eosapi.N(vm), 8, 'little') #scope
    r = eosapi.push_action(account,'delete',msg,{account:'active'})
    assert r
Example #29
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_action('auction1', 'start', msg,
                               {'auction1': 'active'})
        assert r
Example #30
0
def deploy():
    src_dir = get_src_dir()
    src_file = os.path.join(src_dir, 'lib.py')
    with open(src_file, 'rb') as f:
        src = f.read()
    r = eosapi.push_action('deploytest', 'deploy', src,
                           {'deploytest': 'active'})
    assert r