コード例 #1
0
ファイル: SameElementTest.py プロジェクト: vporton/Meros
  def testBlockchain(
    b: int
  ) -> None:
    #Data.
    data: Data = Data.fromJSON(vectors["data"])

    #pylint: disable=no-member
    #MeritRemoval.
    removal: SignedMeritRemoval = SignedMeritRemoval.fromSignedJSON(vectors["removals"][b])

    #Create and execute a Liver to send the MeritRemoval.
    def sendMeritRemoval() -> None:
      #Send the Data.
      if rpc.meros.liveTransaction(data) != rpc.meros.live.recv():
        raise TestError("Meros didn't send back the Data.")

      rpc.meros.signedElement(removal)
      try:
        if len(rpc.meros.live.recv()) != 0:
          raise Exception()
      except TestError:
        raise SuccessError("Meros rejected our MeritRemoval created from the same Element.")
      except Exception:
        raise TestError("Meros accepted our MeritRemoval created from the same Element.")

    Liver(
      rpc,
      vectors["blockchain"],
      callbacks={
        1: sendMeritRemoval
      }
    ).live()
コード例 #2
0
def MultipleTest(rpc: RPC) -> None:
    file: IO[Any] = open("e2e/Vectors/Consensus/MeritRemoval/Multiple.json",
                         "r")
    vectors: Dict[str, Any] = json.loads(file.read())
    file.close()

    #MeritRemovals.
    removals: List[SignedMeritRemoval] = [
        SignedMeritRemoval.fromSignedJSON(vectors["removals"][0]),
        SignedMeritRemoval.fromSignedJSON(vectors["removals"][1])
    ]

    #Send and verify the MeritRemoval.
    def sendMeritRemovals() -> None:
        removalBuf: bytes = rpc.meros.signedElement(removals[0])
        if removalBuf != rpc.meros.live.recv():
            raise TestError("Meros didn't send us the Merit Removal.")
        verifyMeritRemoval(rpc, 1, 1, removals[0].holder, True)

        rpc.meros.signedElement(removals[1])
        if removalBuf != rpc.meros.live.recv():
            raise TestError("Meros didn't send us the first Merit Removal.")
        verifyMeritRemoval(rpc, 1, 1, removals[0].holder, True)

    #Verify the holder has 0 Merit and is marked as malicious.
    def verifyFirstMeritRemoval() -> None:
        verifyMeritRemoval(rpc, 0, 0, removals[0].holder, True)

    #Create and execute a Liver to handle the Signed MeritRemovals.
    Liver(rpc,
          vectors["blockchain"],
          callbacks={
              1: sendMeritRemovals,
              2: verifyFirstMeritRemoval,
              3:
              lambda: verifyMeritRemoval(rpc, 0, 0, removals[0].holder, False)
          }).live()

    #Create and execute a Syncer to handle a Signed MeritRemoval.
    Syncer(rpc, vectors["blockchain"]).sync()
    verifyMeritRemoval(rpc, 0, 0, removals[0].holder, False)
