def test_have_two_proposals(self):
        ppy = self.ppy
        tx1 = ppy.new_tx()

        # Proposal 1
        proposal1 = ppy.new_proposal(tx1, proposer="init0")
        op = operations.Transfer(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "from": "1.2.0",
                "to": "1.2.0",
                "amount": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "prefix": "PPY",
            })
        for i in range(0, 3):
            proposal1.appendOps(op)

        # Proposal 1
        proposal2 = ppy.new_proposal(tx1, proposer="init0")
        op = operations.Transfer(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "from": "1.2.0",
                "to": "1.2.0",
                "amount": {
                    "amount": 5555555,
                    "asset_id": "1.3.0"
                },
                "prefix": "PPY",
            })
        for i in range(0, 2):
            proposal2.appendOps(op)
        tx = tx1.json()

        self.assertEqual(len(tx["operations"]), 2)  # 2 proposals

        # Test proposal 1
        prop = tx["operations"][0]
        self.assertEqual(prop[0], 22)
        ps = prop[1]
        self.assertEqual(len(ps["proposed_ops"]), 3)
        for i in range(0, 3):
            self.assertEqual(ps["proposed_ops"][i]["op"][0], 0)

        # Test proposal 2
        prop = tx["operations"][1]
        self.assertEqual(prop[0], 22)
        ps = prop[1]
        self.assertEqual(len(ps["proposed_ops"]), 2)
        for i in range(0, 2):
            self.assertEqual(ps["proposed_ops"][i]["op"][0], 0)
 def test_add_one_proposal_two_ops(self):
     ppy = self.ppy
     tx1 = ppy.new_tx()
     proposal1 = ppy.new_proposal(tx1, proposer="init0")
     op = operations.Transfer(
         **{
             "fee": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "from": "1.2.0",
             "to": "1.2.0",
             "amount": {
                 "amount": 0,
                 "asset_id": "1.3.0"
             },
             "prefix": "PPY",
         })
     proposal1.appendOps(op)
     proposal1.appendOps(op)
     tx = tx1.json()
     self.assertEqual(tx["operations"][0][0], 22)
     self.assertEqual(len(tx["operations"]), 1)
     ps = tx["operations"][0][1]
     self.assertEqual(len(ps["proposed_ops"]), 2)
     self.assertEqual(ps["proposed_ops"][0]["op"][0], 0)
     self.assertEqual(ps["proposed_ops"][1]["op"][0], 0)
