Ejemplo n.º 1
0
 def test_leeq(self):
     a1 = Amount(1, self.symbol)
     a2 = Amount(1, self.symbol)
     self.assertTrue(a1 <= a2)
     self.assertTrue(a1 >= a2)
     self.assertTrue(a1 <= 1)
     self.assertTrue(a1 >= 1)
Ejemplo n.º 2
0
 def test_ltge(self):
     a1 = Amount(1, self.symbol)
     a2 = Amount(2, self.symbol)
     self.assertTrue(a1 < a2)
     self.assertTrue(a2 > a1)
     self.assertTrue(a2 > 1)
     self.assertTrue(a1 < 5)
Ejemplo n.º 3
0
 def reset(self):
     """ Resets the arrays not the stored account history
     """
     self.own_vests = [
         Amount(0, self.crea.vests_symbol, crea_instance=self.crea)
     ]
     self.own_crea = [
         Amount(0, self.crea.crea_symbol, crea_instance=self.crea)
     ]
     self.own_sbd = [
         Amount(0, self.crea.sbd_symbol, crea_instance=self.crea)
     ]
     self.delegated_vests_in = [{}]
     self.delegated_vests_out = [{}]
     self.timestamps = [addTzInfo(datetime(1970, 1, 1, 0, 0, 0, 0))]
     import creabase.operationids
     self.ops_statistics = creabase.operationids.operations.copy()
     for key in self.ops_statistics:
         self.ops_statistics[key] = 0
     self.reward_timestamps = []
     self.author_rewards = []
     self.curation_rewards = []
     self.curation_per_1000_SP_timestamp = []
     self.curation_per_1000_SP = []
     self.out_vote_timestamp = []
     self.out_vote_weight = []
     self.in_vote_timestamp = []
     self.in_vote_weight = []
     self.in_vote_rep = []
     self.in_vote_rshares = []
     self.vp = []
     self.vp_timestamp = []
     self.rep = []
     self.rep_timestamp = []
Ejemplo n.º 4
0
 def test_ne(self):
     a1 = Amount(1, self.symbol)
     a2 = Amount(2, self.symbol)
     self.assertTrue(a1 != a2)
     self.assertTrue(a1 != 5)
     a1 = Amount(1, self.symbol)
     a2 = Amount(1, self.symbol)
     self.assertTrue(a1 == a2)
     self.assertTrue(a1 == 1)
Ejemplo n.º 5
0
 def test_json_appbase(self):
     asset = Asset("CBD", crea_instance=self.bts)
     amount = Amount("1",
                     asset,
                     new_appbase_format=False,
                     crea_instance=self.bts)
     if self.bts.rpc.get_use_appbase():
         self.assertEqual(
             amount.json(),
             [str(1 * 10**asset.precision), asset.precision, asset.asset])
     else:
         self.assertEqual(amount.json(), "1.000 CBD")
Ejemplo n.º 6
0
 def test_plus(self):
     a1 = Amount(1, self.symbol)
     a2 = Amount(2, self.symbol)
     self.dotest(a1 + a2, 3, self.symbol)
     self.dotest(a1 + 2, 3, self.symbol)
     with self.assertRaises(Exception):
         a1 + Amount(1, asset=self.asset2)
     # inline
     a2 = Amount(2, self.symbol)
     a2 += a1
     self.dotest(a2, 3, self.symbol)
     a2 += 5
     self.dotest(a2, 8, self.symbol)
     with self.assertRaises(Exception):
         a1 += Amount(1, asset=self.asset2)
Ejemplo n.º 7
0
 def test_json_appbase2(self):
     asset = Asset("CBD", crea_instance=self.bts)
     amount = Amount("1",
                     asset,
                     new_appbase_format=True,
                     crea_instance=self.bts)
     if self.bts.rpc.get_use_appbase():
         self.assertEqual(
             amount.json(), {
                 'amount': str(1 * 10**asset.precision),
                 'nai': asset.asset,
                 'precision': asset.precision
             })
     else:
         self.assertEqual(amount.json(), "1.000 CBD")