コード例 #3
0
def SameNonceTest(rpc: RPC) -> None:
    file: IO[Any] = open("e2e/Vectors/Consensus/MeritRemoval/SameNonce.json",
                         "r")
    vectors: Dict[str, Any] = json.loads(file.read())
    file.close()

    #MeritRemoval.
    #pylint: disable=no-member
    removal: SignedMeritRemoval = SignedMeritRemoval.fromSignedJSON(
        vectors["removal"])

    #Create and execute a Liver to cause a Signed MeritRemoval.
    def sendElements() -> None:
        #Send the Elements.
        rpc.meros.signedElement(removal.se1)
        rpc.meros.signedElement(removal.se2)

        #Verify the first Element.
        if rpc.meros.live.recv() != (MessageType.SignedDataDifficulty.toByte()
                                     + removal.se1.signedSerialize()):
            raise TestError("Meros didn't send us the first Data Difficulty.")

        #Verify the MeritRemoval.
        if rpc.meros.live.recv() != (MessageType.SignedMeritRemoval.toByte() +
                                     removal.signedSerialize()):
            raise TestError("Meros didn't send us the Merit Removal.")
        verifyMeritRemoval(rpc, 1, 1, removal.holder, True)

    Liver(rpc,
          vectors["blockchain"],
          callbacks={
              1: sendElements,
              2: lambda: verifyMeritRemoval(rpc, 1, 1, removal.holder, False)
          }).live()

    #Create and execute a Liver to handle a Signed MeritRemoval.
    def sendMeritRemoval() -> None:
        #Send and verify the MeritRemoval.
        if rpc.meros.signedElement(removal) != rpc.meros.live.recv():
            raise TestError("Meros didn't send us the Merit Removal.")
        verifyMeritRemoval(rpc, 1, 1, removal.holder, True)

    Liver(rpc,
          vectors["blockchain"],
          callbacks={
              1: sendMeritRemoval,
              2: lambda: verifyMeritRemoval(rpc, 1, 1, removal.holder, False)
          }).live()

    #Create and execute a Syncer to handle a Signed MeritRemoval.
    Syncer(rpc, vectors["blockchain"]).sync()
    verifyMeritRemoval(rpc, 1, 1, removal.holder, False)
コード例 #4
0
def InvalidCompetingTest(rpc: RPC) -> None:
    file: IO[Any] = open(
        "e2e/Vectors/Consensus/MeritRemoval/InvalidCompeting.json", "r")
    vectors: Dict[str, Any] = json.loads(file.read())
    file.close()

    #Transactions.
    transactions: Transactions = Transactions.fromJSON(vectors["transactions"])

    #MeritRemoval.
    #pylint: disable=no-member
    removal: SignedMeritRemoval = SignedMeritRemoval.fromSignedJSON(
        vectors["removal"])

    #Create and execute a Liver to handle the MeritRemoval.
    def sendMeritRemoval() -> None:
        #Send and verify the MeritRemoval.
        removalBytes: bytes = rpc.meros.signedElement(removal)

        sent: int = 0
        while True:
            if sent == 2:
                break

            msg: bytes = rpc.meros.sync.recv()
            if MessageType(msg[0]) == MessageType.TransactionRequest:
                rpc.meros.syncTransaction(transactions.txs[msg[1:33]])
                sent += 1
            else:
                raise TestError("Unexpected message sent: " +
                                msg.hex().upper())

        if removalBytes != rpc.meros.live.recv():
            raise TestError("Meros didn't send us the Merit Removal.")
        verifyMeritRemoval(rpc, 1, 1, removal.holder, True)

    #Verify the MeritRemoval and the Blockchain.
    def verify() -> None:
        verifyMeritRemoval(rpc, 1, 1, removal.holder, False)
        verifyBlockchain(rpc, Blockchain.fromJSON(vectors["blockchain"]))
        raise SuccessError(
            "MeritRemoval and Blockchain were properly handled.")

    Liver(rpc,
          vectors["blockchain"],
          transactions,
          callbacks={
              1: sendMeritRemoval,
              2: verify
          }).live()
