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

add test_golos

testnet is not reliable, so using golos for testing
parent 4976a12a
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,8 @@ asset_precision = {
"STEEM": 3,
"VESTS": 6,
"SBD": 3,
"GBG": 3,
"GOLOS": 3
}
......
......@@ -22,9 +22,8 @@ from beemgrapheneapi.rpcutils import NumRetriesReached
# Py3 compatibility
import sys
password = "yfABsiDXWcCVyDC2udXGYD2psFUiQy"
core_unit = "STX"
wif = "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"
core_unit = "GLS"
class Testcases(unittest.TestCase):
......@@ -33,44 +32,28 @@ class Testcases(unittest.TestCase):
super().__init__(*args, **kwargs)
set_shared_steem_instance(None)
self.bts = Steem(
node=["wss://testnet.steem.vc"],
node=["wss://ws.golos.io"],
keys={"active": wif, "owner": wif, "memo": wif},
nobroadcast=True,
)
# from getpass import getpass
# self.bts.wallet.unlock(getpass())
set_shared_steem_instance(self.bts)
self.bts.set_default_account("beem")
stm = self.bts
stm.wallet.wipe(True)
stm.wallet.create("123")
stm.wallet.unlock("123")
account_name = "beem"
active_key = PasswordKey(account_name, password, role="active", prefix=stm.prefix)
owner_key = PasswordKey(account_name, password, role="owner", prefix=stm.prefix)
posting_key = PasswordKey(account_name, password, role="posting", prefix=stm.prefix)
memo_key = PasswordKey(account_name, password, role="memo", prefix=stm.prefix)
active_privkey = active_key.get_private_key()
posting_privkey = posting_key.get_private_key()
owner_privkey = owner_key.get_private_key()
memo_privkey = memo_key.get_private_key()
stm.wallet.addPrivateKey(owner_privkey)
stm.wallet.addPrivateKey(active_privkey)
stm.wallet.addPrivateKey(memo_privkey)
stm.wallet.addPrivateKey(posting_privkey)
self.bts.set_default_account("test")
def test_transfer(self):
bts = self.bts
# bts.prefix ="STX"
acc = Account("beem", steem_instance=bts)
acc = Account("test", steem_instance=bts)
tx = acc.transfer(
"test1", 1.33, "SBD", memo="Foobar")
"test1", 1.33, "GBG", memo="Foobar")
self.assertEqual(
tx["operations"][0][0],
"transfer"
)
op = tx["operations"][0][1]
self.assertIn("memo", op)
self.assertEqual(op["from"], "beem")
self.assertEqual(op["from"], "test")
self.assertEqual(op["to"], "test1")
amount = Amount(op["amount"])
self.assertEqual(float(amount), 1.33)
......@@ -85,7 +68,7 @@ class Testcases(unittest.TestCase):
key5 = PrivateKey()
tx = bts.create_account(
name,
creator="beem",
creator="test",
owner_key=format(key1.pubkey, core_unit),
active_key=format(key2.pubkey, core_unit),
posting_key=format(key3.pubkey, core_unit),
......@@ -123,15 +106,14 @@ class Testcases(unittest.TestCase):
[x[0] for x in op[role]["account_auths"]])
self.assertEqual(
op["creator"],
"beem")
"test")
def test_connect(self):
self.bts.connect(node=["wss://testnet.steem.vc"])
bts = self.bts
self.assertEqual(bts.prefix, "STX")
self.assertEqual(bts.prefix, "GLS")
def test_set_default_account(self):
self.bts.set_default_account("beem")
self.bts.set_default_account("test")
def test_info(self):
info = self.bts.info()
......@@ -150,10 +132,10 @@ class Testcases(unittest.TestCase):
tx1 = bts.new_tx()
tx2 = bts.new_tx()
acc = Account("beem", steem_instance=bts)
acc.transfer("test1", 1, "STEEM", append_to=tx1)
acc.transfer("test1", 2, "STEEM", append_to=tx2)
acc.transfer("test1", 3, "STEEM", append_to=tx1)
acc = Account("test", steem_instance=bts)
acc.transfer("test1", 1, "GOLOS", append_to=tx1)
acc.transfer("test1", 2, "GOLOS", append_to=tx2)
acc.transfer("test1", 3, "GOLOS", append_to=tx1)
tx1 = tx1.json()
tx2 = tx2.json()
ops1 = tx1["operations"]
......@@ -166,15 +148,15 @@ class Testcases(unittest.TestCase):
auth = {'account_auths': [['test', 1]],
'extensions': [],
'key_auths': [
['STX55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n', 1],
['STX7GM9YXcsoAJAgKbqW2oVj7bnNXFNL4pk9NugqKWPmuhoEDbkDv', 1]],
['GLS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n', 1],
['GLS7GM9YXcsoAJAgKbqW2oVj7bnNXFNL4pk9NugqKWPmuhoEDbkDv', 1]],
'weight_threshold': 3} # threshold fine
bts._test_weights_treshold(auth)
auth = {'account_auths': [['test', 1]],
'extensions': [],
'key_auths': [
['STX55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n', 1],
['STX7GM9YXcsoAJAgKbqW2oVj7bnNXFNL4pk9NugqKWPmuhoEDbkDv', 1]],
['GLS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n', 1],
['GLS7GM9YXcsoAJAgKbqW2oVj7bnNXFNL4pk9NugqKWPmuhoEDbkDv', 1]],
'weight_threshold': 4} # too high
with self.assertRaises(ValueError):
......@@ -182,12 +164,12 @@ class Testcases(unittest.TestCase):
def test_allow(self):
bts = self.bts
self.assertIn(bts.prefix, "STX")
acc = Account("beem", steem_instance=bts)
self.assertIn(acc.steem.prefix, "STX")
self.assertIn(bts.prefix, "GLS")
acc = Account("test", steem_instance=bts)
self.assertIn(acc.steem.prefix, "GLS")
tx = acc.allow(
"STX55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n",
account="beem",
"GLS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n",
account="test",
weight=1,
threshold=1,
permission="owner",
......@@ -199,27 +181,27 @@ class Testcases(unittest.TestCase):
op = tx["operations"][0][1]
self.assertIn("owner", op)
self.assertIn(
["STX55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n", '1'],
["GLS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n", '1'],
op["owner"]["key_auths"])
self.assertEqual(op["owner"]["weight_threshold"], 1)
def test_disallow(self):
bts = self.bts
acc = Account("beem", steem_instance=bts)
acc = Account("test", steem_instance=bts)
if sys.version > '3':
_assertRaisesRegex = self.assertRaisesRegex
else:
_assertRaisesRegex = self.assertRaisesRegexp
with _assertRaisesRegex(ValueError, ".*Changes nothing.*"):
acc.disallow(
"STX55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n",
"GLS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n",
weight=1,
threshold=1,
permission="owner"
)
with _assertRaisesRegex(ValueError, ".*Changes nothing!.*"):
acc.disallow(
"STX6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
"GLS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV",
weight=1,
threshold=1,
permission="owner"
......@@ -227,9 +209,9 @@ class Testcases(unittest.TestCase):
def test_update_memo_key(self):
bts = self.bts
self.assertEqual(bts.prefix, "STX")
acc = Account("beem", steem_instance=bts)
tx = acc.update_memo_key("STX55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n")
self.assertEqual(bts.prefix, "GLS")
acc = Account("test", steem_instance=bts)
tx = acc.update_memo_key("GLS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n")
self.assertEqual(
(tx["operations"][0][0]),
"account_update"
......@@ -237,11 +219,11 @@ class Testcases(unittest.TestCase):
op = tx["operations"][0][1]
self.assertEqual(
op["memo_key"],
"STX55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n")
"GLS55VCzsb47NZwWe5F3qyQKedX9iHBHMVVFSc96PDvV7wuj7W86n")
def test_approvewitness(self):
bts = self.bts
w = Account("beem", steem_instance=bts)
w = Account("test", steem_instance=bts)
tx = w.approvewitness("test1")
self.assertEqual(
(tx["operations"][0][0]),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment