How to use get_signature method in localstack

Best Python code snippet using localstack_python

rpc_payment.py

Source:rpc_payment.py Github

copy

Full Screen

...48 output = subprocess.check_output([self.make_test_signature]).decode('utf-8').rstrip()49 fields = output.split()50 assert len(fields) == 251 return fields52 def get_signature(self):53 return subprocess.check_output([self.make_test_signature, self.secret_key]).decode('utf-8').rstrip()54 def reset(self):55 print('Resetting blockchain')56 daemon = Daemon(idx=1)57 res = daemon.get_height()58 daemon.pop_blocks(res.height - 1)59 daemon.flush_txpool()60 def test_access_tracking(self):61 print('Testing access tracking')62 daemon = Daemon(idx=1)63 res = daemon.rpc_access_tracking(True)64 res = daemon.rpc_access_tracking()65 data = sorted(res.data, key = lambda k: k['rpc'])66 assert len(data) == 167 entry = data[0]68 assert entry.rpc == 'rpc_access_tracking'69 assert entry.count == 170 assert entry.time >= 071 assert entry.credits == 072 daemon.get_connections()73 res = daemon.rpc_access_tracking()74 data = sorted(res.data, key = lambda k: k['rpc'])75 assert len(data) == 276 entry = data[0]77 assert entry.rpc == 'get_connections'78 assert entry.count == 179 assert entry.time >= 080 assert entry.credits == 081 daemon.get_connections()82 res = daemon.rpc_access_tracking()83 data = sorted(res.data, key = lambda k: k['rpc'])84 assert len(data) == 285 entry = data[0]86 assert entry.rpc == 'get_connections'87 assert entry.count == 288 assert entry.time >= 089 assert entry.credits == 090 daemon.get_alternate_chains()91 res = daemon.rpc_access_tracking()92 data = sorted(res.data, key = lambda k: k['rpc'])93 assert len(data) == 394 entry = data[0]95 assert entry.rpc == 'get_alternate_chains'96 assert entry.count == 197 assert entry.time >= 098 assert entry.credits == 099 entry = res.data[1]100 assert entry.rpc == 'get_connections'101 assert entry.count == 2102 assert entry.time >= 0103 assert entry.credits == 0104 res = daemon.rpc_access_tracking(True)105 res = daemon.rpc_access_tracking()106 data = sorted(res.data, key = lambda k: k['rpc'])107 assert len(data) == 1108 entry = data[0]109 assert entry.rpc == 'rpc_access_tracking'110 assert entry.count == 1111 def test_access_mining(self):112 print('Testing access mining')113 daemon = Daemon(idx=1)114 wallet = Wallet(idx=3)115 res = daemon.rpc_access_info(client = self.get_signature())116 assert len(res.hashing_blob) > 39117 assert res.height == 1118 assert res.top_hash == '418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3'119 assert res.credits_per_hash_found == 5000120 assert res.diff == 10121 assert res.credits == 0122 cookie = res.cookie123 # Try random nonces till we find one that's valid and one that's invalid124 nonce = 0125 found_valid = 0126 found_invalid = 0127 last_credits = 0128 while found_valid == 0 or found_invalid == 0:129 nonce += 1130 try:131 res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())132 found_valid += 1133 assert res.credits == last_credits + 5000134 except Exception as e:135 found_invalid += 1136 res = daemon.rpc_access_info(client = self.get_signature())137 assert res.credits < last_credits or res.credits == 0138 assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails139 last_credits = res.credits140 # we should now have 1 valid nonce, and a number of bad ones141 res = daemon.rpc_access_info(client = self.get_signature())142 assert len(res.hashing_blob) > 39143 assert res.height > 1144 assert res.top_hash != '418015bb9ae982a1975da7d79277c2705727a56894ba0fb246adaabb1f4632e3' # here, any share matches network diff145 assert res.credits_per_hash_found == 5000146 assert res.diff == 10147 cookie = res.cookie148 res = daemon.rpc_access_data()149 assert len(res.entries) > 0150 e = [x for x in res.entries if x['client'] == self.public_key]151 assert len(e) == 1152 e = e[0]153 assert e.nonces_stale == 0154 assert e.nonces_bad == found_invalid155 assert e.nonces_good == found_valid156 assert e.nonces_dupe == 0157 # Try random nonces till we find one that's valid so we get a load of credits158 while last_credits == 0:159 nonce += 1160 try:161 res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())162 found_valid += 1163 last_credits = res.credits164 break165 except:166 found_invalid += 1167 assert nonce < 1000 # can't find a valid none -> the RPC probably fails168 # we should now have at least 5000169 res = daemon.rpc_access_info(client = self.get_signature())170 assert res.credits == last_credits171 assert res.credits >= 5000 # last one was a valid nonce172 res = daemon.rpc_access_data()173 assert len(res.entries) > 0174 e = [x for x in res.entries if x['client'] == self.public_key]175 assert len(e) == 1176 e = e[0]177 assert e.nonces_stale == 0178 assert e.nonces_bad == found_invalid179 assert e.nonces_good == found_valid180 assert e.nonces_dupe == 0181 assert e.balance == 5000182 assert e.credits_total >= 5000183 # find a valid one, then check dupes aren't allowed184 res = daemon.rpc_access_info(client = self.get_signature())185 cookie = res.cookie186 old_cookie = cookie # we keep that so can submit a stale later187 while True:188 nonce += 1189 try:190 res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())191 found_valid += 1192 break193 except:194 found_invalid += 1195 assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails196 res = daemon.rpc_access_data()197 assert len(res.entries) > 0198 e = [x for x in res.entries if x['client'] == self.public_key]199 assert len(e) == 1200 e = e[0]201 assert e.nonces_stale == 0202 assert e.nonces_bad == found_invalid203 assert e.nonces_good == found_valid204 assert e.nonces_dupe == 0205 ok = False206 try:207 res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())208 except:209 ok = True210 assert ok211 res = daemon.rpc_access_data()212 assert len(res.entries) > 0213 e = [x for x in res.entries if x['client'] == self.public_key]214 assert len(e) == 1215 e = e[0]216 assert e.nonces_stale == 0217 assert e.nonces_bad == found_invalid218 assert e.nonces_good == found_valid219 assert e.nonces_dupe == 1220 # find stales without updating cookie, one within 5 seconds (accepted), one later (rejected)221 res = daemon.rpc_access_info(client = self.get_signature())222 found_close_stale = 0223 found_late_stale = 0224 while found_close_stale == 0 or found_late_stale == 0:225 nonce += 1226 try:227 res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())228 found_close_stale += 1229 found_valid += 1230 except Exception as e:231 #if e[0]['error']['code'] == -18: # stale232 if "'code': -18" in str(e): # stale (ugly version, but also works with python 3)233 found_late_stale += 1234 else:235 found_invalid += 1236 assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails237 res = daemon.rpc_access_data()238 assert len(res.entries) > 0239 e = [x for x in res.entries if x['client'] == self.public_key]240 assert len(e) == 1241 e = e[0]242 assert e.nonces_stale == found_late_stale # close stales are accepted, don't count here243 assert e.nonces_bad == found_invalid244 assert e.nonces_good == found_valid245 assert e.nonces_dupe == 1246 # find very stale with old cookie (rejected)247 res = daemon.rpc_access_info(client = self.get_signature())248 nonce += 1249 ok = False250 try:251 res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = old_cookie, client = self.get_signature())252 except:253 found_late_stale += 1254 ok = True255 assert ok256 res = daemon.rpc_access_data()257 assert len(res.entries) > 0258 e = [x for x in res.entries if x['client'] == self.public_key]259 assert len(e) == 1260 e = e[0]261 assert e.nonces_stale == found_late_stale262 assert e.nonces_bad == found_invalid263 assert e.nonces_good == found_valid264 assert e.nonces_dupe == 1265 def test_access_payment(self):266 print('Testing access payment')267 daemon = Daemon(idx=1)268 wallet = Wallet(idx=3)269 # Try random nonces till we find one that's valid so we get a load of credits270 res = daemon.rpc_access_info(client = self.get_signature())271 credits = res.credits272 cookie = res.cookie273 nonce = 0274 while credits <= 100:275 nonce += 1276 try:277 res = daemon.rpc_access_submit_nonce(nonce = nonce, cookie = cookie, client = self.get_signature())278 break279 except:280 pass281 assert nonce < 1000 # can't find both valid and invalid -> the RPC probably fails282 res = daemon.rpc_access_info(client = self.get_signature())283 credits = res.credits284 assert credits > 0285 res = daemon.get_info(client = self.get_signature())286 assert res.credits == credits - 1287 credits = res.credits288 res = daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 100)289 block_hashes = res.blocks290 # ask for 1 block -> 1 credit291 res = daemon.getblockheadersrange(0, 0, client = self.get_signature())292 assert res.credits == credits - 1293 credits = res.credits294 # ask for 100 blocks -> >1 credit295 res = daemon.getblockheadersrange(1, 100, client = self.get_signature())296 assert res.credits < credits - 1297 credits = res.credits298 # external users299 res = daemon.rpc_access_pay(payment = 1, paying_for = 'foo', client = self.get_signature())300 assert res.credits == credits - 1301 res = daemon.rpc_access_pay(payment = 4, paying_for = 'bar', client = self.get_signature())302 assert res.credits == credits - 5303 res = daemon.rpc_access_pay(payment = credits, paying_for = 'baz', client = self.get_signature())304 assert "PAYMENT REQUIRED" in res.status305 res = daemon.rpc_access_pay(payment = 2, paying_for = 'quux', client = self.get_signature())306 assert res.credits == credits - 7307 res = daemon.rpc_access_pay(payment = 3, paying_for = 'bar', client = self.get_signature())308 assert res.credits == credits - 10309 # that should be rejected because its cost is massive310 ok = False311 try: res = daemon.get_output_histogram(amounts = [], client = self.get_signature())312 except Exception as e: print('e: ' + str(e)); ok = "PAYMENT REQUIRED" in e.status313 assert ok or "PAYMENT REQUIRED" in res.status314 def test_access_account(self):315 print('Testing access account')316 daemon = Daemon(idx=1)317 wallet = Wallet(idx=3)318 res = daemon.rpc_access_info(client = self.get_signature())319 credits = res.credits320 res = daemon.rpc_access_account(self.get_signature(), 0)321 assert res.credits == credits322 res = daemon.rpc_access_account(self.get_signature(), 50)323 assert res.credits == credits + 50324 res = daemon.rpc_access_account(self.get_signature(), -10)325 assert res.credits == credits + 40326 res = daemon.rpc_access_account(self.get_signature(), -(credits + 50))327 assert res.credits == 0328 res = daemon.rpc_access_account(self.get_signature(), 2**63 - 5)329 assert res.credits == 2**63 - 5330 res = daemon.rpc_access_account(self.get_signature(), 2**63 - 1)331 assert res.credits == 2**64 - 6332 res = daemon.rpc_access_account(self.get_signature(), 2)333 assert res.credits == 2**64 - 4334 res = daemon.rpc_access_account(self.get_signature(), 8)335 assert res.credits == 2**64 - 1336 res = daemon.rpc_access_account(self.get_signature(), -1)337 assert res.credits == 2**64 - 2338 res = daemon.rpc_access_account(self.get_signature(), -(2**63 - 1))339 assert res.credits == 2**64 - 2 -(2**63 - 1)340 res = daemon.rpc_access_account(self.get_signature(), -(2**63 - 1))341 assert res.credits == 0342 def test_free_access(self):343 print('Testing free access')344 daemon = Daemon(idx=0)345 wallet = Wallet(idx=0)346 res = daemon.rpc_access_info(client = self.get_signature())347 assert res.credits_per_hash_found == 0348 assert res.diff == 0349 assert res.credits == 0350 res = daemon.get_info(client = self.get_signature())351 assert res.credits == 0352 # any nonce will do here353 res = daemon.rpc_access_submit_nonce(nonce = 0, cookie = 0, client = self.get_signature())354 assert res.credits == 0355class Guard:356 def __enter__(self):357 for i in range(4):358 Wallet(idx = i).auto_refresh(False)359 def __exit__(self, exc_type, exc_value, traceback):360 for i in range(4):361 Wallet(idx = i).auto_refresh(True)362if __name__ == '__main__':363 with Guard() as guard:...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful