def test_buildInfoData(self): # with api_handling = ApiHandling() api_com = ApiCommunication(api_handling, 'Lemanopolis') # When function_1 = "0x11111111" function_2 = "11111111" address_1 = '0xE00000000000000000000000000000000000000E' address_2 = 'E00000000000000000000000000000000000000E' #then self.assertEqual( api_com.buildInfoData(function_1, address_1), '0x11111111000000000000000000000000E00000000000000000000000000000000000000E' ) self.assertEqual( api_com.buildInfoData(function_2, address_1), '0x11111111000000000000000000000000E00000000000000000000000000000000000000E' ) self.assertEqual( api_com.buildInfoData(function_1, address_2), '0x11111111000000000000000000000000E00000000000000000000000000000000000000E' ) self.assertEqual( api_com.buildInfoData(function_2, address_2), '0x11111111000000000000000000000000E00000000000000000000000000000000000000E' )
def main(): # Load the API api_handling = ApiHandling() # refresh the node list api_handling.updateNodeRepo() # Open the admin account account_opener = LocalAccountOpener() server, admin_account = account_opener.openAccountInteractively('open admin account',account_file='') #open the list of account to process publics = openKeyListFile() # get the amount to be pledged amount = int(input("Amount to be pledged: ")) #load the high level functions api_com = ApiCommunication(api_handling, server) print('------------- PROCESSING ------------------------') for public in publics: status = api_com.getAccountStatus(public) print('Status of '+public + ' is '+str(status)) bal = api_com.getAccountGlobalBalance(public) print('Balance of '+public + ' is '+str(bal)) total = amount - bal if total>0: res, r = api_com.lockUnlockAccount(admin_account, public, lock=False) res, r = api_com.pledgeAccount(admin_account, public, total) res, r = api_com.lockUnlockAccount(admin_account, public, lock=True) print(' - done with '+public) # Wite the next block while not api_com.hasChangedBlock(): time.sleep( 5 ) print('------------- END PROCESSING ------------------------')
def test_encodeNumber(self): # with api_handling = ApiHandling() api_com = ApiCommunication(api_handling, 'Lemanopolis') # When number_m10 = -10 number_m1 = -1 number_0 = 0 number_1 = 1 number_10 = 10 number_100 = 100 number_1000 = 1000 #then self.assertEqual( api_com.encodeNumber(number_m10), 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6') self.assertEqual( api_com.encodeNumber(number_m1), 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') self.assertEqual( api_com.encodeNumber(number_0), '0000000000000000000000000000000000000000000000000000000000000000') self.assertEqual( api_com.encodeNumber(number_1), '0000000000000000000000000000000000000000000000000000000000000001') self.assertEqual( api_com.encodeNumber(number_10), '000000000000000000000000000000000000000000000000000000000000000a') self.assertEqual( api_com.encodeNumber(number_100), '0000000000000000000000000000000000000000000000000000000000000064') self.assertEqual( api_com.encodeNumber(number_1000), '00000000000000000000000000000000000000000000000000000000000003e8')
def test_decodeNumber(self): # with api_handling = ApiHandling() api_com = ApiCommunication(api_handling, 'Lemanopolis') # When number_m10 = 'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6' number_m1 = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' number_0 = '0000000000000000000000000000000000000000000000000000000000000000' number_1 = '0000000000000000000000000000000000000000000000000000000000000001' number_10 = '000000000000000000000000000000000000000000000000000000000000000a' number_100 = '0000000000000000000000000000000000000000000000000000000000000064' number_1000 = '00000000000000000000000000000000000000000000000000000000000003e8' #then self.assertEqual(api_com.decodeNumber(number_m10), -10) self.assertEqual(api_com.decodeNumber(number_m1), -1) self.assertEqual(api_com.decodeNumber(number_0), 0) self.assertEqual(api_com.decodeNumber(number_1), 1) self.assertEqual(api_com.decodeNumber(number_10), 10) self.assertEqual(api_com.decodeNumber(number_100), 100) self.assertEqual(api_com.decodeNumber(number_1000), 1000)
def test_encodeAddressForTransaction(self): # with api_handling = ApiHandling() api_com = ApiCommunication(api_handling, 'Lemanopolis') # When address_1 = '0xE00000000000000000000000000000000000000E' address_2 = 'E00000000000000000000000000000000000000E' address_3 = 'E000000000000000000000000000000000000000E' address_4 = 'E0000000000000000000000000000000000000E' #then self.assertEqual( api_com.encodeAddressForTransaction(address_1), '000000000000000000000000E00000000000000000000000000000000000000E') self.assertEqual( api_com.encodeAddressForTransaction(address_2), '000000000000000000000000E00000000000000000000000000000000000000E') with self.assertRaises(Exception): api_com.encodeAddressForTransaction(address_3) with self.assertRaises(Exception): api_com.encodeAddressForTransaction(address_4)
from PythonClient.ApiCommunication import ApiCommunication # Load the API api_handling = ApiHandling() # refresh the node list api_handling.updateNodeRepo() account_opener = LocalAccountOpener() server, admin_account = account_opener.openAccountInteractively( 'open admin account', account_file='') address_test_lock = '0xE00000000000000000000000000000000000000E' #load the high level functions api_com = ApiCommunication(api_handling, server) status = api_com.getAccountStatus(address_test_lock) print('Account ' + address_test_lock + ' is currently actif = ' + str(status)) print('Balance = ' + str(api_com.getAccountGlobalBalance(address_test_lock))) res, r = api_com.lockUnlockAccount(admin_account, address_test_lock, lock=False) print(res) print(r.text) print("") res, r = api_com.pledgeAccount(admin_account, address_test_lock, 0.01) print(res) print(r.text)
from PythonClient.ApiHandling import ApiHandling from PythonClient.ApiCommunication import ApiCommunication from datetime import datetime, timedelta import numpy as np import time # Load the API api_handling = ApiHandling() # refresh the node list api_handling.updateNodeRepo() #load the high level functions api_com = ApiCommunication(api_handling, 'Lemanopolis') # configure run test_duration = 20 # [min] step = 2 # [sec] number = int((test_duration * 60) / step) # test run blocks = [] dt = [] print('Staring the run. See you in ' + str(test_duration) + ' min') start_block = api_com.getBlockNumber() start_time = datetime.now() for counter in range(number): curr_block = api_com.getBlockNumber() curr_time = datetime.now() if curr_block > start_block:
################################################################################ ## (2) Load the account and check funds availability ################################################################################ # Load the API api_handling = ApiHandling() # refresh the node list api_handling.updateNodeRepo() account_opener = LocalAccountOpener() server, sender_account = account_opener.openAccountInteractively( 'Select Sender Wallet', account_file=account_file, password=password) #load the high level functions api_com = ApiCommunication(api_handling, server) CM_balance = api_com.getAccountCMBalance(sender_account.address) CM_limit = api_com.getAccountCMLimitMinimum(sender_account.address) Nant_balance = api_com.getAccountNantBalance(sender_account.address) Sender_status = api_com.getAccountStatus(sender_account.address) if Sender_status != 1: print("Error: The Sender Wallet is locked!") sys.exit() use_cm = False use_negative_cm = False use_nant = False use_mix = False
from PythonClient.ApiHandling import ApiHandling from PythonClient.ApiCommunication import ApiCommunication # Load the API api_handling = ApiHandling() # refresh the node list api_handling.updateNodeRepo() account_opener = LocalAccountOpener() server, sender_account = account_opener.openAccountInteractively( 'open sender account', account_file='') target_address = '0xE00000000000000000000000000000000000000E' #load the high level functions api_com = ApiCommunication(api_handling, server) print('The sender wallet ' + sender_account.address + ', on server ' + server + ' has a balance of = ' + str(api_com.getAccountGlobalBalance(sender_account.address))) res, r = api_com.transfertNant(sender_account, target_address, 0.01, message_from="test", message_to="test") print(res) print(r.text) print("")
# Load the API print('INFO: Load the API.') api_handling = ApiHandling() # refresh the node list print('INFO: refresh the node list.') api_handling.updateNodeRepo() account_opener = LocalAccountOpener() server, sender_account = account_opener.openAccountInteractively( 'Select Admin Wallet', account_file=account_file, password=password) #load the high level functions print('INFO: load the high level functions.') api_com = ApiCommunication(api_handling, server) print('INFO: Check the provided account to have admin role.') api_com.checkAdmin(sender_account.address) Sender_status = api_com.getAccountStatus(sender_account.address) if Sender_status != 1: print("Error: The Admin Wallet is locked!") sys.exit() ################################################################################ ## (3) Check target accounts are available ################################################################################ print('INFO: Check the targets accounts are not locked.') for tran in prepared_transactions: