theAbiFullySorted = sortJson(theAbiWithSortedKeys) sanitizedAbiString = sanitizeString(json.dumps(theAbiFullySorted, sort_keys=False)) return sanitizedAbiString randomAbis = [] abiUrl = "https://raw.githubusercontent.com/tpmccallum/mixed_ordered_erc20_abis_for_testing/master/vanilla.txt" singleAbiString = requests.get(abiUrl).content singleAbiJSON = json.loads(singleAbiString) for i in range(20): string = randomizeAndConvertAbiToText(singleAbiJSON) randomAbis.append(string) outputHashes = [] print("Hashes of random ABIs") for rItem in randomAbis: hashToPrint = harvester.createHashFromString(rItem) print(hashToPrint) jsonAbi = json.loads(rItem) singleHash = harvester.shaAnAbi(jsonAbi) outputHashes.append(singleHash) print("Output hashes are as follows, these should all be exactly the same") print("Hashes of sorted ABIs ...") for singleHash in outputHashes: print(singleHash) # Output will look something like this # Hashes of random ABIs # 0x43064f4849beb02ce7998480bf90ee4dd4123782c6f409da4e800f8021d9cef6 # 0x8375c0a54cc9f59f1b8b4d3dc217100b26ff4be1f487d7fa0220638c47df77af # 0x58873a40bffb7101ec49f989e2c5dbf34a52a9e923aa09ca9aacf35880f42a91
if str(k) == "inputs": inputs = str(v) if str(k) == "outputs": outputs = str(v) print("Type: " + typeOuter) print("Name: " + nameOuter) print("Inputs" + inputs) print("Outputs" + outputs) print("\n") # Test the sorting and hashing of all ABIs in the abiUrls list (please add any new oddly ordered ABIs to that list so that we can ensure this code is robust) outputHashes = [] for singleAbiUrl in abiUrls: singleAbiString = requests.get(singleAbiUrl).content singleAbiJSON = json.loads(singleAbiString) abiWithSortedInternals = sortInternalListsInJsonObject(singleAbiJSON) abiWithSortedKeys = sortABIKeys(abiWithSortedInternals) abiFullySorted = sort(abiWithSortedKeys) sanitizedString = harvester.sanitizeString(json.dumps(abiFullySorted)) print("ABI") print(sanitizedString) hashOfAbi = harvester.createHashFromString(sanitizedString) outputHashes.append(hashOfAbi) print("Output hashes are as follows, these should all be exactly the same") for singleHash in outputHashes: print(singleHash)