-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_override_transfer.py
223 lines (190 loc) · 8.42 KB
/
test_override_transfer.py
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# coding=utf-8
'''
Created on 2018-09-19
@author: holly
Project: test override transfer
'''
from modules import *
@pytest.mark.skip(reason="skip to save money in nathan")
def test_override_transfer(INSTANCE, cleartxpool):
instance = INSTANCE
reset_wallet(instance)
# instance.wallet.removeAccount("nathan")
# create three account
logging.info("create new accounts")
accounts = create_accounts(instance, num=3)
if accounts == False:
logging.info('create account error')
assert 0
# get account accountName and id
accountName1 = accounts[0]['account']
accountName2 = accounts[1]['account']
accountName3 = accounts[2]['account']
account1 = cybex.Account(accountName1, cybex_instance=instance)
accountId1 = dict(account1)['id']
account2 = cybex.Account(accountName2, cybex_instance=instance)
account3 = cybex.Account(accountName3, cybex_instance=instance)
# unlock wallet and add private key
activeKey1 = accounts[0]['active']['wif_priv_key']
activeKey2 = accounts[1]['active']['wif_priv_key']
instance.wallet.unlock("123456")
assert instance.wallet.unlocked()
instance.wallet.addPrivateKey(activeKey1)
# transfer 5 CYB to account1 from nathan
acc = instance.const['master_account']
valu = 5
instance.transfer(accountName1, valu, 'CYB', '', acc)
logging.info("transfer %s CYB from %s to %s" % (valu, acc, account1))
account1.refresh()
assert int(account1.balances[0]) == valu * 10 ** account1.balances[0].asset.precision
# upgrade account1 to lifetime number
logging.info("upgrade %s to lifetime number" % (account1))
instance.upgrade_account(account=account1)
account1.refresh()
ac1 = dict(account1)
assert ac1['registrar'] == ac1['referrer'] == ac1['lifetime_referrer'] == ac1['id']
# create asset
symbol = genSymbol()
logging.info(" %s create asset %s" % (account1, symbol))
precision = 5
max_supply = 1000
core_exchange_rate = 200
ass = instance.create_asset(symbol, precision, max_supply, {symbol: 1, 'CYB': core_exchange_rate}, override_authority=True, account=account1)
# logging.info(ass)
account1.refresh()
logging.info(account1.balances)
assert cybex.Asset(symbol, cybex_instance=instance)['symbol'] == symbol
assert cybex.Asset(symbol, cybex_instance=instance)['precision'] == precision
assert cybex.Asset(symbol, cybex_instance=instance)['issuer'] == accountId1
assert cybex.Asset(symbol, cybex_instance=instance)['options']['issuer_permissions'] == 79
assert cybex.Asset(symbol, cybex_instance=instance)['options']['max_supply'] == max_supply * 10 ** precision
# issue asset
logging.info("issue all asset from %s to %s" % (account1, account2))
instance.issue_asset(account2, max_supply, symbol, account=account1)
account2.refresh()
assert account2.balance(symbol) == max_supply
# override transfer
over_amount = 100
flags = {"override_authority":0x04}
ast = cybex.Asset(symbol, cybex_instance=instance)
ast.setoptions(flags)
logging.info("override transfer %s asset from %s to %s" % (over_amount, account2, account3))
try:
instance.override_transfer(account2, account3, over_amount, symbol)
assert 0
except Exception as err:
instance.clear()
logging.info(err)
pass
logging.info("override transfer %s asset from %s to %s by %s" % (over_amount, account2, account3, account2))
instance.wallet.removeAccount(accountName1)
instance.wallet.addPrivateKey(activeKey2)
try:
instance.override_transfer(account2, account3, over_amount, symbol, account=account2)
assert 0
except Exception as err:
instance.clear()
logging.info(err)
pass
logging.info("override transfer %s asset from %s to %s by %s" % (over_amount, account2, account3, account1))
instance.wallet.removeAccount(accountName2)
instance.wallet.addPrivateKey(activeKey1)
instance.override_transfer(account2, account3, over_amount, symbol, account=account1)
# check the balances in account2 and account3
logging.info("check balances in %s and %s" % (account2, account3))
account2.refresh()
account3.refresh()
assert int(account2.balances[0].amount) == (max_supply - over_amount)
assert int(account3.balances[0].amount) == over_amount
@pytest.mark.skip(reason="skip to save money in nathan")
def test_override_transfer_test2(INSTANCE, cleartxpool):
instance = INSTANCE
reset_wallet(instance)
# instance.wallet.removeAccount("nathan")
# create three account
logging.info("create new accounts")
accounts = create_accounts(instance, num=3)
if accounts == False:
logging.info('create account error')
assert 0
# get account accountName and id
accountName1 = accounts[0]['account']
accountName2 = accounts[1]['account']
accountName3 = accounts[2]['account']
account1 = cybex.Account(accountName1, cybex_instance=instance)
accountId1 = dict(account1)['id']
account2 = cybex.Account(accountName2, cybex_instance=instance)
account3 = cybex.Account(accountName3, cybex_instance=instance)
# unlock wallet and add private key
activeKey1 = accounts[0]['active']['wif_priv_key']
activeKey2 = accounts[1]['active']['wif_priv_key']
instance.wallet.unlock("123456")
assert instance.wallet.unlocked()
instance.wallet.addPrivateKey(activeKey1)
# transfer 5 CYB to account1 from nathan
acc = instance.const['master_account']
valu = 5
instance.transfer(accountName1, valu, 'CYB', '', acc)
logging.info("transfer %s CYB from %s to %s" % (valu, acc, account1))
account1.refresh()
assert int(account1.balances[0]) == valu * 10 ** account1.balances[0].asset.precision
# upgrade account1 to lifetime number
logging.info("upgrade %s to lifetime number" % (account1))
instance.upgrade_account(account=account1)
account1.refresh()
ac1 = dict(account1)
assert ac1['registrar'] == ac1['referrer'] == ac1['lifetime_referrer'] == ac1['id']
# create asset
symbol = genSymbol()
logging.info(" %s create asset %s" % (account1, symbol))
precision = 5
max_supply = 1000
core_exchange_rate = 200
ass = instance.create_asset(symbol, precision, max_supply, {symbol: 1, 'CYB': core_exchange_rate}, override_authority=True, account=account1)
# logging.info(ass)
account1.refresh()
logging.info(account1.balances)
assert cybex.Asset(symbol, cybex_instance=instance)['symbol'] == symbol
assert cybex.Asset(symbol, cybex_instance=instance)['precision'] == precision
assert cybex.Asset(symbol, cybex_instance=instance)['issuer'] == accountId1
assert cybex.Asset(symbol, cybex_instance=instance)['options']['issuer_permissions'] == 79
assert cybex.Asset(symbol, cybex_instance=instance)['options']['max_supply'] == max_supply * 10 ** precision
# issue asset
logging.info("issue all asset from %s to %s" % (account1, account2))
instance.issue_asset(account2, max_supply, symbol, account=account1)
account2.refresh()
assert account2.balance(symbol) == max_supply
# override transfer
over_amount = 100
logging.info("override transfer %s asset from %s to %s" % (over_amount, account2, account3))
try:
instance.override_transfer(account2, account3, over_amount, symbol)
assert 0
except Exception as err:
instance.clear()
logging.info(err)
pass
logging.info("override transfer %s asset from %s to %s by %s" % (over_amount, account2, account3, account2))
instance.wallet.removeAccount(accountName1)
instance.wallet.addPrivateKey(activeKey2)
try:
instance.override_transfer(account2, account3, over_amount, symbol, account=account2)
assert 0
except Exception as err:
instance.clear()
logging.info(err)
pass
logging.info("override transfer %s asset from %s to %s by %s" % (over_amount, account2, account3, account1))
instance.wallet.removeAccount(accountName2)
instance.wallet.addPrivateKey(activeKey1)
try:
instance.override_transfer(account2, account3, over_amount, symbol, account=account1)
assert 0
except Exception as err:
instance.clear()
logging.info(err)
pass
# check the balances in account2
logging.info("check balances in %s" % (account2))
account2.refresh()
assert int(account2.balances[0].amount) == max_supply