Skip to content
Snippets Groups Projects
Commit 2d364c67 authored by Holger Nahrstaedt's avatar Holger Nahrstaedt
Browse files

Add clearWifs and improve unit tests

Transactionbuild
* add clearWifs
Examples
* use nodes from get_node_list
test_testnet
* improved tests for Transactionbuilder
parent 8b8b4761
No related branches found
No related tags found
No related merge requests found
......@@ -209,6 +209,10 @@ class TransactionBuilder(dict):
except:
raise InvalidWifError
def clearWifs(self):
"""Clear all stored wifs"""
self.wifs = set()
def constructTx(self):
""" Construct the actual transaction and store it in the class's dict
store
......
......@@ -234,10 +234,10 @@ def make_patch(a, b, n=3):
def get_node_list(appbase=False):
"""Returns node list"""
if appbase:
return ["https://api.steem.house", "https://api.steemit.com", "wss://steemd.steemitstage.com",
return ["https://api.steem.house", "https://api.steemit.com", "wss://steemd.steemitstage.com",
"wss://steemd.steemitdev.com", "wss://appbasetest.timcliff.com"]
else:
return ["wss://steemd.privex.io", "wss://steemd.pevo.science", "wss://rpc.steemliberator.com", "wss://rpc.buildteam.io", "wss://gtg.steem.house:8090",
return ["wss://steemd.privex.io", "wss://steemd.pevo.science", "wss://rpc.steemliberator.com", "wss://rpc.buildteam.io", "wss://gtg.steem.house:8090",
"wss://rpc.steemviz.com", "wss://seed.bitcoiner.me", "wss://steemd.steemgigs.org",
"wss://steemd.minnowsupportproject.org", "https://rpc.buildteam.io",
"https://steemd.minnowsupportproject.org", "https://steemd.pevo.science", "https://rpc.steemviz.com", "https://seed.bitcoiner.me",
......
......@@ -12,17 +12,11 @@ from beem.blockchain import Blockchain
from beem.account import Account
from beem.block import Block
from beem.steem import Steem
from beem.utils import parse_time, formatTimedelta
from beem.utils import parse_time, formatTimedelta, get_node_list
from beemgrapheneapi.rpcutils import NumRetriesReached
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
nodes = ["wss://steemd.pevo.science", "wss://gtg.steem.house:8090", "wss://rpc.steemliberator.com", "wss://rpc.buildteam.io",
"wss://rpc.steemviz.com", "wss://seed.bitcoiner.me", "wss://node.steem.ws", "wss://steemd.steemgigs.org",
"wss://steemd.minnowsupportproject.org", "https://api.steemit.com", "https://rpc.buildteam.io",
"https://steemd.minnowsupportproject.org", "https://steemd.pevo.science", "https://rpc.steemviz.com", "https://seed.bitcoiner.me",
"https://rpc.steemliberator.com", "https://steemd.privex.io", "https://gtg.steem.house:8090", "https://api.steem.house",
"https://rpc.curiesteem.com"]
if __name__ == "__main__":
how_many_minutes = 10
......@@ -30,6 +24,8 @@ if __name__ == "__main__":
max_batch_size = None
threading = False
thread_num = 16
nodes = get_node_list(appbase=True)
nodes.append(get_node_list(appbase=False))
t = PrettyTable(["node", "10 blockchain minutes", "10000 virtual account op", "version"])
t.align = "l"
for node in nodes:
......
......@@ -122,6 +122,7 @@ class Testcases(unittest.TestCase):
)
tx.appendWif(self.active_key)
tx.sign()
tx.sign()
self.assertEqual(len(tx['signatures']), 1)
tx.broadcast()
steem.nobroadcast = True
......@@ -137,8 +138,10 @@ class Testcases(unittest.TestCase):
"memo": '2 of 2 simple transaction'}))
tx.appendWif(self.active_private_key_of_elf)
tx.appendWif(self.active_private_key_of_steemfiles)
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
......@@ -180,6 +183,7 @@ class Testcases(unittest.TestCase):
tx.appendSigner("elf", "active")
tx.sign()
tx.clearWifs()
self.assertEqual(len(tx['signatures']), 1)
new_tx = TransactionBuilder(tx=tx.json(), steem_instance=steem)
self.assertEqual(len(new_tx['signatures']), 1)
......@@ -191,6 +195,35 @@ class Testcases(unittest.TestCase):
new_tx.broadcast()
steem.nobroadcast = True
def test_transfer_2of2_offline(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")
steem.wallet.addPrivateKey(self.active_private_key_of_steemfiles)
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_elf)
def test_verifyAuthority(self):
stm = self.bts
stm.wallet.unlock("123")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment