예제 #1
0
    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"])
예제 #2
0
    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"])
예제 #3
0
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()
예제 #4
0
    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"])))
예제 #5
0
from typing import IO, Any
import json

from e2e.Classes.Consensus.DataDifficulty import DataDifficulty
from e2e.Classes.Consensus.MeritRemoval import MeritRemoval

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

proto: PrototypeChain = PrototypeChain(25)
proto.add(elements=[DataDifficulty(2, 0, 0)])
for _ in range(24):
    proto.add()
proto.add(elements=[DataDifficulty(1, 1, 0)])

proto.add(elements=[
    MeritRemoval(DataDifficulty(1, 1, 0), DataDifficulty(2, 1, 0), True)
])

for _ in range(50):
    proto.add()

vectors: IO[Any] = open(
    "e2e/Vectors/Consensus/Difficulties/DataDifficulty.json", "w")
vectors.write(json.dumps({"blockchain": proto.toJSON()}))
vectors.close()
예제 #6
0
data: Data = Data(bytes(32), edPubKey)
data.sign(edPrivKey)
data.beat(dataFilter)
transactions.add(data)
packet: VerificationPacket = VerificationPacket(data.hash, [1])

blocks.append(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   packets=[VerificationPacket(data.hash, [1])],
                   minerID=blsPrivKey).finish(0, merit).toJSON())

#Generate the SendDifficulty Block.
blocks.append(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   elements=[SendDifficulty(0, 0, 1)],
                   minerID=blsPrivKey).finish(0, merit).toJSON())

#Generate the DataDifficulty Block.
blocks.append(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   elements=[DataDifficulty(0, 0, 1)],
                   minerID=blsPrivKey).finish(0, merit).toJSON())

with open("e2e/Vectors/Consensus/HundredSix/BlockElements.json",
          "w") as vectors:
    vectors.write(
        json.dumps({
            "blocks": blocks,
            "transactions": transactions.toJSON()
        }))
예제 #7
0
    transactions.add(datas[-1])
    datas.append(Data(datas[-1].hash, b'\0'))
del datas[-1]

merit.add(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   packets=[
                       VerificationPacket(claim.hash, [0]),
                       VerificationPacket(send.hash, [0, 1, 2]),
                       VerificationPacket(datas[0].hash, [0, 2]),
                       VerificationPacket(datas[1].hash, [0, 1, 3]),
                       VerificationPacket(datas[2].hash, [0, 1, 2, 3, 4]),
                       VerificationPacket(datas[3].hash, [0, 1, 2, 3])
                   ],
                   elements=[
                       DataDifficulty(8, 0, 3),
                       SendDifficulty(1, 0, 0),
                       DataDifficulty(4, 0, 3),
                       DataDifficulty(1, 2, 4),
                       SendDifficulty(3, 1, 4),
                       SendDifficulty(2, 1, 2),
                       DataDifficulty(7, 0, 0),
                   ]).finish(0, merit))

with open("e2e/Vectors/RPC/Merit/GetBlock.json", "w") as vectors:
    vectors.write(
        json.dumps({
            "blockchain": merit.toJSON(),
            "transactions": transactions.toJSON(),
            "claim": claim.toJSON(),
            "send": send.toJSON(),
import json

from e2e.Classes.Consensus.SendDifficulty import SendDifficulty
from e2e.Classes.Consensus.DataDifficulty import DataDifficulty

from e2e.Classes.Merit.Merit import Merit

from e2e.Vectors.Generation.PrototypeChain import PrototypeBlock, PrototypeChain

merit: Merit = Merit.fromJSON(PrototypeChain(49).finish().toJSON())

#Add the Difficulties.
merit.add(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   elements=[SendDifficulty(2, 0, 0),
                             DataDifficulty(2, 1, 0)],
                   minerID=0).finish(0, merit))

#Close out this, and the next, Checkpoint period to lock our Merit.
for _ in range(9):
    merit.add(
        PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                       minerID=0).finish(0, merit))

#Become Pending.
merit.add(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   minerID=0).finish(1, merit))

vectors: IO[Any] = open("e2e/Vectors/Consensus/Difficulties/LockedMerit.json",
                        "w")
예제 #9
0
import json

from e2e.Classes.Consensus.DataDifficulty import DataDifficulty

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

keepsUnlockedViaElements: PrototypeChain = PrototypeChain(1, False)
for b in range(24):
    keepsUnlockedViaElements.add(elements=[DataDifficulty(b, b, 0)])

with open("e2e/Vectors/Merit/LockedMerit/KeepUnlocked.json", "w") as vectors:
    vectors.write(
        json.dumps(
            [PrototypeChain(25).toJSON(),
             keepsUnlockedViaElements.toJSON()]))
예제 #10
0
    BlockHeader(0, blockchain.last(), BlockHeader.createContents([],
                                                                 elements), 1,
                bytes(4), BlockHeader.createSketchCheck(bytes(4), []),
                blsPrivKey.toPublicKey().serialize(),
                blockchain.blocks[-1].header.time + 1200),
    BlockBody([], elements, blsPrivKey.sign(b"")))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#Add it to the vectors.
blocks.append(block.toJSON())
print("Generated Hundred Six Block Elements SendDifficulty Block.")

#Generate the DataDifficulty Block.
elements = []
elements.append(DataDifficulty(0, 0, 1))
block = Block(
    BlockHeader(0, blockchain.last(), BlockHeader.createContents([],
                                                                 elements), 1,
                bytes(4), BlockHeader.createSketchCheck(bytes(4), []),
                blsPrivKey.toPublicKey().serialize(),
                blockchain.blocks[-1].header.time + 1200),
    BlockBody([], elements, blsPrivKey.sign(b"")))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#Add it to the vectors.
blocks.append(block.toJSON())
print("Generated Hundred Six Block Elements DataDifficulty Block.")

result: Dict[str, Any] = {
예제 #11
0
import json

from e2e.Classes.Consensus.DataDifficulty import DataDifficulty

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

proto: PrototypeChain = PrototypeChain(25)
proto.add(elements=[DataDifficulty(2, 0, 0)])
for _ in range(24):
    proto.add()
proto.add(elements=[DataDifficulty(1, 1, 0)])

proto.add(elements=[DataDifficulty(2, 1, 0)])

with open("e2e/Vectors/Consensus/Difficulties/DataDifficulty.json",
          "w") as vectors:
    vectors.write(json.dumps(proto.toJSON()))