Beispiel #1
0
def VCompetingTest(rpc: RPC) -> None:
    vectors: Dict[str, Any]
    with open("e2e/Vectors/Consensus/Verification/Competing.json",
              "r") as file:
        vectors = json.loads(file.read())

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

    #Function to verify the right Transaction was confirmed.
    def verifyConfirmation() -> None:
        if not rpc.call("consensus", "getStatus",
                        {"hash": vectors["verified"]})["verified"]:
            raise TestError(
                "Didn't verify the Send which should have been verified.")

        if rpc.call("consensus", "getStatus",
                    {"hash": vectors["beaten"]})["verified"]:
            raise TestError(
                "Did verify the Send which should have been beaten.")

    Liver(rpc,
          vectors["blockchain"],
          transactions,
          callbacks={
              19: verifyConfirmation
          }).live()
    Syncer(rpc, vectors["blockchain"], transactions).sync()
def ChainAdvancementTest(rpc: RPC) -> None:
    file: IO[Any] = open("e2e/Vectors/Merit/BlankBlocks.json", "r")
    chain: List[Dict[str, Any]] = json.loads(file.read())
    file.close()

    Liver(rpc, chain).live()
    Syncer(rpc, chain).sync()
def DataDifficultyTest(rpc: RPC) -> None:
    file: IO[Any] = open(
        "e2e/Vectors/Consensus/Difficulties/DataDifficulty.json", "r")
    vectors: Dict[str, Any] = json.loads(file.read())
    file.close()

    #Verify functions.
    vddStarting: Callable[[], None] = lambda: verifyDataDifficulty(rpc, 5)
    vddEarnedVote: Callable[[], None] = lambda: verifyDataDifficulty(rpc, 2)
    vddVoted: Callable[[], None] = lambda: verifyDataDifficulty(rpc, 1)

    def vmr() -> None:
        verifyMeritRemoval(rpc, 52, 52, 0, False)
        vddStarting()

    def vEarnedBack() -> None:
        vddStarting()

    #Create and execute a Liver/Syncer.
    Liver(rpc,
          vectors["blockchain"],
          callbacks={
              26: vddStarting,
              50: vddEarnedVote,
              51: vddVoted,
              52: vmr,
              103: vEarnedBack
          }).live()
    Syncer(rpc, vectors["blockchain"]).sync()
Beispiel #4
0
def FiftyTest(rpc: RPC) -> None:
    with open("e2e/Vectors/Transactions/Fifty.json", "r") as file:
        vectors: Dict[str, Any] = json.loads(file.read())
        Liver(rpc, vectors["blockchain"],
              Transactions.fromJSON(vectors["transactions"])).live()
        Syncer(rpc, vectors["blockchain"],
               Transactions.fromJSON(vectors["transactions"])).sync()
def MultiInputClaimTest(rpc: RPC) -> None:
    with open("e2e/Vectors/Transactions/MultiInputClaim.json", "r") as file:
        vectors: Dict[str, Any] = json.loads(file.read())
        transactions: Transactions = Transactions.fromJSON(
            vectors["transactions"])
        Liver(rpc, vectors["blockchain"], transactions).live()
        Syncer(rpc, vectors["blockchain"], transactions).sync()
Beispiel #6
0
def ChainAdvancementTest(rpc: RPC) -> None:
    file: IO[Any] = open("e2e/Vectors/Merit/BlankBlocks.json", "r")
    blocks: List[Dict[str, Any]] = json.loads(file.read())
    file.close()

    #Create and execute a Liver/Syncer.
    Liver(rpc, blocks).live()
    Syncer(rpc, blocks).sync()
def MultiInputClaimTest(rpc: RPC) -> None:
    file: IO[Any] = open("e2e/Vectors/Transactions/MultiInputClaim.json", "r")
    vectors: Dict[str, Any] = json.loads(file.read())
    file.close()

    Liver(rpc, vectors["blockchain"],
          Transactions.fromJSON(vectors["transactions"])).live()
    Syncer(rpc, vectors["blockchain"],
           Transactions.fromJSON(vectors["transactions"])).sync()