コード例 #5
0
ファイル: MultipleTest.py プロジェクト: frozenghozt/Meros
def MultipleTest(rpc: RPC) -> None:
    vectors: Dict[str, Any]
    with open("e2e/Vectors/Consensus/MeritRemoval/Multiple.json", "r") as file:
        vectors = json.loads(file.read())

    removals: List[SignedMeritRemoval] = [
        SignedMeritRemoval.fromSignedJSON(vectors["removals"][0]),
        SignedMeritRemoval.fromSignedJSON(vectors["removals"][1])
    ]

    #Send and verify the MeritRemovals.
    def sendMeritRemovals() -> None:
        if rpc.meros.meritRemoval(removals[0]) != rpc.meros.live.recv():
            raise TestError("Meros didn't send us the Merit Removal.")
        verifyMeritRemoval(rpc, 1, 1, removals[0].holder, True)

        if rpc.meros.meritRemoval(removals[1]) != rpc.meros.live.recv():
            raise TestError("Meros didn't send us the new Merit Removal.")
        verifyMeritRemoval(rpc, 1, 1, removals[0].holder, True)

    #Verify the holder has 0 Merit and isn't marked as malicious.
    #Since they had one MeritRemoval archived, they're dead.
    #They should have 0 merit, with the other MR being unaddable and therefore dropped.
    def verifyFirstMeritRemoval() -> None:
        verifyMeritRemoval(rpc, 0, 0, removals[0].holder, False)

    Liver(rpc,
          vectors["blockchain"],
          callbacks={
              1: sendMeritRemovals,
              2: verifyFirstMeritRemoval
          }).live()

    #Create and execute a Syncer to handle a Signed MeritRemoval.
    Syncer(rpc, vectors["blockchain"]).sync()
    verifyMeritRemoval(rpc, 0, 0, removals[0].holder, False)
コード例 #6
0
def HundredThirtyFiveTest(
  rpc: RPC
) -> None:
  file: IO[Any] = open("e2e/Vectors/Consensus/MeritRemoval/HundredThirtyFive.json", "r")
  vectors: Dict[str, Any] = json.loads(file.read())
  file.close()

  #Datas.
  datas: List[Data] = [
    Data.fromJSON(vectors["datas"][0]),
    Data.fromJSON(vectors["datas"][1]),
    Data.fromJSON(vectors["datas"][2])
  ]

  #Transactions.
  transactions: Transactions = Transactions()
  for data in datas:
    transactions.add(data)

  #First MeritRemoval.
  mr: SignedMeritRemoval = SignedMeritRemoval.fromSignedJSON(vectors["removal"])

  def sendMeritRemoval() -> None:
    #Send the Datas.
    for data in datas:
      if rpc.meros.liveTransaction(data) != rpc.meros.live.recv():
        raise TestError("Meros didn't send us the Data.")

    #Send and verify the original MeritRemoval.
    if rpc.meros.signedElement(mr) != rpc.meros.live.recv():
      raise TestError("Meros didn't send us the Merit Removal.")
    verifyMeritRemoval(rpc, 1, 1, mr.holder, True)

  Liver(
    rpc,
    vectors["blockchain"],
    transactions,
    callbacks={
      1: sendMeritRemoval
    }
  ).live()
コード例 #7
0
data: Data = Data(bytes.fromhex("11" * 32), bytes(1))
transactions.add(data)

#Create a competing Data using the same input.
competingData: Data = Data(bytes.fromhex("11" * 32), bytes(2))
transactions.add(competingData)

#Verify the Datas.
verif: SignedVerification = SignedVerification(data.hash)
verif.sign(0, blsPrivKey)

competingVerif: SignedVerification = SignedVerification(competingData.hash)
competingVerif.sign(0, blsPrivKey)

#Create a MeritRemoval out of the conflicting Verifications.
mr: SignedMeritRemoval = SignedMeritRemoval(verif, competingVerif)

#Generate a Block containing the MeritRemoval.
block = Block(
    BlockHeader(0, blockchain.last(), BlockHeader.createContents([], [mr]), 1,
                bytes(4), BlockHeader.createSketchCheck(bytes(4), []), 0,
                blockchain.blocks[-1].header.time + 1200),
    BlockBody([], [mr], mr.signature))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Invalid Competing Block " + str(len(blockchain.blocks)) + ".")