Ejemplo n.º 3
0
    def test_Transfer(self):
        pub = format(account.PrivateKey(wif).pubkey, prefix)
        from_account_id = "1.2.0"
        to_account_id = "1.2.1"
        amount = 1000000
        asset_id = "1.3.4"
        message = "abcdefgABCDEFG0123456789"
        nonce = "5862723643998573708"

        fee = objects.Asset(amount=0, asset_id="1.3.0")
        amount = objects.Asset(amount=int(amount), asset_id=asset_id)
        encrypted_memo = memo.encode_memo(
            account.PrivateKey(wif), account.PublicKey(pub, prefix=prefix),
            nonce, message)
        op = operations.Transfer(
            **{
                "fee": fee,
                "from": from_account_id,
                "to": to_account_id,
                "amount": amount,
                "memo": {
                    "from": pub,
                    "to": pub,
                    "nonce": nonce,
                    "message": encrypted_memo,
                },
                "prefix": prefix
            })
        ops = [Operation(op)]
        tx = Signed_Transaction(ref_block_num=ref_block_num,
                                ref_block_prefix=ref_block_prefix,
                                expiration=expiration,
                                operations=ops)
        tx = tx.sign([wif], chain=prefix)
        tx.verify([PrivateKey(wif).pubkey], prefix)
        txWire = hexlify(bytes(tx)).decode("ascii")

        compare = ("f68585abf4dce7c804570100000000000000000000000140420"
                   "f0000000000040102c0ded2bc1f1305fb0faac5e6c03ee3a192"
                   "4234985427b6167ca569d13df435cf02c0ded2bc1f1305fb0fa"
                   "ac5e6c03ee3a1924234985427b6167ca569d13df435cf8c94d1"
                   "9817945c5120fa5b6e83079a878e499e2e52a76a7739e9de409"
                   "86a8e3bd8a68ce316cee50b210000011f39e3fa7071b795491e"
                   "3b6851d61e7c959be92cc7deb5d8491cf1c3c8c99a1eb44553c"
                   "348fb8f5001a78b18233ac66727e32fc776d48e92d9639d64f6"
                   "8e641948")
        self.assertEqual(compare[:-130], txWire[:-130])
    def test_Transfer(self):
        pub = format(account.PrivateKey(wif).pubkey, prefix)
        from_account_id = "1.2.0"
        to_account_id = "1.2.1"
        amount = 1000000
        asset_id = "1.3.4"
        message = "abcdefgABCDEFG0123456789"
        nonce = "5862723643998573708"

        fee = objects.Asset(amount=0, asset_id="1.3.0")
        amount = objects.Asset(amount=int(amount), asset_id=asset_id)
        encrypted_memo = memo.encode_memo(
            account.PrivateKey(wif),
            account.PublicKey(pub, prefix=prefix),
            nonce,
            message,
        )
        self.op = operations.Transfer(
            **{
                "fee": fee,
                "from": from_account_id,
                "to": to_account_id,
                "amount": amount,
                "memo": {
                    "from": pub,
                    "to": pub,
                    "nonce": nonce,
                    "message": encrypted_memo,
                },
                "prefix": prefix,
            }
        )
        self.cm = (
            "f68585abf4dce7c804570100000000000000000000000140420"
            "f0000000000040102c0ded2bc1f1305fb0faac5e6c03ee3a192"
            "4234985427b6167ca569d13df435cf02c0ded2bc1f1305fb0fa"
            "ac5e6c03ee3a1924234985427b6167ca569d13df435cf8c94d1"
            "9817945c5120fa5b6e83079a878e499e2e52a76a7739e9de409"
            "86a8e3bd8a68ce316cee50b210000011f39e3fa7071b795491e"
            "3b6851d61e7c959be92cc7deb5d8491cf1c3c8c99a1eb44553c"
            "348fb8f5001a78b18233ac66727e32fc776d48e92d9639d64f6"
            "8e641948"
        )
        self.doit()
Ejemplo n.º 5
0
    def test_finalize(self):
        account = Account(account_id)

        op = operations.Transfer(
            **{
                "fee": {
                    "asset_id": "1.3.0",
                    "amount": 1
                },
                "from": account_id,
                "to": '1.2.8',
                "amount": {
                    "asset_id": "1.3.0",
                    "amount": 1
                }
            })

        tx = self.ppy.finalizeOp(op, account, "active")
        self.assertEqual(len(tx["signatures"]), 1)
Ejemplo n.º 6
0
    def transfer(self, to, amount, asset, memo="", account=None):
        """ Transfer an asset to another account.

            :param str to: Recipient
            :param float amount: Amount to transfer
            :param str asset: Asset to transfer
            :param str memo: (optional) Memo, may begin with `#` for encrypted messaging
            :param str account: (optional) the source account for the transfer if not ``default_account``
        """
        from .memo import Memo
        if not account:
            if "default_account" in config:
                account = config["default_account"]
        if not account:
            raise ValueError("You need to provide an account")

        account = Account(account, peerplays_instance=self)
        amount = Amount(amount, asset, peerplays_instance=self)
        to = Account(to, peerplays_instance=self)

        memoObj = Memo(from_account=account,
                       to_account=to,
                       peerplays_instance=self)

        op = operations.Transfer(
            **{
                "fee": {
                    "amount": 0,
                    "asset_id": "1.3.0"
                },
                "from": account["id"],
                "to": to["id"],
                "amount": {
                    "amount": int(amount),
                    "asset_id": amount.asset["id"]
                },
                "memo": memoObj.encrypt(memo),
                "prefix": self.rpc.chain_params["prefix"]
            })
        return self.finalizeOp(op, account, "active")