def fromSignedJSON(jsonArg: Dict[str, Any]) -> Any: json: Dict[str, Any] = dict(jsonArg) json["elements"] = list(json["elements"]) json["elements"][0] = dict(json["elements"][0]) json["elements"][1] = dict(json["elements"][1]) json["elements"][0]["holder"] = json["holder"] json["elements"][1]["holder"] = json["holder"] e1: MeritRemovalElement = SignedVerification(bytes(32), 0) if json["elements"][0]["descendant"] == "Verification": e1 = Verification.fromJSON(json["elements"][0]) elif json["elements"][0]["descendant"] == "VerificationPacket": e1 = SignedMeritRemovalVerificationPacket.fromJSON( json["elements"][0]) elif json["elements"][0]["descendant"] == "SendDifficulty": e1 = SendDifficulty.fromJSON(json["elements"][0]) elif json["elements"][0]["descendant"] == "DataDifficulty": e1 = DataDifficulty.fromJSON(json["elements"][0]) e2: MeritRemovalElement = SignedVerification(bytes(32), 0) if json["elements"][1]["descendant"] == "Verification": e2 = SignedVerification.fromSignedJSON(json["elements"][1]) elif json["elements"][1]["descendant"] == "VerificationPacket": e2 = SignedMeritRemovalVerificationPacket.fromSignedJSON( json["elements"][1]) elif json["elements"][1]["descendant"] == "SendDifficulty": e2 = SignedSendDifficulty.fromSignedJSON(json["elements"][1]) elif json["elements"][1]["descendant"] == "DataDifficulty": e2 = SignedDataDifficulty.fromSignedJSON(json["elements"][1]) return PartialMeritRemoval(e1, e2, json["holder"])
def fromJSON(jsonArg: Dict[str, Any]) -> Any: json: Dict[str, Any] = dict(jsonArg) json["elements"] = list(json["elements"]) json["elements"][0] = dict(json["elements"][0]) json["elements"][1] = dict(json["elements"][1]) json["elements"][0]["holder"] = json["holder"] json["elements"][1]["holder"] = json["holder"] e1: Element = Verification(bytes(32), 0) if json["elements"][0]["descendant"] == "Verification": e1 = Verification.fromJSON(json["elements"][0]) elif json["elements"][0]["descendant"] == "VerificationPacket": e1 = MeritRemovalVerificationPacket.fromJSON(json["elements"][0]) elif json["elements"][0]["descendant"] == "SendDifficulty": e1 = SendDifficulty.fromJSON(json["elements"][0]) elif json["elements"][0]["descendant"] == "DataDifficulty": e1 = DataDifficulty.fromJSON(json["elements"][0]) else: raise Exception( "Unknown Element used to construct a MeritRemoval.") e2: Element = Verification(bytes(32), 0) if json["elements"][1]["descendant"] == "Verification": e2 = Verification.fromJSON(json["elements"][1]) elif json["elements"][1]["descendant"] == "VerificationPacket": e2 = MeritRemovalVerificationPacket.fromJSON(json["elements"][1]) elif json["elements"][1]["descendant"] == "SendDifficulty": e2 = SendDifficulty.fromJSON(json["elements"][1]) elif json["elements"][1]["descendant"] == "DataDifficulty": e2 = DataDifficulty.fromJSON(json["elements"][1]) else: raise Exception( "Unknown Element used to construct a MeritRemoval.") return MeritRemoval(e1, e2, json["partial"], json["holder"])
def HundredTwentyTest( rpc: RPC ) -> None: file: IO[Any] = open("e2e/Vectors/Consensus/MeritRemoval/HundredTwenty.json", "r") vectors: Dict[str, Any] = json.loads(file.read()) file.close() #DataDifficulty for the mempool. mempoolDataDiff: SignedDataDifficulty = SignedDataDifficulty.fromSignedJSON(vectors["mempoolDataDiff"]) #DataDifficulty for the Blockchain. blockchainDataDiff: DataDifficulty = DataDifficulty.fromJSON(vectors["blockchainDataDiff"]) def sendDataDifficulty() -> None: #Send the Data Difficulty for the mempool. rpc.meros.signedElement(mempoolDataDiff) #Verify its sent back. if rpc.meros.live.recv() != ( MessageType.SignedDataDifficulty.toByte() + mempoolDataDiff.signedSerialize() ): raise TestError("Meros didn't send us the mempool Data Difficulty.") def receiveMeritRemoval() -> None: #We should receive a MeritRemoval, which is partial. #The unsigned Element should be the Block's DataDifficulty. #The signed Element should be the mempool's DataDifficulty. if rpc.meros.live.recv() != ( MessageType.SignedMeritRemoval.toByte() + PartialMeritRemoval( blockchainDataDiff, mempoolDataDiff, 0 ).signedSerialize() ): raise TestError("Meros didn't create the partial Merit Removal.") #Verify Meros didn't just broadcast it, yet also added it. verifyMeritRemoval(rpc, 2, 2, 0, True) Liver( rpc, vectors["blockchain"], callbacks={ 1: sendDataDifficulty, 2: receiveMeritRemoval } ).live()
def fromJSON(json: Dict[str, Any]) -> Any: packets: List[VerificationPacket] = [] elements: List[Element] = [] for packet in json["transactions"]: packets.append( VerificationPacket(bytes.fromhex(packet["hash"]), packet["holders"])) for element in json["elements"]: if element["descendant"] == "SendDifficulty": elements.append(SendDifficulty.fromJSON(element)) elif element["descendant"] == "DataDifficulty": elements.append(DataDifficulty.fromJSON(element)) return BlockBody(packets, elements, Signature(bytes.fromhex(json["aggregate"])))