def test_create_proposal(self): op = operations.Proposal_create( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "fee_paying_account": "1.2.0", "expiration_time": "1970-01-01T00:00:00", "proposed_ops": [{ "op": [ 0, { "fee": { "amount": 0, "asset_id": "1.3.0" }, "from": "1.2.0", "to": "1.2.0", "amount": { "amount": 0, "asset_id": "1.3.0" }, "extensions": [] } ] }], "extensions": [] }) 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], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c80457011600000000000000000000000000" "00010000000000000000000000000000000000000000000000" "00000001204baf7f11a7ff12337fc097ac6e82e7b68f82f02c" "c7e24231637c88a91ae5716674acec8a1a305073165c65e520" "a64769f5f62c0301ce21ab4f7c67a6801b4266") self.assertEqual(compare[:-130], txWire[:-130])
def doit(self, printWire=False): ops = [Operation(self.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") if printWire: print() print(txWire) print() self.assertEqual(self.cm[:-130], txWire[:-130]) # Test against Bitshares backened bitshares = BitShares() self.cm = bitshares.rpc.get_transaction_hex(tx.json()) self.assertEqual(self.cm[:-130], txWire[:-130])
def compareConstructedTX(self): self.maxDiff = None self.op = operations.Call_order_update( **{ "fee": { "amount": 100, "asset_id": "1.3.0" }, "delta_debt": { "amount": 10000, "asset_id": "1.3.22" }, "delta_collateral": { "amount": 100000000, "asset_id": "1.3.0" }, "funding_account": "1.2.29", "extensions": { "target_collateral_ratio": 12345 }, }) ops = [Operation(self.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") print("=" * 80) pprint(tx.json()) print("=" * 80) # Test against Bitshares backened self.cm = bitshares.rpc.get_transaction_hex(tx.json()) print("soll: %s" % self.cm[:-130]) print("ist: %s" % txWire[:-130]) print(txWire[:-130] == self.cm[:-130]) self.assertEqual(self.cm[:-130], txWire[:-130])
def test_proposal_update(self): op = operations.Proposal_update( **{ 'fee_paying_account': "1.2.1", 'proposal': "1.10.90", 'active_approvals_to_add': ["1.2.5"], "fee": objects.Asset(amount=12512, asset_id="1.3.0"), }) 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], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c804570117e03000000000000000015a01050000000" "000000001203255378db6dc19443e74421c954ad7fdcf23f4ea45fe4f" "e5a1b078a0f94fb529594819c9799d68efa5cfb5b271a9333a2f516ca" "4fb5093226275f48a42d9e8cf") self.assertEqual(compare[:-130], txWire[:-130])
def test_pricefeed(self): feed = objects.PriceFeed( **{ "settlement_price": objects.Price( base=objects.Asset(amount=214211, asset_id="1.3.0"), quote=objects.Asset(amount=1241, asset_id="1.3.14"), ), "core_exchange_rate": objects.Price( base=objects.Asset(amount=1241, asset_id="1.3.0"), quote=objects.Asset(amount=6231, asset_id="1.3.14"), ), "maximum_short_squeeze_ratio": 1100, "maintenance_collateral_ratio": 1750, }) op = operations.Asset_publish_feed(fee=objects.Asset(amount=100, asset_id="1.3.0"), publisher="1.2.0", asset_id="1.3.3", feed=feed) 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], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c8045701136400000000000000000003c344030" "00000000000d9040000000000000ed6064c04d904000000000000" "0057180000000000000e0000012009e13f9066fedc3c8c1eb2ac3" "3b15dc67ecebf708890d0f8ab62ec8283d1636002315a189f1f5a" "a8497b41b8e6bb7c4dc66044510fae25d8f6aebb02c7cdef10") self.assertEqual(compare[:-130], txWire[:-130])
def compareConstructedTX(self): # def test_online(self): # self.maxDiff = None op = operations.Worker_create( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "owner": "1.2.0", "work_begin_date": "1970-01-01T00:00:00", "work_end_date": "1970-01-01T00:00:00", "daily_pay": 0, "name": "Myname", "url": "myURL", "initializer": [1, { "pay_vesting_period_days": 125 }] }) 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], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") print("=" * 80) pprint(tx.json()) print("=" * 80) from grapheneapi.grapheneapi import GrapheneAPI rpc = GrapheneAPI("localhost", 8092) compare = rpc.serialize_transaction(tx.json()) print("soll: %s" % compare[:-130]) print("ist: %s" % txWire[:-130]) print(txWire[:-130] == compare[:-130]) self.assertEqual(compare[:-130], txWire[:-130])
def get_raw(self): """ Returns an instance of base "Operations" for further processing """ if not self.ops: return ops = [operations.Op_wrapper(op=o) for o in list(self.ops)] proposer = Account(self.proposer, bitshares_instance=self.bitshares) data = { "fee": { "amount": 0, "asset_id": "1.3.0" }, "fee_paying_account": proposer["id"], "expiration_time": transactions.formatTimeFromNow(self.proposal_expiration), "proposed_ops": [o.json() for o in ops], "extensions": [] } if self.proposal_review: data.update({"review_period_seconds": self.proposal_review}) ops = operations.Proposal_create(**data) return Operation(ops)
def doit(self, printWire=False): ops = [Operation(self.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") if printWire: print() print(txWire) print() self.assertEqual(self.cm[:-130], txWire[:-130]) if TEST_AGAINST_CLI_WALLET: from grapheneapi.grapheneapi import GrapheneAPI rpc = GrapheneAPI("localhost", 8092) self.cm = rpc.serialize_transaction(tx.json()) # print("soll: %s" % self.cm[:-130]) # print("ist: %s" % txWire[:-130]) # print(txWire[:-130] == self.cm[:-130]) self.assertEqual(self.cm[:-130], txWire[:-130])
def test_limit_order_cancel(self): op = operations.Limit_order_cancel( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "fee_paying_account": "1.2.104", "order": "1.7.51840", "extensions": [] }) 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], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c8045701020000000000000000006880950300000" "11f3fb754814f3910c1a8845486b86057d2b4588ae559b4c3810828" "c0d4cbec0e5b23517937cd7e0cc5ee8999d0777af7fe56d3c4b2e58" "7421bfb7400d4efdae97a") self.assertEqual(compare[:-130], txWire[:-130])
def test_upgrade_account(self): op = operations.Account_upgrade( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "account_to_upgrade": "1.2.0", "upgrade_to_lifetime_member": True, "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], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c804570108000000000000000000000100000" "11f4e42562ada1d3fed8f8eb51dd58117e3a4024959c46955a0" "0d2a7e7e8b40ae7204f4617913aaaf028248d43e8c3463b8776" "0ca569007dba99a2c49de75bd69b3") self.assertEqual(compare[:-130], txWire[:-130])
def compareNewWire(self): # def test_online(self): # self.maxDiff = None from grapheneapi.grapheneapi import GrapheneAPI rpc = GrapheneAPI("localhost", 8092) tx = rpc.create_account("xeroc", "fsafaasf", "", False) pprint(tx) compare = rpc.serialize_transaction(tx) ref_block_num = tx["ref_block_num"] ref_block_prefix = tx["ref_block_prefix"] expiration = tx["expiration"] ops = [Operation(operations.Account_create(**tx["operations"][0][1]))] 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], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") print("\n") print(txWire[:-130]) print(compare[:-130])
def compareConstructedTX(self): # def test_online(self): # self.maxDiff = None op = operations.Vesting_balance_withdraw( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "vesting_balance": "1.13.0", "owner": "1.2.0", "amount": { "amount": 0, "asset_id": "1.3.0" }, "prefix": "TEST" }) 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], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") print("=" * 80) pprint(tx.json()) print("=" * 80) from grapheneapi.grapheneapi import GrapheneAPI rpc = GrapheneAPI("localhost", 8092) compare = rpc.serialize_transaction(tx.json()) print(compare[:-130]) print(txWire[:-130]) print(txWire[:-130] == compare[:-130]) self.assertEqual(compare[:-130], txWire[:-130])
def list_operations(self): return [Operation(o) for o in self.ops]
def test_create_account(self): s = { "fee": { "amount": 1467634, "asset_id": "1.3.0" }, "registrar": "1.2.33", "referrer": "1.2.27", "referrer_percent": 3, "name": "foobar-f124", "owner": { "weight_threshold": 1, "account_auths": [], 'key_auths': [['BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x', 1], ['BTS6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp', 1]], "address_auths": [] }, "active": { "weight_threshold": 1, "account_auths": [], 'key_auths': [['BTS6pbVDAjRFiw6fkiKYCrkz7PFeL7XNAfefrsREwg8MKpJ9VYV9x', 1], ['BTS6zLNtyFVToBsBZDsgMhgjpwysYVbsQD6YhP3kRkQhANUB4w7Qp', 1], ['BTS8CemMDjdUWSV5wKotEimhK6c4dY7p2PdzC2qM1HpAP8aLtZfE7', 1]], "address_auths": [] }, "options": { "memo_key": "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE", "voting_account": "1.2.5", "num_witness": 0, "num_committee": 0, "votes": [], "extensions": [] }, "extensions": {} } op = operations.Account_create(**s) 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], "BTS") txWire = hexlify(bytes(tx)).decode("ascii") compare = ("f68585abf4dce7c804570105f26416000000000000211b03000b666f" "6f6261722d6631323401000000000202fe8cc11cc8251de6977636b5" "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91" "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01" "000001000000000303b453f46013fdbccb90b09ba169c388c34d8445" "4a3b9fbec68d5a7819a734fca0010002fe8cc11cc8251de6977636b5" "5c1ab8a9d12b0b26154ac78e56e7c4257d8bcf6901000314aa202c91" "58990b3ec51a1aa49b2ab5d300c97b391df3beb34bb74f3c62699e01" "0000024ab336b4b14ba6d881675d1c782912783c43dbbe31693aa710" "ac1896bd7c3d61050000000000000000011f61ad276120bc3f189296" "2bfff7db5e8ce04d5adec9309c80529e3a978a4fa1073225a6d56929" "e34c9d2a563e67a8f4a227e4fadb4a3bb6ec91bfdf4e57b80efd") self.assertEqual(compare[:-130], txWire[:-130])