forked from bitshares/python-bitshares
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfixtures.py
More file actions
82 lines (67 loc) · 2.45 KB
/
fixtures.py
File metadata and controls
82 lines (67 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
import os
import yaml
from pprint import pprint
from bitshares import BitShares, storage
from bitshares.instance import set_shared_blockchain_instance
from bitshares.blockchainobject import BlockchainObject, ObjectCache
from bitshares.asset import Asset
from bitshares.account import Account
from bitshares.proposal import Proposals, Proposal
from bitsharesbase.operationids import operations
# default wifs key for testing
wifs = [
"5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3",
"5KCBDTcyDqzsqehcb52tW5nU6pXife6V2rX9Yf7c3saYSzbDZ5W",
]
wif = wifs[0]
# bitshares instance
bitshares = BitShares(
"wss://node.bitshares.eu", keys=wifs, nobroadcast=True, num_retries=1
)
config = bitshares.config
# Set defaults
bitshares.set_default_account("init0")
set_shared_blockchain_instance(bitshares)
# Ensure we are not going to transaction anythin on chain!
assert bitshares.nobroadcast
def fixture_data():
# Clear tx buffer
bitshares.clear()
Account.clear_cache()
with open(os.path.join(os.path.dirname(__file__), "fixtures.yaml")) as fid:
data = yaml.safe_load(fid)
for account in data.get("accounts"):
Account.cache_object(account, account["id"])
Account.cache_object(account, account["name"])
for asset in data.get("assets"):
Asset.cache_object(asset, asset["symbol"])
Asset.cache_object(asset, asset["id"])
proposals = []
for proposal in data.get("proposals", []):
ops = list()
for _op in proposal["operations"]:
for opName, op in _op.items():
ops.append([operations[opName], op])
# Proposal!
proposal_id = proposal["proposal_id"]
proposal_data = {
"available_active_approvals": [],
"available_key_approvals": [],
"available_owner_approvals": [],
"expiration_time": "2018-05-29T10:23:13",
"id": proposal_id,
"proposed_transaction": {
"expiration": "2018-05-29T10:23:13",
"extensions": [],
"operations": ops,
"ref_block_num": 0,
"ref_block_prefix": 0,
},
"proposer": "1.2.7",
"required_active_approvals": ["1.2.1"],
"required_owner_approvals": [],
}
proposals.append(Proposal(proposal_data))
Proposals.cache_objects(proposals, "1.2.1")
Proposals.cache_objects(proposals, "witness-account")