Esempio n. 1
0
def make_one_batch(i):
    keys = private_keys[i * num_per_batch : (i + 1) * num_per_batch]
    addrs = addresses[i * num_per_batch : (i + 1) * num_per_batch]
    for i in range(int(num_per_batch/2)):
        acc1 = Account(keys[i])
        acc2 = Account(keys[num_per_batch - 1 - i])
        raw_tx, tx_hash = acc1.sign({
            'nonce': 0,
            'value': 1,
            'gasPrice': 1,
            'gas': 21000,
            'to': bytes(bytearray.fromhex(addrs[num_per_batch - 1 - i][2:])),
            'data': b'',
        })
        lines.append('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))

        raw_tx, tx_hash = acc2.sign({
            'nonce': 0,
            'value': 1,
            'gasPrice': 1,
            'gas': 21000,
            'to': bytes(bytearray.fromhex(addrs[i][2:])),
            'data': b'',
        })
        lines.append('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))
def make_one_batch(i):
    users = all_users[i * 2000 : (i+1) * 2000]

    for i in range(num_per_batch):
        acc = Account(users[i]['private_key'])
        raw_tx, tx_hash = acc.sign(kitty_core_contract.functions.approveSiring(
            users[i + num_per_batch]['address'],
            users[i]['kitty'],
        ).buildTransaction({
            'value': 0,
            'gas': 100000000,
            'gasPrice': 1,
        }))
        lines1.append('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))

    for i in range(num_per_batch):
        acc = Account(users[i + num_per_batch]['private_key'])
        raw_tx, tx_hash = acc.sign(kitty_core_contract.functions.breedWithAuto(
            users[i + num_per_batch]['kitty'],
            users[i]['kitty'],
        ).buildTransaction({
            'value': int(1e15),
            'gas': 100000000,
            'gasPrice': 1,
        }))
        lines2.append('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))
Esempio n. 3
0
def make_one_batch():
    users = []
    idsToRemove = []
    ret_set = db.candidates.aggregate([{
        '$sample': {
            'size': num_per_batch * 2
        }
    }])
    for i in ret_set:
        users.append(i)
        idsToRemove.append(i['_id'])

    if len(users) < num_per_batch * 2:
        assert False
    db.candidates.remove({'_id': {'$in': idsToRemove}})

    txs = {}
    hashes = []
    for i in range(num_per_batch):
        acc = Account(users[i]['private_key'])
        raw_tx, tx_hash = acc.sign(
            kitty_core_contract.functions.createSaleAuction(
                users[i]['kitty'],
                int(1e15),
                0,
                86400,
            ).buildTransaction({
                'value': 0,
                'gas': 100000000,
                'gasPrice': 1,
            }))
        txs[tx_hash] = raw_tx
        hashes.append(tx_hash)

    cli.sendTransactions(txs)
    receipts = wait_for_receipts(cli, hashes)

    with open(output, 'a') as f:
        for i in range(num_per_batch):
            receipt = receipts[hashes[i]]
            if receipt['status'] != 1:
                assert False

            processed_receipt = sale_auction_contract.processReceipt(receipt)
            if 'AuctionCreated' not in processed_receipt:
                assert False

            acc = Account(users[i + num_per_batch]['private_key'])
            raw_tx, tx_hash = acc.sign(
                sale_auction_contract.functions.bid(
                    users[i]['kitty']).buildTransaction({
                        'value': int(1e15),
                        'gas': 100000000,
                        'gasPrice': 1,
                    }))
            f.write('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))
Esempio n. 4
0
def make_one_batch(i):
    users = all_users[i * 1000 : (i+1) * 1000]
    #idsToRemove = []
    #ret_set = db.candidates.aggregate([{'$sample': {'size': num_per_batch}}])
    #for i in ret_set:
    #    users.append(i)
    #    idsToRemove.append(i['_id'])

    #if len(users) < num_per_batch:
    #    assert False
    #db.candidates.remove({'_id': {'$in': idsToRemove}})

    with open(output, 'a') as f:
        for i in range(num_per_batch):
            acc = Account(users[i]['private_key'])
            raw_tx, tx_hash = acc.sign(kitty_core_contract.functions.createSaleAuction(
                users[i]['kitty'],
                int(1e15),
                0,
                86400,
            ).buildTransaction({
                'gas': 100000000,
                'gasPrice': 1,
            }))
            lines.append('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))
def make_one_batch(i):
    for j in range(int(num_per_batch / 2)):
        acc = Account(private_keys[int(i * num_per_batch + j)])
        raw_tx, tx_hash = acc.sign(
            ds_token_contract.functions.transfer(
                addresses[int(i * num_per_batch + num_per_batch / 2 + j)],
                1,
            ).buildTransaction({
                'gas': 10000000000,
                'gasPrice': 1,
            }))
        lines.append('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))
Esempio n. 6
0
def make_one_batch(i):
    users = all_users[i * 1000:(i + 1) * 1000]

    for i in range(num_per_batch):
        acc = Account(users[i]['private_key'])
        raw_tx, tx_hash = acc.sign(
            kitty_core_contract.functions.createSiringAuction(
                users[i]['kitty'],
                int(1e15),
                0,
                86400,
            ).buildTransaction({
                'gas': 100000000,
                'gasPrice': 1,
            }))
        lines.append('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))
Esempio n. 7
0
_, contract_interface = compiled_sol.popitem()
cli = Cli(HTTPProvider("http://localhost:8080"))

example_contract = cli.eth.contract(abi=contract_interface['abi'],
                                    bytecode=contract_interface['bin'])
tx = example_contract.constructor(1).buildTransaction({
    'nonce': 1,
    'gas': 100000,
    'gasPrice': 100,
})
print(tx)

account = Account(
    "cfac4f5fa828072ba8313b0686f02f576fa0fc8caba947569429e88968577865")
raw_tx, tx_hash = account.sign(tx)
# print("raw_tx = {}, tx_hash = {}".format(raw_tx, tx_hash))

cli.sendTransactions({tx_hash: raw_tx})
receipt = cli.getTransactionReceipt(tx_hash)
example_contract.setAddress(receipt['contractAddress'])
tx = example_contract.functions.func1(2).buildTransaction({
    'nonce': 2,
    'gas': 200000,
    'gasPrice': 100,
})
raw_tx, tx_hash = account.sign(tx)
cli.sendTransactions({tx_hash: raw_tx})

balance = cli.getBalance("1234567890123456789012345678901234567890", height=1)
print('balance = {}'.format(balance))
kitty_core = compiled_sol['./contract/KittyCore.sol:KittyCore']
kitty_core_contract = cli.eth.contract(
    abi=kitty_core['abi'],
    address='b1e0e9e68297aae01347f6ce0ff21d5f72d3fa0f',
)

coo_private_key = '2289ae919f03075448d567c9c4a22846ce3711731c895f1bea572cef25bb346f'
user_private_key = 'd9815a0fa4f31172530f17a6ae64bf5f00a3a651f3d6476146d2c62ae5527dc4'

coo = Account(coo_private_key)
user1 = Account(user_private_key)
user2_address = '230DCCC4660dcBeCb8A6AEA1C713eE7A04B35cAD'

raw_tx, tx_hash = coo.sign(
    kitty_core_contract.functions.createPromoKitty(
        0, user1.address()).buildTransaction({
            'gas': 1000000,
            'gasPrice': 1,
        }))
cli.sendTransactions({tx_hash: raw_tx})

receipts = []
while True:
    receipts = cli.getTransactionReceipts([tx_hash])
    if receipts is None or len(receipts) != 1:
        time.sleep(1)
        continue
    break
events = kitty_core_contract.processReceipt(receipts[0])
new_kitty = events['Birth']['kittyId']
print(
    f'New kitty {new_kitty} born and assigned to {events["Birth"]["owner"][24:]}'
Esempio n. 9
0
storage_svc = compiled_sol['./contract/MainService.sol:StorageService']
computing_svc = compiled_sol['./contract/MainService.sol:ComputingService']
main_svc = compiled_sol['./contract/MainService.sol:MainService']

cli = Cli(HTTPProvider(frontend))
storage_svc_contract = cli.eth.contract(abi=storage_svc['abi'],
                                        bytecode=storage_svc['bin'])
computing_svc_contract = cli.eth.contract(abi=computing_svc['abi'],
                                          bytecode=computing_svc['bin'])
main_svc_contract = cli.eth.contract(abi=main_svc['abi'],
                                     bytecode=main_svc['bin'])

account = Account(private_key)
raw_tx, tx_hash = account.sign(
    storage_svc_contract.constructor().buildTransaction({
        'nonce': 1,
        'gas': 1000000000,
        'gasPrice': 1,
    }))
cli.sendTransactions({tx_hash: raw_tx})
receipts = wait_for_receipts(cli, [tx_hash])
storage_svc_address = receipts[tx_hash]['contractAddress']

raw_tx, tx_hash = account.sign(
    computing_svc_contract.constructor().buildTransaction({
        'nonce': 2,
        'gas': 1000000000,
        'gasPrice': 1,
    }))
cli.sendTransactions({tx_hash: raw_tx})
receipts = wait_for_receipts(cli, [tx_hash])
computing_svc_address = receipts[tx_hash]['contractAddress']
Esempio n. 10
0
acc_from = Account('316b4cb5409a7c8998c04ad81ffb5f771c70ae7305cbd976845c27320aa2fb36')
to_address1 = 'd024a83F83394B90AA2db581250Bc00B0B0f414a'
to_address2 = 'd7cB260c7658589fe68789F2d678e1e85F7e4831'

origin_balance_from = cli.getBalance(acc_from.address())
origin_balance_to1 = cli.getBalance(to_address1)
origin_balance_to2 = cli.getBalance(to_address2)
print('Before transfer:')
print(f'\tBalance of {acc_from.address()}: {origin_balance_from}')
print(f'\tBalance of {to_address1}: {origin_balance_to1}')
print(f'\tBalance of {to_address2}: {origin_balance_to2}')

raw_tx1, tx_hash1 = acc_from.sign({
    'nonce': 1,
    'value': origin_balance_from - 21000,
    'gas': 21000,
    'gasPrice': 1,
    'data': b'',
    'to': bytearray.fromhex(to_address1)
})
raw_tx2, tx_hash2 = acc_from.sign({
    'nonce': 2,
    'value': origin_balance_from - 21000,
    'gas': 21000,
    'gasPrice': 1,
    'data': b'',
    'to': bytearray.fromhex(to_address2)
})
cli.sendTransactions({tx_hash1: raw_tx1, tx_hash2: raw_tx2})

while True:
    receipts = cli.getTransactionReceipts([tx_hash1, tx_hash2])
Esempio n. 11
0
    for line in f:
        line = line.rstrip('\n')
        segments = line.split(',')
        addresses.append(segments[1])

lines = []
print('len(addresses) = {}'.format(len(addresses)))
num_batches = int(math.ceil(len(addresses)) / 1000)
#num_batches = 1
for i in range(num_batches):
    batch_start = i * 1000
    batch_end = (i + 1) * 1000
    if i == num_batches - 1:
        batch_end = len(addresses)
    print('batch_start = {}, batch_end = {}'.format(batch_start, batch_end))

    for j in range(batch_start, batch_end):
        raw_tx, tx_hash = owner.sign(
            ds_token_contract.functions.mint(
                addresses[j],
                10000000000,
            ).buildTransaction({
                'gas': 10000000000,
                'gasPrice': 1,
            }))
        lines.append('{},{}'.format(raw_tx.hex(), tx_hash.hex()))

print('len(lines) = {}'.format(len(lines)))
with open(output, 'a') as f:
    for l in lines:
        f.write(l + '\n')
coo = Account(coo_private_key)
num_batches = int(math.ceil(len(private_keys)) / 1000)
for i in range(num_batches):
    batch_start = i * 1000
    batch_end = (i + 1) * 1000
    if i == num_batches - 1:
        batch_end = len(private_keys)
    print('batch_start = {}, batch_end = {}'.format(batch_start, batch_end))

    txs = {}
    hashes = []
    for j in range(batch_start, batch_end):
        raw_tx, tx_hash = coo.sign(
            kitty_core_contract.functions.createPromoKitty(
                j, addresses[j]).buildTransaction({
                    'nonce': j,
                    'gas': 1000000,
                    'gasPrice': 1,
                }))
        txs[tx_hash] = raw_tx
        hashes.append(tx_hash)

    cli.sendTransactions(txs)
    candidates = []
    receipts = wait_for_receipts(cli, hashes)
    for j in range(len(hashes)):
        receipt = receipts[hashes[j]]
        if receipt['status'] != 1:
            assert False

        processed_receipt = kitty_core_contract.processReceipt(receipt)
Esempio n. 13
0
from utils import wait_for_receipt

frontend = sys.argv[1]
private_key = sys.argv[2]

compiled_sol = compile_files(
    [
        './contract/ConcurrentCounter.sol',
        './contract/ConcurrentLibInterface.sol'
    ],
    output_values=['abi', 'bin'],
)

concurrent_counter = compiled_sol[
    './contract/ConcurrentCounter.sol:ConcurrentCounter']
cli = Cli(HTTPProvider(frontend))
concurrent_counter_contract = cli.eth.contract(
    abi=concurrent_counter['abi'],
    bytecode=concurrent_counter['bin'],
)

account = Account(private_key)
raw_tx, tx_hash = account.sign(
    concurrent_counter_contract.constructor().buildTransaction({
        'nonce': 1,
        'gas': 1000000000,
        'gasPrice': 1,
    }))
cli.sendTransactions({tx_hash: raw_tx})
receipt = wait_for_receipt(cli, tx_hash)
print(f'python test.py {frontend} {private_key} {receipt["contractAddress"]}')
Esempio n. 14
0
    get_keys_by_weights(private_keys, config['test_case_weights'],
                        'kitties_exchanger'), kitty_exchanger_keys)

cli = Cli(HTTPProvider(frontend))
kitty_core_contract = cli.eth.contract(abi=kitty_core['abi'],
                                       bytecode=kitty_core['bin'])

# 1. Deploy KittyCore.
ceo = Account(ceo_private_key)
coo = Account(coo_private_key)
cfo = Account(cfo_private_key)

raw_tx, tx_hash = ceo.sign(kitty_core_contract.constructor().buildTransaction({
    'nonce':
    1,
    'gas':
    10000000000,
    'gasPrice':
    1,
}))

cli.sendTransactions({tx_hash: raw_tx})
receipts = wait_for_receipts(cli, [tx_hash])
check_receipts(receipts)
kitty_core_address = receipts[tx_hash]['contractAddress']
kitty_core_contract.setAddress(kitty_core_address)

# 2. Deploy SaleClockAuction, SiringAuction and GeneScience.
sale_auction_contract = cli.eth.contract(abi=sale_auction['abi'],
                                         bytecode=sale_auction['bin'])
raw_tx1, tx_hash1 = ceo.sign(
    sale_auction_contract.constructor(kitty_core_address,
Esempio n. 15
0
    abi = sale_auction['abi'],
    address = sale_auction_address
)

# print(kitty_core['abi'])
mongo = MongoClient('localhost', 32768)
db = mongo['parallelkitties']

hashes = []
coo = Account(coo_private_key)
for i in range(10):
    txs = {}
    for j in range(kitty_count):
        raw_tx, tx_hash = coo.sign(kitty_core_contract.functions.createGen0Auction(j+i*kitty_count).buildTransaction({
            'nonce': 100+j+i*kitty_count,
            'gas': 1000000,
            'gasPrice': 1,
        }))
        txs[tx_hash] = raw_tx
        hashes.append(tx_hash)

    cli.sendTransactions(txs)
    time.sleep(30)
    print(i)

#print(txs.keys())
for i in range(10):
    print(i)
    l = hashes[i*kitty_count:(i+1)*kitty_count]
    auctions = []
    kitties = []
Esempio n. 16
0
concurrent_counter_contract = cli.eth.contract(
    abi = concurrent_counter['abi'],
    address = address,
)

account = Account(private_key)
txs = {}
hashes = []

for i in range(100):
    tx = concurrent_counter_contract.functions.increment(i).buildTransaction({
        'nonce': 1 + i,
        'gas': 1000000000,
        'gasPrice': 1,
    })
    raw_tx, tx_hash = account.sign(tx)
    txs[tx_hash] = raw_tx
    hashes.append(tx_hash)

cli.sendTransactions(txs)
receipts = wait_for_receipts(cli, hashes)
for receipt in receipts.values():
    if receipt['status'] != 1:
        print(receipt)
        exit(1)

raw_tx, tx_hash = account.sign(concurrent_counter_contract.functions.getCounter().buildTransaction({
    'gas': 1000000000,
    'gasPrice': 1,
}))
cli.sendTransactions({tx_hash: raw_tx})
Esempio n. 17
0
from ammolite import (Cli, HTTPProvider, Account)
from utils import wait_for_receipt

frontend = sys.argv[1]
private_key = sys.argv[2]

compiled_sol = compile_files(
    ['./contract/PhoneBook.sol', './contract/ConcurrentLibInterface.sol'],
    output_values = ['abi', 'bin']
)

phone_book = compiled_sol['./contract/PhoneBook.sol:PhoneBook']

cli = Cli(HTTPProvider(frontend))
phone_book_contract = cli.eth.contract(
    abi = phone_book['abi'],
    bytecode = phone_book['bin']
)

account = Account(private_key)
raw_tx, tx_hash = account.sign(phone_book_contract.constructor().buildTransaction({
    'nonce': 1,
    'gas': 1000000,
    'gasPrice': 1,
}))
cli.sendTransactions({tx_hash: raw_tx})
receipt = wait_for_receipt(cli, tx_hash)

print('Deployment complete, run this command to start the test:')
print('python3 run.py {} accounts.txt {}'.format(frontend, receipt['contractAddress']))
cli = Cli(HTTPProvider('http://192.168.1.111:8080'))
acc_from = Account(
    '3d381aaf963bc03c634664cddfbf48c71962c2747824bebdf2505d7a5640c47f')
to_address = '0xd024a83F83394B90AA2db581250Bc00B0B0f414a'

origin_balance_from = cli.getBalance(acc_from.address())
origin_balance_to = cli.getBalance(to_address)

print('Before transfer:')
print(f'\tBalance of {acc_from.address()}: {origin_balance_from}')
print(f'\tBalance of {to_address}: {origin_balance_to}')

raw_tx, tx_hash = acc_from.sign({
    'nonce': 1,
    'value': 1000000000,
    'gas': 21000,
    'gasPrice': 10,
    'data': b'',
    'to': bytearray.fromhex(to_address[2:])
})
print(
    f'Transfer 1000000000 from {acc_from.address()} to {to_address}, pay 210000 for gas'
)
cli.sendTransactions({tx_hash: raw_tx})
while True:
    receipts = cli.getTransactionReceipts([tx_hash])
    if receipts is None or len(receipts) != 1:
        time.sleep(1)
        continue
    break

new_balance_from = cli.getBalance(acc_from.address())
def make_one_batch():
    users = []
    idsToRemove = []
    ret_set = db.candidates.aggregate([{
        '$sample': {
            'size': num_per_batch * 2
        }
    }])
    for i in ret_set:
        users.append(i)
        idsToRemove.append(i['_id'])

    if len(users) < num_per_batch * 2:
        assert False
    db.candidates.remove({'_id': {'$in': idsToRemove}})

    txs = {}
    hashes = []
    for i in range(num_per_batch):
        acc = Account(users[i]['private_key'])
        raw_tx, tx_hash = acc.sign(
            kitty_core_contract.functions.approveSiring(
                users[i + num_per_batch]['address'],
                users[i]['kitty'],
            ).buildTransaction({
                'value': 0,
                'gas': 100000000,
                'gasPrice': 1,
            }))
        txs[tx_hash] = raw_tx
        hashes.append(tx_hash)

    cli.sendTransactions(txs)
    receipts = wait_for_receipts(cli, hashes)

    txs = {}
    hashes2 = []
    for i in range(num_per_batch):
        receipt = receipts[hashes[i]]
        if receipt['status'] != 1:
            assert False

        acc = Account(users[i + num_per_batch]['private_key'])
        raw_tx, tx_hash = acc.sign(
            kitty_core_contract.functions.breedWithAuto(
                users[i + num_per_batch]['kitty'],
                users[i]['kitty'],
            ).buildTransaction({
                'value': int(1e15),
                'gas': 100000000,
                'gasPrice': 1,
            }))
        txs[tx_hash] = raw_tx
        hashes2.append(tx_hash)

    cli.sendTransactions(txs)
    receipts = wait_for_receipts(cli, hashes2)
    miner = Account(miner_private_key)
    with open(output, 'a') as f:
        for i in range(num_per_batch):
            receipt = receipts[hashes2[i]]
            if receipt['status'] != 1:
                assert False

            raw_tx, tx_hash = miner.sign(
                kitty_core_contract.functions.giveBirth(
                    users[i + num_per_batch]['kitty']).buildTransaction({
                        'value':
                        0,
                        'gas':
                        100000000,
                        'gasPrice':
                        1,
                    }))
            f.write('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))
Esempio n. 20
0
compiled_sols = compile_files(sols, output_values = ['abi', 'bin'])
ds_token = compiled_sols[sol_dir + 'token.sol:DSToken']

cli = Cli(HTTPProvider(frontend))
ds_token_contract = cli.eth.contract(
    abi = ds_token['abi'],
    bytecode = ds_token['bin'],
)

contract_owner = Account(owner_key)

console = Console()
with console.status('[bold green]Working on tasks...') as status:
    raw_tx, tx_hash = contract_owner.sign(ds_token_contract.constructor(b'DST').buildTransaction({
        'nonce': 1,
        'gas': 10000000000,
        'gasPrice': 1,
    }))
    #print(tx_hash.hex())
    cli.sendTransactions({tx_hash: raw_tx})

    while True:
        time.sleep(1)
        receipts = cli.getTransactionReceipts([tx_hash])
        #print(receipts)
        if receipts is None or len(receipts) != 1:
            continue
        if receipts[0]['status'] != 1:
            console.log('Deploy DSToken failed.')
            exit(1)
        #print(receipts)