Ejemplo n.º 1
0
    def __init__(
        self,
        genesis: bytes,
        blockTime: int,
        startDifficulty: int
    ) -> None:
        self.blockTime: int = blockTime

        self.startDifficulty: int = startDifficulty
        self.maxDifficulty: int = (2 ** 384) - 1
        self.difficulty: int = startDifficulty
        self.difficultyUntil: int = 1

        self.blocks: List[Block] = [
            Block(
                BlockHeader(
                    0,
                    genesis.rjust(48, b'\0'),
                    0
                ),
                BlockBody(
                    miners = []
                )
            )
        ]
Ejemplo n.º 2
0
def ChainAdvancementTest(rpc: RPC) -> None:
    #Blockchain.
    blockchain: Blockchain = Blockchain(
        b"MEROS_DEVELOPER_NETWORK", 60,
        int(
            "FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
            16))
    #Blocks.
    file: IO[Any] = open("python_tests/Vectors/Merit/BlankBlocks.json", "r")
    blocks: List[Dict[str, Any]] = json.loads(file.read())
    file.close()

    #Publish Blocks.
    for jsonBlock in blocks:
        #Parse the Block.
        block: Block = Block.fromJSON(jsonBlock)

        #Add it locally.
        blockchain.add(block)

        #Publish it.
        rpc.call("merit", "publishBlock", [block.serialize().hex()])

        #Verify the difficulty.
        if int(rpc.call("merit", "getDifficulty"),
               16) != blockchain.difficulty:
            raise TestError("Difficulty doesn't match.")

    #Verify the Blockchain.
    verifyBlockchain(rpc, blockchain)
Ejemplo n.º 3
0
 def fromJSON(
     genesis: bytes,
     blockTime: int,
     startDifficulty: int,
     blocks: List[Dict[str, Any]]
 ) -> Any:
     result = Blockchain(
         genesis,
         blockTime,
         startDifficulty
     )
     for block in blocks:
         result.add(Block.fromJSON(block))
     return result
Ejemplo n.º 4
0
        "FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
        16))

#BLS Keys.
privKey: blspy.PrivateKey = blspy.PrivateKey.from_seed(b'\0')
pubKey: blspy.PublicKey = privKey.get_public_key()

#Ed25519 keys.
edKeys: List[ed25519.SigningKey] = []
for i in range(6):
    edKeys.append(ed25519.SigningKey(i.to_bytes(1, byteorder="big") * 32))

#Add a single Block to create Merit.
bbFile: IO[Any] = open("python_tests/Vectors/Merit/BlankBlocks.json", "r")
blocks: List[Dict[str, Any]] = json.loads(bbFile.read())
blockchain.add(Block.fromJSON(blocks[0]))
bbFile.close()

#Create a Data per key.
datas: List[Data] = []
for edPrivKey in edKeys:
    datas.append(
        Data(edPrivKey.get_verifying_key().to_bytes().rjust(48, b'\0'),
             bytes()))
    datas[-1].sign(edPrivKey)
    datas[-1].beat(consensus.dataFilter)

#Create 1 Verification per Data.
verifs: List[SignedVerification] = []
for d in range(len(datas)):
    verifs.append(SignedVerification(datas[d].hash))
Ejemplo n.º 5
0
    60,
    int("FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", 16),
    100
)

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

#BLS keys.
blsPrivKey: blspy.PrivateKey = blspy.PrivateKey.from_seed(b'\0')
blsPubKey: blspy.PublicKey = blsPrivKey.get_public_key()

#Add 13 Blank Blocks.
for i in range(13):
    merit.add(transactions, consensus, Block.fromJSON(blankBlocks[i]))

#Create the Data.
data: Data = Data(
    edPubKey.to_bytes().rjust(48, b'\0'),
    bytes()
)
data.sign(edPrivKey)
data.beat(consensus.dataFilter)
data.verified = True
transactions.add(data)

#Verify it.
verif: SignedVerification = SignedVerification(data.hash)
verif.sign(blsPrivKey, 0)
consensus.add(verif)
Ejemplo n.º 6
0
from python_tests.Classes.Merit.Block import Block
from python_tests.Classes.Merit.Blockchain import Blockchain

#Time standard function.
from time import time

#JSON standard lib.
import json

#Blockchain.
blockchain: Blockchain = Blockchain(
    b"MEROS_DEVELOPER_NETWORK", 60,
    int(
        "FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
        16))

#Generate blocks.
for i in range(1, 26):
    #Create the Block.
    block: Block = Block(BlockHeader(i, blockchain.last(), int(time())),
                         BlockBody())
    block.mine(blockchain.difficulty)

    #Add it locally.
    blockchain.add(block)
    print("Generated Blank Block " + str(i) + ".")

vectors: IO[Any] = open("python_tests/Vectors/Merit/BlankBlocks.json", "w")
vectors.write(json.dumps(blockchain.toJSON()))
vectors.close()
Ejemplo n.º 7
0
    transactions.add(sends[-1])

    sends.append(
        Send([(sends[-1].hash, 0)],
             [(edPubKey.to_bytes(), sends[-1].outputs[0][1])]))

#Verify 0 and 1 in order.
order: List[int] = [0, 1]
verif: SignedVerification
for s in order:
    verif = SignedVerification(sends[s].hash)
    verif.sign(blsPrivKey1, len(consensus.holders[blsPubKey1.serialize()]))
    consensus.add(verif)

block: Block = Block(
    BlockHeader(21, blockchain.last(), int(time()),
                consensus.getAggregate([(blsPubKey1, 2, -1)])),
    BlockBody([(blsPubKey1, 3, consensus.getMerkle(blsPubKey1, 2))]))
block.mine(blockchain.difficulty)
blockchain.add(block)
print("Generated Fifty Block " + str(block.header.nonce) + ".")

#Verify 3, and then 2, while giving Merit to a second Merit Holder.
order = [3, 2]
for s in order:
    verif = SignedVerification(sends[s].hash)
    verif.sign(blsPrivKey1, len(consensus.holders[blsPubKey1.serialize()]))
    consensus.add(verif)

block = Block(
    BlockHeader(22, blockchain.last(), int(time()),
                consensus.getAggregate([(blsPubKey1, 4, -1)])),
Ejemplo n.º 8
0
    int(
        "FAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
        16))

#BLS Keys.
privKey: blspy.PrivateKey = blspy.PrivateKey.from_seed(b'\0')
pubKey: blspy.PublicKey = privKey.get_public_key()

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

#Add a single Block to create Merit.
bbFile: IO[Any] = open("python_tests/Vectors/Merit/BlankBlocks.json", "r")
blocks: List[Dict[str, Any]] = json.loads(bbFile.read())
blockchain.add(Block.fromJSON(blocks[0]))
bbFile.close()

#Create a Data to verify.
data: Data = Data(edPubKey.to_bytes().rjust(48, b'\0'), bytes())
data.sign(edPrivKey)
data.beat(consensus.dataFilter)

#Create two Verifications with the same nonce, yet for the different Datas.
sv1: SignedVerification = SignedVerification(data.hash)
sv1.sign(privKey, 0)

sv2: SignedVerification = SignedVerification(b'\0' * 48)
sv2.sign(privKey, 0)

removal: SignedMeritRemoval = SignedMeritRemoval(