def set_premise_a(neo_path_a, neo_path_b): result = False contract_address = None # 初始化合约B管理员为A用户, contract_address_B = API.contract().deploy_contract(neo_path_b) # 部署智能合约A contract_address_A = API.contract().deploy_contract(neo_path_a) time.sleep(5) (result, response) = API.contract().init_admin(contract_address_B, Config.ontID_A) if not result: raise (Error("init_admin error")) # 用户A创建角色A (result, response) = API.native().bind_role_function( contract_address_B, Config.ontID_A, Config.roleA_hex, ["contractB_Func_A"]) if not result: raise (Error("bind_role_function error [1]")) # setp 1 用户A绑定角色A (result, response) = API.native().bind_user_role( contract_address_B, Config.ontID_A, Config.roleA_hex, [Config.ontID_A]) if not result: raise (Error("bind_user_role error")) if result: return (contract_address_A, contract_address_B) else: raise (Error("set_premise error"))
def set_premise_b(neo_path): result = False contract_address = API.contract().deploy_contract(neo_path) time.sleep(5) (result, response) = API.contract().init_admin(contract_address, Config.ontID_A) if not result: raise (Error("init_admin error")) (result, response) = API.native().bind_role_function( contract_address, Config.ontID_A, Config.roleA_hex, ["transfer", "approve", "transferFrom", "allowance", "balanceOf"]) if not result: raise (Error("bind_role_function error [1]")) # setp 1 用户A绑定角色A (result, response) = API.native().bind_user_role( contract_address, Config.ontID_A, Config.roleA_hex, [Config.ontID_A]) if not result: raise (Error("bind_user_role error")) if result: return contract_address else: raise (Error("set_premise error"))
def test_normal_007_gover(self): process = False try: (wallet_A_address, wallet_B_address, vote_price, node_B_puiblic_key, blocks_per_round, punish_ratio) = test_api.get_config() # step 1 wallet A vote for node B (process, response) = API.native().vote_for_peer(wallet_A_address, [node_B_puiblic_key], [vote_price], 8) self.ASSERT(process, "vote_for_peer error") API.node().wait_gen_block() time.sleep(5) # step 2 wallet A unvote in the second round API.native().commit_dpos() time.sleep(5) (process, response) = API.native().unvote_for_peer(wallet_A_address, [node_B_puiblic_key], [vote_price], 8) self.ASSERT(process, "unvote_for_peer error") API.node().wait_gen_block() time.sleep(5) # step 3 wallet A withdraw ont in the third round API.native().commit_dpos() time.sleep(5) API.native().commit_dpos() time.sleep(5) (process, response) = API.native().withdraw_ont(wallet_A_address, [node_B_puiblic_key], [vote_price]) self.ASSERT(process, "withdraw_ont1 error") # this should be failed (process, response) = API.native().withdraw_ont(wallet_A_address, [node_B_puiblic_key], ["1"], 8) self.ASSERT(not process, "withdraw_ont2 error") except Exception as e: logger.print(e.args[0])
def test_normal_007_benefit(self): try: process = False address1 = Config.NODES[self.m_checknode]["address"] (process, response) = API.rpc().getbalance(address1) self.BLOCK(process, "get balance error[1]") ong1 = int(response["result"]["ong"]) (process, response) = API.native().transfer_ont( Config.NODES[0]["address"], Config.NODES[0]["address"], "1", gas_price=test_config.PRICE_TEST) #判断是否分润,至少需要等待1个共识时间 except_benifit = int( test_api.get_benifit_value( 20000 * test_config.PRICE_TEST * 0.5, 1000, [1000, 1000, 1000, 1000, 1000, 1000, 1000])) logger.print("except_benifit: " + str(except_benifit)) (process, response) = API.native().commit_dpos(sleep=0) self.BLOCK(process, "commit_dpos error") API.node().wait_gen_block() (process, response) = API.rpc().getbalance(address1) self.BLOCK(process, "get balance error[2]") ong2 = int(response["result"]["ong"]) print("before cost[1]: " + str(ong1)) print("after cost[1]: " + str(ong2)) self.ASSERT((int(ong2 - ong1) == int(except_benifit)), "") except Exception as e: logger.print(e.args[0])
def test_init(self): for node_index in range(len(Config.NODES)): API.node().stop_nodes([node_index]) API.node().start_nodes([0, 1, 2, 3, 4, 5, 6], Config.DEFAULT_NODE_ARGS, True, True, config="config-dbft.json") #start_nodes([0,1,2,3,4,5,6], Config.DEFAULT_NODE_ARGS, True, True) for node_index in range(7): API.native().regid_with_publickey(node_index) API.native().init_ont_ong() (test_config.m_contract_addr, test_config.m_contract_txhash) = API.contract().deploy_contract_full( test_config.deploy_neo_1, test_config.name1, test_config.desc, test_config.price) (test_config.m_contract_addr2, test_config.m_contract_txhash2) = API.contract().deploy_contract_full( test_config.deploy_neo_2, test_config.name1, test_config.desc, test_config.price) #A节点是Admin节点 (process, response) = API.contract().init_admin(test_config.m_contract_addr, Config.ontID_A) time.sleep(6) (process, response) = API.native().bind_role_function( test_config.m_contract_addr, Config.ontID_A, Config.roleA_hex, ["auth_put"])
def test_normal_002_benefit(self): process = False try: address1 = Config.NODES[self.m_checknode]["address"] (process, response) = API.rpc().getbalance(address1) self.BLOCK(process, "get balance error") ong1 = int(response["result"]["ong"]) (process, response) = API.native().transfer_ont( Config.NODES[0]["address"], Config.NODES[0]["address"], "1", gas_price=test_config.PRICE_TEST) #判断是否分润,至少需要等待1个共识时间 (process, response) = API.native().commit_dpos(sleep=0) self.BLOCK(process, "commit_dpos error") API.node().wait_gen_block() (process, response) = API.rpc().getbalance(address1) self.BLOCK(process, "get balance error") ong2 = int(response["result"]["ong"]) print("before cost[1]: " + str(ong1)) print("after cost[1]: " + str(ong2)) self.ASSERT(ong2 != ong1, "get balance error") except Exception as e: logger.print(e.args[0]) process = False
def init_bft_node(self, bft_index): API.node().stop_all_nodes() API.node().start_nodes([0, 1, 2, 3, 4], Config.DEFAULT_NODE_ARGS, True, True, program="ontology") logger.info("start bft node: " + "ontology-bft_" + str(bft_index)) API.node().start_nodes([5, 6], Config.DEFAULT_NODE_ARGS, True, True, program="ontology-bft_" + str(bft_index)) for node_index in range(7): API.native().regid_with_publickey(node_index) API.native().init_ont_ong() (test_config.m_contract_addr, test_config.m_contract_txhash) = API.contract().deploy_contract_full( test_config.deploy_neo_1, test_config.name1, test_config.desc, test_config.price) (test_config.m_contract_addr2, test_config.m_contract_txhash2) = API.contract().deploy_contract_full( test_config.deploy_neo_2, test_config.name1, test_config.desc, test_config.price)
def test_init(self): API.node().stop_all_nodes() API.node().start_nodes(range(0, 8), Config.DEFAULT_NODE_ARGS, clear_chain = True, clear_log = True) #time.sleep(10) API.native().init_ont_ong() #time.sleep(20) test_config.contract_address = API.contract().deploy_contract(test_path + "/resource/ontid.json")
def test_normal_013_benefit(self): try: address = Config.NODES[self.m_checknode]["address"] process = False unpeer_node = 10 #未被投票节点 API.native().update_global_param("0", "1000", "32", "10", "0", "100", "5", "5") for i in range(7, 14): test_api.add_candidate_node(i, init_pos=5000, from_node=i - 7) #先共识一次,确保节点都会在下一次共识分红 (process, response) = API.native().commit_dpos(sleep=0) self.BLOCK(process, "commit_dpos error") API.node().wait_gen_block() #交易 (process, response) = API.native().transfer_ont( Config.NODES[0]["address"], Config.NODES[0]["address"], "1", gas_price=test_config.PRICE_TEST) (process, response) = API.rpc().getbalance(address) self.BLOCK(process, "get balance error") normal_ong = int(response["result"]["ong"]) (process, response) = API.rpc().getbalance( Config.NODES[unpeer_node]["address"]) self.BLOCK(process, "get balance error") candidate_ong = int(response["result"]["ong"]) (process, response) = API.native().commit_dpos(sleep=0) self.BLOCK(process, "commit_dpos error") API.node().wait_gen_block() (process, response) = API.rpc().getbalance(address) self.BLOCK(process, "get balance error") normal_ong2 = int(response["result"]["ong"]) (process, response) = API.rpc().getbalance( Config.NODES[unpeer_node]["address"]) self.BLOCK(process, "get balance error") candidate_ong2 = int(response["result"]["ong"]) except_benifit1 = int( test_api.get_candidate_benifit_value( 20000 * test_config.PRICE_TEST, 5000, [5000, 5000, 5000, 5000, 5000, 5000, 5000])) except_benifit2 = 0 logger.info("normal_ong1: " + str(normal_ong)) logger.info("normal_ong2: " + str(normal_ong2)) logger.info("candidate_ong1: " + str(candidate_ong)) logger.info("candidate_ong2: " + str(candidate_ong2)) self.ASSERT((normal_ong2 - normal_ong) == except_benifit2, "benefit normal node error") self.ASSERT((candidate_ong2 - candidate_ong) == except_benifit1, "benefit candidate node error") except Exception as e: logger.print(e.args[0]) process = False
def test_normal_005_benefit(self): try: process = False #启动拜占庭节点 API.node().stop_nodes(self.m_dbft_nodes) API.node().start_nodes(self.m_dbft_nodes, Config.DEFAULT_NODE_ARGS, True, True, program="ontology-bft_1") (process, response) = API.native().update_global_param( "0", "1000", "32", "1", "50", "50", "5", "5") self.BLOCK(process, "updateGlobalParam error") (process, response) = API.rpc().getbalance( Config.NODES[self.m_checknode]["address"]) self.BLOCK(process, "get balance error") ong1 = int(response["result"]["ong"]) (process, response) = API.rpc().getbalance( Config.NODES[self.m_dbft_nodes[0]]["address"]) self.BLOCK(process, "get balance error") dbft_ong1 = int(response["result"]["ong"]) #进行第一轮共识 (process, response) = API.native().commit_dpos(sleep=0) self.BLOCK(process, "commit_dpos error") API.node().wait_gen_block() (process, response) = API.native().transfer_ont( Config.NODES[0]["address"], Config.NODES[0]["address"], "1", gas_price=test_config.PRICE_TEST) (process, response) = API.native().commit_dpos(sleep=0) self.BLOCK(process, "commit_dpos error") API.node().wait_gen_block() (process, response) = API.rpc().getbalance( Config.NODES[self.m_checknode]["address"]) self.BLOCK(process, "get balance error") ong2 = int(response["result"]["ong"]) (process, response) = API.rpc().getbalance( Config.NODES[self.m_dbft_nodes[0]]["address"]) self.BLOCK(process, "get balance error") dbft_ong2 = int(response["result"]["ong"]) #第二轮判断 except_benifit = int( test_api.get_benifit_value( 20000 * test_config.PRICE_TEST * 0.5, 10000, [10000, 10000, 10000, 10000, 10000, 10000, 10000])) self.ASSERT((dbft_ong2 != dbft_ong1), "bft node benefit error") self.ASSERT((ong2 != ong1), "normal node benefit error") except Exception as e: logger.print(e.args[0])
def test_init(self): API.node().stop_all_nodes() API.node().start_nodes(range(0, 7), Config.DEFAULT_NODE_ARGS, clear_chain=True, clear_log=True) API.native().init_ont_ong() os.system(test_config.nodePath + "/ontology account import -s " + test_path + "resource/wallettest.dat -w " + test_config.nodePath + "/wallet.dat") #deploy_contract #API.contract().deploy_contract(); test_config.contractaddress = API.contract().deploy_contract( test_path + "/resource/transferong_ont.json")
def setUp(self): logger.open("test_consensus/" + self._testMethodName + ".log", self._testMethodName) self.m_checknode = 4 time.sleep(2) print("stop all") API.node().stop_all_nodes() print("start all") API.node().start_nodes([0, 1, 2, 3, 4, 5, 6], Config.DEFAULT_NODE_ARGS, True, True) for i in range(0, 7): API.native().regid_with_publickey(i) API.native().init_ont_ong()
def test_normal_012_gover(self): process = False try: (wallet_A_address, wallet_B_address, vote_price, node_B_puiblic_key, blocks_per_round, punish_ratio) = test_api.get_config() API.native().update_global_param("2000000000", "10000", "32", "1", "50", "50", "50", "0") # step 1 wallet A vote for node B (process, response) = API.native().vote_for_peer(wallet_A_address, [node_B_puiblic_key], [vote_price], 8) self.ASSERT(process, "vote_for_peer error") # step 2 black node b (process, response) = API.native().black_node([node_B_puiblic_key]) self.ASSERT(process, "black_node error") API.native().commit_dpos() API.node().wait_gen_block() time.sleep(15) # step 3 withdraw ont (process, response) = API.native().withdraw_ont(wallet_A_address, [node_B_puiblic_key], [vote_price], 8) self.ASSERT(process, "withdraw_ont1 error") # this should be failed (process, response) = API.native().withdraw_ont(wallet_A_address, [node_B_puiblic_key], ["1000"], 8) self.ASSERT(not process, "withdraw_ont2 error") except Exception as e: logger.print(e.args[0])
def add_candidate_node(new_node, init_ont=500000, init_ong=1000, init_pos=1000, from_node=0): #新加入节点, 并申请候选节点 API.node().start_nodes([new_node], clear_chain=True, clear_log=True) (process, response) = API.native().regid_with_publickey(new_node) if not process: return (process, response) (process, response) = API.native().bind_role_function( "0700000000000000000000000000000000000000", ByteToHex(bytes(Config.NODES[0]["ontid"], encoding="utf8")), ByteToHex(b"roleA"), ["registerCandidate"]) if not process: return (process, response) (process, response) = API.native().bind_user_role( "0700000000000000000000000000000000000000", ByteToHex(bytes(Config.NODES[0]["ontid"], encoding="utf8")), ByteToHex(b"roleA"), [ ByteToHex( bytes(Config.NODES[new_node]["ontid"], encoding="utf8")) ]) if not process: return (process, response) API.native().transfer_ont(Config.NODES[from_node]["address"], Config.NODES[new_node]["address"], str(init_ont), gas_price=0) API.native().transfer_ong(Config.NODES[from_node]["address"], Config.NODES[new_node]["address"], str(init_ong), gas_price=0) #time.sleep(10) (process, response) = API.native().register_candidate( Config.NODES[new_node]["pubkey"], Config.NODES[new_node]["address"], str(init_pos), ByteToHex(bytes(Config.NODES[new_node]["ontid"], encoding="utf8")), "1") if not process: return (process, response) (process, response) = API.native().approve_candidate( Config.NODES[new_node]["pubkey"]) return (process, response)
def test_base_001_gover(self): process = False try: (wallet_A_address, wallet_B_address, vote_price, node_B_puiblic_key, blocks_per_round, punish_ratio) = test_api.get_config() # step 1 before vote get balance of wallet A B print("*******", API.rpc().getbalance(wallet_A_address)) balance_of_wallet_A_1 = int(API.rpc().getbalance(wallet_A_address)[1]["result"]["ont"]) balance_of_wallet_B_1 = int(API.rpc().getbalance(wallet_B_address)[1]["result"]["ont"]) # step 2 wallet A vote for node B (process, response) = API.native().vote_for_peer(wallet_A_address, [node_B_puiblic_key], [vote_price], 8) self.ASSERT(process, "vote_for_peer error") API.node().wait_gen_block() # step 3 after vote get balance of wallet A B balance_of_wallet_A_2 = int(API.rpc().getbalance(wallet_A_address)[1]["result"]["ont"]) balance_of_wallet_B_2 = int(API.rpc().getbalance(wallet_B_address)[1]["result"]["ont"]) # step 4 compare self.ASSERT(balance_of_wallet_B_1 == balance_of_wallet_B_2, "balance of wallte B changed.") self.ASSERT(balance_of_wallet_A_1 - balance_of_wallet_A_2 == int(vote_price), "the decrease of balance of wallet A is not %s." % vote_price) except Exception as e: logger.print(e.args[0])
def test_abnormal_003_benefit(self): try: address = Config.NODES[self.m_checknode]["address"] # logger.open("test_003_benefit.log", "test_003_benefit") process = True (process, response) = API.rpc().getbalance(address) self.BLOCK(process, "get balance error[1]") ong1 = int(response["result"]["ong"]) ont1 = int(response["result"]["ont"]) API.node().transfer_ont(0, 0, 9999999999999999999, test_config.PRICE_TEST) #判断是否分润,至少需要等待1个共识时间 (process, response) = API.native().commit_dpos(sleep=0) self.BLOCK(process, "commit_dpos error") API.node().wait_gen_block() (process, response) = API.rpc().getbalance(address) self.BLOCK(process, "get balance error[2]") ong2 = int(response["result"]["ong"]) ont2 = int(response["result"]["ont"]) self.ASSERT((ong2 - ong1) == 0, "error") except Exception as e: logger.print(e.args[0]) process = False
def test_base_030_consensus(self): try: test_api.init() # ensure balance of wallet A is 1000 balance_of_wallet_A1 = int(API.rpc().getbalance( test_config.ADDRESS_A)[1]["result"]["ont"]) (process, response) = API.native().transfer_ont( test_config.ADDRESS_A, test_config.ADDRESS_B, str(balance_of_wallet_A1 - 1000), 0) balance_of_wallet_A1 = int(API.rpc().getbalance( test_config.ADDRESS_A)[1]["result"]["ont"]) balance_of_wallet_B1 = int(API.rpc().getbalance( test_config.ADDRESS_B)[1]["result"]["ont"]) balance_of_wallet_C1 = int(API.rpc().getbalance( test_config.ADDRESS_C)[1]["result"]["ont"]) (process, response) = API.native().transfer_ont(test_config.ADDRESS_A, test_config.ADDRESS_B, "1000", 0, sleep=0) (process, response) = API.native().transfer_ont(test_config.ADDRESS_A, test_config.ADDRESS_C, "1000", 0, sleep=0) API.node().wait_gen_block() balance_of_wallet_A2 = int(API.rpc().getbalance( test_config.ADDRESS_A)[1]["result"]["ont"]) balance_of_wallet_B2 = int(API.rpc().getbalance( test_config.ADDRESS_B)[1]["result"]["ont"]) balance_of_wallet_C2 = int(API.rpc().getbalance( test_config.ADDRESS_C)[1]["result"]["ont"]) self.ASSERT(balance_of_wallet_A2 == 0, "wallet A balance changed[1]") self.ASSERT((balance_of_wallet_A1 + balance_of_wallet_B1 + balance_of_wallet_C1) == (balance_of_wallet_A2 + balance_of_wallet_B2 + balance_of_wallet_C2), "wallet A balance changed[2]") except Exception as e: logger.print(e.args[0])
def test_abnormal_031_consensus(self): try: test_api.init() # ensure balance of wallet A is 1000 balance_of_wallet_A = int(API.rpc().getbalance( test_config.ADDRESS_A)[1]["result"]["ont"]) (process, response) = API.native().transfer_ont( test_config.ADDRESS_A, test_config.ADDRESS_B, str(balance_of_wallet_A - 1000), 0) API.node().wait_gen_block() (process, response) = API.native().approve_ont(test_config.ADDRESS_A, test_config.ADDRESS_B, "1000", 0, sleep=0) (process, response) = API.native().approve_ont(test_config.ADDRESS_A, test_config.ADDRESS_C, "1000", 0, sleep=0) API.node().wait_gen_block() balance_of_wallet_A = int(API.rpc().getbalance( test_config.ADDRESS_A)[1]["result"]["ont"]) self.ASSERT(balance_of_wallet_A == 1000, "wallet A balance changed") (process, responseb) = API.native().allowance_ont(test_config.ADDRESS_A, test_config.ADDRESS_B, 0) # need to check #self.ASSERT(response["result"] == "00" , "allowance to wallet B is not 0") (process, responsec) = API.native().allowance_ont(test_config.ADDRESS_A, test_config.ADDRESS_C, 0) # need to checkADDRESS_C #e803 == 1000 num self.ASSERT( responseb["result"]["Result"] == "e803" or responsec["result"]["Result"] == "e803", "allowance to wallet B/C is not 0") except Exception as e: logger.print(e.args[0])
def init(): API.node().stop_all_nodes() API.node().start_nodes([0,1,2,3,4,5,6], Config.DEFAULT_NODE_ARGS, True, True) for index in range(7): API.native().regid_with_publickey(index, sleep=1) API.native().init_ont_ong() time.sleep(10) (test_config.m_contract_addr, test_config.m_contract_txhash) = API.contract().deploy_contract_full(test_config.deploy_neo_1, test_config.name1, test_config.desc, test_config.price) (test_config.m_contract_addr2, test_config.m_contract_txhash2) = API.contract().deploy_contract_full(test_config.deploy_neo_2, test_config.name2, test_config.desc2, test_config.price) API.node().wait_gen_block() #A节点是Admin节点 (process, response) = API.contract().init_admin(test_config.m_contract_addr, Config.ontID_A) (process, response) = API.native().bind_role_function(test_config.m_contract_addr, Config.ontID_A, Config.roleA_hex, ["auth_put"])
def test_normal_006_benefit(self): try: process = False (process, response) = API.native().update_global_param( "0", "1000", "32", "1", "50", "50", "5", "5") self.BLOCK(process, "updateGlobalParam error") (process, response) = API.rpc().getbalance( Config.NODES[self.m_checknode]["address"]) self.BLOCK(process, "get balance error") ong1 = int(response["result"]["ong"]) (process, response) = API.native().transfer_ont( Config.NODES[0]["address"], Config.NODES[0]["address"], "1", gas_price=test_config.PRICE_TEST) (process, response) = API.rpc().getbalance( Config.NODES[self.m_checknode]["address"]) self.BLOCK(process, "get balance error") ong2 = int(response["result"]["ong"]) #第一轮判断 self.ASSERT(ong1 == ong2, "benefit error") #进行第一轮共识 (process, response) = API.native().commit_dpos(sleep=0) self.BLOCK(process, "commit_dpos error") API.node().wait_gen_block() (process, response) = API.rpc().getbalance( Config.NODES[self.m_checknode]["address"]) self.BLOCK(process, "get balance error") ong3 = int(response["result"]["ong"]) #第二轮判断 except_benifit = int( test_api.get_benifit_value( 20000 * test_config.PRICE_TEST * 0.5, 10000, [10000, 10000, 10000, 10000, 10000, 10000, 10000])) self.ASSERT((ong3 - ong2) == except_benifit, "first benefit error") except Exception as e: logger.print(e.args[0])
def native_transfer_ont(pay_address, get_address, amount, node_index1=None, errorcode1=0): return API.native().transfer_ont(pay_address, get_address, str(amount), node_index=node_index1, errorcode=errorcode1)
def test_normal_015_gover(self): process = False try: (wallet_A_address, wallet_B_address, vote_price, node_B_puiblic_key, blocks_per_round, punish_ratio) = test_api.get_config() API.native().update_global_param("2000000000","10000","32","10","50","50","50","50") time.sleep(15) # step 1 wallet A vote for node B (process, response) = API.native().vote_for_peer(Config.NODES[8]["address"], [node_B_puiblic_key], ["90000"], 8) self.ASSERT(process, "vote_for_peer error") # step 1 wallet A vote for node B (process, response) = API.native().vote_for_peer(wallet_A_address, [node_B_puiblic_key], ["10000"]) self.ASSERT(process, "vote_for_peer error") except Exception as e: logger.print(e.args[0])
def test_normal_004_benefit(self): try: process = False address_stop = Config.NODES[self.m_stop_2_nodes[0]]["address"] (process, response) = API.rpc().getbalance(address_stop) self.BLOCK(process, "get balance error[1]") ong_stop1 = int(response["result"]["ong"]) API.node().stop_nodes(self.m_stop_2_nodes) address1 = Config.NODES[1]["address"] (process, response) = API.rpc().getbalance(address1) self.BLOCK(process, "get balance error[2]") ong1 = int(response["result"]["ong"]) (process, response) = API.native().transfer_ont( Config.NODES[0]["address"], Config.NODES[0]["address"], "1", gas_price=test_config.PRICE_TEST) #判断是否分润,至少需要等待1个共识时间 (process, response) = API.native().commit_dpos(sleep=0) self.BLOCK(process, "commit_dpos error") API.node().wait_gen_block() (process, response) = API.rpc().getbalance(address1) self.BLOCK(process, "get balance error[3]") ong2 = int(response["result"]["ong"]) self.BLOCK(ong2 != ong1, "no benefit[1]") #start_nodes(self.m_stop_2_nodes) #time.sleep(10) (process, response) = API.rpc().getbalance(address_stop) self.BLOCK(process, "get balance error[4]") ong_stop2 = int(response["result"]["ong"]) print("no benefit, before cost[1]: " + str(ong_stop1)) print("no benefit, after cost[1]: " + str(ong_stop2)) self.ASSERT(ong_stop2 != ong_stop1, "benefit[2]") except Exception as e: logger.print(e.args[0]) process = False
def test_abnormal_012_consensus(self): process = False try: storage_key = ByteToHex(b'Test Key 12') storage_value = ByteToHex(b'Test Value 12') for i in range(1, 4): self.init_bft_node(i) API.node().wait_gen_block() time.sleep(5) #A节点是Admin节点 (process, response) = API.contract().init_admin( test_config.m_contract_addr, Config.ontID_A, sleep=0) self.ASSERT(process, "init_admin error...") API.node().wait_gen_block() time.sleep(2) (process, response) = API.native().bind_role_function( test_config.m_contract_addr, Config.ontID_A, Config.roleA_hex, ["auth_put"], sleep=0) self.ASSERT(process, "bind_role_function error...") API.node().wait_gen_block() time.sleep(2) (process, response) = API.contract().invoke_function( test_config.m_contract_addr, "auth_put", Config.ontID_B, "1", argvs=[{ "type": "bytearray", "value": storage_key }, { "type": "bytearray", "value": storage_value }], sleep=0) self.ASSERT(process, "invoke_function put error...") API.node().wait_gen_block() time.sleep(2) (process, response) = API.contract().invoke_function( test_config.m_contract_addr, "get", Config.ontID_B, "1", argvs=[{ "type": "bytearray", "value": storage_key }]) self.ASSERT(response["result"]["Result"] == '', "invoke_function get error...") except Exception as e: logger.print(e.args[0])
def setUp(self): logger.open("test_benefit_model/" + self._testMethodName + ".log", self._testMethodName) if self._testMethodName == "test_init": return API.node().stop_all_nodes() API.node().start_nodes([0, 1, 2, 3, 4, 5, 6], Config.DEFAULT_NODE_ARGS, True, True) for i in range(7): API.native().regid_with_publickey(i, sleep=0) API.native().init_ont_ong(sleep=0) time.sleep(5) self.m_current_node = 0 self.m_stop_2_nodes = [5, 6] self.m_new_2_nodes = [7, 8] self.m_checknode = 4 self.m_dbft_nodes = [5, 6] #拜占庭节点
def test_base_033_consensus(self): process = False try: test_api.add_candidate_node(7, init_pos=2000, from_node=0) test_api.getStorageConf("vbftConfig") # step 2 wallet A unvote in the second round (process, response) = API.native().commit_dpos() API.node().wait_gen_block() test_api.getStorageConf("vbftConfig") self.ASSERT(process, "") except Exception as e: logger.print(e.args[0])
def test_normal_006_gover(self): process = False try: (wallet_A_address, wallet_B_address, vote_price, node_B_puiblic_key, blocks_per_round, punish_ratio) = test_api.get_config() # step 1 wallet A vote for node B (process, response) = API.native().vote_for_peer(wallet_A_address, [node_B_puiblic_key], [vote_price], 8) self.ASSERT(process, "vote_for_peer error") # step 2 wallet A unvote in the same round (process, response) = API.native().unvote_for_peer(wallet_A_address, [node_B_puiblic_key], [vote_price], 8) self.ASSERT(process, "unvote_for_peer error") # step 3 wallet A withdraw ont (process, response) = API.native().withdraw_ont(wallet_A_address, [node_B_puiblic_key], [vote_price], 8) self.ASSERT(process, "withdraw_ont error") # this should be failed (process, response) = API.native().withdraw_ont(wallet_A_address, [node_B_puiblic_key], ["1"]) self.ASSERT(not process, "withdraw_ont error") except Exception as e: logger.print(e.args[0])
def set_premise(neo_path): result = False contract_address = None contract_address = API.contract().deploy_contract(neo_path) time.sleep(5) (result, response) = API.contract().init_admin(contract_address, Config.ontID_A) if not result: raise (Error("init_admin error")) (result, response) = API.native().bind_role_function( contract_address, Config.ontID_A, Config.roleA_hex, ["A", "C"]) if not result: raise (Error("bind_role_function error [1]")) (result, response) = API.native().bind_role_function( contract_address, Config.ontID_A, Config.roleB_hex, ["B", "C"]) if not result: raise (Error("bind_role_function error [2]")) if not result: raise (Error("set_premise error")) return contract_address
def test_normal_100_getmerkleproof(self): try: (process, response) = API.native().transfer_ont(Config.NODES[0]["address"], Config.NODES[1]["address"], "100000000", 0, twice=True, check_state=False) tx_hash_failed = response["txhash"] API.node().wait_tx_result(tx_hash_failed) (process, response) = API.ws().getmerkleproof(tx_hash_failed) self.ASSERT(process, "") except Exception as e: logger.print(e.args[0])
def test_normal_088_getsmartcodeeventbyhash(self): try: (process, response) = API.native().transfer_ont(Config.NODES[0]["address"], Config.NODES[1]["address"], "100000000", 0, twice=True, check_state=True) tx_hash_failed = response["txhash"] (process, response) = API.ws().getsmartcodeeventbyhash(tx_hash_failed) self.ASSERT(process, "") except Exception as e: logger.print(e.args[0])