Exemple #1
0
def test_async(sign=True):
    _src_dir = os.path.dirname(__file__)
    actions = []
    eosapi.produce_block()
    for i in range(TRX_COUNT):
        code = struct.pack('QBB', N('async'), 1, 0)
        with open(os.path.join(_src_dir, 'async.py'), 'rb') as f:
            code += eosapi.pack_bytes(b'\x00' + f.read() + b'\n1==(%d)'%(i,))
        setcode_action = [N('eosio'), N('setcode'), [[N('async'), N('active')]], code]
        setabi_action = gen_setabi_action()
        callcode_action = [N('async'), N('sayhello'), [[N('async'), N('active')]], b'hello,world%d'%(i,)]
        actions.append([setcode_action, setabi_action, callcode_action])
    eosapi.push_transactions2(actions, sign, 0, True)
Exemple #2
0
def call_wasm_with_setcode(sign=True):
    _src_dir = os.path.dirname(__file__)
    actions = []
    for i in range(TRX_COUNT):
        code = struct.pack('QBB', N('actiontest'), 0, 0)

        #break the wasm cache
        key_words = b"hello,world"
        wast_file = os.path.join(_src_dir, 'actiontest.wast')
        #        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"hhh%d" % (i, )
            replace_str.zfill(len(key_words))
            data = data.replace(key_words, replace_str)
            wasm = eosapi.wast2wasm(data)
            code += eosapi.pack_bytes(wasm)

        act = [
            N('eosio'),
            N('setcode'), [[N('actiontest'), N('active')]], code
        ]
        setabi_action = gen_setabi_action()
        actions.append([act, setabi_action])

    cost_time = eosapi.push_transactions2(actions, sign)
    start = time.time()
    eosapi.produce_block()
    print('produce_block: ', time.time() - start)
    print(1e6 / (cost_time / TRX_COUNT))

    return 1e6 / (cost_time / TRX_COUNT)
Exemple #3
0
def call_mpy_with_setcode(sign=True):
    _src_dir = os.path.dirname(__file__)
    actions = []
    for i in range(TRX_COUNT):
        code = struct.pack('QBB', N('actiontest'), 1, 0)
        py_file = os.path.join(_src_dir, 'actiontest.py')
        with open(py_file, 'rb') as f:
            src_code = f.read()
        src_code += b'\n1==(%d)' % (i, )

        with open(py_file[:-3] + '2.py', 'wb') as f:
            f.write(src_code)

        mpy_code = eosapi.mp_compile(py_file[:-3] + '2.py')
        code += eosapi.pack_bytes(b'\x01' + mpy_code)

        act = [
            N('eosio'),
            N('setcode'), [[N('actiontest'), N('active')]], code
        ]
        setabi_action = gen_setabi_action()
        actions.append([act, setabi_action])

    cost_time = eosapi.push_transactions2(actions, sign)

    start = time.time()
    eosapi.produce_block()
    print('produce_block: ', time.time() - start)

    print(1e6 / (cost_time / TRX_COUNT))
    return 1e6 / (cost_time / TRX_COUNT)
Exemple #4
0
def test2(count=100):
    actions = []
    for i in range(count):
        act = [N('storagetest'), N('sayhello'), [[N('storagetest'), N('active')]], b'hello,world%d'%(i,)]
        actions.append([act])
    cost_time = eosapi.push_transactions2(actions, True)
    print(1.0/(cost_time/1e6/100.0), cost_time)
Exemple #5
0
def change_active_key():
    key = 'EOS8muoEdY4L9WRYXYB55WmEzYw9A314fW1uMPUqUrFUBMMjWNpxd'
    auth = eosapi.pack_updateauth('test', 'active', 'owner', key, 0)
    act = [N('eosio'), N('updateauth'), [[N('test'), N('active')]], auth]
    r = eosapi.push_transactions2([[act]])
    assert r
    eosapi.produce_block()
Exemple #6
0
def setabi():
    _src_dir = os.path.dirname(__file__)

    setabi = eosapi.pack_setabi(os.path.join(_src_dir, 'lockunlock.abi'), eosapi.N('lockunlock'))
    action = [N('eosio'), N('setabi'), [[N('lockunlock'), N('active')]], setabi]

    cost_time = eosapi.push_transactions2([[action]], sign)
    eosapi.produce_block()
Exemple #7
0
def setcode(sign=True):
    _src_dir = os.path.dirname(__file__)
    code = struct.pack('QBB', N('lockunlock'), 1, 0)
    with open(os.path.join(_src_dir, 'lockunlock.py'), 'rb') as f:
        code += eosapi.pack_bytes(b'\x00'+f.read())
    act = [N('eosio'), N('setcode'), [[N('lockunlock'), N('active')]], code]

    cost_time = eosapi.push_transactions2([[act]], sign)
    eosapi.produce_block()
Exemple #8
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()
Exemple #9
0
def test_module_memory_leak(sign=True):
    _src_dir = os.path.dirname(__file__)
    actions = []
    for i in range(10000):
        code = struct.pack('QBB', N('bugs'), 1, 0)
        with open(os.path.join(_src_dir, 'bugs.py'), 'rb') as f:
            code += eosapi.pack_bytes(b'\x00'+f.read() + b'\n1==(%d)'%(i+100,))
        act = [N('eosio'), N('setcode'), [[N('bugs'), N('active')]], code]
        cost_time = eosapi.push_transactions2([[act]], sign)
        if i % 50 == 0:
            eosapi.produce_block()
