Exemple #1
0
    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, 1, 1, 0, False)
Exemple #2
0
def PartialTest(
  rpc: RPC
) -> None:
  vectors: Dict[str, Any]
  with open("e2e/Vectors/Consensus/MeritRemoval/Partial.json", "r") as file:
    vectors = json.loads(file.read())

  removal: PartialMeritRemoval = PartialMeritRemoval.fromSignedJSON(vectors["removal"])

  #Create and execute a Liver to cause a Partial MeritRemoval.
  def sendElement() -> None:
    #Send the second Element.
    rpc.meros.signedElement(removal.se2)

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

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

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

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

  #Create and execute a Syncer to handle a Partial MeritRemoval.
  Syncer(rpc, vectors["blockchain"]).sync()
  verifyMeritRemoval(rpc, 2, 2, removal.holder, False)
Exemple #3
0
block = Block(
    BlockHeader(0, blockchain.last(),
                BlockHeader.createContents([], [sendDiff]), 1, bytes(4),
                bytes(32), 0, blockchain.blocks[-1].header.time + 1200),
    BlockBody([], [sendDiff], sendDiff.signature))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

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

#Create a MeritRemoval by reusing a nonce.
competing: SignedSendDifficulty = SignedSendDifficulty(0, 1)
competing.sign(0, blsPrivKey)
mr: PartialMeritRemoval = PartialMeritRemoval(sendDiff, competing)

#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 SendDifficulty Block " + str(len(blockchain.blocks)) + ".")

#Mine another 50 Blocks.
Exemple #4
0
                BlockHeader.createContents([], [dataDiff]), 1, bytes(4),
                bytes(32), 0, blockchain.blocks[-1].header.time + 1200),
    BlockBody([], [dataDiff], dataDiff.signature))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

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

#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: PartialMeritRemoval = PartialMeritRemoval(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 Repeat Block " + str(len(blockchain.blocks)) + ".")

#Generate another Block containing the MeritRemoval.
Exemple #5
0
    bytes(4),
    bytes(32),
    0,
    blockchain.blocks[-1].header.time + 1200
  ),
  BlockBody([], [dataDiffs[0]], dataDiffs[0].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 partial MeritRemoval out of the conflicting Data Difficulties.
partial: PartialMeritRemoval = PartialMeritRemoval(dataDiffs[0], dataDiffs[1])

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