コード例 #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)
コード例 #2
0
ファイル: PartialTest.py プロジェクト: bitcoinsfacil/Meros
def PartialTest(rpc: RPC) -> None:
    file: IO[Any] = open(
        "PythonTests/Vectors/Consensus/MeritRemoval/Partial.json", "r")
    vectors: Dict[str, Any] = json.loads(file.read())
    file.close()

    keys: Dict[bytes, int] = {
        bytes.fromhex(vectors["blockchain"][0]["header"]["miner"]): 0
    }
    nicks: List[bytes] = [
        bytes.fromhex(vectors["blockchain"][0]["header"]["miner"])
    ]

    #MeritRemoval.
    #pylint: disable=no-member
    removal: PartialMeritRemoval = PartialMeritRemoval.fromSignedJSON(
        keys, 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.recv() != (MessageType.SignedMeritRemoval.toByte() +
                                removal.signedSerialize(nicks)):
            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.signedElement(removal) != rpc.meros.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)
コード例 #3
0
    BlockBody([], [dataDiff], dataDiff.signature))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

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

#Create a conflicting DataDifficulty with the same nonce.
dataDiffConflicting = SignedDataDifficulty(
    bytes.fromhex(
        "8888888888888888888888888888888888888888888888888888888888888888"), 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 Partial Block " + str(len(blockchain.blocks)) + ".")
コード例 #4
0
#Now that we have aa vote, update our vote.
block = Block(
    BlockHeader(0, blockchain.last(),
                BlockHeader.createContents([], [dataDiffs[1]]), 1, bytes(4),
                bytes(32), 0, blockchain.blocks[-1].header.time + 1200),
    BlockBody([], [dataDiffs[1]], dataDiffs[1].signature))
block.mine(blsPrivKey, blockchain.difficulty())
blockchain.add(block)
print("Generated DataDifficulty Block " + str(len(blockchain.blocks)) + ".")

#Create MeritRemovals by reusing nonces.
for n in range(2):
    competing: SignedDataDifficulty = SignedDataDifficulty(0, n)
    competing.sign(0, blsPrivKey)
    mr: PartialMeritRemoval = PartialMeritRemoval(dataDiffs[n], competing)
    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))
    block.mine(blsPrivKey, blockchain.difficulty())
    blockchain.add(block)
    print("Generated DataDifficulty Block " + str(len(blockchain.blocks)) +
          ".")

#Mine another 50 Blocks.
for _ in range(50):
    block = Block(
        BlockHeader(0, blockchain.last(), bytes(32), 1, bytes(4), bytes(32), 0,
コード例 #5
0
ファイル: SendDifficulty.py プロジェクト: developerfred/Meros
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.
コード例 #6
0
#Generate a Block containing the first Data Difficulty.
block = Block(
    BlockHeader(0, blockchain.last(),
                BlockHeader.createContents([], [dataDiffs[0]]), 1, 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))
#Mine it.
block.mine(blsPrivKey, blockchain.difficulty())

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