Exemple #10
0
def change_owner_key():
    '''
    struct updateauth {
    account_name                      account;
    permission_name                   permission;
    permission_name                   parent;
    authority                         data;
    uint32_t                          delay;
   '''
    key = 'EOS8muoEdY4L9WRYXYB55WmEzYw9A314fW1uMPUqUrFUBMMjWNpxd'
    auth = eosapi.pack_updateauth('hello', 'owner', '', key, 0)
    act = [N('eosio'), N('updateauth'), [[N('hello'), N('owner')]], auth]
    r = eosapi.push_transactions2([[act]])
    assert r
    eosapi.produce_block()
Exemple #11
0
def send_actions(sign=True):
    actions = []
    for i in range(TRX_COUNT):
        act = [
            N('actiontest'),
            N('sayhello'), [[N('actiontest'), N('active')]],
            b'hello,world%d' % (i, )
        ]
        actions.append([act])
    cost_time = eosapi.push_transactions2(actions, sign)
    print(1.0 / (cost_time / 1e6 / 100.0))
    start = time.time()
    eosapi.produce_block()
    print('produce_block: ', time.time() - start)

    return cost_time
Exemple #12
0
def create_multisig_account():
    #PW5KKNC8zM2KVLrb1cw4YNXZ69NLK7Fr5B35wHmsPt35tyiYkY4RR
    test_keys = {
        'EOS8mqCBdG8yiaULU3YyiD1ZhySzt64KjNb1gQiy4GdUPMEQMxVJJ': '5KZB2UCfpD3qCEUviXrgMdwDb6TDpuvuWvZKH85u9mBYK85Rqzd', 
        'EOS8mrwBdRz1zyaBiMexqJw6UybR9gNLzBC1tdLqqcfVdA2TFcgAb': '5KM6MvhsNRUtafGCghEYWXYXqWidaGTKqfsida6h5mNg5ouQUTv', 
        'EOS8mqgm5kx88XzsxsAAKH5vnq1vGNcSZDfJyar17FnTm1HvBRuXi': '5JiwrohmpRR3PjUcf6NpSLBE2QdAUTJZf1tAHYvK7iAUTWnaGgZ',
        'EOS8msM7326VykwCSdEXZrj8U3goUPYWZ84KxBTy6GajGkpQCXQNX': '5K6HPpxgq5qFkRpUcaVdZVr4hmT61EzU1AFEfkm428pEQP59neB',
    }
    all_keys = wallet.list_keys()
    for pub in test_keys:
        priv = test_keys[pub]
        if not pub in all_keys:
            wallet.import_key('mywallet', priv)
    keys = [
            [
                initeos.key1, 
                initeos.key2
            ],
            [
                'EOS8mqCBdG8yiaULU3YyiD1ZhySzt64KjNb1gQiy4GdUPMEQMxVJJ',
                'EOS8mrwBdRz1zyaBiMexqJw6UybR9gNLzBC1tdLqqcfVdA2TFcgAb'
            ],
            [
                 'EOS8mqgm5kx88XzsxsAAKH5vnq1vGNcSZDfJyar17FnTm1HvBRuXi', 
                 'EOS8msM7326VykwCSdEXZrj8U3goUPYWZ84KxBTy6GajGkpQCXQNX'
            ]
        ]
    accounts = ['test', 'test1', 'test2']
    index = 0
    for key in keys:
        a = accounts[index]
        if not eosapi.get_account(a):
            eosapi.create_account('eosio', a, key[0], key[1])
        index += 1

    eosapi.produce_block()
#"test2" must come first to satisfy the tricky verifycation in authority.hpp:validate
    per = '{"threshold" : 100, "keys" : [], "accounts" : [{"permission":{"actor":"test2","permission":"active"},"weight":50},{"permission":{"actor":"test1","permission":"active"},"weight":50}]}'
#    key = 'EOS8muoEdY4L9WRYXYB55WmEzYw9A314fW1uMPUqUrFUBMMjWNpxd'
    auth = eosapi.pack_updateauth('test', 'active', 'owner', per, 0)
    act = [N('eosio'), N('updateauth'), [[N('test'), N('active')]], auth]
    r = eosapi.push_transactions2([[act]])
    assert r
    print(r)
    eosapi.produce_block()
Exemple #13
0
def call_wasm_without_setcode(sign=True):
    _src_dir = os.path.dirname(__file__)
    actions = []
    for i in range(TRX_COUNT):
        act = [
            N('actiontest'),
            N('sayhello'), [[N('actiontest'), N('active')]],
            b'hello,world%d' % (i, )
        ]
        actions.append([act])

    cost_time = eosapi.push_transactions2(actions, sign)

    start = time.time()
    eosapi.produce_block()
    print('produce_block: ', time.time() - start)

    print(1e6 / (cost_time / TRX_COUNT))
    return 1e6 / (cost_time / TRX_COUNT)
Exemple #14
0
def call_py_with_setcode(sign=True):
    _src_dir = os.path.dirname(__file__)
    actions = []
    for i in range(TRX_COUNT):
        code = struct.pack('QBB', N('actiontest'), 1, 0)
        with open(os.path.join(_src_dir, 'actiontest.py'), 'rb') as f:
            code += eosapi.pack_bytes(b'\x00' + f.read() + b'\n1==(%d)' %
                                      (i + 100, ))
        act = [
            N('eosio'),
            N('setcode'), [[N('actiontest'), N('active')]], code
        ]

        setabi_action = gen_setabi_action()
        actions.append([act, setabi_action])

    cost_time = eosapi.push_transactions2(actions, sign)
    print(1e6 / (cost_time / TRX_COUNT))
    start = time.time()
    eosapi.produce_block()
    print('produce_block: ', time.time() - start)

    return 1e6 / (cost_time / TRX_COUNT)