def test_finalizeOps_changeproposer_legacy(self): grv = self.grv grv.proposer = "init5" tx = grv.transfer("init1", 1, "ZGV") ops = tx["operations"] self.assertEqual(len(ops), 1) self.assertEqual(getOperationNameForId(ops[0][0]), "proposal_create") prop = ops[0][1] self.assertEqual(len(prop["proposed_ops"]), 1) self.assertEqual(prop["fee_paying_account"], "1.2.12") self.assertEqual( getOperationNameForId(prop["proposed_ops"][0]["op"][0]), "transfer")
def test_finalizeOps_proposal2(self): grv = self.grv proposal = grv.new_proposal() # proposal = grv.proposal() self.grv.transfer("init1", 1, "ZGV", append_to=proposal) tx = grv.tx().json() # default tx buffer ops = tx["operations"] self.assertEqual(len(ops), 1) self.assertEqual(getOperationNameForId(ops[0][0]), "proposal_create") prop = ops[0][1] self.assertEqual(len(prop["proposed_ops"]), 1) self.assertEqual( getOperationNameForId(prop["proposed_ops"][0]["op"][0]), "transfer")
def test_finalizeOps_combined_proposal(self): grv = self.grv parent = grv.new_tx() proposal = grv.new_proposal(parent) self.grv.transfer("init1", 1, "ZGV", append_to=proposal) self.grv.transfer("init1", 1, "ZGV", append_to=parent) tx = parent.json() ops = tx["operations"] self.assertEqual(len(ops), 2) self.assertEqual(getOperationNameForId(ops[0][0]), "proposal_create") self.assertEqual(getOperationNameForId(ops[1][0]), "transfer") prop = ops[0][1] self.assertEqual(len(prop["proposed_ops"]), 1) self.assertEqual( getOperationNameForId(prop["proposed_ops"][0]["op"][0]), "transfer")
def ops(self, start=None, stop=None, **kwargs): """ Yields all operations (including virtual operations) starting from ``start``. :param int start: Starting block :param int stop: Stop at this block :param str mode: We here have the choice between "head" (the last block) and "irreversible" (the block that is confirmed by 2/3 of all block producers and is thus irreversible) :param bool only_virtual_ops: Only yield virtual operations This call returns a list that only carries one operation and its type! """ for block in self.blocks(start=start, stop=stop, **kwargs): for tx in block["transactions"]: for op in tx["operations"]: # Replace opid by op name op[0] = getOperationNameForId(op[0]) yield { "block_num": block["block_num"], "op": op, "timestamp": block["timestamp"] }
def test_create_account(self): grv = self.grv name = ''.join(random.choice(string.ascii_lowercase) for _ in range(12)) key1 = PrivateKey() key2 = PrivateKey() key3 = PrivateKey() key4 = PrivateKey() tx = grv.create_account( name, registrar="init0", # 1.2.7 referrer="init1", # 1.2.8 referrer_percent=33, owner_key=str(key1.pubkey), active_key=str(key2.pubkey), memo_key=str(key3.pubkey), additional_owner_keys=[str(key4.pubkey)], additional_active_keys=[str(key4.pubkey)], additional_owner_accounts=["committee-account"], # 1.2.0 additional_active_accounts=["committee-account"], proxy_account="init0", storekeys=False ) self.assertEqual( getOperationNameForId(tx["operations"][0][0]), "account_create" ) op = tx["operations"][0][1] role = "active" self.assertIn( str(key2.pubkey), [x[0] for x in op[role]["key_auths"]]) self.assertIn( str(key4.pubkey), [x[0] for x in op[role]["key_auths"]]) self.assertIn( "1.2.0", [x[0] for x in op[role]["account_auths"]]) role = "owner" self.assertIn( str(key1.pubkey), [x[0] for x in op[role]["key_auths"]]) self.assertIn( str(key4.pubkey), [x[0] for x in op[role]["key_auths"]]) self.assertIn( "1.2.0", [x[0] for x in op[role]["account_auths"]]) self.assertEqual( op["options"]["voting_account"], "1.2.7") self.assertEqual( op["registrar"], "1.2.7") self.assertEqual( op["referrer"], "1.2.8") self.assertEqual( op["referrer_percent"], 33 * 100)
def test_approvecommittee(self): grv = self.grv tx = grv.approvecommittee("1.5.0") self.assertEqual( getOperationNameForId(tx["operations"][0][0]), "account_update" ) op = tx["operations"][0][1] self.assertIn( "0:11", op["new_options"]["votes"])
def test_approvewitness(self): grv = self.grv tx = grv.approvewitness("1.6.1") self.assertEqual( getOperationNameForId(tx["operations"][0][0]), "account_update" ) op = tx["operations"][0][1] self.assertIn( "1:0", op["new_options"]["votes"])
def test_update_memo_key(self): grv = self.grv tx = grv.update_memo_key("ZGV55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n") self.assertEqual( getOperationNameForId(tx["operations"][0][0]), "account_update" ) op = tx["operations"][0][1] self.assertEqual( op["new_options"]["memo_key"], "ZGV55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n")
def test_account_upgrade(self): account = Account("witness-account") tx = account.upgrade() ops = tx["operations"] op = ops[0][1] self.assertEqual(len(ops), 1) self.assertEqual(getOperationNameForId(ops[0][0]), "account_upgrade") self.assertTrue(op["upgrade_to_lifetime_member"]) self.assertEqual( op["account_to_upgrade"], "1.2.1", )
def test_transfer(self): grv = self.grv tx = grv.transfer( "1.2.8", 1.33, core_unit, memo="Foobar", account="1.2.7") self.assertEqual( getOperationNameForId(tx["operations"][0][0]), "transfer" ) op = tx["operations"][0][1] self.assertIn("memo", op) self.assertEqual(op["from"], "1.2.7") self.assertEqual(op["to"], "1.2.8") amount = Amount(op["amount"]) self.assertEqual(float(amount), 1.33)
def test_allow(self): grv = self.grv tx = grv.allow( "ZGV55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n", weight=1, threshold=1, permission="owner" ) self.assertEqual( getOperationNameForId(tx["operations"][0][0]), "account_update" ) op = tx["operations"][0][1] self.assertIn("owner", op) self.assertIn( ["ZGV55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n", '1'], op["owner"]["key_auths"]) self.assertEqual(op["owner"]["weight_threshold"], 1)
def fees(ctx): """ List fees """ from gravitybase.operationids import getOperationNameForId chain = Blockchain(gravity_instance=ctx.gravity) feesObj = chain.chainParameters().get("current_fees") fees = feesObj["parameters"] t = PrettyTable(["Operation", "Type", "Fee"]) t.align = "l" t.align["Fee"] = "r" for fee in fees: for f in fee[1]: t.add_row([ getOperationNameForId(fee[0]), f, str(Amount({ "amount": fee[1].get(f, 0), "asset_id": "1.3.0" })) ]) click.echo(t)