def test_transfer_2of2_serialized_deserialized(self): # Send a 2 of 2 transaction from elf which needs steemfiles'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 steemfiles's key. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") steem.wallet.removeAccount("steemfiles") tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'elf', "to": 'leprechaun', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction' })) tx.appendSigner("elf", "active") tx.addSigningInformation("elf", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) steem.wallet.removeAccount("elf") tx_json = tx.json() del tx new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem) self.assertEqual(len(new_tx['signatures']), 1) steem.wallet.addPrivateKey(self.active_private_key_of_steemfiles) new_tx.appendMissingSignatures() new_tx.sign(reconstruct_tx=False) self.assertEqual(len(new_tx['signatures']), 2) new_tx.broadcast() steem.nobroadcast = True
def test_transfer_2of2_wif(self): # Send a 2 of 2 transaction from elf which needs steemfiles'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 steemfiles's key. steem = Steem(node=["wss://testnet.steem.vc"], num_retries=10, keys=[self.active_private_key_of_elf]) tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'elf', "to": 'leprechaun', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction' })) tx.appendSigner("elf", "active") tx.addSigningInformation("elf", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) tx_json = tx.json() del steem del tx steem = Steem(node=["wss://testnet.steem.vc"], num_retries=10, keys=[self.active_private_key_of_steemfiles]) new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem) new_tx.appendMissingSignatures() new_tx.sign(reconstruct_tx=False) self.assertEqual(len(new_tx['signatures']), 2) new_tx.broadcast()
def test_transfer_2of2_offline(self): # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send # funds but sign the transaction with beem5's key and then serialize the transaction # and deserialize the transaction. After that, sign with beem4's key. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") steem.wallet.removeAccount("beem4") tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'beem5', "to": 'beem', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction' })) tx.appendSigner("beem5", "active") tx.addSigningInformation("beem5", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) steem.wallet.removeAccount("beem5") steem.wallet.addPrivateKey(self.active_private_key_of_beem4) tx.appendMissingSignatures() tx.sign(reconstruct_tx=False) self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True steem.wallet.addPrivateKey(self.active_private_key_of_beem5)
def test_transfer_2of2_serialized_deserialized(self): # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send # funds but sign the transaction with beem5's key and then serialize the transaction # and deserialize the transaction. After that, sign with beem4's key. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") # steem.wallet.removeAccount("beem4") steem.wallet.removePrivateKeyFromPublicKey(str(PublicKey(self.active_private_key_of_beem4, prefix=core_unit))) tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem) tx.appendOps(Transfer(**{"from": 'beem5', "to": 'beem1', "amount": Amount("0.01 STEEM", steem_instance=steem), "memo": '2 of 2 serialized/deserialized transaction'})) tx.appendSigner("beem5", "active") tx.addSigningInformation("beem5", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) # steem.wallet.removeAccount("beem5") steem.wallet.removePrivateKeyFromPublicKey(str(PublicKey(self.active_private_key_of_beem5, prefix=core_unit))) tx_json = tx.json() del tx new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem) self.assertEqual(len(new_tx['signatures']), 1) steem.wallet.addPrivateKey(self.active_private_key_of_beem4) new_tx.appendMissingSignatures() new_tx.sign(reconstruct_tx=False) self.assertEqual(len(new_tx['signatures']), 2) new_tx.broadcast() steem.nobroadcast = True
def test_verifyAuthority(self): stm = self.bts stm.wallet.unlock("123") tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", "to": "beem1", "amount": Amount("1.300 SBD", steem_instance=stm), "memo": "Foobar"})) account = Account("beem", steem_instance=stm) tx.appendSigner(account, "active") self.assertTrue(len(tx.wifs) > 0) tx.sign() tx.verify_authority() self.assertTrue(len(tx["signatures"]) > 0)
def test_Transfer_broadcast(self): nodelist = NodeList() stm = Steem(node=self.nodes, keys=[self.active_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, expiration=10, steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""})) tx.appendSigner("beem", "active") tx.sign() tx.broadcast()
def test_Transfer_broadcast_appbase(self): stm = Steem(node=get_node_list(appbase=True), keys=[wif], num_retries=10) tx = TransactionBuilder(expiration=10, steem_instance=stm) tx.appendOps( Transfer( **{ "from": "test", "to": "test1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" })) tx.appendSigner("test", "active") tx.sign() with self.assertRaises(exceptions.MissingRequiredActiveAuthority): tx.broadcast()
def test_TransactionConstructor(self): stm = self.bts opTransfer = Transfer(**{"from": "beem", "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""}) tx1 = TransactionBuilder(use_condenser_api=True, steem_instance=stm) tx1.appendOps(opTransfer) tx = TransactionBuilder(tx1, steem_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("beem", steem_instance=stm) tx.appendSigner(account, "active") self.assertTrue(len(tx.wifs) > 0) tx.sign() self.assertTrue(len(tx["signatures"]) > 0)
def test_transfer_1of1(self): steem = self.bts steem.nobroadcast = False tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem) tx.appendOps(Transfer(**{"from": 'beem', "to": 'beem1', "amount": Amount("0.01 STEEM", steem_instance=steem), "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() steem.nobroadcast = True
def test_transfer_2of2_simple(self): # Send a 2 of 2 transaction from elf which needs beem4's cosign to send funds steem = self.bts steem.nobroadcast = False tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem) tx.appendOps(Transfer(**{"from": 'beem5', "to": 'beem1', "amount": Amount("0.01 STEEM", steem_instance=steem), "memo": '2 of 2 simple transaction'})) tx.appendWif(self.active_private_key_of_beem5) tx.sign() tx.clearWifs() tx.appendWif(self.active_private_key_of_beem4) tx.sign(reconstruct_tx=False) self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True
def test_verifyAuthority_appbase(self): stm = self.appbase tx = TransactionBuilder(steem_instance=stm) tx.appendOps( Transfer( **{ "from": "test", "to": "test1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" })) account = Account("test", steem_instance=stm) tx.appendSigner(account, "active") tx.appendWif(wif) self.assertTrue(len(tx.wifs) > 0) tx.sign() with self.assertRaises(exceptions.MissingRequiredActiveAuthority): tx.verify_authority() self.assertTrue(len(tx["signatures"]) > 0)
def test_transfer_1of1(self): steem = self.bts steem.nobroadcast = False tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'beem', "to": 'leprechaun', "amount": '0.01 SBD', "memo": '1 of 1 transaction' })) self.assertEqual(tx["operations"][0][0], "transfer") tx.appendWif(self.active_key) tx.sign() tx.sign() self.assertEqual(len(tx['signatures']), 1) tx.broadcast() steem.nobroadcast = True
def test_transfer_2of2_wallet(self): # Send a 2 of 2 transaction from beem5 which needs beem4's cosign to send # priv key of beem5 and beem4 are stored in the wallet # appendSigner fetches both keys and signs automatically with both keys. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem) tx.appendOps(Transfer(**{"from": 'beem5', "to": 'beem1', "amount": Amount("0.01 STEEM", steem_instance=steem), "memo": '2 of 2 serialized/deserialized transaction'})) tx.appendSigner("beem5", "active") tx.sign() self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True
def test_transfer_2of2_wif(self): nodelist = NodeList() # Send a 2 of 2 transaction from elf which needs beem4'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 beem4's key. steem = Steem( node=self.nodes, num_retries=10, keys=[self.active_private_key_of_beem5], expiration=360, ) tx = TransactionBuilder(use_condenser_api=True, steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'beem5', "to": 'beem', "amount": Amount("0.01 STEEM", steem_instance=steem), "memo": '2 of 2 serialized/deserialized transaction' })) tx.appendSigner("beem5", "active") tx.addSigningInformation("beem5", "active") tx.sign() tx.clearWifs() self.assertEqual(len(tx['signatures']), 1) tx_json = tx.json() del steem del tx steem = Steem( node=self.nodes, num_retries=10, keys=[self.active_private_key_of_beem4], expiration=360, ) new_tx = TransactionBuilder(tx=tx_json, steem_instance=steem) new_tx.appendMissingSignatures() new_tx.sign(reconstruct_tx=False) self.assertEqual(len(new_tx['signatures']), 2) new_tx.broadcast()
def test_appendSigner(self): nodelist = NodeList() stm = Steem(node=self.nodes, keys=[self.active_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""})) account = Account("beem", steem_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)
def test_appendSigner(self, node_param): if node_param == "non_appbase": stm = self.stm else: stm = self.appbase tx = TransactionBuilder(steem_instance=stm) tx.appendOps( Transfer( **{ "from": "test", "to": "test1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" })) account = Account("test", steem_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)
def test_appendWif(self, node_param): if node_param == "non_appbase": stm = self.stm else: stm = self.appbase tx = TransactionBuilder(steem_instance=stm) tx.appendOps( Transfer( **{ "from": "test", "to": "test1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" })) with self.assertRaises(MissingKeyError): tx.sign() with self.assertRaises(InvalidWifError): tx.appendWif("abcdefg") tx.appendWif(wif) tx.sign() self.assertTrue(len(tx["signatures"]) > 0)
def test_transfer_2of2_simple(self): # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send funds steem = self.bts steem.nobroadcast = False tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'elf', "to": 'leprechaun', "amount": '0.01 SBD', "memo": '2 of 2 simple transaction' })) tx.appendWif(self.active_private_key_of_elf) tx.sign() tx.clearWifs() tx.appendWif(self.active_private_key_of_steemfiles) tx.sign(reconstruct_tx=False) self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True
def test_verifyAuthorityException(self): nodelist = NodeList() stm = Steem(node=self.nodes, keys=[self.posting_key], nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm) tx.appendOps(Transfer(**{"from": "beem", "to": "beem1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": ""})) account = Account("beem2", steem_instance=stm) tx.appendSigner(account, "active") tx.appendWif(self.posting_key) self.assertTrue(len(tx.wifs) > 0) tx.sign() with self.assertRaises( exceptions.MissingRequiredActiveAuthority ): tx.verify_authority() self.assertTrue(len(tx["signatures"]) > 0)
def test_appendWif(self): nodelist = NodeList() stm = Steem(node=self.nodes, nobroadcast=True, expiration=120, num_retries=10) tx = TransactionBuilder(use_condenser_api=True, steem_instance=stm) tx.appendOps( Transfer( **{ "from": "beem", "to": "beem1", "amount": Amount("1 STEEM", steem_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)
def test_transfer_2of2_wallet(self): # Send a 2 of 2 transaction from elf which needs steemfiles's cosign to send # priv key of elf and steemfiles are stored in the wallet # appendSigner fetches both keys and signs automatically with both keys. steem = self.bts steem.nobroadcast = False steem.wallet.unlock("123") tx = TransactionBuilder(steem_instance=steem) tx.appendOps( Transfer( **{ "from": 'elf', "to": 'leprechaun', "amount": '0.01 SBD', "memo": '2 of 2 serialized/deserialized transaction' })) tx.appendSigner("elf", "active") tx.sign() self.assertEqual(len(tx['signatures']), 2) tx.broadcast() steem.nobroadcast = True
def test_TransactionConstructor(self, node_param): if node_param == "non_appbase": stm = self.stm else: stm = self.appbase opTransfer = Transfer( **{ "from": "test", "to": "test1", "amount": Amount("1 STEEM", steem_instance=stm), "memo": "" }) tx1 = TransactionBuilder(steem_instance=stm) tx1.appendOps(opTransfer) tx = TransactionBuilder(tx1, steem_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("test", steem_instance=stm) tx.appendSigner(account, "active") self.assertTrue(len(tx.wifs) > 0) tx.sign() self.assertTrue(len(tx["signatures"]) > 0)
def test_Transfer(self): transferJson = { 'from': 'test', 'to': 'test1', 'amount': "1.000 STEEM", 'memo': 'foobar' } t = Transfer(transferJson) self.assertEqual(transferJson, json.loads(str(t))) self.assertEqual(transferJson, t.json()) self.assertEqual(transferJson, t.toJson()) self.assertEqual(transferJson, t.__json__()) transferJson = { 'from': 'test', 'to': 'test1', 'amount': ['3000', 3, '@@000000037'], 'memo': 'foobar' } t = Transfer(transferJson) self.assertEqual(transferJson, json.loads(str(t))) self.assertEqual(transferJson, t.json()) self.assertEqual(transferJson, t.toJson()) self.assertEqual(transferJson, t.__json__()) o = Operation(Transfer(transferJson)) self.assertEqual(o.json()[1], transferJson) tx = { 'ref_block_num': 0, 'ref_block_prefix': 0, 'expiration': '2018-04-07T09:30:53', 'operations': [o], 'extensions': [], 'signatures': [] } s = Signed_Transaction(tx) s.sign(wifkeys=[wif], chain="STEEMAPPBASE") self.assertEqual(s.json()["operations"][0][1], transferJson)