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()))
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.transfer( users[num_per_batch + i]['address'], users[i]['kitty'], ).buildTransaction({ 'value': 0, 'gas': 100000000, 'gasPrice': 1, })) lines.append('{},{}\n'.format(raw_tx.hex(), tx_hash.hex()))
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()))
def init_accounts(file): accounts = [] with open(file, 'r') as f: for key in f: # print('---' + key + '---') accounts.append(Account(key[:-1])) return accounts
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(): 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()))
['./contract/MainService.sol', './contract/ConcurrentLibInterface.sol'], output_values=['abi', 'bin']) 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,
from ammolite import (Cli, HTTPProvider, Account) from utils import (wait_for_receipts, compile_contracts) frontend = sys.argv[1] ds_token_address = sys.argv[2] owner_key = sys.argv[3] accounts_file = sys.argv[4] output = sys.argv[5] cli = Cli(HTTPProvider(frontend)) compiled_sols = compile_contracts('../../contracts') ds_token = compiled_sols['../../contracts/token.sol:DSToken'] ds_token_contract = cli.eth.contract(abi=ds_token['abi'], address=ds_token_address) owner = Account(owner_key) addresses = [] with open(accounts_file, 'r') as f: 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:
import sys sys.path.append('../../..') from ammolite import (Cli, HTTPProvider, Account) import time cli = Cli(HTTPProvider('http://192.168.1.111:8080')) 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,
segments = line.split(',') private_keys.append(segments[0]) addresses.append(segments[1]) cli = Cli(HTTPProvider(frontend)) compiled_sol = compile_contracts('./contract') kitty_core = compiled_sol['./contract/KittyCore.sol:KittyCore'] kitty_core_contract = cli.eth.contract( abi=kitty_core['abi'], address=kitty_core_address, ) mongo = MongoClient('localhost', 32768) db = mongo[database] 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,
storage_svc_address = sys.argv[3] computing_svc_address = sys.argv[4] main_svc_address = sys.argv[5] compiled_sol = compile_files( ['./contract/MainService.sol', './contract/ConcurrentLibInterface.sol'], output_values=['abi']) main_svc = compiled_sol['./contract/MainService.sol:MainService'] cli = Cli(HTTPProvider(frontend)) main_service_contract = cli.eth.contract( abi=main_svc['abi'], address=main_svc_address, ) account = Account(private_key) buf_size = 1000 batch_size = 10 index = 0 buf = [] def create_new_txs(offset): txs = [] for i in range(batch_size): tx = main_service_contract.functions.func( offset + i, int(0x010203040506), #b'This is the data segment', storage_svc_address, int(0x010203),
abi = kitty_core['abi'], address = kitty_core_address ) sale_auction = compiled_sol['./contract/Auction/SaleClockAuction.sol:SaleClockAuction'] sale_auction_contract = cli.eth.contract( 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)
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']))
''' compiled_sol = compile_source(source) _, 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)
import sys sys.path.append('../../..') from ammolite import (Cli, HTTPProvider, Account) import time 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:
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()))
sols = [] for root, _, files in os.walk(sol_dir): for f in files: if f.endswith('.sol'): sols.append(os.path.join(root, f)) 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)
for file in files: if file.endswith('.sol'): sources.append(os.path.join(root, file)) cli = Cli(HTTPProvider('http://192.168.1.111:8080')) compiled_sol = compile_files(sources, output_values=['abi', 'bin']) 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:
['./contract/PhoneBook.sol', './contract/ConcurrentLibInterface.sol'], output_values=['abi']) phone_book = compiled_sol['./contract/PhoneBook.sol:PhoneBook'] cli = Cli(HTTPProvider(frontend)) contract = cli.eth.contract( abi=phone_book['abi'], address=contract_address, ) accounts = [] with open(account_file, 'r') as f: lines = f.readlines() for l in lines: parts = l.split(',') accounts.append(Account(parts[0])) txs = {} for acc in accounts: tx = contract.functions.set(12345678).buildTransaction({ 'gas': 1000000, 'gasPrice': 1, }) raw_tx, tx_hash = acc.sign(tx) txs[tx_hash] = raw_tx print(txs) while True: cli.sendTransactions(txs) time.sleep(10)
write_private_keys( get_keys_by_weights(private_keys, config['test_case_weights'], 'siring_auction_bidder'), siring_auction_bidder_keys) write_private_keys( get_keys_by_weights(private_keys, config['test_case_weights'], 'kitty_raiser'), kitty_raiser_keys) write_private_keys( 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)
private_key = sys.argv[2] address = sys.argv[3] compiled_sol = compile_files( ['./contract/ConcurrentCounter.sol', './contract/ConcurrentLibInterface.sol'], output_values = ['abi'], ) concurrent_counter = compiled_sol['./contract/ConcurrentCounter.sol:ConcurrentCounter'] cli = Cli(HTTPProvider(frontend)) 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)