def test_action_updfungible(self): # create a new fungible pub_key, priv_key = ecc.generate_new_pair() sym_name, sym_prec = fake_symbol() symbol = base.Symbol(name=sym_name, precision=sym_prec) asset = base.new_asset(symbol) newfungible = AG.new_action('newfungible', sym=symbol, creator=pub_key, total_supply=asset(100000)) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(newfungible) trx.add_sign(priv_key) api.push_transaction(trx.dumps()) # add pub2 into manage permission pub2, priv2 = ecc.generate_new_pair() ar1 = base.AuthorizerRef('A', pub_key) ar2 = base.AuthorizerRef('A', pub2) manage = base.PermissionDef('manage', threshold=2) manage.add_authorizer(ar1, weight=1) manage.add_authorizer(ar2, weight=1) updfungible = AG.new_action('updfungible', sym=symbol, manage=manage) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(updfungible) trx.add_sign(priv_key) resp = api.push_transaction(trx.dumps()).text self.assertTrue('transaction_id' in resp)
def test_action_issuefungible(self): # Create a fungible, and then use the issue fungible with the asset pub_key, priv_key = ecc.generate_new_pair() sym_name, sym_prec = fake_symbol() symbol = base.Symbol(name=sym_name, precision=sym_prec) asset = base.new_asset(symbol) newfungible = AG.new_action('newfungible', sym=symbol, creator=pub_key, total_supply=asset(100000)) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(newfungible) trx.add_sign(priv_key) api.push_transaction(trx.dumps()) pub2, priv2 = ecc.generate_new_pair() issuefungible = AG.new_action('issuefungible', address=pub2, number=asset(100), memo='goodluck') trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(issuefungible) trx.add_sign(priv_key) resp = api.push_transaction(trx.dumps()).text self.assertTrue('transaction_id' in resp)
def test_action_updatedomain(self): # Example: Add another user into issue permimssion # Create a new domain pub_key, priv_key = ecc.generate_new_pair() name = fake_name() newdomain = AG.new_action('newdomain', name=name, creator=pub_key) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(newdomain) trx.add_sign(priv_key) api.push_transaction(data=trx.dumps()) # Create manage Permission with both user pub_key2, priv_key2 = ecc.generate_new_pair() # another user ar1 = base.AuthorizerRef('A', pub_key) ar2 = base.AuthorizerRef('A', pub_key2) issue_per = base.PermissionDef('issue', threshold=2) issue_per.add_authorizer(ar1, weight=1) issue_per.add_authorizer(ar2, weight=1) updatedomain = AG.new_action( 'updatedomain', name=name, issue=issue_per) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(updatedomain) trx.add_sign(priv_key) api.push_transaction(data=trx.dumps()) resp = api.get_domain('{"name": "%s"}' % (name)).json() self.assertTrue({'ref': ar2.value(), 'weight': 1} in resp['issue']['authorizers'])
def test_action_transfer(self): pub_key, priv_key = ecc.generate_new_pair() domain_name = fake_name() token_name = fake_name('token') newdomain = AG.new_action('newdomain', name=domain_name, creator=pub_key) issuetoken = AG.new_action( 'issuetoken', domain=domain_name, names=[token_name], owner=[base.Address().set_public_key(pub_key)]) # create a new domain trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(newdomain) trx.add_sign(priv_key) api.push_transaction(trx.dumps()) # issue a new token trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(issuetoken) trx.add_sign(priv_key) api.push_transaction(trx.dumps()) # transfer the token to pub2 pub2, priv2 = ecc.generate_new_pair() transfer = AG.new_action('transfer', domain=domain_name, name=token_name, to=[pub2], memo='haha') trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(transfer) trx.add_sign(priv_key) # priv_key of the owner of this token api.push_transaction(trx.dumps()) resp = api.get_token(''' { "name": "%s", "domain": "%s" } ''' % (token_name, domain_name)).json() self.assertTrue(resp['owner'][0] == pub2.to_string())
def test_action_updatedomain(self): # Example: Add another user into issue permimssion # Create a new domain name = fake_name() newdomain = AG.new_action('newdomain', name=name, creator=user.pub_key) trx = TG.new_trx() trx.add_action(newdomain) trx.add_sign(user.priv_key) api.push_transaction(data=trx.dumps()) # Create manage Permission with both user pub_key2, priv_key2 = ecc.generate_new_pair() # another user ar1 = base.AuthorizerRef('A', user.pub_key) ar2 = base.AuthorizerRef('A', pub_key2) issue_per = base.PermissionDef('issue', threshold=2) issue_per.add_authorizer(ar1, weight=1) issue_per.add_authorizer(ar2, weight=1) updatedomain = AG.new_action('updatedomain', name=name, issue=issue_per) trx = TG.new_trx() trx.add_action(updatedomain) trx.add_sign(user.priv_key) resp = api.push_transaction(data=trx.dumps()) self.assertTrue('transaction_id' in resp.text)
def test_action_issuefungible(self): # Create a fungible, and then use the issue fungible with the asset sym_name, sym_id, sym_prec = fake_symbol() symbol = base.Symbol(sym_name=sym_name, sym_id=sym_id, precision=sym_prec) asset = base.new_asset(symbol) newfungible = AG.new_action('newfungible', name=sym_name, sym_name=sym_name, sym=symbol, creator=user.pub_key, total_supply=asset(100000)) trx = TG.new_trx() trx.add_action(newfungible) trx.add_sign(user.priv_key) api.push_transaction(trx.dumps()) pub2, priv2 = ecc.generate_new_pair() issuefungible = AG.new_action( 'issuefungible', address=base.Address().set_public_key(pub2), number=asset(100), memo='goodluck') trx = TG.new_trx() trx.add_action(issuefungible) trx.add_sign(user.priv_key) resp = api.push_transaction(trx.dumps()).text self.assertTrue('transaction_id' in resp)
def test_action_addmeta(self): pub_key, priv_key = ecc.generate_new_pair() # create a new domain domain_name = fake_name() newdomain = AG.new_action('newdomain', name=domain_name, creator=pub_key) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(newdomain) trx.add_sign(priv_key) api.push_transaction(trx.dumps()) ar = base.AuthorizerRef('A', pub_key) # add meta to this domain addmeta = AG.new_action('addmeta', meta_key='meta-key-test', meta_value='meta-value-test', creator=ar, domain='domain', key=domain_name) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(addmeta) trx.add_sign(priv_key) api.push_transaction(trx.dumps())
def test_action_issuetoken(self): pub_key, priv_key = ecc.generate_new_pair() domain_name = fake_name() token_name = fake_name('token') newdomain = AG.new_action('newdomain', name=domain_name, creator=pub_key) issuetoken = AG.new_action('issuetoken', domain=domain_name, names=[token_name], owner=[pub_key]) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(newdomain) trx.add_sign(priv_key) api.push_transaction(trx.dumps()) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(issuetoken) trx.add_sign(priv_key) api.push_transaction(trx.dumps()) resp = api.get_token(''' { "name": "%s", "domain": "%s" } ''' % (token_name, domain_name)).json() self.assertTrue(resp['domain'] == domain_name)
def test_action_newfungible(self): pub_key, priv_key = ecc.generate_new_pair() sym_name, sym_prec = fake_symbol() symbol = base.Symbol(name=sym_name, precision=sym_prec) asset = base.new_asset(symbol) newfungible = AG.new_action( 'newfungible', sym=symbol, creator=pub_key, total_supply=asset(100000)) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(newfungible) trx.add_sign(priv_key) resp = api.push_transaction(trx.dumps()).text self.assertTrue('transaction_id' in resp)
def test_action_newdomain(self): pub_key, priv_key = ecc.generate_new_pair() name = fake_name() newdomain = AG.new_action('newdomain', name=name, creator=pub_key) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(newdomain) trx.add_sign(priv_key) api.push_transaction(data=trx.dumps()) resp = api.get_domain('''{"name": "%s"}''' % (name)).json() self.assertTrue(pub_key.to_string() == resp['creator'])
def test_action_newgroup(self): pub_key, priv_key = ecc.generate_new_pair() name = fake_name('group') group_json = json.loads(group_json_raw) group_json['name'] = name group_json['group']['name'] = name group_json['group']['key'] = str(pub_key) newgroup = AG.new_action_from_json('newgroup', json.dumps(group_json)) trx = transaction.Transaction() trx.set_header(url=host_url) trx.add_action(newgroup) trx.add_sign(priv_key) api.push_transaction(data=trx.dumps()).text resp = api.get_group('''{"name": "%s"}''' % (name)).json() self.assertTrue(pub_key.to_string() == resp['key'])
def test_action_transferft(self): # Create a fungible and issue sym_name, sym_id, sym_prec = fake_symbol() symbol = base.Symbol(sym_name=sym_name, sym_id=sym_id, precision=sym_prec) asset = base.new_asset(symbol) newfungible = AG.new_action('newfungible', name=sym_name, sym_name=sym_name, sym=symbol, creator=user.pub_key, total_supply=asset(100000)) trx = TG.new_trx() trx.add_action(newfungible) trx.add_sign(user.priv_key) api.push_transaction(trx.dumps()) issuefungible = AG.new_action('issuefungible', address=user.pub_key, number=asset(100), memo='goodluck') trx = TG.new_trx() trx.add_action(issuefungible) trx.add_sign(user.priv_key) api.push_transaction(trx.dumps()) # Transfer asset to pub2 pub2, priv2 = ecc.generate_new_pair() transferft = AG.new_action('transferft', _from=user.pub_key, to=pub2, number=asset(1), memo='goodjob') trx = TG.new_trx() trx.add_action(transferft) trx.add_sign(user.priv_key) resp = api.push_transaction(trx.dumps()).text self.assertTrue('transaction_id' in resp)
def test_action_transfer(self): domain_name = fake_name() token_name = fake_name('token') newdomain = AG.new_action('newdomain', name=domain_name, creator=user.pub_key) issuetoken = AG.new_action( 'issuetoken', domain=domain_name, names=[token_name], owner=[base.Address().set_public_key(user.pub_key)]) # create a new domain trx = TG.new_trx() trx.add_action(newdomain) trx.add_sign(user.priv_key) api.push_transaction(trx.dumps()) # issue a new token trx = TG.new_trx() trx.add_action(issuetoken) trx.add_sign(user.priv_key) api.push_transaction(trx.dumps()) # transfer the token to pub2 pub2, priv2 = ecc.generate_new_pair() transfer = AG.new_action('transfer', domain=domain_name, name=token_name, to=[pub2], memo='haha') trx = TG.new_trx() trx.add_action(transfer) trx.add_sign(user.priv_key) # priv_key of the owner of this token resp = api.push_transaction(trx.dumps()) self.assertTrue('transaction_id' in resp.text)
def main(url, start_evtd, evtd_path, public_key, private_key): global evtdout evtdout = None p = None if start_evtd == True: evtdout = open('/tmp/evt_api_tests_evtd.log', 'w') p = subprocess.Popen([evtd_path, '-e', '--http-validate-host=false', '--charge-free-mode', '--loadtest-mode', '--plugin=evt::mongo_db_plugin', '--plugin=evt::history_plugin', '--plugin=evt::history_api_plugin', '--plugin=evt::chain_api_plugin', '--plugin=evt::evt_api_plugin', '--plugin=evt::evt_link_plugin', '--producer-name=evt', '--delete-all-blocks', '-d', '/tmp/evt', '-m', 'mongodb://127.0.0.1:27017'], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=evtdout, shell=False) # wait for evtd to initialize time.sleep(3) try: global domain_name domain_name = 'cookie' global token1_name, token2_name, token3_name token1_name = fake_name('token') token2_name = fake_name('token') token3_name = 'tpass' global group_name group_name = fake_name('group') global sym_name, sym_id, sym_prec sym_name, sym_id, sym_prec = fake_symbol() sym_id = 3 sym_prec = 5 global pub2, priv2 pub2, priv2 = ecc.generate_new_pair() global evt_pub, priv_evt evt_pub = ecc.PublicKey.from_string( 'EVT6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV') priv_evt = ecc.PrivateKey.from_string( '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3') global TG TG = transaction.TrxGenerator(url=url, payer=public_key) global user user = base.User.from_string(public_key, private_key) global api, EvtAsset, AG api = api.Api(url) EvtAsset = base.EvtAsset AG = action.ActionGenerator() pre_action() suite = unittest.TestLoader().loadTestsFromTestCase(Test) runner = unittest.TextTestRunner() result = runner.run(suite) finally: if p is not None: p.kill() if evtdout is not None: evtdout.close()
def __init__(self): self.pub_key, self.priv_key = ecc.generate_new_pair()
def create(config): f = open('launch.config', 'r') text = f.read() f.close() paras = json.loads(text) producer_number = paras['producer_number'] # the number of the producer nodes_number = paras['nodes_number'] # the number of nodes we run evtd_port_http = paras[ 'evtd_port_http'] # the begin port of nodes port,port+1 .... evtd_port_p2p = paras[ 'evtd_port_p2p'] # the begin port of nodes port,port+1 .... evtd_dir = paras['evtd_dir'] # the data directory of the evtd use_tmpfs = paras['use_tmpfs'] # use the tmpfs or not tmpfs_size = paras['tmpfs_size'] # the memory usage per node client = docker.from_env() print('check and free the container before') free_container('evtd_', client) # network=client.networks.create("evt-net",driver="bridge") # begin the nodes one by one print('begin open the evtd') for i in range(0, nodes_number): # create files in evtd_dir if (not os.path.exists(evtd_dir)): os.mkdir(evtd_dir, 0o755) file = os.path.join(evtd_dir, 'dir_{}'.format(i)) if (os.path.exists(file)): print("Warning: the file before didn't freed ") else: os.mkdir(file, 0o755) # make the command cmd = command('evtd.sh') cmd.add_option('--delete-all-blocks') if (i < producer_number): cmd.add_option('--enable-stale-production') cmd.add_option('--producer-name=evt') libevt.init_lib() pub_key, priv_key = ecc.generate_new_pair() cmd.add_option('--private-key={}'.format(priv_key.to_string())) # cmd.add_option('--private-key=5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3') cmd.add_option('--http-server-address=evtd_{}:{}'.format(i, 8888 + i)) cmd.add_option('--p2p-listen-endpoint=evtd_{}:{}'.format(i, 9876 + i)) # cmd.add_option(('--p2p-peer-address=evtd_{}:{}'.format((i+1)%nodes_number, 9876+(i+1)%nodes_number))) for j in range(0, nodes_number): if (i == j): continue cmd.add_option( ('--p2p-peer-address=evtd_{}:{}'.format(j, 9876 + j))) # break # run the image evtd in container if (not use_tmpfs): print('********evtd {} **************'.format(i)) print('name: evtd_{}'.format(i)) print('nework: evt-net') print('http port: {} /tcp: {}'.format(evtd_port_http + i, 8888 + i)) print('p2p port: {} /tcp: {}'.format(evtd_port_p2p + i, 9876 + i)) print('mount location: {}'.format(file)) print('****************************') container = client.containers.run( image='everitoken/evt:latest', name='evtd_{}'.format(i), command=cmd.get_arguments(), network='evt-net', ports={ '{}'.format(evtd_port_http + i): 8888 + i, '{}/tcp'.format(evtd_port_p2p + i): 9876 + i }, detach=True, volumes={file: { 'bind': '/opt/evtd/data', 'mode': 'rw' }}) else: print('********evtd {} **************'.format(i)) print('name: evtd_{}'.format(i)) print('nework: evt-net') print('http port: {} /tcp: {}'.format(evtd_port_http + i, 8888 + i)) print('p2p port: {} /tcp: {}'.format(evtd_port_p2p + i, 9876 + i)) print('tmpfs use size: {} M'.format(tmpfs_size)) print('****************************') container = client.containers.run( image='everitoken/evt:latest', name='evtd_{}'.format(i), command=cmd.get_arguments(), network='evt-net', ports={ '{}'.format(evtd_port_http + i): 8888 + i, '{}/tcp'.format(evtd_port_p2p + i): 9876 + i }, detach=True, tmpfs={'/opt/evtd/data': 'size=' + str(tmpfs_size) + 'M'} # )