Beispiel #8
0
def KeyChangeTest(
  rpc: RPC
) -> None:
  file: IO[Any] = open("e2e/Vectors/Merit/RandomX/KeyChange.json", "r")
  chain: List[Dict[str, Any]] = json.loads(file.read())
  file.close()

  Liver(rpc, chain).live()
  Syncer(rpc, chain).sync()
Beispiel #9
0
def KeepUnlockedTest(rpc: RPC) -> None:
    def verifyUnlocked(_: int) -> None:
        if rpc.call("merit", "getMerit", {"nick": 0})["status"] != "Unlocked":
            raise TestError("Meros didn't keep Merit unlocked.")

    with open("e2e/Vectors/Merit/LockedMerit/KeepUnlocked.json", "r") as file:
        for chain in json.loads(file.read()):
            Liver(rpc, chain, everyBlock=verifyUnlocked).live()
            Syncer(rpc, chain).sync()
Beispiel #10
0
def FiftyTest(rpc: RPC) -> None:
    file: IO[Any] = open("e2e/Vectors/Transactions/Fifty.json", "r")
    vectors: Dict[str, Any] = json.loads(file.read())
    file.close()

    #Create and execute a Liver/Syncer.
    Liver(rpc, vectors["blockchain"],
          Transactions.fromJSON(vectors["transactions"])).live()
    Syncer(rpc, vectors["blockchain"],
           Transactions.fromJSON(vectors["transactions"])).sync()
Beispiel #11
0
def OOOElementsTest(rpc: RPC) -> None:
    with open("e2e/Vectors/Merit/OutOfOrder/Elements.json", "r") as file:
        vectors: List[Dict[str, Any]] = json.loads(file.read())

        Liver(rpc,
              vectors,
              callbacks={
                  50: lambda: verifyDataDifficulty(rpc, 1),
                  51: lambda: verifyDataDifficulty(rpc, 4)
              }).live()
        Syncer(rpc, vectors).sync()
Beispiel #12
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)
Beispiel #13
0
def KeepUnlockedTest(rpc: RPC) -> None:
    file: IO[Any] = open("e2e/Vectors/Merit/LockedMerit/KeepUnlocked.json",
                         "r")
    chains: List[List[Dict[str, Any]]] = json.loads(file.read())
    file.close()

    def verifyUnlocked(_: int) -> None:
        if rpc.call("merit", "getMerit", [0])["status"] != "Unlocked":
            raise TestError("Meros didn't keep Merit unlocked.")

    for chain in chains:
        Liver(rpc, chain, everyBlock=verifyUnlocked).live()
        Syncer(rpc, chain).sync()
Beispiel #14
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)
Beispiel #15
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)
Beispiel #16
0
def SendDifficultyTest(rpc: RPC) -> None:
    #Verify functions.
    vddStarting: Callable[[], None] = lambda: verifySendDifficulty(rpc, 3)
    vddEarnedVote: Callable[[], None] = lambda: verifySendDifficulty(rpc, 2)
    vddVoted: Callable[[], None] = lambda: verifySendDifficulty(rpc, 1)

    def vmr() -> None:
        verifyMeritRemoval(rpc, 52, 52, 0, False)
        vddStarting()

    #Create and execute a Liver/Syncer.
    with open("e2e/Vectors/Consensus/Difficulties/SendDifficulty.json",
              "r") as file:
        vectors: List[Dict[str, Any]] = json.loads(file.read())
        Liver(rpc,
              vectors,
              callbacks={
                  26: vddStarting,
                  50: vddEarnedVote,
                  51: vddVoted,
                  52: vmr
              }).live()
        Syncer(rpc, vectors).sync()
Beispiel #17
0
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)
Beispiel #18
0
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)
Beispiel #19
0
def ChainAdvancementTest(rpc: RPC) -> None:
    with open("e2e/Vectors/Merit/BlankBlocks.json", "r") as file:
        vectors: List[Dict[str, Any]] = json.loads(file.read())
        Liver(rpc, vectors).live()
        Syncer(rpc, vectors).sync()