Ejemplo n.º 8
0
 def test_amount(self, node_param):
     if node_param == "instance":
         stm = Crea(node="https://abc.d", autoconnect=False, num_retries=1)
         set_shared_crea_instance(self.bts)
         o = Amount("1 CBD")
         self.assertIn(o.crea.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Amount("1 CBD", crea_instance=stm)
     else:
         set_shared_crea_instance(
             Crea(node="https://abc.d", autoconnect=False, num_retries=1))
         stm = self.bts
         o = Amount("1 CBD", crea_instance=stm)
         self.assertIn(o.crea.rpc.url, self.urls)
         with self.assertRaises(RPCConnection):
             Amount("1 CBD")
Ejemplo n.º 9
0
 def test_minus(self):
     a1 = Amount(1, self.symbol)
     a2 = Amount(2, self.symbol)
     self.dotest(a1 - a2, -1, self.symbol)
     self.dotest(a1 - 5, -4, self.symbol)
     with self.assertRaises(Exception):
         a1 - Amount(1, asset=self.asset2)
     # inline
     a2 = Amount(2, self.symbol)
     a2 -= a1
     self.dotest(a2, 1, self.symbol)
     a2 -= 1
     self.dotest(a2, 0, self.symbol)
     self.dotest(a2 - 2, -2, self.symbol)
     with self.assertRaises(Exception):
         a1 -= Amount(1, asset=self.asset2)
Ejemplo n.º 10
0
    def test_init(self):
        stm = self.bts
        # String init
        asset = Asset("CBD", crea_instance=stm)
        symbol = asset["symbol"]
        precision = asset["precision"]
        amount = Amount("1 {}".format(symbol), crea_instance=stm)
        self.dotest(amount, 1, symbol)

        # Amount init
        amount = Amount(amount, crea_instance=stm)
        self.dotest(amount, 1, symbol)

        # blockchain dict init
        amount = Amount({
            "amount": 1 * 10**precision,
            "asset_id": asset["id"]
        },
                        crea_instance=stm)
        self.dotest(amount, 1, symbol)

        # API dict init
        amount = Amount({
            "amount": 1.3 * 10**precision,
            "asset": asset["id"]
        },
                        crea_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # Asset as symbol
        amount = Amount(1.3, Asset("CBD"), crea_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # Asset as symbol
        amount = Amount(1.3, symbol, crea_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # keyword inits
        amount = Amount(amount=1.3,
                        asset=Asset("CBD", crea_instance=stm),
                        crea_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # keyword inits
        amount = Amount(amount=1.3,
                        asset=dict(Asset("CBD", crea_instance=stm)),
                        crea_instance=stm)
        self.dotest(amount, 1.3, symbol)

        # keyword inits
        amount = Amount(amount=1.3, asset=symbol, crea_instance=stm)
        self.dotest(amount, 1.3, symbol)
Ejemplo n.º 11
0
    def test_sell(self):
        bts = self.bts
        bts.txbuffer.clear()
        m = Market(u'CREA:CBD', crea_instance=bts)
        tx = m.sell(5, 0.1, account="test")
        self.assertEqual((tx["operations"][0][0]), "limit_order_create")
        op = tx["operations"][0][1]
        self.assertIn("test", op["owner"])
        self.assertEqual(str(Amount('0.500 CBD', crea_instance=bts)),
                         op["min_to_receive"])
        self.assertEqual(str(Amount('0.100 CREA', crea_instance=bts)),
                         op["amount_to_sell"])

        p = Price(5, u"CBD:CREA")
        tx = m.sell(p, 0.1, account="test")
        op = tx["operations"][0][1]
        self.assertEqual(str(Amount('0.500 CBD', crea_instance=bts)),
                         op["min_to_receive"])
        self.assertEqual(str(Amount('0.100 CREA', crea_instance=bts)),
                         op["amount_to_sell"])

        p = Price(5, u"CBD:CREA", crea_instance=bts)
        a = Amount(0.1, "CREA", crea_instance=bts)
        tx = m.sell(p, a, account="test")
        op = tx["operations"][0][1]
        self.assertEqual(str(Amount('0.500 CBD', crea_instance=bts)),
                         op["min_to_receive"])
        self.assertEqual(str(Amount('0.100 CREA', crea_instance=bts)),
                         op["amount_to_sell"])
Ejemplo n.º 12
0
 def time_transfer(self):
     self.op = operations.Transfer(**{
         "from": "foo",
         "to": "baar",
         "amount": Amount("111.110 CREA", crea_instance=self.stm),
         "memo": "Fooo",
         "prefix": self.default_prefix
     })
     self.doit()
Ejemplo n.º 13
0
 def test_filled_order(self):
     order = {
         "date": "1900-01-01T00:00:00",
         "current_pays": "2 CBD",
         "open_pays": "1 CREA"
     }
     filledOrder = FilledOrder(order)
     self.assertTrue(repr(filledOrder) is not None)
     self.assertEqual(filledOrder.json()["current_pays"],
                      Amount("2.000 CBD").json())
Ejemplo n.º 14
0
    def test_init(self):
        # self.assertEqual(1, 1)

        Price("0.315 CREA/CBD")
        Price(1.0, "CREA/CBD")
        Price(0.315, base="CREA", quote="CBD")
        Price(0.315, base=Asset("CREA"), quote=Asset("CBD"))
        Price({
            "base": {
                "amount": 1,
                "asset_id": "CBD"
            },
            "quote": {
                "amount": 10,
                "asset_id": "CREA"
            }
        })
        Price("", quote="10 CBD", base="1 CREA")
        Price("10 CBD", "1 CREA")
        Price(Amount("10 CBD"), Amount("1 CREA"))
Ejemplo n.º 15
0
 def test_transfer(self):
     bts = self.bts
     bts.nobroadcast = False
     bts.wallet.unlock("123")
     # bts.wallet.addPrivateKey(self.active_key)
     # bts.prefix ="STX"
     acc = Account("crea", crea_instance=bts)
     tx = acc.transfer("crea1", 1.33, "CBD", memo="Foobar")
     self.assertEqual(tx["operations"][0][0], "transfer")
     self.assertEqual(len(tx['signatures']), 1)
     op = tx["operations"][0][1]
     self.assertIn("memo", op)
     self.assertEqual(op["from"], "crea")
     self.assertEqual(op["to"], "crea1")
     amount = Amount(op["amount"], crea_instance=bts)
     self.assertEqual(float(amount), 1.33)
     bts.nobroadcast = True
Ejemplo n.º 16
0
    def test_div2(self):
        p1 = Price(10.0, "CREA/CBD")
        p2 = Price(5.0, "CREA/CBD")

        # 10 CREA/CBD / 5 CREA/VESTS = 2 VESTS/CBD
        p3 = p1 / p2
        self.assertTrue(isinstance(p3, (float, int)))
        self.assertEqual(float(p3), 2.0)
        p3 = p1 / 5
        self.assertEqual(float(p3), 2.0)
        p3 = p1 / Amount("1 CBD")
        self.assertEqual(float(p3), 0.1)
        p3 = p1
        p3 /= p2
        self.assertEqual(float(p3), 2.0)
        p3 = p1
        p3 /= 5
        self.assertEqual(float(p3), 2.0)
Ejemplo n.º 17
0
 def test_verifyAuthority(self):
     stm = self.bts
     stm.wallet.unlock("123")
     tx = TransactionBuilder(use_condenser_api=True, crea_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "crea",
                 "to": "crea1",
                 "amount": Amount("1.300 CBD", crea_instance=stm),
                 "memo": "Foobar"
             }))
     account = Account("crea", crea_instance=stm)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     tx.verify_authority()
     self.assertTrue(len(tx["signatures"]) > 0)
Ejemplo n.º 18
0
 def test_transfer_1of1(self):
     crea = self.bts
     crea.nobroadcast = False
     tx = TransactionBuilder(use_condenser_api=True, crea_instance=crea)
     tx.appendOps(
         Transfer(
             **{
                 "from": 'crea',
                 "to": 'crea1',
                 "amount": Amount("0.01 CREA", crea_instance=crea),
                 "memo": '1 of 1 transaction'
             }))
     self.assertEqual(tx["operations"][0]["type"], "transfer_operation")
     tx.appendWif(self.active_key)
     tx.sign()
     tx.sign()
     self.assertEqual(len(tx['signatures']), 1)
     tx.broadcast()
     crea.nobroadcast = True
Ejemplo n.º 19
0
 def test_pow(self):
     a1 = Amount(15, self.symbol)
     a2 = Amount(3, self.symbol)
     self.dotest(a1**3, 15**3, self.symbol)
     self.dotest(a1**a2, 15**3, self.symbol)
     self.dotest(a1**2, 15**2, self.symbol)
     with self.assertRaises(Exception):
         a1**Amount(1, asset=self.asset2)
     # inline
     a2 = a1.copy()
     a2 **= 3
     self.dotest(a2, 15**3, self.symbol)
     with self.assertRaises(Exception):
         a1 **= Amount(2, asset=self.asset2)
Ejemplo n.º 20
0
 def test_mod(self):
     a1 = Amount(15, self.symbol)
     a2 = Amount(3, self.symbol)
     self.dotest(a1 % 3, 0, self.symbol)
     self.dotest(a1 % a2, 0, self.symbol)
     self.dotest(a1 % 2, 1, self.symbol)
     with self.assertRaises(Exception):
         a1 % Amount(1, asset=self.asset2)
     # inline
     a2 = a1.copy()
     a2 %= 3
     self.dotest(a2, 0, self.symbol)
     with self.assertRaises(Exception):
         a1 %= Amount(2, asset=self.asset2)
Ejemplo n.º 21
0
    def test_transfer_2of2_wif(self):
        nodelist = NodeList()
        # Send a 2 of 2 transaction from elf which needs crea4's cosign to send
        # funds but sign the transaction with elf's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with crea4's key.
        crea = Crea(
            node=self.nodes,
            num_retries=10,
            keys=[self.active_private_key_of_crea5],
            expiration=360,
        )

        tx = TransactionBuilder(use_condenser_api=True, crea_instance=crea)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'crea5',
                    "to": 'crea',
                    "amount": Amount("0.01 CREA", crea_instance=crea),
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("crea5", "active")
        tx.addSigningInformation("crea5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        tx_json = tx.json()
        del crea
        del tx

        crea = Crea(
            node=self.nodes,
            num_retries=10,
            keys=[self.active_private_key_of_crea4],
            expiration=360,
        )
        new_tx = TransactionBuilder(tx=tx_json, crea_instance=crea)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()
Ejemplo n.º 22
0
 def test_div(self):
     a1 = Amount(15, self.symbol)
     self.dotest(a1 / 3, 5, self.symbol)
     self.dotest(a1 // 2, 7, self.symbol)
     with self.assertRaises(Exception):
         a1 / Amount(1, asset=self.asset2)
     # inline
     a2 = a1.copy()
     a2 /= 3
     self.dotest(a2, 5, self.symbol)
     a2 = a1.copy()
     a2 //= 2
     self.dotest(a2, 7, self.symbol)
     with self.assertRaises(Exception):
         a1 *= Amount(2, asset=self.asset2)
Ejemplo n.º 23
0
 def test_TransactionConstructor(self):
     stm = self.bts
     opTransfer = Transfer(
         **{
             "from": "crea",
             "to": "crea1",
             "amount": Amount("1 CREA", crea_instance=stm),
             "memo": ""
         })
     tx1 = TransactionBuilder(use_condenser_api=True, crea_instance=stm)
     tx1.appendOps(opTransfer)
     tx = TransactionBuilder(tx1, crea_instance=stm)
     self.assertFalse(tx.is_empty())
     self.assertTrue(len(tx.list_operations()) == 1)
     self.assertTrue(repr(tx) is not None)
     self.assertTrue(str(tx) is not None)
     account = Account("crea", crea_instance=stm)
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Ejemplo n.º 24
0
    def test_transfer_memo(self):
        bts = self.bts
        bts.nobroadcast = False
        bts.wallet.unlock("123")
        acc = Account("crea", crea_instance=bts)
        tx = acc.transfer("crea1", 1.33, "CBD", memo="#Foobar")
        self.assertEqual(tx["operations"][0][0], "transfer")
        op = tx["operations"][0][1]
        self.assertIn("memo", op)
        self.assertIn("#", op["memo"])
        m = Memo(from_account=op["from"],
                 to_account=op["to"],
                 crea_instance=bts)
        memo = m.decrypt(op["memo"])
        self.assertEqual(memo, "Foobar")

        self.assertEqual(op["from"], "crea")
        self.assertEqual(op["to"], "crea1")
        amount = Amount(op["amount"], crea_instance=bts)
        self.assertEqual(float(amount), 1.33)
        bts.nobroadcast = True
Ejemplo n.º 25
0
 def test_mul(self):
     a1 = Amount(5, self.symbol)
     a2 = Amount(2, self.symbol)
     self.dotest(a1 * a2, 10, self.symbol)
     self.dotest(a1 * 3, 15, self.symbol)
     with self.assertRaises(Exception):
         a1 * Amount(1, asset=self.asset2)
     # inline
     a2 = Amount(2, self.symbol)
     a2 *= 5
     self.dotest(a2, 10, self.symbol)
     a2 = Amount(2, self.symbol)
     a2 *= a1
     self.dotest(a2, 10, self.symbol)
     with self.assertRaises(Exception):
         a1 *= Amount(2, asset=self.asset2)
Ejemplo n.º 26
0
    def test_transfer_2of2_simple(self):
        # Send a 2 of 2 transaction from elf which needs crea4's cosign to send funds
        crea = self.bts
        crea.nobroadcast = False
        tx = TransactionBuilder(use_condenser_api=True, crea_instance=crea)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'crea5',
                    "to": 'crea1',
                    "amount": Amount("0.01 CREA", crea_instance=crea),
                    "memo": '2 of 2 simple transaction'
                }))

        tx.appendWif(self.active_private_key_of_crea5)
        tx.sign()
        tx.clearWifs()
        tx.appendWif(self.active_private_key_of_crea4)
        tx.sign(reconstruct_tx=False)
        self.assertEqual(len(tx['signatures']), 2)
        tx.broadcast()
        crea.nobroadcast = True
Ejemplo n.º 27
0
    def test_transfer_2of2_serialized_deserialized(self):
        # Send a 2 of 2 transaction from crea5 which needs crea4's cosign to send
        # funds but sign the transaction with crea5's key and then serialize the transaction
        # and deserialize the transaction.  After that, sign with crea4's key.
        crea = self.bts
        crea.nobroadcast = False
        crea.wallet.unlock("123")
        # crea.wallet.removeAccount("crea4")
        crea.wallet.removePrivateKeyFromPublicKey(
            str(PublicKey(self.active_private_key_of_crea4, prefix=core_unit)))

        tx = TransactionBuilder(use_condenser_api=True, crea_instance=crea)
        tx.appendOps(
            Transfer(
                **{
                    "from": 'crea5',
                    "to": 'crea1',
                    "amount": Amount("0.01 CREA", crea_instance=crea),
                    "memo": '2 of 2 serialized/deserialized transaction'
                }))

        tx.appendSigner("crea5", "active")
        tx.addSigningInformation("crea5", "active")
        tx.sign()
        tx.clearWifs()
        self.assertEqual(len(tx['signatures']), 1)
        # crea.wallet.removeAccount("crea5")
        crea.wallet.removePrivateKeyFromPublicKey(
            str(PublicKey(self.active_private_key_of_crea5, prefix=core_unit)))
        tx_json = tx.json()
        del tx
        new_tx = TransactionBuilder(tx=tx_json, crea_instance=crea)
        self.assertEqual(len(new_tx['signatures']), 1)
        crea.wallet.addPrivateKey(self.active_private_key_of_crea4)
        new_tx.appendMissingSignatures()
        new_tx.sign(reconstruct_tx=False)
        self.assertEqual(len(new_tx['signatures']), 2)
        new_tx.broadcast()
        crea.nobroadcast = True
Ejemplo n.º 28
0
 def test_appendWif(self):
     nodelist = NodeList()
     stm = Crea(node=self.nodes,
                nobroadcast=True,
                expiration=120,
                num_retries=10)
     tx = TransactionBuilder(use_condenser_api=True, crea_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "crea",
                 "to": "crea1",
                 "amount": Amount("1 CREA", crea_instance=stm),
                 "memo": ""
             }))
     with self.assertRaises(MissingKeyError):
         tx.sign()
     with self.assertRaises(InvalidWifError):
         tx.appendWif("abcdefg")
     tx.appendWif(self.active_key)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)