result: Dict[str, Any] = {
コード例 #8
0
#Create the initial Data and two competing Datas.
datas: List[Data] = [Data(bytes(32), edPubKey.to_bytes())]
datas.append(Data(datas[0].hash, b"Initial Data."))
datas.append(Data(datas[0].hash, b"Second Data."))
for data in datas:
  data.sign(edPrivKey)
  data.beat(spamFilter)

#Create Verifications for all 3.
verifs: List[SignedVerification] = []
for data in datas:
  verifs.append(SignedVerification(data.hash, 0))
  verifs[-1].sign(0, blsPrivKey)

#Create a MeritRemoval out of the conflicting Verifications.
mr: SignedMeritRemoval = SignedMeritRemoval(verifs[1], verifs[2])

#Create a MeritRemoval with random keys.
packeted: SignedMeritRemoval = SignedMeritRemoval(
  SignedMeritRemovalVerificationPacket(
    SignedVerificationPacket(verifs[1].hash),
    [
      blsPubKey.serialize(),
      PrivateKey(1).toPublicKey().serialize(),
      PrivateKey(2).toPublicKey().serialize()
    ],
    Signature.aggregate([
      blsPrivKey.sign(verifs[1].signatureSerialize()),
      PrivateKey(1).sign(verifs[1].signatureSerialize()),
      PrivateKey(2).sign(verifs[1].signatureSerialize())
    ])
コード例 #9
0
    def testBlockchain(i: int) -> None:
        #First MeritRemoval.
        mr: SignedMeritRemoval = SignedMeritRemoval.fromSignedJSON(
            vectors["removals"][i])

        def sendMeritRemoval() -> None:
            #Send the Datas.
            for data in datas:
                if rpc.meros.liveTransaction(data) != rpc.meros.live.recv():
                    raise TestError("Meros didn't send us the Data.")

            #Send and verify the MeritRemoval.
            if rpc.meros.signedElement(mr) != rpc.meros.live.recv():
                raise TestError("Meros didn't send us the Merit Removal.")
            verifyMeritRemoval(rpc, 1, 1, mr.holder, True)

        def sendRepeatMeritRemoval() -> None:
            #Send the Block containing the modified Merit Removal.
            block: Block = Block.fromJSON(vectors["blockchains"][i][-1])
            rpc.meros.liveBlockHeader(block.header)

            #Flag of if the Block's Body synced.
            blockBodySynced: bool = False

            #Handle sync requests.
            reqHash: bytes = bytes()
            while True:
                if blockBodySynced:
                    #Sleep for a second so Meros handles the Block.
                    sleep(1)

                    #Try receiving from the Live socket, where Meros sends keep-alives.
                    try:
                        if len(rpc.meros.live.recv()) != 0:
                            raise Exception()
                    except TestError:
                        #Verify the height is 3.
                        #The genesis Block, the Block granting Merit, and the Block containing the MeritRemoval originally.
                        try:
                            if rpc.call("merit", "getHeight") != 3:
                                raise Exception()
                        except Exception:
                            raise TestError(
                                "Node added a Block containg a repeat MeritRemoval."
                            )

                        #Since the node didn't add the Block, raise SuccessError.
                        raise SuccessError(
                            "Node didn't add a Block containing a repeat MeritRemoval."
                        )
                    except Exception:
                        raise TestError("Meros sent a keep-alive.")

                msg: bytes = rpc.meros.sync.recv()
                if MessageType(msg[0]) == MessageType.BlockBodyRequest:
                    reqHash = msg[1:33]
                    if reqHash != block.header.hash:
                        raise TestError(
                            "Meros asked for a Block Body that didn't belong to the Block we just sent it."
                        )

                    #Send the BlockBody.
                    blockBodySynced = True
                    rpc.meros.blockBody(block)

                else:
                    raise TestError("Unexpected message sent: " +
                                    msg.hex().upper())

        Liver(rpc,
              vectors["blockchains"][i],
              transactions,
              callbacks={
                  1: sendMeritRemoval,
                  2: sendRepeatMeritRemoval
              }).live()
コード例 #10
0
datas.append(Data(datas[0].hash, b"Initial Data."))
datas.append(Data(datas[0].hash, b"Second Data."))
for data in datas:
    data.sign(edPrivKey)
    data.beat(spamFilter)

#Create Verifications for all 3.
verifs: List[SignedVerification] = []
packets: List[VerificationPacket] = []
for data in datas:
    verifs.append(SignedVerification(data.hash, 0))
    verifs[-1].sign(0, blsPrivKey)
    packets.append(VerificationPacket(data.hash, [0]))

#Create a MeritRemoval out of the conflicting Verifications.
mr: SignedMeritRemoval = SignedMeritRemoval(verifs[1], verifs[2])

#Generate a Block containing the MeritRemoval.
proto.add(packets=packets, elements=[mr])

result: Dict[str, Any] = {
    "blockchain": proto.toJSON(),
    "datas": [datas[0].toJSON(), datas[1].toJSON(), datas[2].toJSON()],
    "verification": verifs[0].toSignedJSON(),
    "removal": mr.toSignedJSON()
}
vectors: IO[Any] = open(
    "e2e/Vectors/Consensus/MeritRemoval/VerifyCompeting.json", "w")
vectors.write(json.dumps(result))
vectors.close()
コード例 #11
0
ファイル: HundredThirtyFive.py プロジェクト: vporton/Meros
#Create the initial Data and two competing Datas.
datas: List[Data] = [Data(bytes(32), edPubKey.to_bytes())]
datas.append(Data(datas[0].hash, b"Initial Data."))
datas.append(Data(datas[0].hash, b"Second Data."))
for data in datas:
    data.sign(edPrivKey)
    data.beat(spamFilter)

#Create Verifications for all 3.
verifs: List[SignedVerification] = []
for data in datas:
    verifs.append(SignedVerification(data.hash, 0))
    verifs[-1].sign(0, blsPrivKey)

#Create a MeritRemoval out of the conflicting Verifications.
mr: SignedMeritRemoval = SignedMeritRemoval(verifs[1], verifs[2])

#Create a MeritRemoval with random keys.
packeted: SignedMeritRemoval = SignedMeritRemoval(
    SignedMeritRemovalVerificationPacket(
        SignedVerificationPacket(verifs[1].hash), [
            blsPubKey.serialize(),
            PrivateKey(blake2b(
                b'\1', digest_size=32).digest()).toPublicKey().serialize(),
            PrivateKey(blake2b(
                b'\2', digest_size=32).digest()).toPublicKey().serialize()
        ],
        Signature.aggregate([
            blsPrivKey.sign(verifs[1].signatureSerialize()),
            PrivateKey(blake2b(b'\1', digest_size=32).digest()).sign(
                verifs[1].signatureSerialize()),
コード例 #12
0
ファイル: VerifyCompetingTest.py プロジェクト: vporton/Meros
def VerifyCompetingTest(rpc: RPC) -> None:
    file: IO[Any] = open(
        "e2e/Vectors/Consensus/MeritRemoval/VerifyCompeting.json", "r")
    vectors: Dict[str, Any] = json.loads(file.read())
    file.close()

    #Datas.
    datas: List[Data] = [
        Data.fromJSON(vectors["datas"][0]),
        Data.fromJSON(vectors["datas"][1]),
        Data.fromJSON(vectors["datas"][2])
    ]

    #Transactions.
    transactions: Transactions = Transactions()
    for data in datas:
        transactions.add(data)

    #Initial Data's Verification.
    verif: SignedVerification = SignedVerification.fromSignedJSON(
        vectors["verification"])

    #MeritRemoval.
    #pylint: disable=no-member
    removal: SignedMeritRemoval = SignedMeritRemoval.fromSignedJSON(
        vectors["removal"])

    #Create and execute a Liver to cause a Signed MeritRemoval.
    def sendElements() -> None:
        #Send the Datas.
        for data in datas:
            if rpc.meros.liveTransaction(data) != rpc.meros.live.recv():
                raise TestError("Meros didn't send us the Data.")

        #Send the initial Data's verification.
        if rpc.meros.signedElement(verif) != rpc.meros.live.recv():
            raise TestError("Meros didn't us the initial Data's Verification.")

        #Send the first Element.
        if rpc.meros.signedElement(removal.se1) != rpc.meros.live.recv():
            raise TestError("Meros didn't send us the Verification.")

        #Trigger the MeritRemoval.
        rpc.meros.signedElement(removal.se2)
        if rpc.meros.live.recv() != (MessageType.SignedMeritRemoval.toByte() +
                                     removal.signedSerialize()):
            raise TestError("Meros didn't send us the Merit Removal.")
        verifyMeritRemoval(rpc, 1, 1, removal.holder, True)

    Liver(rpc,
          vectors["blockchain"],
          transactions,
          callbacks={
              1: sendElements,
              2: lambda: verifyMeritRemoval(rpc, 1, 1, removal.holder, False)
          }).live()

    #Create and execute a Liver to handle a Signed MeritRemoval.
    def sendMeritRemoval() -> None:
        #Send the Datas.
        for data in datas:
            if rpc.meros.liveTransaction(data) != rpc.meros.live.recv():
                raise TestError("Meros didn't send us the Data.")

        #Send the initial Data's verification.
        if rpc.meros.signedElement(verif) != rpc.meros.live.recv():
            raise TestError("Meros didn't us the initial Data's Verification.")

        #Send and verify the MeritRemoval.
        if rpc.meros.signedElement(removal) != rpc.meros.live.recv():
            raise TestError("Meros didn't send us the Merit Removal.")
        verifyMeritRemoval(rpc, 1, 1, removal.holder, True)

    Liver(rpc,
          vectors["blockchain"],
          transactions,
          callbacks={
              1: sendMeritRemoval,
              2: lambda: verifyMeritRemoval(rpc, 1, 1, removal.holder, False)
          }).live()

    #Create and execute a Syncer to handle a Signed MeritRemoval.
    Syncer(rpc, vectors["blockchain"], transactions).sync()
    verifyMeritRemoval(rpc, 1, 1, removal.holder, False)
コード例 #13
0
ファイル: SameNonce.py プロジェクト: vporton/Meros
block.mine(blsPrivKey, blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Same Nonce Block " + str(len(blockchain.blocks)) + ".")

#Create a DataDifficulty.
dataDiff: SignedDataDifficulty = SignedDataDifficulty(3, 0)
dataDiff.sign(0, blsPrivKey)

#Create a conflicting DataDifficulty with the same nonce.
dataDiffConflicting = SignedDataDifficulty(1, 0)
dataDiffConflicting.sign(0, blsPrivKey)

#Create a MeritRemoval out of the two of them.
mr: SignedMeritRemoval = SignedMeritRemoval(dataDiff, dataDiffConflicting)

#Generate a Block containing the MeritRemoval.
block = Block(
    BlockHeader(0, blockchain.last(), BlockHeader.createContents([], [mr]), 1,
                bytes(4), bytes(32), 0,
                blockchain.blocks[-1].header.time + 1200),
    BlockBody([], [mr], mr.signature))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Same Nonce Block " + str(len(blockchain.blocks)) + ".")

result: Dict[str, Any] = {
コード例 #14
0
ファイル: HundredThirtyThree.py プロジェクト: vporton/Meros
    [
      PrivateKey(blake2b(b'\1', digest_size=32).digest()).toPublicKey().serialize()
    ],
    PrivateKey(blake2b(b'\1', digest_size=32).digest()).sign(verifs[1].signatureSerialize())
  ),
  SignedMeritRemovalVerificationPacket(
    SignedVerificationPacket(verifs[1].hash),
    [
      PrivateKey(blake2b(b'\1', digest_size=32).digest()).toPublicKey().serialize()
    ],
    PrivateKey(blake2b(b'\1', digest_size=32).digest()).sign(verifs[1].signatureSerialize())
  )
]

#Create a MeritRemoval out of the conflicting Verifications.
e1MR: SignedMeritRemoval = SignedMeritRemoval(verifs[1], packets[0], 0)
e2MR: SignedMeritRemoval = SignedMeritRemoval(packets[1], verifs[2], 0)

#Generate a Block containing the MeritRemoval for each chain.
block = Block(
  BlockHeader(
    0,
    e1Chain.last(),
    BlockHeader.createContents([], [e1MR]),
    1,
    bytes(4),
    bytes(32),
    0,
    e1Chain.blocks[-1].header.time + 1200
  ),
  BlockBody([], [e1MR], e1MR.signature)
コード例 #15
0
ファイル: SameElement.py プロジェクト: Tesconanopay/MerosDeFi
from e2e.Classes.Consensus.SpamFilter import SpamFilter

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

proto: PrototypeChain = PrototypeChain(1, False)

blsPrivKey: PrivateKey = PrivateKey(0)
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

edPrivKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key()

#Create the SendDifficulty MR.
sendDiff: SignedSendDifficulty = SignedSendDifficulty(4, 0)
sendDiff.sign(0, blsPrivKey)
sendDiffMR: SignedMeritRemoval = SignedMeritRemoval(sendDiff, sendDiff)

#Create the DataDifficulty MR.
dataDiff: SignedDataDifficulty = SignedDataDifficulty(4, 0)
dataDiff.sign(0, blsPrivKey)
dataDiffMR: SignedMeritRemoval = SignedMeritRemoval(dataDiff, dataDiff)

#Create the Verification MR.
data: Data = Data(bytes(32), edPubKey.to_bytes())
data.sign(edPrivKey)
data.beat(SpamFilter(5))
verif: SignedVerification = SignedVerification(data.hash)
verif.sign(0, blsPrivKey)

#Transform the Verification to a SignedMeritRemovalVerificationPacket.
packet: SignedMeritRemovalVerificationPacket = SignedMeritRemovalVerificationPacket(
コード例 #16
0
from e2e.Classes.Consensus.MeritRemoval import SignedMeritRemoval

from e2e.Vectors.Generation.PrototypeChain import PrototypeChain

blsPrivKey: PrivateKey = PrivateKey(0)
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

proto: PrototypeChain = PrototypeChain(1, False)

#Create conflicting Data Difficulties.
dataDiffs: List[SignedDataDifficulty] = [
    SignedDataDifficulty(3, 0),
    SignedDataDifficulty(4, 0)
]
dataDiffs[0].sign(0, blsPrivKey)
dataDiffs[1].sign(0, blsPrivKey)

#Create a MeritRemoval out of the conflicting Data Difficulties.
mr: SignedMeritRemoval = SignedMeritRemoval(dataDiffs[0], dataDiffs[1])
proto.add(elements=[mr])

#Create a MeritRemoval with the Elements swapped.
swapped: SignedMeritRemoval = SignedMeritRemoval(dataDiffs[1], dataDiffs[0])
proto.add(elements=[swapped])

result: Dict[str, Any] = {"blockchain": proto.toJSON()}
vectors: IO[Any] = open(
    "e2e/Vectors/Consensus/MeritRemoval/HundredTwentyThree/Swap.json", "w")
vectors.write(json.dumps(result))
vectors.close()
コード例 #17
0
    bytes(4),
    bytes(32),
    0,
    blockchain.blocks[-1].header.time + 1200
  ),
  BlockBody([], [partial], partial.signature)
)
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

#Add it.
blockchain.add(block)
print("Generated Hundred Twenty Three Partial Block " + str(len(blockchain.blocks)) + ".")

#Create a MeritRemoval which isn't partial.
mr: SignedMeritRemoval = SignedMeritRemoval(dataDiffs[0], dataDiffs[1])

#Generate a Block containing the MeritRemoval.
block = Block(
  BlockHeader(
    0,
    blockchain.last(),
    BlockHeader.createContents([], [mr]),
    1,
    bytes(4),
    bytes(32),
    0,
    blockchain.blocks[-1].header.time + 1200
  ),
  BlockBody([], [mr], mr.signature)
)