Ejemplo n.º 29
0
    def test_Transfer_broadcast(self):
        nodelist = NodeList()
        stm = Crea(node=self.nodes,
                   keys=[self.active_key],
                   nobroadcast=True,
                   expiration=120,
                   num_retries=10)

        tx = TransactionBuilder(use_condenser_api=True,
                                expiration=10,
                                crea_instance=stm)
        tx.appendOps(
            Transfer(
                **{
                    "from": "crea",
                    "to": "crea1",
                    "amount": Amount("1 CREA", crea_instance=stm),
                    "memo": ""
                }))
        tx.appendSigner("crea", "active")
        tx.sign()
        tx.broadcast()
Ejemplo n.º 30
0
 def test_appendSigner(self):
     nodelist = NodeList()
     stm = Crea(node=self.nodes,
                keys=[self.active_key],
                nobroadcast=True,
                expiration=120,
                num_retries=10)
     tx = TransactionBuilder(use_condenser_api=True, crea_instance=stm)
     tx.appendOps(
         Transfer(
             **{
                 "from": "crea",
                 "to": "crea1",
                 "amount": Amount("1 CREA", crea_instance=stm),
                 "memo": ""
             }))
     account = Account("crea", crea_instance=stm)
     with self.assertRaises(AssertionError):
         tx.appendSigner(account, "abcdefg")
     tx.appendSigner(account, "active")
     self.assertTrue(len(tx.wifs) > 0)
     tx.sign()
     self.assertTrue(len(tx["signatures"]) > 0)