├── .gitignore ├── wallet_api.docm ├── contract_hello.lua ├── t10_other_api.py ├── LICENSE ├── config.py ├── README.md ├── t04_contract.py ├── t01_common_api.py ├── chain_param.py ├── utils.py ├── t02_wallet_info.py ├── t05_candidates.py ├── t09_file.py ├── t03_account.py ├── t08_trx_proposal.py ├── t06_asset.py └── t07_nh_asset.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | test.py 3 | 4 | -------------------------------------------------------------------------------- /wallet_api.docm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cocos-BCX/Cocos-cli_wallet-API/HEAD/wallet_api.docm -------------------------------------------------------------------------------- /contract_hello.lua: -------------------------------------------------------------------------------- 1 | function hello() 2 | chainhelper:log('contract test by create_contract_from_file') 3 | end -------------------------------------------------------------------------------- /t10_other_api.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import unittest 4 | from config import * 5 | from utils import * 6 | import sys 7 | 8 | ''' 9 | TODO: 10 | ''' 11 | 12 | class test_other_api(request_unittest): 13 | @classmethod 14 | def setUpClass(self): 15 | req_data = { 16 | "jsonrpc": "2.0", 17 | "method": "unlock", 18 | "params": [wallet_password], 19 | "id":1 20 | } 21 | request_post(req_data) 22 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 23 | 24 | 25 | @classmethod 26 | def tearDownClass(self): 27 | req_data = { 28 | "jsonrpc": "2.0", 29 | "method": "lock", 30 | "params": [], 31 | "id":1 32 | } 33 | request_post(req_data) 34 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 35 | 36 | if __name__ == "__main__": 37 | unittest.main() 38 | 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 gkany 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | host = '127.0.0.1' 4 | port = 8048 5 | cli_wallet_url = "http://{}:{}".format(host, port) 6 | 7 | wallet_password = "123456" 8 | 9 | headers = {"content-type": "application/json"} 10 | 11 | test_account = 'nicotest' 12 | test_account_private_key = '5J2SChqa9QxrCkdMor9VC2k9NT4R4ctRrJA6odQCPkb3yL89vxo' 13 | test_account_public_key = 'COCOS56a5dTnfGpuPoWACnYj65dahcXMpTrNQkV3hHWCFkLxMF5mXpx' 14 | 15 | test_balance_address = '5KAUeN3Yv51FzpLGGf4S1ByKpMqVFNzXTJK7euqc3NnaaLz1GJm' # 链启动后已经导入过 16 | 17 | test_witness_account = 'init1' 18 | test_witness_account_public_key = 'COCOS5TrJztVAY5F9aWDw5KtDHfdrffQn7F3sjgbL8YyssiKhVCLNf7' 19 | test_witness_account_private_key = '5K5fqjvMrH5UtUisCgSZHQjiQf9BvtZ5vsKPhCErDy7P2gnLQmw' 20 | 21 | 22 | test_committee_account = 'init5' 23 | test_committee_account_public_key = 'COCOS8LQSvCgZvwW44iJuCBkVmpR3uUh6J2VFkBJScA3vJq3gXTLCLr' 24 | test_committee_account_private_key = '5KVEqMvCQf5CP4Stkd9CW479uwQnDbhCiFxbdRLXgkxS3RchZ6X' 25 | 26 | test_nh_creator = "creator2" 27 | 28 | core_asset = "COCOS" 29 | asset_gas = "GAS" 30 | test_default_asset = "AAAA" 31 | test_default_bitasset = "BBBB" 32 | 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cli_wallet api 2 | ## 1. 一般命令 3 | ``` text 4 | (help)(gethelp)(info)(about) 5 | 6 | (network_add_nodes)(network_get_connected_peers) 7 | 8 | (get_block)(get_object) 9 | 10 | (get_global_properties)(get_dynamic_global_properties)(get_chain_properties) 11 | 12 | (get_prototype_operation_by_name)(get_prototype_operation_by_idx) 13 | 14 | (is_public_key_registered) 15 | ``` 16 | 17 | ## 2. 钱包相关 18 | ``` text 19 | (is_new)(is_locked)(lock)(unlock)(set_password)(dump_private_keys) 20 | 21 | (import_key)(import_balance)(suggest_brain_key)(derive_owner_keys_from_brain_key)(suggest_brain_address_key) 22 | 23 | (get_transaction_id)(get_private_key)(normalize_brain_key) 24 | 25 | (load_wallet_file)(save_wallet_file)(add_extern_sign_key) 26 | ``` 27 | 28 | 29 | ## 3. 账号相关 30 | ``` text 31 | (list_my_accounts)(list_accounts)(list_account_balances) 32 | 33 | (register_account)(upgrade_account)(create_account_with_brain_key) 34 | 35 | (transfer)(transfer2)(get_account)(get_account_id) 36 | 37 | (get_account_count)(get_account_history)(get_relative_account_history) 38 | 39 | (get_vesting_balances)(withdraw_vesting) 40 | 41 | (update_collateral_for_gas) 42 | ``` 43 | 44 | 45 | ## 4. 合约 46 | ``` text 47 | (create_contract)(create_contract_from_file)(call_contract_function)(revise_contract) 48 | 49 | (get_contract)(get_account_contract_data)(get_contract_public_data) 50 | 51 | ``` 52 | 53 | ## 5. 理事会和见证人 54 | ``` text 55 | # (get_witness)(get_committee_member)(list_witnesses)(list_committee_members) 56 | 57 | # (create_committee_member)(update_committee_member)(create_witness)(update_witness) 58 | 59 | # (vote_for_committee_member)(vote_for_witness) 60 | ``` 61 | 62 | 63 | ## 6. 同质资产 64 | ``` text 65 | (get_limit_orders)(get_call_orders)(get_settle_orders) 66 | 67 | (list_assets)(list_asset_restricted_objects)(asset_update_restricted_list) 68 | 69 | (sell_asset)(sell)(buy)(borrow_asset)(cancel_order) 70 | 71 | (create_asset)(update_asset)(update_bitasset)(update_asset_feed_producers) 72 | 73 | (publish_asset_feed)(issue_asset)(get_asset)(get_bitasset_data)(reserve_asset) 74 | 75 | (global_settle_asset)(settle_asset)(bid_collateral) 76 | 77 | (get_market_history) (get_order_book) 78 | ``` 79 | 80 | ## 7. 非同质资产 81 | ``` text 82 | (register_nh_asset_creator)(create_world_view)(propose_relate_world_view)(create_nh_asset) 83 | 84 | (list_nh_asset_by_creator)(list_account_nh_asset)(transfer_nh_asset)(get_nh_creator) 85 | 86 | (delete_nh_asset)(create_nh_asset_order)(list_nh_asset_order)(cancel_nh_asset_order) 87 | 88 | (fill_nh_asset_order)(list_account_nh_asset_order) 89 | ``` 90 | 91 | ## 8. 事物和提议 92 | ``` text 93 | (begin_builder_transaction)(add_operation_to_builder_transaction) 94 | 95 | (replace_operation_in_builder_transaction)(preview_builder_transaction) 96 | 97 | (sign_builder_transaction)(propose_builder_transaction)(remove_builder_transaction) 98 | 99 | (get_transaction_by_id)(get_transaction_in_block_info)(get_account_top_transaction) 100 | 101 | (get_account_transaction)(get_signature_keys) 102 | 103 | (serialize_transaction)(sign_transaction)(validate_transaction) 104 | 105 | (propose_parameter_change)(propose_fee_change)(approve_proposal) 106 | ``` 107 | 108 | ## 9. 文件 109 | ``` text 110 | (create_file)(add_file_relate_account)(file_signature) 111 | 112 | (list_account_created_file)(lookup_file) 113 | 114 | (propose_relate_parent_file) 115 | ``` 116 | 117 | 118 | ## 10. 其他 119 | ``` text 120 | (set_node_message_send_cache_size)(set_node_deduce_in_verification_mode) 121 | 122 | (get_collateral_bids)(adjustment_temporary_authorization) 123 | 124 | (sign_memo)(read_memo)(set_key_label)(get_key_label)(get_public_key) 125 | 126 | (create_crontab)(cancel_crontab)(list_account_crontab)(crontab_builder_transaction)(recover_crontab) 127 | 128 | (dbg_push_blocks)(dbg_generate_blocks)(dbg_stream_json_objects)(dbg_update_object) 129 | ``` 130 | 131 | -------------------------------------------------------------------------------- /t04_contract.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import unittest 4 | from config import * 5 | from utils import * 6 | import os 7 | 8 | class test_wallet_contract_api(request_unittest): 9 | @classmethod 10 | def setUpClass(self): 11 | self.owner = test_account 12 | self.pub_key = test_account_public_key 13 | self.contract_name = "contract.debug.hello" 14 | # self.contract_name = "contract.debug.world" 15 | self.function_name = "hello" 16 | self.contract_data = "function {}() chainhelper:log('create contract test') end".format(self.function_name) 17 | 18 | req_data = { 19 | "jsonrpc": "2.0", 20 | "method": "unlock", 21 | "params": [wallet_password], 22 | "id":1 23 | } 24 | request_post(req_data) 25 | 26 | req_data = { 27 | "jsonrpc": "2.0", 28 | "method": "import_key", 29 | "params": [test_account, test_account_private_key], 30 | "id":1 31 | } 32 | request_post(req_data) 33 | 34 | req_data = { 35 | "jsonrpc": "2.0", 36 | "method": "import_key", 37 | "params": [test_witness_account, test_witness_account_private_key], 38 | "id":1 39 | } 40 | request_post(req_data) 41 | 42 | @classmethod 43 | def tearDownClass(self): 44 | req_data = { 45 | "jsonrpc": "2.0", 46 | "method": "lock", 47 | "params": [], 48 | "id":1 49 | } 50 | request_post(req_data) 51 | 52 | def setUp(self): 53 | pass 54 | 55 | def tearDown(self): 56 | pass 57 | 58 | @unittest.skipIf(True, 'test other') 59 | def test_create_contract(self): 60 | req_data = { 61 | "jsonrpc": "2.0", 62 | "method": "create_contract", 63 | "params": [self.owner, self.contract_name, self.pub_key, self.contract_data, 'true'], 64 | "id":1 65 | } 66 | self.request_post(req_data) 67 | 68 | @unittest.skipIf(True, 'no support') 69 | def test_create_contract_from_file(self): 70 | #generate random contract_name by suggest_brain_key 71 | tokens = generate_random_words() 72 | owner = test_account 73 | contract_name = "test.contract." + tokens[0].lower() 74 | contract_authority = test_account_public_key 75 | current_path = os.path.abspath(os.path.dirname(__file__)) 76 | filename = current_path + '/' + "contract_hello.lua" 77 | print('filename: {}'.format(filename)) 78 | req_data = { 79 | "jsonrpc": "2.0", 80 | "method": "create_contract_from_file", 81 | "params": [owner, contract_name, contract_authority, filename, 'true'], 82 | "id":1 83 | } 84 | self.request_post(req_data) 85 | 86 | def test_get_contract(self): 87 | req_data = { 88 | "jsonrpc": "2.0", 89 | "method": "get_contract", 90 | "params": [self.contract_name], 91 | "id":1 92 | } 93 | self.request_post(req_data) 94 | 95 | def test_call_contract_function(self): 96 | req_data = { 97 | "jsonrpc": "2.0", 98 | "method": "call_contract_function", 99 | "params": [self.owner, self.contract_name, self.function_name, [], 'true'], 100 | "id":1 101 | } 102 | self.request_post(req_data) 103 | 104 | def test_revise_contract(self): 105 | contract_data = "function {}() chainhelper:log('revise_contract test') end".format(self.function_name) 106 | req_data = { 107 | "jsonrpc": "2.0", 108 | "method": "revise_contract", 109 | "params": [self.owner, self.contract_name, contract_data, 'true'], 110 | "id":1 111 | } 112 | self.request_post(req_data) 113 | 114 | def test_get_account_contract_data(self): 115 | req_data = { 116 | "jsonrpc": "2.0", 117 | "method": "get_account_contract_data", 118 | "params": [self.owner, self.contract_name], 119 | "id":1 120 | } 121 | self.request_post(req_data) 122 | 123 | def test_get_contract_public_data(self): 124 | filter = [[]] 125 | req_data = { 126 | "jsonrpc": "2.0", 127 | "method": "get_contract_public_data", 128 | "params": [self.contract_name, filter], 129 | "id":1 130 | } 131 | self.request_post(req_data) 132 | 133 | if __name__ == "__main__": 134 | unittest.main() 135 | 136 | -------------------------------------------------------------------------------- /t01_common_api.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import math 4 | import unittest 5 | from utils import request_unittest 6 | from chain_param import operation_list 7 | from config import * 8 | 9 | class test_wallet_common_api(request_unittest): 10 | def test_help(self): 11 | req_data = { 12 | "jsonrpc": "2.0", 13 | "method": "help", 14 | "params": [], 15 | "id":1 16 | } 17 | self.request_post_error_asset_false(req_data) 18 | 19 | def test_gethelp(self): 20 | methods = ['transfer', 'register_account', 'about'] 21 | for method in methods: 22 | req_data = { 23 | "jsonrpc": "2.0", 24 | "method": "gethelp", 25 | "params": [method], 26 | "id":1 27 | } 28 | self.request_post_error_asset_false(req_data) 29 | 30 | def test_info(self): 31 | req_data = { 32 | "jsonrpc": "2.0", 33 | "method": "info", 34 | "params": [], 35 | "id":1 36 | } 37 | self.request_post_error_asset_false(req_data) 38 | 39 | def test_about(self): 40 | req_data = { 41 | "jsonrpc": "2.0", 42 | "method": "about", 43 | "params": [], 44 | "id":1 45 | } 46 | self.request_post_error_asset_false(req_data) 47 | 48 | def test_network_add_nodes(self): 49 | req_data = { 50 | "jsonrpc": "2.0", 51 | "method": "network_add_nodes", 52 | "params": [["127.0.0.1:8090"]], 53 | "id":1 54 | } 55 | # self.request_post_error_asset_false(req_data) 56 | self.request_post_error_asset_true(req_data) 57 | 58 | def test_network_get_connected_peers(self): 59 | req_data = { 60 | "jsonrpc": "2.0", 61 | "method": "network_get_connected_peers", 62 | "params": [], 63 | "id":1 64 | } 65 | self.request_post_error_asset_false(req_data) 66 | 67 | def test_get_block(self): 68 | req_data = { 69 | "jsonrpc": "2.0", 70 | "method": "info", 71 | "params": [], 72 | "id":1 73 | } 74 | info = self.request_post(req_data)['result'] 75 | num = math.ceil(info['head_block_num']/2) 76 | 77 | req_data = { 78 | "jsonrpc": "2.0", 79 | "method": "get_block", 80 | "params": [num], 81 | "id":1 82 | } 83 | self.request_post(req_data) 84 | 85 | def test_get_global_properties(self): 86 | req_data = { 87 | "jsonrpc": "1.2.0", 88 | "method": "get_global_properties", 89 | "params": [], 90 | "id":1 91 | } 92 | self.request_post(req_data) 93 | 94 | def test_get_dynamic_global_properties(self): 95 | req_data = { 96 | "jsonrpc": "1.2.0", 97 | "method": "get_dynamic_global_properties", 98 | "params": [], 99 | "id":1 100 | } 101 | self.request_post(req_data) 102 | 103 | def test_get_chain_properties(self): 104 | req_data = { 105 | "jsonrpc": "1.2.0", 106 | "method": "get_chain_properties", 107 | "params": [], 108 | "id":1 109 | } 110 | self.request_post(req_data) 111 | 112 | @unittest.skipIf(True, 'test other') 113 | def test_get_prototype_operation_by_name(self): 114 | for operation in operation_list: 115 | req_data = { 116 | "jsonrpc": "1.2.0", 117 | "method": "get_prototype_operation_by_name", 118 | "params": [operation], 119 | "id":1 120 | } 121 | self.request_post(req_data) 122 | 123 | @unittest.skipIf(True, 'test other') 124 | def test_get_prototype_operation_by_idx(self): 125 | for index in range(0, len(operation_list)): 126 | req_data = { 127 | "jsonrpc": "1.2.0", 128 | "method": "get_prototype_operation_by_idx", 129 | "params": [index], 130 | "id":1 131 | } 132 | self.request_post(req_data) 133 | 134 | def test_is_public_key_registered(self): 135 | pub_key = test_account_public_key 136 | req_data = { 137 | "jsonrpc": "1.2.0", 138 | "method": "is_public_key_registered", 139 | "params": [pub_key], 140 | "id":1 141 | } 142 | # self.request_post(req_data) 143 | self.request_post_result_asset_true(req_data) 144 | 145 | if __name__ == '__main__': 146 | unittest.main() -------------------------------------------------------------------------------- /chain_param.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | operation_list = [ 4 | "transfer_operation", #0 static_variant operation 5 | "limit_order_create_operation", #1 #自动检测是否有相符的订单,自动调用fill_order_operation撮合 6 | "limit_order_cancel_operation", #2 7 | "call_order_update_operation", #3 #调整抵押单 8 | "fill_order_operation", #4 # 系统私有op 9 | "account_create_operation", #5 10 | "account_update_operation", #6 11 | "account_upgrade_operation", #7 12 | "asset_create_operation", #8 13 | "asset_update_operation", #9 14 | "asset_update_restricted_operation", #10 15 | "asset_update_bitasset_operation", #11 #/更新智能资产 16 | "asset_update_feed_producers_operation", #12 #/ 修改智能资产喂价账户 17 | "asset_issue_operation", #13 #/定向发行资产 18 | "asset_reserve_operation", #14 ##放弃部分资产,指定资产将被回收,流通量减少,总量不变 19 | "asset_settle_operation", #15 ## 清算bitasset资产 20 | "asset_global_settle_operation", #16 #/ 在global_settle允许的情况下清算货币交易市场 21 | "asset_publish_feed_operation", #17 22 | "witness_create_operation", #18 见证人 23 | "witness_update_operation", #19 24 | "proposal_create_operation", #20 25 | "proposal_update_operation", #21 26 | "proposal_delete_operation", #22 #提议 27 | "committee_member_create_operation", #23 #理事会成员创建 28 | "committee_member_update_operation", #24 #理事会成员更新 29 | "committee_member_update_global_parameters_operation", #25 #理事会更新链上运行参数 30 | "vesting_balance_create_operation", #26 #保留资金 ,锁定资金 31 | "vesting_balance_withdraw_operation", #27 #领取解冻的保留资金 32 | "worker_create_operation", #28 33 | "balance_claim_operation", #29 取回链初始化时分配的资产 34 | "asset_settle_cancel_operation", # VIRTUAL #30 #未有实体的清算取消操作 35 | "asset_claim_fees_operation", #31 #资产发行人从资产累计池中取回资产 36 | "bid_collateral_operation", #32 #智能货币抵押投标 37 | "execute_bid_operation", # VIRTUAL #33 # 内部私有op 38 | "contract_create_operation", #34 39 | "call_contract_function_operation", #35 40 | "temporary_authority_change_operation", #36 41 | "register_nh_asset_creator_operation", #37 42 | "create_world_view_operation", #38 43 | "relate_world_view_operation", #39 44 | "create_nh_asset_operation", #40 45 | "delete_nh_asset_operation", #41 46 | "transfer_nh_asset_operation", #42 47 | "create_nh_asset_order_operation", #43 48 | "cancel_nh_asset_order_operation", #44 49 | "fill_nh_asset_order_operation", #45 50 | "create_file_operation", #46 51 | "add_file_relate_account_operation", #47 52 | "file_signature_operation", #48 53 | "relate_parent_file_operation", #49 54 | "revise_contract_operation", #50 55 | "crontab_create_operation", #51 56 | "crontab_cancel_operation", #52 57 | "crontab_recover_operation", #53 58 | "update_collateral_for_gas_operation", #54 59 | "account_authentication_operation" #55 60 | ] 61 | 62 | 63 | restricted_enum = [ 64 | "all_restricted", #0, 65 | "whitelist_authorities", #1, 66 | "blacklist_authorities", #2, 67 | "whitelist_markets", #3, 68 | "blacklist_markets", #4 69 | ] 70 | 71 | 72 | # enum class nh_asset_list_type 73 | nh_asset_list_type = [ 74 | "only_active" , # = 0, // target with NHA active permission only 75 | "only_owner" , # = 1, // target with NHA owner permission only 76 | "all_active" , # = 2, // target with NHA active permission 77 | "all_owner" , # = 3, // target with NHA active permission 78 | "owner_and_active" , # = 4 // target with NHA both active and owner permission 79 | ] -------------------------------------------------------------------------------- /utils.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import json 4 | import requests 5 | import unittest 6 | 7 | import time 8 | import sys 9 | import datetime 10 | 11 | from config import * 12 | 13 | def request_post(req_data, is_assert=True): 14 | response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 15 | print('>> {} {}\n{}\n'.format(req_data['method'], req_data['params'], response)) 16 | if is_assert: 17 | assert 'error' not in response 18 | return response 19 | 20 | #default: 21 | # user issuer asset: AAAA 22 | # bit asset : BBBB 23 | def get_asset_if_not_create(symbol, is_bitasset=False): 24 | print('[{}] symbol: {}'.format(sys._getframe().f_code.co_name, symbol)) 25 | req_data = { 26 | "jsonrpc": "2.0", 27 | "method": "get_asset", 28 | "params": [symbol], 29 | "id":1 30 | } 31 | # response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 32 | response = request_post(req_data, False) 33 | if 'error' in response: 34 | precision = 5 35 | asset_opts = { 36 | "max_supply":"2100000000000000", 37 | "market_fee_percent":0, 38 | "max_market_fee":0, 39 | "flags":0, 40 | "core_exchange_rate":{ 41 | "base":{"amount":1,"asset_id":"1.3.3"}, 42 | "quote":{"amount":1,"asset_id":"1.3.0"} 43 | }, 44 | "description":"", 45 | "extensions":[] 46 | } 47 | bitasset_opts = None 48 | if is_bitasset: 49 | asset_opts = { 50 | "issuer_permissions": 511, 51 | "flags": 0, 52 | "core_exchange_rate":{ 53 | "base":{"amount":1,"asset_id":"1.3.4"}, 54 | "quote":{"amount":1,"asset_id":"1.3.0"} 55 | } 56 | } 57 | bitasset_opts = { 58 | "new_feed_producers":[], 59 | "feed_lifetime_sec":120 60 | } 61 | req_data = { 62 | "jsonrpc": "2.0", 63 | "method": "create_asset", 64 | "params": [test_account, symbol, precision, asset_opts, bitasset_opts, 'true'], 65 | "id":1 66 | } 67 | # response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 68 | response = request_post(req_data) 69 | # assert 'bitasset_data_id' in response 70 | return response['result'] 71 | return response['result'] 72 | 73 | #generate random words by suggest_brain_key 74 | def generate_random_words(): 75 | req_data = { 76 | "jsonrpc": "2.0", 77 | "method": "suggest_brain_key", 78 | "params": [], 79 | "id":1 80 | } 81 | suggest_brain_key = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text)['result'] 82 | brain_key = suggest_brain_key['brain_priv_key'] 83 | return brain_key.split() 84 | 85 | 86 | class request_unittest(unittest.TestCase): 87 | def request_post(self, req_data): 88 | response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 89 | print('>> {} {}\n{}\n'.format(req_data['method'], req_data['params'], response)) 90 | self.assertFalse('error' in response) 91 | return response 92 | 93 | def request_post_error_asset_false(self, req_data): 94 | response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 95 | #print('>> {} {}\n{}\n'.format(req_data['method'], req_data['params'], response)) 96 | self.assertFalse('error' in response, '{} {} error'.format(req_data['method'], req_data['params'])) 97 | 98 | def request_post_error_asset_true(self, req_data): 99 | response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 100 | self.assertTrue('error' in response, '{} {} error'.format(req_data['method'], req_data['params'])) 101 | 102 | def request_post_result_asset_false(self, req_data): 103 | response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 104 | self.assertFalse('error' in response) 105 | self.assertFalse(response['result']) 106 | 107 | def request_post_result_asset_true(self, req_data): 108 | response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 109 | self.assertFalse('error' in response) 110 | self.assertTrue(response['result']) 111 | 112 | def request_post_result_asset_is_none(self, req_data): 113 | response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 114 | self.assertFalse('error' in response) 115 | self.assertIsNone(response['result']) 116 | 117 | def request_post_result_asset_in(self, req_data, first_or_second, is_first=True): 118 | response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 119 | self.assertFalse('error' in response) 120 | if is_first: 121 | self.assertIn(first_or_second, response['result']) 122 | else: 123 | self.assertIn(response['result'], first_or_second) 124 | 125 | def request_post_result_asset_equal(self, req_data, value): 126 | response = json.loads(requests.post(cli_wallet_url, data = json.dumps(req_data), headers = headers).text) 127 | self.assertFalse('error' in response) 128 | self.assertEqual(value, response['result']) 129 | 130 | 131 | def datetime_N_ago(n): 132 | n_ago = (datetime.datetime.now() - datetime.timedelta(days = n)) 133 | # return n_ago.strftime("%Y-%m-%d %H:%M:%S") 134 | return n_ago 135 | -------------------------------------------------------------------------------- /t02_wallet_info.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import unittest 4 | from utils import request_unittest, request_post 5 | from config import * 6 | import sys 7 | 8 | class test_wallet_info_api(request_unittest): 9 | @classmethod 10 | def setUpClass(self): 11 | req_data = { 12 | "jsonrpc": "2.0", 13 | "method": "unlock", 14 | "params": [wallet_password], 15 | "id":1 16 | } 17 | request_post(req_data) 18 | 19 | req_data = { 20 | "jsonrpc": "2.0", 21 | "method": "import_key", 22 | "params": [test_account, test_account_private_key], 23 | "id":1 24 | } 25 | request_post(req_data) 26 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 27 | 28 | @classmethod 29 | def tearDownClass(self): 30 | req_data = { 31 | "jsonrpc": "2.0", 32 | "method": "lock", 33 | "params": [], 34 | "id":1 35 | } 36 | request_post(req_data) 37 | 38 | def test_is_new(self): 39 | req_data = { 40 | "jsonrpc": "2.0", 41 | "method": "is_new", 42 | "params": [], 43 | "id":1 44 | } 45 | # self.request_post(req_data) 46 | self.request_post_result_asset_false(req_data) 47 | 48 | def test_is_locked(self): 49 | req_data = { 50 | "jsonrpc": "2.0", 51 | "method": "is_locked", 52 | "params": [], 53 | "id":1 54 | } 55 | self.request_post_result_asset_false(req_data) 56 | 57 | def test_lock(self): 58 | req_data = { 59 | "jsonrpc": "2.0", 60 | "method": "lock", 61 | "params": [], 62 | "id":1 63 | } 64 | # self.request_post(req_data) 65 | self.request_post_result_asset_is_none(req_data) 66 | 67 | def test_unlock(self): 68 | req_data = { 69 | "jsonrpc": "2.0", 70 | "method": "unlock", 71 | "params": [wallet_password], 72 | "id":1 73 | } 74 | # self.request_post(req_data) 75 | self.request_post_result_asset_is_none(req_data) 76 | 77 | def test_set_password(self): 78 | req_data = { 79 | "jsonrpc": "2.0", 80 | "method": "unlock", 81 | "params": [wallet_password], 82 | "id":1 83 | } 84 | self.request_post(req_data) 85 | 86 | req_data = { 87 | "jsonrpc": "2.0", 88 | "method": "set_password", 89 | "params": [wallet_password], 90 | "id":1 91 | } 92 | # self.request_post(req_data) 93 | self.request_post_result_asset_is_none(req_data) 94 | 95 | def test_dump_private_keys(self): 96 | req_data = { 97 | "jsonrpc": "2.0", 98 | "method": "dump_private_keys", 99 | "params": [wallet_password], 100 | "id":1 101 | } 102 | keys = [test_account_public_key, test_account_private_key] 103 | self.request_post_result_asset_in(req_data, keys) 104 | 105 | def test_import_key(self): 106 | req_data = { 107 | "jsonrpc": "2.0", 108 | "method": "import_key", 109 | "params": [test_account, test_account_private_key], 110 | "id":1 111 | } 112 | # self.request_post(req_data) 113 | self.request_post_result_asset_true(req_data) 114 | 115 | def test_import_balance(self): 116 | req_data = { 117 | "jsonrpc": "2.0", 118 | "method": "import_balance", 119 | "params": [test_account, [test_balance_address], 'true'], 120 | "id":1 121 | } 122 | value = [] # 链初始化时已经执行过import_balance, 再次执行result = [] 123 | self.request_post_result_asset_equal(req_data, value) 124 | 125 | def test_suggest_brain_key(self): 126 | req_data = { 127 | "jsonrpc": "2.0", 128 | "method": "suggest_brain_key", 129 | "params": [], 130 | "id":1 131 | } 132 | # self.request_post(req_data) 133 | self.request_post_error_asset_false(req_data) 134 | 135 | @unittest.skipIf(True, 'test other') 136 | def test_get_transaction_id(self): 137 | transfer_req_data = { 138 | "jsonrpc": "2.0", 139 | "method": "transfer", 140 | "params": [test_account, test_witness_account, 100, 'COCOS', 'get_transaction_id test', 'false'], 141 | "id":1 142 | } 143 | response = self.request_post(transfer_req_data) 144 | result = response['result'] 145 | # print('result: {}'.format(result)) 146 | transaction_id = result[0] 147 | transaction = result[1] 148 | # print('trx_id: {}, trx: {}'.format(transaction_id, transaction)) 149 | 150 | req_data = { 151 | "jsonrpc": "2.0", 152 | "method": "get_transaction_id", 153 | "params": [transaction], 154 | "id":1 155 | } 156 | # self.request_post(req_data) 157 | self.request_post_result_asset_in(req_data, transaction_id, False) 158 | 159 | def test_get_private_key(self): 160 | req_data = { 161 | "jsonrpc": "2.0", 162 | "method": "get_private_key", 163 | "params": [test_account_public_key], 164 | "id":1 165 | } 166 | # self.request_post(req_data) 167 | self.request_post_result_asset_equal(req_data, test_account_private_key) 168 | 169 | def test_normalize_brain_key(self): 170 | test_brain_key = " test wallet API NORMALIZE BRAIN key by python unit TEST " 171 | normalize_brain_key = "TEST WALLET API NORMALIZE BRAIN KEY BY PYTHON UNIT TEST" 172 | req_data = { 173 | "jsonrpc": "2.0", 174 | "method": "normalize_brain_key", 175 | "params": [test_brain_key], 176 | "id":1 177 | } 178 | # self.request_post(req_data) 179 | self.request_post_result_asset_equal(req_data, normalize_brain_key) 180 | 181 | def test_save_wallet_file(self): 182 | req_data = { 183 | "jsonrpc": "2.0", 184 | "method": "save_wallet_file", 185 | "params": ["test_wallet.json"], 186 | "id":1 187 | } 188 | # self.request_post(req_data) 189 | self.request_post_result_asset_is_none(req_data) 190 | 191 | def test_load_wallet_file(self): 192 | req_data = { 193 | "jsonrpc": "2.0", 194 | "method": "load_wallet_file", 195 | "params": [""], 196 | "id":1 197 | } 198 | # self.request_post(req_data) 199 | self.request_post_result_asset_true(req_data) 200 | 201 | def test_derive_owner_keys_from_brain_key(self): 202 | req_data = { 203 | "jsonrpc": "2.0", 204 | "method": "suggest_brain_key", 205 | "params": [], 206 | "id":1 207 | } 208 | suggest_brain_key = self.request_post(req_data)['result'] 209 | brain_key = suggest_brain_key['brain_priv_key'] 210 | private_key = suggest_brain_key['wif_priv_key'] 211 | public_key = suggest_brain_key['pub_key'] 212 | 213 | req_data = { 214 | "jsonrpc": "2.0", 215 | "method": "derive_owner_keys_from_brain_key", 216 | "params": [brain_key, 1], 217 | "id":1 218 | } 219 | result = self.request_post(req_data)['result'][0] 220 | self.assertTrue(private_key, result['wif_priv_key']) 221 | self.assertTrue(public_key, result['pub_key']) 222 | 223 | @unittest.skipIf(True, "master branch no api") 224 | def test_suggest_brain_address_key(self): 225 | req_data = { 226 | "jsonrpc": "2.0", 227 | "method": "suggest_brain_address_key", 228 | "params": [], 229 | "id":1 230 | } 231 | self.request_post(req_data) 232 | # self.request_post_error_asset_false(req_data) 233 | 234 | if __name__ == '__main__': 235 | unittest.main() 236 | 237 | -------------------------------------------------------------------------------- /t05_candidates.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import unittest 4 | from config import * 5 | from utils import * 6 | import os 7 | 8 | class test_wallet_candidates_api(request_unittest): 9 | @classmethod 10 | def setUpClass(self): 11 | # self.new_witness = "test.witness" 12 | # self.new_committee = "test.committee" 13 | # self.new_witness_pub_key = test_witness_account_public_key 14 | self.new_witness = "" 15 | self.new_committee = "" 16 | 17 | req_data = { 18 | "jsonrpc": "2.0", 19 | "method": "unlock", 20 | "params": [wallet_password], 21 | "id":1 22 | } 23 | request_post(req_data) 24 | 25 | req_data = { 26 | "jsonrpc": "2.0", 27 | "method": "import_key", 28 | "params": [test_account, test_account_private_key], 29 | "id":1 30 | } 31 | request_post(req_data) 32 | 33 | req_data = { 34 | "jsonrpc": "2.0", 35 | "method": "import_key", 36 | "params": [test_witness_account, test_witness_account_private_key], 37 | "id":1 38 | } 39 | request_post(req_data) 40 | 41 | #register_account new_witness_account 42 | tokens = generate_random_words() 43 | size = len(tokens[0])+len(tokens[1])+len(tokens[2]) 44 | new_witness_account_name = tokens[0].lower() + str(size) 45 | # pub_key = suggest_brain_key['pub_key'] 46 | pub_key = test_witness_account_public_key 47 | register = test_account 48 | req_data = { 49 | "jsonrpc": "2.0", 50 | "method": "register_account", 51 | "params": [new_witness_account_name, pub_key, pub_key, register, 'true'], 52 | "id":1 53 | } 54 | request_post(req_data) 55 | self.new_witness = new_witness_account_name 56 | req_data = { 57 | "jsonrpc": "2.0", 58 | "method": "import_key", 59 | "params": [new_witness_account_name, test_witness_account_private_key], 60 | "id":1 61 | } 62 | request_post(req_data) 63 | 64 | #register_account new_committee_account 65 | size = len(tokens[0])+len(tokens[3])+len(tokens[4]) 66 | new_committee_account_name = tokens[1].lower() + str(size) 67 | # pub_key = suggest_brain_key['pub_key'] 68 | pub_key = test_committee_account_public_key 69 | register = test_account 70 | req_data = { 71 | "jsonrpc": "2.0", 72 | "method": "register_account", 73 | "params": [new_committee_account_name, pub_key, pub_key, register, 'true'], 74 | "id":1 75 | } 76 | request_post(req_data) 77 | self.new_committee = new_committee_account_name 78 | req_data = { 79 | "jsonrpc": "2.0", 80 | "method": "import_key", 81 | "params": [new_committee_account_name, test_committee_account_private_key], 82 | "id":1 83 | } 84 | request_post(req_data) 85 | print('setUpClass done') 86 | 87 | @classmethod 88 | def tearDownClass(self): 89 | req_data = { 90 | "jsonrpc": "2.0", 91 | "method": "lock", 92 | "params": [], 93 | "id":1 94 | } 95 | request_post(req_data) 96 | print('tearDownClass done') 97 | 98 | def setUp(self): 99 | print('setUp done') 100 | 101 | def tearDown(self): 102 | print('tearDown done') 103 | 104 | # @unittest.skipIf(True, 'test other') 105 | def test_get_witness(self): 106 | req_data = { 107 | "jsonrpc": "2.0", 108 | "method": "get_witness", 109 | "params": [test_witness_account], 110 | "id":1 111 | } 112 | self.request_post(req_data) 113 | 114 | def test_get_committee_member(self): 115 | req_data = { 116 | "jsonrpc": "2.0", 117 | "method": "get_committee_member", 118 | "params": [test_committee_account], 119 | "id":1 120 | } 121 | self.request_post(req_data) 122 | 123 | def test_list_witnesses(self): 124 | lowerbound = "" 125 | limit = 3 126 | req_data = { 127 | "jsonrpc": "2.0", 128 | "method": "list_witnesses", 129 | "params": [lowerbound, limit], 130 | "id":1 131 | } 132 | self.request_post(req_data) 133 | 134 | def test_list_committee_members(self): 135 | lowerbound = "" 136 | limit = 3 137 | req_data = { 138 | "jsonrpc": "2.0", 139 | "method": "list_committee_members", 140 | "params": [lowerbound, limit], 141 | "id":1 142 | } 143 | self.request_post(req_data) 144 | 145 | @unittest.skipIf(True, 'test other') 146 | def test_vote_for_witness(self): 147 | req_data = { 148 | "jsonrpc": "2.0", 149 | "method": "vote_for_witness", 150 | "params": [test_account, test_witness_account, 10000, 'true'], 151 | "id":1 152 | } 153 | self.request_post(req_data) 154 | 155 | @unittest.skipIf(True, 'test other') 156 | def test_vote_for_committee_member(self): 157 | req_data = { 158 | "jsonrpc": "2.0", 159 | "method": "vote_for_committee_member", 160 | "params": [test_account, test_committee_account, 10000, 'true'], 161 | "id":1 162 | } 163 | self.request_post(req_data) 164 | 165 | @unittest.skipIf(True, 'test other') 166 | def test_create_witness(self): 167 | # fee 168 | req_data = { 169 | "jsonrpc": "2.0", 170 | "method": "transfer", 171 | "params": [test_account, self.new_witness, 80000000, 'COCOS', 'test account', 'true'], 172 | "id":1 173 | } 174 | self.request_post(req_data) 175 | 176 | req_data = { 177 | "jsonrpc": "2.0", 178 | "method": "upgrade_account", 179 | "params": [self.new_witness, 'true'], 180 | "id":1 181 | } 182 | self.request_post(req_data) 183 | 184 | url = "www.create_witness-test.org" 185 | req_data = { 186 | "jsonrpc": "2.0", 187 | "method": "create_witness", 188 | "params": [self.new_witness, url, 'true'], 189 | "id":1 190 | } 191 | self.request_post(req_data) 192 | req_data = { 193 | "jsonrpc": "2.0", 194 | "method": "get_witness", 195 | "params": [self.new_witness], 196 | "id":1 197 | } 198 | self.request_post(req_data) 199 | 200 | @unittest.skipIf(True, 'test other') 201 | def test_create_committee_member(self): 202 | # fee 203 | req_data = { 204 | "jsonrpc": "2.0", 205 | "method": "transfer", 206 | "params": [test_account, self.new_committee, 80000000, 'COCOS', 'test account', 'true'], 207 | "id":1 208 | } 209 | self.request_post(req_data) 210 | 211 | req_data = { 212 | "jsonrpc": "2.0", 213 | "method": "upgrade_account", 214 | "params": [self.new_committee, 'true'], 215 | "id":1 216 | } 217 | self.request_post(req_data) 218 | 219 | url = "www.create_committee-test.org" 220 | req_data = { 221 | "jsonrpc": "2.0", 222 | "method": "create_committee_member", 223 | "params": [self.new_committee, url, 'true'], 224 | "id":1 225 | } 226 | self.request_post(req_data) 227 | 228 | req_data = { 229 | "jsonrpc": "2.0", 230 | "method": "get_committee_member", 231 | "params": [self.new_committee], 232 | "id":1 233 | } 234 | self.request_post(req_data) 235 | 236 | def test_update_witness(self): 237 | req_data = { 238 | "jsonrpc": "2.0", 239 | "method": "update_witness", 240 | "params": [test_witness_account, "www.update_witness.org", test_witness_account_public_key, 'true', 'true'], 241 | "id":1 242 | } 243 | self.request_post(req_data) 244 | 245 | def test_update_committee_member(self): 246 | req_data = { 247 | "jsonrpc": "2.0", 248 | "method": "update_committee_member", 249 | "params": [test_committee_account, "www.update_committee_member.org", 'true', 'true'], 250 | "id":1 251 | } 252 | self.request_post(req_data) 253 | 254 | 255 | if __name__ == "__main__": 256 | unittest.main() 257 | 258 | -------------------------------------------------------------------------------- /t09_file.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import unittest 4 | from config import * 5 | from utils import * 6 | import os 7 | import sys 8 | 9 | class test_wallet_file_api(request_unittest): 10 | @classmethod 11 | def setUpClass(self): 12 | req_data = { 13 | "jsonrpc": "2.0", 14 | "method": "unlock", 15 | "params": [wallet_password], 16 | "id":1 17 | } 18 | request_post(req_data) 19 | 20 | req_data = { 21 | "jsonrpc": "2.0", 22 | "method": "import_key", 23 | "params": [test_account, test_account_private_key], 24 | "id":1 25 | } 26 | request_post(req_data) 27 | 28 | req_data = { 29 | "jsonrpc": "2.0", 30 | "method": "import_key", 31 | "params": [test_witness_account, test_witness_account_private_key], 32 | "id":1 33 | } 34 | request_post(req_data) 35 | 36 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 37 | 38 | @classmethod 39 | def tearDownClass(self): 40 | req_data = { 41 | "jsonrpc": "2.0", 42 | "method": "lock", 43 | "params": [], 44 | "id":1 45 | } 46 | request_post(req_data) 47 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 48 | 49 | # def setUp(self): 50 | # print('setUp done') 51 | 52 | # def tearDown(self): 53 | # print('tearDown done') 54 | 55 | def test_create_file(self): 56 | req_data = { 57 | "jsonrpc": "2.0", 58 | "method": "info", 59 | "params": [], 60 | "id":1 61 | } 62 | info = self.request_post(req_data)['result'] 63 | head_block_num = info['head_block_num'] 64 | head_block_id = info['head_block_id'] 65 | 66 | filename = 'block_num_' + str(head_block_num) 67 | file_content = 'block id = ' + head_block_id 68 | req_data = { 69 | "jsonrpc": "2.0", 70 | "method": "create_file", 71 | "params": [test_account, filename, file_content, 'true'], 72 | "id":1 73 | } 74 | self.request_post(req_data) 75 | 76 | req_data = { 77 | "jsonrpc": "2.0", 78 | "method": "lookup_file", 79 | "params": [filename], 80 | "id":1 81 | } 82 | file = self.request_post(req_data)['result'] 83 | file_id = file['id'] 84 | 85 | req_data = { 86 | "jsonrpc": "2.0", 87 | "method": "add_file_relate_account", 88 | "params": [test_account, file_id, [test_witness_account], 'true'], 89 | "id":1 90 | } 91 | self.request_post(req_data) 92 | 93 | req_data = { 94 | "jsonrpc": "2.0", 95 | "method": "file_signature", 96 | "params": [test_witness_account, file_id, "relate accout signature", 'true'], 97 | "id":1 98 | } 99 | self.request_post(req_data) 100 | 101 | req_data = { 102 | "jsonrpc": "2.0", 103 | "method": "list_account_created_file", 104 | "params": [test_account], 105 | "id":1 106 | } 107 | self.request_post(req_data) 108 | 109 | 110 | # signed_transaction propose_relate_parent_file(const string &file_creator, 111 | # const string &parent_file_name_or_id, const string &sub_file_name_or_id, 112 | # fc::time_point_sec expiration_time, bool broadcast = false) 113 | def test_propose_relate_parent_file(self): 114 | req_data = { 115 | "jsonrpc": "2.0", 116 | "method": "info", 117 | "params": [], 118 | "id":1 119 | } 120 | info = self.request_post(req_data)['result'] 121 | head_block_num = info['head_block_num'] 122 | head_block_id = info['head_block_id'] 123 | 124 | parent_filename = 'p_block_num_' + str(head_block_num) 125 | sub_filename = 's_block_num_' + str(head_block_num) 126 | size = len(head_block_id) 127 | parent_file_content = 'block id : ' + head_block_id 128 | sub_file_content = 'part block id: ' + head_block_id[0:int(size/2)] 129 | req_data = { 130 | "jsonrpc": "2.0", 131 | "method": "create_file", 132 | "params": [test_account, parent_filename, parent_file_content, 'true'], 133 | "id":1 134 | } 135 | self.request_post(req_data) 136 | 137 | req_data = { 138 | "jsonrpc": "2.0", 139 | "method": "create_file", 140 | "params": [test_account, sub_filename, sub_file_content, 'true'], 141 | "id":1 142 | } 143 | self.request_post(req_data) 144 | 145 | expiration_time = datetime_N_ago(-1).strftime("%Y-%m-%dT%H:%M:%S") 146 | req_data = { 147 | "jsonrpc": "2.0", 148 | "method": "propose_relate_parent_file", 149 | "params": [test_account, parent_filename, sub_filename, expiration_time, 'true'], 150 | "id":1 151 | } 152 | self.request_post(req_data) 153 | 154 | if __name__ == "__main__": 155 | unittest.main() 156 | 157 | 158 | ''' 159 | >> unlock ['123456'] 160 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 161 | 162 | >> import_key ['nicotest', '5J2SChqa9QxrCkdMor9VC2k9NT4R4ctRrJA6odQCPkb3yL89vxo'] 163 | {u'jsonrpc': u'2.0', u'id': 1, u'result': True} 164 | 165 | >> import_key ['init1', '5K5fqjvMrH5UtUisCgSZHQjiQf9BvtZ5vsKPhCErDy7P2gnLQmw'] 166 | {u'jsonrpc': u'2.0', u'id': 1, u'result': True} 167 | 168 | setUpClass done 169 | 170 | >> info [] 171 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'active_committee_members': [u'1.5.0', u'1.5.1', u'1.5.2', u'1.5.3', u'1.5.4', u'1.5.5', u'1.5.6', u'1.5.7', u'1.5.8', u'1.5.9', 172 | u'1.5.10'], u'head_block_age': u'0 second ago', u'chain_id': u'c1ac4bb7bd7d94874a1cb98b39a8a582421d03d022dfa4be8c70567076e03ad0', u'active_witnesses': [u'1.6.1', u'1.6.2', 173 | u'1.6.3', u'1.6.4', u'1.6.5', u'1.6.6', u'1.6.7', u'1.6.8', u'1.6.9', u'1.6.10', u'1.6.11'], u'head_block_id': u'000007cbf009cc7583d9dbcbaffcc1989caf54bb', u'next_maintena 174 | nce_time': u'13 minutes in the future', u'participation': u'90.62500000000000000', u'head_block_num': 1995}} 175 | 176 | >> create_file ['nicotest', 'block_num_1995', u'block id = 000007cbf009cc7583d9dbcbaffcc1989caf54bb', 'true'] 177 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 678620151, u'operations': [[46, {u'file_owner': u'1.2.16', u'file_name': u'block_num_1995', u'file_content': 178 | u'block id = 000007cbf009cc7583d9dbcbaffcc1989caf54bb'}]], u'signatures': [u'1f3be4a084cf38fde521e45028b32ee32720a561405a2aa63234f57575da0d5acd1d4d3aa29130e470eb41656affa9 179 | 12b825d8a2cfc67cbd8d958c6c35e906fd08'], u'ref_block_num': 1986, u'extensions': [], u'expiration': u'2019-11-30T18:07:12'}} 180 | 181 | >> lookup_file ['block_num_1995'] 182 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'file_owner': u'1.2.16', u'file_content': u'block id = 000007cbf009cc7583d9dbcbaffcc1989caf54bb', u'file_name': u'block_num_1995 183 | ', u'create_time': u'2019-11-30T17:46:42', u'signature': [], u'sub_file': [], u'id': u'1.18.9', u'related_account': []}} 184 | 185 | >> add_file_relate_account ['nicotest', u'1.18.9', ['init1'], 'true'] 186 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 678620151, u'operations': [[47, {u'file_owner': u'1.2.16', u'file_id': u'1.18.9', u'related_account': [u'1.2 187 | .6']}]], u'signatures': [u'1f05badb9da90d02d52cf07d0c07413efc91e7aabf5c8b75a2c49661ad779ed3b928736d10c6df6fa67afdb0e9b8bc4d6733669159224cf872459bc90734201c2f'], u'ref_block 188 | _num': 1986, u'extensions': [], u'expiration': u'2019-11-30T18:07:12'}} 189 | 190 | >> file_signature ['init1', u'1.18.9', 'relate accout signature', 'true'] 191 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 678620151, u'operations': [[48, {u'signature': u'relate accout signature', u'file_id': u'1.18.9', u'signatur 192 | e_account': u'1.2.6'}]], u'signatures': [u'207513eb23c18f06712dd5746e307b243c0fa2db239a08dd5ed787dd5ed5a5a6da19b756cad70ed2eae2976f1200c9506d450bc43e2ce4f0ce44c384a7cc9b326 193 | 0'], u'ref_block_num': 1986, u'extensions': [], u'expiration': u'2019-11-30T18:07:12'}} 194 | 195 | >> list_account_created_file ['nicotest'] 196 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [[u'block_num_1200', u'1.18.0'], [u'block_num_1433', u'1.18.1'], [u'block_num_1881', u'1.18.2'], [u'block_num_1898', u'1.18.3'], [ 197 | u'block_num_1927', u'1.18.4'], [u'block_num_1951', u'1.18.5'], [u'block_num_1975', u'1.18.6'], [u'block_num_1995', u'1.18.9'], [u'p_block_num_1975', u'1.18.7'], [u's_block_ 198 | num_1975', u'1.18.8']]} 199 | 200 | .>> info [] 201 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'active_committee_members': [u'1.5.0', u'1.5.1', u'1.5.2', u'1.5.3', u'1.5.4', u'1.5.5', u'1.5.6', u'1.5.7', u'1.5.8', u'1.5.9', 202 | u'1.5.10'], u'head_block_age': u'0 second ago', u'chain_id': u'c1ac4bb7bd7d94874a1cb98b39a8a582421d03d022dfa4be8c70567076e03ad0', u'active_witnesses': [u'1.6.1', u'1.6.2', 203 | u'1.6.3', u'1.6.4', u'1.6.5', u'1.6.6', u'1.6.7', u'1.6.8', u'1.6.9', u'1.6.10', u'1.6.11'], u'head_block_id': u'000007cbf009cc7583d9dbcbaffcc1989caf54bb', u'next_maintena 204 | nce_time': u'13 minutes in the future', u'participation': u'90.62500000000000000', u'head_block_num': 1995}} 205 | 206 | >> create_file ['nicotest', 'p_block_num_1995', u'block id : 000007cbf009cc7583d9dbcbaffcc1989caf54bb', 'true'] 207 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 678620151, u'operations': [[46, {u'file_owner': u'1.2.16', u'file_name': u'p_block_num_1995', u'file_content 208 | ': u'block id : 000007cbf009cc7583d9dbcbaffcc1989caf54bb'}]], u'signatures': [u'1f2dfedf823b4eeadff6c0e1fa7beaaca9a55e39f53ee363ffc6369f47502224fd7f520b232117075993f1d562bf 209 | 704244e1696d0968e963dba917a8e539c6682a'], u'ref_block_num': 1986, u'extensions': [], u'expiration': u'2019-11-30T18:07:12'}} 210 | 211 | >> create_file ['nicotest', 's_block_num_1995', u'part block id: 000007cbf009cc7583d9', 'true'] 212 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 678620151, u'operations': [[46, {u'file_owner': u'1.2.16', u'file_name': u's_block_num_1995', u'file_content 213 | ': u'part block id: 000007cbf009cc7583d9'}]], u'signatures': [u'200cabb937e09ecd7e23b99e83895706351b29aba8a9cfcd398e44fb2ef14e0efd5ab8fb5e887091d9e7d2d1f10e9fe5593e82c0a0cf 214 | 8081d3c1550c2137284060'], u'ref_block_num': 1986, u'extensions': [], u'expiration': u'2019-11-30T18:07:12'}} 215 | 216 | >> propose_relate_parent_file ['nicotest', 'p_block_num_1995', 's_block_num_1995', '2019-12-01T17:46:42', 'true'] 217 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 678620151, u'operations': [[20, {u'expiration_time': u'2019-12-01T17:46:42', u'proposed_ops': [{u'op': [49, 218 | {u'parent_file_owner': u'1.2.16', u'sub_file_owner': u'1.2.16', u'parent_file': u'1.18.10', u'sub_file': u'1.18.11'}]}], u'extensions': [], u'fee_paying_account': u'1.2.16' 219 | }]], u'signatures': [u'1f01c045e5051d803f55b2a0145fe7aee8c748a4ac68b89e3c4ac0a7ba011e788f38ff5afcf4a5ab85bd35c3ce6bd42739608d7e9008734120877baf38367854dd'], u'ref_block_num 220 | ': 1986, u'extensions': [], u'expiration': u'2019-11-30T18:07:12'}} 221 | 222 | .>> lock [] 223 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 224 | 225 | tearDownClass done 226 | 227 | 228 | ---------------------------------------------------------------------- 229 | Ran 2 tests in 0.143s 230 | 231 | OK 232 | ''' -------------------------------------------------------------------------------- /t03_account.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import unittest 4 | from utils import request_unittest, request_post 5 | from config import * 6 | import sys 7 | 8 | class test_wallet_account_api(request_unittest): 9 | @classmethod 10 | def setUpClass(self): 11 | req_data = { 12 | "jsonrpc": "2.0", 13 | "method": "unlock", 14 | "params": [wallet_password], 15 | "id":1 16 | } 17 | request_post(req_data) 18 | 19 | req_data = { 20 | "jsonrpc": "2.0", 21 | "method": "import_key", 22 | "params": [test_account, test_account_private_key], 23 | "id":1 24 | } 25 | request_post(req_data) 26 | 27 | req_data = { 28 | "jsonrpc": "2.0", 29 | "method": "import_key", 30 | "params": [test_witness_account, test_witness_account_private_key], 31 | "id":1 32 | } 33 | request_post(req_data) 34 | 35 | req_data = { 36 | "jsonrpc": "2.0", 37 | "method": "get_account", 38 | "params": [test_account], 39 | "id":1 40 | } 41 | account = request_post(req_data)["result"] 42 | self.test_account_id = account["id"] 43 | 44 | req_data = { 45 | "jsonrpc": "2.0", 46 | "method": "get_account", 47 | "params": [test_witness_account], 48 | "id":1 49 | } 50 | account = request_post(req_data)["result"] 51 | self.test_witness_account_id = account["id"] 52 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 53 | 54 | @classmethod 55 | def tearDownClass(self): 56 | req_data = { 57 | "jsonrpc": "2.0", 58 | "method": "lock", 59 | "params": [], 60 | "id":1 61 | } 62 | request_post(req_data) 63 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 64 | 65 | def test_list_my_accounts(self): 66 | req_data = { 67 | "jsonrpc": "2.0", 68 | "method": "list_my_accounts", 69 | "params": [], 70 | "id":1 71 | } 72 | # self.request_post(req_data) 73 | self.request_post_error_asset_false(req_data) 74 | 75 | def test_list_accounts(self): 76 | committee_account = ["committee-account", "1.2.0"] 77 | committee_relaxed = ["committee-relaxed", "1.2.1"] 78 | lowerbound = "" 79 | limit = 10 80 | req_data = { 81 | "jsonrpc": "2.0", 82 | "method": "list_accounts", 83 | "params": [lowerbound, limit], 84 | "id":1 85 | } 86 | self.request_post_result_asset_in(req_data, committee_account) 87 | self.request_post_result_asset_in(req_data, committee_relaxed) 88 | 89 | def test_list_account_balances(self): 90 | req_data = { 91 | "jsonrpc": "2.0", 92 | "method": "list_account_balances", 93 | "params": [test_account], 94 | "id":1 95 | } 96 | # self.request_post(req_data) 97 | self.request_post_error_asset_false(req_data) 98 | 99 | @unittest.skipIf(True, 'test other') 100 | def test_register_account(self): 101 | req_data = { 102 | "jsonrpc": "2.0", 103 | "method": "suggest_brain_key", 104 | "params": [], 105 | "id":1 106 | } 107 | suggest_brain_key = self.request_post(req_data)['result'] 108 | brain_priv_key = suggest_brain_key['brain_priv_key'] 109 | # print('suggest_brain_key: {}'.format(brain_priv_key)) 110 | tokens = brain_priv_key.split() 111 | # print('token: {}'.format(tokens)) 112 | # new_account_name = tokens[0].lower() + tokens[1].lower() 113 | size = len(tokens[0])+len(tokens[1])+len(tokens[2]) 114 | new_account_name = tokens[0].lower() + str(size) 115 | pub_key = suggest_brain_key['pub_key'] 116 | register = test_account 117 | req_data = { 118 | "jsonrpc": "2.0", 119 | "method": "register_account", 120 | "params": [new_account_name, pub_key, pub_key, register, 'true'], 121 | "id":1 122 | } 123 | self.request_post(req_data) 124 | 125 | # upgrade_account fee 126 | req_data = { 127 | "jsonrpc": "2.0", 128 | "method": "transfer", 129 | "params": [test_account, new_account_name, 10000*2, 'COCOS', 'test account', 'true'], 130 | "id":1 131 | } 132 | self.request_post(req_data) 133 | 134 | req_data = { 135 | "jsonrpc": "2.0", 136 | "method": "import_key", 137 | "params": [new_account_name, suggest_brain_key['wif_priv_key']], 138 | "id":1 139 | } 140 | self.request_post(req_data) 141 | 142 | req_data = { 143 | "jsonrpc": "2.0", 144 | "method": "upgrade_account", 145 | "params": [new_account_name, 'true'], 146 | "id":1 147 | } 148 | self.request_post(req_data) 149 | 150 | @unittest.skipIf(True, 'test other') 151 | def test_create_account_with_brain_key(self): 152 | req_data = { 153 | "jsonrpc": "2.0", 154 | "method": "suggest_brain_key", 155 | "params": [], 156 | "id":1 157 | } 158 | suggest_brain_key = self.request_post(req_data)['result'] 159 | brain_key = suggest_brain_key['brain_priv_key'] 160 | # print('suggest_brain_key: {}'.format(brain_priv_key)) 161 | 162 | tokens = brain_key.split() 163 | size = len(tokens[0])+len(tokens[3])+len(tokens[4]) 164 | new_account_name = tokens[0].lower() + str(size) 165 | register = test_account 166 | req_data = { 167 | "jsonrpc": "2.0", 168 | "method": "create_account_with_brain_key", 169 | "params": [brain_key, new_account_name, register, 'true'], 170 | "id":1 171 | } 172 | self.request_post(req_data) 173 | 174 | 175 | def test_get_vesting_balances(self): 176 | req_data = { 177 | "jsonrpc": "2.0", 178 | "method": "get_vesting_balances", 179 | "params": [test_witness_account], 180 | "id":1 181 | } 182 | # self.request_post(req_data) 183 | self.request_post_error_asset_false(req_data) 184 | 185 | 186 | @unittest.skipIf(True, 'test other') 187 | def test_withdraw_vesting(self): 188 | req_data = { 189 | "jsonrpc": "2.0", 190 | "method": "get_vesting_balances", 191 | "params": [test_witness_account], 192 | "id":1 193 | } 194 | response = self.request_post(req_data) 195 | # self.request_post_error_asset_false(req_data) 196 | for withdraw in response['result']: 197 | print('withdraw: {}'.format(withdraw)) 198 | withdraw = withdraw['allowed_withdraw'] 199 | # amount = int(withdraw['amount']/1000) 200 | amount = 1000 201 | asset_id = withdraw['asset_id'] 202 | 203 | req_data = { 204 | "jsonrpc": "2.0", 205 | "method": "withdraw_vesting", 206 | "params": [test_witness_account, amount, asset_id, 'true'], 207 | "id":1 208 | } 209 | self.request_post(req_data) 210 | 211 | def test_get_account(self): 212 | req_data = { 213 | "jsonrpc": "2.0", 214 | "method": "get_account", 215 | "params": [test_account], 216 | "id":1 217 | } 218 | self.request_post(req_data) 219 | 220 | 221 | def test_get_account_id(self): 222 | req_data = { 223 | "jsonrpc": "2.0", 224 | "method": "get_account_id", 225 | "params": [test_account], 226 | "id":1 227 | } 228 | self.request_post(req_data) 229 | 230 | 231 | def test_get_account_history(self): 232 | limit = 3 233 | req_data = { 234 | "jsonrpc": "2.0", 235 | "method": "get_account_history", 236 | "params": [test_account, limit], 237 | "id":1 238 | } 239 | self.request_post(req_data) 240 | 241 | @unittest.skipIf(True, " master branch no") 242 | def test_transfer_old(self): 243 | req_data = { 244 | "jsonrpc": "2.0", 245 | "method": "transfer", 246 | "params": [test_account, test_witness_account, 10, 'COCOS', 'test transfer', 'true'], 247 | "id":1 248 | } 249 | self.request_post(req_data) 250 | 251 | @unittest.skipIf(True, " master branch no") 252 | def test_transfer2_old(self): 253 | req_data = { 254 | "jsonrpc": "2.0", 255 | "method": "transfer2", 256 | "params": [test_account, test_witness_account, 10, 'COCOS', 'test transfer2'], 257 | "id":1 258 | } 259 | self.request_post(req_data) 260 | 261 | def test_transfer_memo(self): 262 | amount = 10 263 | req_data = { 264 | "jsonrpc": "2.0", 265 | "method": "transfer", 266 | "params": [test_account, test_witness_account, amount, 'COCOS', ['test transfer', 'false'], 'true'], 267 | "id":1 268 | } 269 | self.request_post(req_data) 270 | 271 | amount = 0.0017598 272 | req_data = { 273 | "jsonrpc": "2.0", 274 | "method": "transfer", 275 | "params": [test_account, test_witness_account, "%.5f"%(amount), 'COCOS', ['test transfer', 'true'], 'true'], 276 | "id":1 277 | } 278 | self.request_post(req_data) 279 | 280 | def test_transfer2_memo(self): 281 | amount = 10 282 | req_data = { 283 | "jsonrpc": "2.0", 284 | "method": "transfer2", 285 | "params": [test_account, test_witness_account, amount, 'COCOS', ['test transfer2', 'true']], 286 | "id":1 287 | } 288 | self.request_post(req_data) 289 | 290 | amount = 0.0017598 291 | req_data = { 292 | "jsonrpc": "2.0", 293 | "method": "transfer2", 294 | "params": [test_account, test_witness_account, "%.5f"%(amount), 'COCOS', ['test transfer2', 'false']], 295 | "id":1 296 | } 297 | self.request_post(req_data) 298 | 299 | def test_get_account_count(self): 300 | req_data = { 301 | "jsonrpc": "2.0", 302 | "method": "get_account_count", 303 | "params": [], 304 | "id":1 305 | } 306 | self.request_post(req_data) 307 | 308 | def test_get_relative_account_history(self): 309 | stop = 0 310 | limit = 12 311 | start = 3 312 | req_data = { 313 | "jsonrpc": "2.0", 314 | "method": "get_relative_account_history", 315 | "params": [test_account, stop, limit, start], 316 | "id":1 317 | } 318 | self.request_post(req_data) 319 | 320 | 321 | @unittest.skipIf(True, " master branch no by account name") 322 | def test_update_collateral_for_gas_by_account_name(self): 323 | amount = 10*10**5 324 | req_data = { 325 | "jsonrpc": "2.0", 326 | "method": "update_collateral_for_gas", 327 | "params": [test_account, test_witness_account, amount, 'true'], 328 | "id":1 329 | } 330 | self.request_post(req_data) 331 | 332 | def test_update_collateral_for_gas_by_account_id(self): 333 | amount = 10*10**5 334 | req_data = { 335 | "jsonrpc": "2.0", 336 | "method": "update_collateral_for_gas", 337 | "params": [self.test_account_id, self.test_witness_account_id, amount, 'true'], 338 | "id":1 339 | } 340 | self.request_post(req_data) 341 | 342 | if __name__ == "__main__": 343 | unittest.main() 344 | 345 | -------------------------------------------------------------------------------- /t08_trx_proposal.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import unittest 4 | from config import * 5 | from utils import * 6 | import os 7 | import sys 8 | 9 | class test_wallet_transaction_proposal_api(request_unittest): 10 | @classmethod 11 | def setUpClass(self): 12 | req_data = { 13 | "jsonrpc": "2.0", 14 | "method": "unlock", 15 | "params": [wallet_password], 16 | "id":1 17 | } 18 | request_post(req_data) 19 | 20 | req_data = { 21 | "jsonrpc": "2.0", 22 | "method": "import_key", 23 | "params": [test_account, test_account_private_key], 24 | "id":1 25 | } 26 | request_post(req_data) 27 | 28 | req_data = { 29 | "jsonrpc": "2.0", 30 | "method": "import_key", 31 | "params": [test_witness_account, test_witness_account_private_key], 32 | "id":1 33 | } 34 | request_post(req_data) 35 | 36 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 37 | 38 | @classmethod 39 | def tearDownClass(self): 40 | req_data = { 41 | "jsonrpc": "2.0", 42 | "method": "lock", 43 | "params": [], 44 | "id":1 45 | } 46 | request_post(req_data) 47 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 48 | 49 | 50 | # (begin_builder_transaction)(add_operation_to_builder_transaction) 51 | # (replace_operation_in_builder_transaction)(preview_builder_transaction) 52 | # (sign_builder_transaction)(propose_builder_transaction)(remove_builder_transaction) 53 | # (get_transaction_by_id)(get_transaction_in_block_info)(get_account_top_transaction) 54 | 55 | # (get_account_transaction) 56 | 57 | # (serialize_transaction)(sign_transaction)(validate_transaction) 58 | 59 | # (propose_parameter_change)(propose_fee_change)(approve_proposal) 60 | 61 | def test_get_account_top_transaction(self): 62 | req_data = { 63 | "jsonrpc": "2.0", 64 | "method": "get_account_top_transaction", 65 | "params": [test_account], 66 | "id":1 67 | } 68 | self.request_post(req_data)['result'] 69 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 70 | 71 | # pair>, processed_transaction> wallet_api::get_account_top_transaction(const string account_id_or_name) 72 | def test_get_transaction(self): 73 | req_data = { 74 | "jsonrpc": "2.0", 75 | "method": "get_account_top_transaction", 76 | "params": [test_account], 77 | "id":1 78 | } 79 | transactions = self.request_post(req_data)['result'] 80 | pair_trx = transactions[0] 81 | trx_id = pair_trx[0] 82 | print("trx_id: {}".format(trx_id)) 83 | req_data = { 84 | "jsonrpc": "2.0", 85 | "method": "get_transaction_by_id", 86 | "params": [trx_id], 87 | "id":1 88 | } 89 | self.request_post(req_data) 90 | 91 | req_data = { 92 | "jsonrpc": "2.0", 93 | "method": "get_transaction_in_block_info", 94 | "params": [trx_id], 95 | "id":1 96 | } 97 | self.request_post(req_data) 98 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 99 | 100 | def test_builder_transaction(self): 101 | req_data = { 102 | "jsonrpc": "2.0", 103 | "method": "begin_builder_transaction", 104 | "params": [], 105 | "id":1 106 | } 107 | transaction_handle = self.request_post(req_data)['result'] 108 | 109 | req_data = { 110 | "jsonrpc": "2.0", 111 | "method": "transfer", 112 | "params": [test_account, test_witness_account, "20", "COCOS", ["test builder trx", 'false'], 'false'], 113 | "id":1 114 | } 115 | transfer_result = self.request_post(req_data)['result'] 116 | transfer_operation = transfer_result[1]["operations"][0] 117 | # transfer_operation_index = transfer_operation[0] 118 | print("transfer_operations: {}".format(transfer_operation)) 119 | 120 | # void wallet_api::add_operation_to_builder_transaction(transaction_handle_type transaction_handle, const operation &op) 121 | req_data = { 122 | "jsonrpc": "2.0", 123 | "method": "add_operation_to_builder_transaction", 124 | "params": [transaction_handle, transfer_operation], 125 | "id":1 126 | } 127 | self.request_post(req_data) 128 | 129 | #preview_builder_transaction 130 | req_data = { 131 | "jsonrpc": "2.0", 132 | "method": "preview_builder_transaction", 133 | "params": [transaction_handle], 134 | "id":1 135 | } 136 | self.request_post(req_data) 137 | 138 | req_data = { 139 | "jsonrpc": "2.0", 140 | "method": "sign_builder_transaction", 141 | "params": [transaction_handle, 'true'], 142 | "id":1 143 | } 144 | self.request_post(req_data) 145 | 146 | #replace_operation_in_builder_transaction 147 | ref_block_num = transfer_result[1]['ref_block_num'] 148 | filename = 'ref_' + str(ref_block_num) 149 | file_content = 'build transaction transfer ref_block_num = ' + str(ref_block_num) 150 | req_data = { 151 | "jsonrpc": "2.0", 152 | "method": "create_file", 153 | "params": [test_account, filename, file_content, 'false'], 154 | "id":1 155 | } 156 | create_file_result = self.request_post(req_data)['result'] 157 | create_file_operation = create_file_result['operations'][0] 158 | create_file_operation_index = create_file_operation[0] 159 | print('create_file_operation_index: {}'.format(create_file_operation_index)) 160 | 161 | req_data = { 162 | "jsonrpc": "2.0", 163 | "method": "add_operation_to_builder_transaction", 164 | "params": [transaction_handle, create_file_operation], 165 | "id":1 166 | } 167 | self.request_post(req_data) 168 | 169 | filename = 'r_' + str(ref_block_num) 170 | file_content = '[replace_operation_in_builder_transaction] build transaction transfer ref_block_num = ' + str(ref_block_num) 171 | # replace_create_file_operations = create_file_operations 172 | req_data = { 173 | "jsonrpc": "2.0", 174 | "method": "create_file", 175 | "params": [test_account, filename, file_content, 'false'], 176 | "id":1 177 | } 178 | create_file_result = self.request_post(req_data)['result'] 179 | replace_create_file_operation = create_file_result['operations'][0] 180 | 181 | # void wallet_api::replace_operation_in_builder_transaction(transaction_handle_type handle, unsigned operation_index, const operation &new_op) 182 | req_data = { 183 | "jsonrpc": "2.0", 184 | "method": "replace_operation_in_builder_transaction", 185 | "params": [transaction_handle, create_file_operation_index, replace_create_file_operation], 186 | "id":1 187 | } 188 | # self.request_post(req_data) 189 | 190 | #>> replace_operation_in_builder_transaction [12, 46, [46, {u'file_owner': u'1.2.16', u'file_name': u'r_13590', u'file_content': u'[replace_operation_in_builder_transaction] 191 | # build transaction transfer ref_block_num = 13590'}]] 192 | # {u'jsonrpc': u'2.0', u'id': 1, u'error': {u'message': u'Assert Exception: operation_index < trx.operations.size(): ', u'code': 1}} 193 | # 之前就遇到的问题,没修复。 194 | 195 | 196 | #preview_builder_transaction 197 | req_data = { 198 | "jsonrpc": "2.0", 199 | "method": "preview_builder_transaction", 200 | "params": [transaction_handle], 201 | "id":1 202 | } 203 | self.request_post(req_data) 204 | 205 | #propose_builder_transaction 206 | expiration_time = datetime_N_ago(-1).strftime("%Y-%m-%dT%H:%M:%S") 207 | req_data = { 208 | "jsonrpc": "2.0", 209 | "method": "propose_builder_transaction", 210 | "params": [transaction_handle, test_account, expiration_time, "600", 'true'], 211 | "id":1 212 | } 213 | self.request_post(req_data) 214 | 215 | # sign_builder_transaction 216 | req_data = { 217 | "jsonrpc": "2.0", 218 | "method": "sign_builder_transaction", 219 | "params": [transaction_handle, 'true'], 220 | "id":1 221 | } 222 | self.request_post(req_data) 223 | 224 | # remove_builder_transaction 225 | req_data = { 226 | "jsonrpc": "2.0", 227 | "method": "remove_builder_transaction", 228 | "params": [transaction_handle], 229 | "id":1 230 | } 231 | self.request_post(req_data) 232 | 233 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 234 | 235 | 236 | 237 | if __name__ == "__main__": 238 | unittest.main() 239 | 240 | 241 | ''' 242 | >> unlock ['123456'] 243 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 244 | 245 | >> import_key ['nicotest', '5J2SChqa9QxrCkdMor9VC2k9NT4R4ctRrJA6odQCPkb3yL89vxo'] 246 | {u'jsonrpc': u'2.0', u'id': 1, u'result': True} 247 | 248 | >> import_key ['init1', '5K5fqjvMrH5UtUisCgSZHQjiQf9BvtZ5vsKPhCErDy7P2gnLQmw'] 249 | {u'jsonrpc': u'2.0', u'id': 1, u'result': True} 250 | 251 | setUpClass done 252 | 253 | >> begin_builder_transaction [] 254 | {u'jsonrpc': u'2.0', u'id': 1, u'result': 13} 255 | 256 | >> transfer ['nicotest', 'init1', '20', 'COCOS', ['test builder trx', 'false'], 'false'] 257 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'4c2a89d795ff88b7204a98201ad3d6bbb511ddab39d5594393e51978edf057ef', {u'ref_block_prefix': 2936364321, u'operations': [[0, {u'to' 258 | : u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': [0, u'test builder trx'], u'extensions': []}]], u'signatures': [u'2072f48fb 259 | 1519d5fb69eaa7bb9793bb63abb3d156e92da5b5c7aebae4a8a098515105502106f549b2124608c4361c6fbc8aab865053e6a0719b889caabf262a90c'], u'ref_block_num': 14542, u'extensions': [], u'e 260 | xpiration': u'2019-12-01T12:45:56'}]} 261 | 262 | transfer_operations: [0, {u'to': u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': [0, u'test builder trx'], u'extensions': []} 263 | ] 264 | >> add_operation_to_builder_transaction [13, [0, {u'to': u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': [0, u'test builder t 265 | rx'], u'extensions': []}]] 266 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 267 | 268 | >> preview_builder_transaction [13] 269 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 0, u'ref_block_num': 0, u'extensions': [], u'expiration': u'1970-01-01T00:00:00', u'operations': [[0, {u'to' 270 | : u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': [0, u'test builder trx'], u'extensions': []}]]}} 271 | 272 | >> sign_builder_transaction [13, 'true'] 273 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'cde93cdbd5c8bafe3e78560746b0c6edb5b322a5ee7f58bea021193f089d3723', {u'ref_block_prefix': 2936364321, u'operations': [[0, {u'to' 274 | : u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': [0, u'test builder trx'], u'extensions': []}]], u'signatures': [u'205d8f9c3 275 | 4accc3f81701ab3eb5826ea1f6f7069d20dac8f0e5c22bd5cf68a23fd1430a9727245dd9ab025dd1726055a418e335546e5768336c7456186381e38c4'], u'ref_block_num': 14542, u'extensions': [], u'e 276 | xpiration': u'2019-12-01T12:45:57'}]} 277 | 278 | >> create_file ['nicotest', 'ref_14542', 'build transaction transfer ref_block_num = 14542', 'false'] 279 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 2936364321, u'operations': [[46, {u'file_owner': u'1.2.16', u'file_name': u'ref_14542', u'file_content': u'b 280 | uild transaction transfer ref_block_num = 14542'}]], u'signatures': [u'2040fc96b10abed5873f3de892f5c07f1fba655094c766456905a2452c9a1b62ea235d7d86c4e068ea987ca7522b4c6592aee 281 | 28f187622f67075f3b06711925b4e'], u'ref_block_num': 14542, u'extensions': [], u'expiration': u'2019-12-01T12:45:56'}} 282 | 283 | create_file_operation_index: 46 284 | >> add_operation_to_builder_transaction [13, [46, {u'file_owner': u'1.2.16', u'file_name': u'ref_14542', u'file_content': u'build transaction transfer ref_block_num = 14542 285 | '}]] 286 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 287 | 288 | >> create_file ['nicotest', 'r_14542', '[replace_operation_in_builder_transaction] build transaction transfer ref_block_num = 14542', 'false'] 289 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 2936364321, u'operations': [[46, {u'file_owner': u'1.2.16', u'file_name': u'r_14542', u'file_content': u'[re 290 | place_operation_in_builder_transaction] build transaction transfer ref_block_num = 14542'}]], u'signatures': [u'1f4d3811600fb60195db8c44176dead86709217990a376aec18f14098658 291 | 423d704521789fb107c12a00b90d1f774b06c85a9879b484fdff1227156aee2a4be6ef'], u'ref_block_num': 14542, u'extensions': [], u'expiration': u'2019-12-01T12:45:56'}} 292 | 293 | >> preview_builder_transaction [13] 294 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 2936364321, u'ref_block_num': 14542, u'extensions': [], u'expiration': u'2019-12-01T12:45:57', u'operations' 295 | : [[0, {u'to': u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': [0, u'test builder trx'], u'extensions': []}], [46, {u'file_ow 296 | ner': u'1.2.16', u'file_name': u'ref_14542', u'file_content': u'build transaction transfer ref_block_num = 14542'}]]}} 297 | 298 | >> propose_builder_transaction [13, 'nicotest', '2019-12-02T12:25:27', '600', 'true'] 299 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'1d5c67ede7932978b3a7fb0ec4ee9fa41cc7d70c695153fb1218dfbdbf6e0dad', {u'ref_block_prefix': 2936364321, u'operations': [[20, {u'ex 300 | piration_time': u'2019-12-02T12:25:27', u'proposed_ops': [{u'op': [0, {u'to': u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': 301 | [0, u'test builder trx'], u'extensions': []}]}, {u'op': [46, {u'file_owner': u'1.2.16', u'file_name': u'ref_14542', u'file_content': u'build transaction transfer ref_block 302 | _num = 14542'}]}], u'extensions': [], u'review_period_seconds': 600, u'fee_paying_account': u'1.2.16'}]], u'signatures': [u'1f025557805b08464ffb3bc1f4b9a84421ba101f7dbb5233 303 | 7a8e7b64b202034df827d738eb042311b174ca9166576dc56440eb481da41f9aa6ea9e0a158bc4bd88'], u'ref_block_num': 14542, u'extensions': [], u'expiration': u'2019-12-01T12:45:56'}]} 304 | 305 | >> sign_builder_transaction [13, 'true'] 306 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'14e9f69cbb50135a8be810e5833a5f094676ca8d073a8a1c4357c60101acaff3', {u'ref_block_prefix': 2936364321, u'operations': [[0, {u'to' 307 | : u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': [0, u'test builder trx'], u'extensions': []}], [46, {u'file_owner': u'1.2.1 308 | 6', u'file_name': u'ref_14542', u'file_content': u'build transaction transfer ref_block_num = 14542'}]], u'signatures': [u'201e356349dda5775f89ab15164339341e4d98391f627553d 309 | 85a3f022ad51a80c31870ffa052303f506aa1e475e969cc13692904302a4105dd0ef7c5fc188be710'], u'ref_block_num': 14542, u'extensions': [], u'expiration': u'2019-12-01T12:45:56'}]} 310 | 311 | >> remove_builder_transaction [13] 312 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 313 | 314 | test_builder_transaction done 315 | 316 | .>> get_account_top_transaction ['nicotest'] 317 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [[u'ff67723c995be4b37606462f01b81297f9ace558e473b5270374bd3189aaf194', [u'2.9.268', u'2.9.266']], {u'ref_block_prefix': 1274356783 318 | , u'operations': [[0, {u'to': u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': [0, u'test builder trx'], u'extensions': []}]], 319 | u'signatures': [u'20157db71c854278a78c092d5035e2e7375973b26c944220615b5ecc20308f168a128207ec5f0dc3780bbfbf6f97945e52f7ae70ad8e29dc9621eb88bd37f0dc99'], u'operation_results 320 | ': [[1, {u'real_running_time': 115, u'fees': [{u'asset_id': u'1.3.0', u'amount': 2018554}]}]], u'ref_block_num': 13590, u'extensions': [], u'expiration': u'2019-12-01T12:10 321 | :59'}]} 322 | 323 | test_get_account_top_transaction done 324 | 325 | .>> get_account_top_transaction ['nicotest'] 326 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [[u'ff67723c995be4b37606462f01b81297f9ace558e473b5270374bd3189aaf194', [u'2.9.268', u'2.9.266']], {u'ref_block_prefix': 1274356783 327 | , u'operations': [[0, {u'to': u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u'from': u'1.2.16', u'memo': [0, u'test builder trx'], u'extensions': []}]], 328 | u'signatures': [u'20157db71c854278a78c092d5035e2e7375973b26c944220615b5ecc20308f168a128207ec5f0dc3780bbfbf6f97945e52f7ae70ad8e29dc9621eb88bd37f0dc99'], u'operation_results 329 | ': [[1, {u'real_running_time': 115, u'fees': [{u'asset_id': u'1.3.0', u'amount': 2018554}]}]], u'ref_block_num': 13590, u'extensions': [], u'expiration': u'2019-12-01T12:10 330 | :59'}]} 331 | 332 | trx_id: ff67723c995be4b37606462f01b81297f9ace558e473b5270374bd3189aaf194 333 | >> get_transaction_by_id [u'ff67723c995be4b37606462f01b81297f9ace558e473b5270374bd3189aaf194'] 334 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'ref_block_prefix': 1274356783, u'operations': [[0, {u'to': u'1.2.6', u'amount': {u'asset_id': u'1.3.0', u'amount': 2000000}, u' 335 | from': u'1.2.16', u'memo': [0, u'test builder trx'], u'extensions': []}]], u'signatures': [u'20157db71c854278a78c092d5035e2e7375973b26c944220615b5ecc20308f168a128207ec5f0dc 336 | 3780bbfbf6f97945e52f7ae70ad8e29dc9621eb88bd37f0dc99'], u'operation_results': [[1, {u'real_running_time': 115, u'fees': [{u'asset_id': u'1.3.0', u'amount': 2018554}]}]], u'r 337 | ef_block_num': 13590, u'extensions': [], u'expiration': u'2019-12-01T12:10:59'}} 338 | 339 | >> get_transaction_in_block_info [u'ff67723c995be4b37606462f01b81297f9ace558e473b5270374bd3189aaf194'] 340 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'trx_hash': u'ff67723c995be4b37606462f01b81297f9ace558e473b5270374bd3189aaf194', u'trx_in_block': 0, u'id': u'3.1.217', u'block_ 341 | num': 13600}} 342 | 343 | test_get_transaction done 344 | 345 | .>> lock [] 346 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 347 | 348 | tearDownClass done 349 | 350 | 351 | ---------------------------------------------------------------------- 352 | Ran 3 tests in 2.537s 353 | 354 | OK 355 | ''' -------------------------------------------------------------------------------- /t06_asset.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import unittest 4 | from utils import * 5 | from chain_param import restricted_enum 6 | from config import * 7 | 8 | import sys 9 | 10 | class test_wallet_asset_api(request_unittest): 11 | @classmethod 12 | def setUpClass(self): 13 | req_data = { 14 | "jsonrpc": "2.0", 15 | "method": "unlock", 16 | "params": [wallet_password], 17 | "id":1 18 | } 19 | request_post(req_data) 20 | 21 | req_data = { 22 | "jsonrpc": "2.0", 23 | "method": "import_key", 24 | "params": [test_account, test_account_private_key], 25 | "id":1 26 | } 27 | request_post(req_data) 28 | 29 | req_data = { 30 | "jsonrpc": "2.0", 31 | "method": "import_key", 32 | "params": [test_witness_account, test_witness_account_private_key], 33 | "id":1 34 | } 35 | request_post(req_data) 36 | 37 | #init new_asset_symbol 38 | tokens = generate_random_words() 39 | self.new_asset_symbol = tokens[0] 40 | self.new_bitasset_symbol = tokens[1] 41 | print('new_asset_symbol: {}, new_bitasset_symbol: {}'.format(self.new_asset_symbol, self.new_bitasset_symbol)) 42 | 43 | # register feeder account 44 | new_account = "feeder" 45 | req_data = { 46 | "jsonrpc": "2.0", 47 | "method": "get_account", 48 | "params": [new_account], 49 | "id":1 50 | } 51 | response = request_post(req_data, is_assert=False) 52 | if 'error' in response: 53 | print('### register feeder account: {}'.format(new_account)) 54 | register = test_account 55 | req_data = { 56 | "jsonrpc": "2.0", 57 | "method": "register_account", 58 | "params": [new_account, test_account_public_key, test_account_public_key, register, 'true'], 59 | "id":1 60 | } 61 | request_post(req_data) 62 | # request_post(req_data, False) 63 | req_data = { 64 | "jsonrpc": "2.0", 65 | "method": "import_key", 66 | "params": [new_account, test_account_private_key], 67 | "id":1 68 | } 69 | request_post(req_data) 70 | req_data = { 71 | "jsonrpc": "2.0", 72 | "method": "transfer", 73 | "params": [test_account, new_account, 1000000, core_asset, "init feeder balance", 'true'], 74 | "id":1 75 | } 76 | request_post(req_data) 77 | self.feeder = new_account 78 | 79 | #feed asset 80 | self.feed_asset = "STEEM" 81 | # result = get_asset_if_not_create(self.feed_asset, True) 82 | # print('###### asset: {}'.format(result)) 83 | get_asset_if_not_create(self.feed_asset, True) 84 | req_data = { 85 | "jsonrpc": "2.0", 86 | "method": "get_asset", 87 | "params": [self.feed_asset], 88 | "id":1 89 | } 90 | asset = request_post(req_data)['result'] 91 | self.feed_asset_id = asset['id'] 92 | self.feed_asset_dynamic_asset_data_id = asset['dynamic_asset_data_id'] 93 | self.feed_asset_bitasset_data_id = asset['bitasset_data_id'] 94 | print('####feed asset| symbol: {}, asset_id: {}, dynamic_asset_data_id: {} bitasset_data_id: {}'.format( 95 | self.feed_asset, self.feed_asset_id, self.feed_asset_dynamic_asset_data_id, 96 | self.feed_asset_bitasset_data_id)) 97 | 98 | print('setUpClass done.') 99 | 100 | @classmethod 101 | def tearDownClass(self): 102 | req_data = { 103 | "jsonrpc": "2.0", 104 | "method": "lock", 105 | "params": [], 106 | "id":1 107 | } 108 | request_post(req_data) 109 | print('tearDownClass done.') 110 | 111 | @unittest.skipIf(True, 'test other') 112 | def test_list_assets(self): 113 | req_data = { 114 | "jsonrpc": "2.0", 115 | "method": "list_assets", 116 | "params": ["", 3], 117 | "id":1 118 | } 119 | self.request_post(req_data) 120 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 121 | 122 | @unittest.skipIf(True, 'test other') 123 | def test_get_asset(self): 124 | symbols = ["COCOS", "GAS"] 125 | for symbol in symbols: 126 | req_data = { 127 | "jsonrpc": "2.0", 128 | "method": "get_asset", 129 | "params": [symbol], 130 | "id":1 131 | } 132 | self.request_post(req_data) 133 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 134 | 135 | @unittest.skipIf(True, 'test other') 136 | def test_list_asset_restricted_objects(self): 137 | asset_id_list = [] 138 | req_data = { 139 | "jsonrpc": "2.0", 140 | "method": "list_assets", 141 | "params": ["", 3], 142 | "id":1 143 | } 144 | assets = self.request_post(req_data)['result'] 145 | for asset in assets: 146 | asset_id_list.append(asset['id']) 147 | print('asset_id_list: {}'.format(asset_id_list)) 148 | 149 | for asset in asset_id_list: 150 | for index in range(0, len(restricted_enum)): 151 | req_data = { 152 | "jsonrpc": "2.0", 153 | "method": "list_asset_restricted_objects", 154 | "params": [asset, index], 155 | "id":1 156 | } 157 | self.request_post(req_data) 158 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 159 | 160 | # # create_asset nicotest NODE 8 {"max_supply":"2100000000000000","market_fee_percent":0,"max_market_fee":0,"flags":0,"core_exchange_rate":{"base":{"amount":1,"asset_id":"1.3.4"},"quote":{"amount":1,"asset_id":"1.3.0"}},"description":"","extensions":[]} null true 161 | # # create asset: params: [issuer, symbol, precision, asset_options, bitasset_opts, broadcast] 162 | 163 | # >> get_asset [u'AUTONYM'] 164 | # {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'symbol': u'AUTONYM', u'precision': 5, u'id': u'1.3.2', u'options': {u'issuer_permissions': 15, u'description': u'', u'max_market_fee': 0, u'max_supply': u'2100000000000000', u'flags': 0, u'extensions': [], u'market_fee_percent': 0, u'core_exchange_rate': {u'quote': {u'asset_id': u'1.3.0', u'amount': 1}, u'base': {u'asset_id': u'1.3.2', u'amount': 1}}}, u'dynamic_asset_data_id': u'2.3.2', u'issuer': u'1.2.16'}} 165 | @unittest.skipIf(True, 'test other') 166 | def test_create_asset(self): 167 | precision = 5 168 | asset_opts = { 169 | "max_supply":"2100000000000000", 170 | "market_fee_percent":0, 171 | "max_market_fee":0, 172 | "flags":0, 173 | "core_exchange_rate":{ 174 | "base":{"amount":1,"asset_id":"1.3.3"}, 175 | "quote":{"amount":1,"asset_id":"1.3.0"} 176 | }, 177 | "description":"", 178 | "extensions":[] 179 | } 180 | req_data = { 181 | "jsonrpc": "2.0", 182 | "method": "create_asset", 183 | "params": [test_account, self.new_asset_symbol, precision, asset_opts, None, 'true'], 184 | "id":1 185 | } 186 | self.request_post(req_data) 187 | 188 | req_data = { 189 | "jsonrpc": "2.0", 190 | "method": "get_asset", 191 | "params": [self.new_asset_symbol], 192 | "id":1 193 | } 194 | self.request_post(req_data) 195 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 196 | 197 | # create asset: params: [issuer, symbol, precision, asset_options, bitasset_opts, broadcast] 198 | # create_asset testbit STEEM 5 {"issuer_permissions": 511,"flags": 0,"core_exchange_rate":{"base":{"amount":1,"asset_id":"1.3.10"},"quote":{"amount":1,"asset_id":"1.3.0"}}} {"new_feed_producers":[],"feed_lifetime_sec":120} true 199 | # >> get_asset [u'NOXIOUS'] 200 | # {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'symbol': u'NOXIOUS', u'precision': 5, u'id': u'1.3.3', u'bitasset_data_id': u'2.4.0', u'options': {u'issuer_permissions': 511, u'description': u'', u'max_market_fee': u'1000000000000000000', u'max_supply': u'1000000000000000000', u'flags': 0, u'extensions': [], u'market_fee_percent': 0, u'core_exchange_rate': {u'quote': {u'asset_id': u'1.3.0', u'amount': 1}, u'base': {u'asset_id': u'1.3.3', u'amount': 1}}}, u'dynamic_asset_data_id': u'2.3.3', u'issuer': u'1.2.16'}} 201 | 202 | @unittest.skipIf(True, 'test other') 203 | def test_create_bitasset(self): 204 | precision = 5 205 | asset_opts = { 206 | "issuer_permissions": 511, 207 | "flags": 0, 208 | "core_exchange_rate":{ 209 | "base":{"amount":1,"asset_id":"1.3.4"}, 210 | "quote":{"amount":1,"asset_id":"1.3.0"} 211 | } 212 | } 213 | bitasset_opts = { 214 | "new_feed_producers":[], 215 | "feed_lifetime_sec":120 216 | } 217 | req_data = { 218 | "jsonrpc": "2.0", 219 | "method": "create_asset", 220 | "params": [test_account, self.new_bitasset_symbol, precision, asset_opts, bitasset_opts, 'true'], 221 | "id":1 222 | } 223 | self.request_post(req_data) 224 | 225 | req_data = { 226 | "jsonrpc": "2.0", 227 | "method": "get_asset", 228 | "params": [self.new_bitasset_symbol], 229 | "id":1 230 | } 231 | self.request_post(req_data) 232 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 233 | 234 | #get_market_history(string symbol1, string symbol2, uint32_t bucket, fc::time_point_sec start, fc::time_point_sec end) 235 | @unittest.skipIf(True, 'test other') 236 | def test_get_market_history(self): 237 | base_quote_list = [] #base:quote 238 | req_data = { 239 | "jsonrpc": "2.0", 240 | "method": "list_assets", 241 | "params": ["", 10], 242 | "id":1 243 | } 244 | assets = self.request_post(req_data)['result'] 245 | for asset in assets: 246 | options = asset['options'] 247 | if 'core_exchange_rate' in options: 248 | base_asset_id = options['core_exchange_rate']['base']['asset_id'] 249 | quote_asset_id = options['core_exchange_rate']['quote']['asset_id'] 250 | base_quote_list.append([base_asset_id, quote_asset_id]) 251 | print('asset_id_list: {}'.format(base_quote_list)) 252 | 253 | bucket = 86400 254 | start = datetime_N_ago(14).strftime("%Y-%m-%dT%H:%M:%S") 255 | # end = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) 256 | end = datetime_N_ago(0).strftime("%Y-%m-%dT%H:%M:%S") 257 | for base_quote in base_quote_list: 258 | req_data = { 259 | "jsonrpc": "2.0", 260 | "method": "get_market_history", 261 | "params": [base_quote[0], base_quote[1], bucket, start, end], 262 | "id":1 263 | } 264 | self.request_post(req_data) 265 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 266 | 267 | # get_order_book(const string &base, const string "e, unsigned limit) 268 | @unittest.skipIf(True, 'test other') 269 | def test_get_order_book(self): 270 | base_quote_list = [] #base:quote 271 | req_data = { 272 | "jsonrpc": "2.0", 273 | "method": "list_assets", 274 | "params": ["", 10], 275 | "id":1 276 | } 277 | assets = self.request_post(req_data)['result'] 278 | for asset in assets: 279 | options = asset['options'] 280 | if 'core_exchange_rate' in options: 281 | base_asset_id = options['core_exchange_rate']['base']['asset_id'] 282 | quote_asset_id = options['core_exchange_rate']['quote']['asset_id'] 283 | base_quote_list.append([base_asset_id, quote_asset_id]) 284 | print('asset_id_list: {}'.format(base_quote_list)) 285 | 286 | limit = 20 287 | for base_quote in base_quote_list: 288 | req_data = { 289 | "jsonrpc": "2.0", 290 | "method": "get_order_book", 291 | "params": [base_quote[0], base_quote[1], 20], 292 | "id":1 293 | } 294 | self.request_post(req_data) 295 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 296 | 297 | @unittest.skipIf(False, 'test other') 298 | def test_get_limit_orders(self): 299 | base_quote_list = [] #base:quote 300 | req_data = { 301 | "jsonrpc": "2.0", 302 | "method": "list_assets", 303 | "params": ["", 10], 304 | "id":1 305 | } 306 | assets = self.request_post(req_data)['result'] 307 | for asset in assets: 308 | options = asset['options'] 309 | if 'core_exchange_rate' in options: 310 | base_asset_id = options['core_exchange_rate']['base']['asset_id'] 311 | quote_asset_id = options['core_exchange_rate']['quote']['asset_id'] 312 | base_quote_list.append([base_asset_id, quote_asset_id]) 313 | print('asset_id_list: {}'.format(base_quote_list)) 314 | 315 | limit = 10 316 | for base_quote in base_quote_list: 317 | req_data = { 318 | "jsonrpc": "2.0", 319 | "method": "get_limit_orders", 320 | "params": [base_quote[0], base_quote[1], 20], 321 | "id":1 322 | } 323 | self.request_post(req_data) 324 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 325 | 326 | @unittest.skipIf(True, 'test other') 327 | def test_get_call_orders(self): 328 | req_data = { 329 | "jsonrpc": "2.0", 330 | "method": "list_assets", 331 | "params": ["", 10], 332 | "id":1 333 | } 334 | assets = self.request_post(req_data)['result'] 335 | limit = 10 336 | for asset in assets: 337 | if 'bitasset_data_id' in asset: 338 | req_data = { 339 | "jsonrpc": "2.0", 340 | "method": "get_call_orders", 341 | "params": [asset['symbol'], limit], 342 | "id":1 343 | } 344 | self.request_post(req_data) 345 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 346 | 347 | @unittest.skipIf(True, 'test other') 348 | def test_get_settle_orders(self): 349 | req_data = { 350 | "jsonrpc": "2.0", 351 | "method": "list_assets", 352 | "params": ["", 10], 353 | "id":1 354 | } 355 | assets = self.request_post(req_data)['result'] 356 | limit = 10 357 | for asset in assets: 358 | req_data = { 359 | "jsonrpc": "2.0", 360 | "method": "get_settle_orders", 361 | "params": [asset['symbol'], limit], 362 | "id":1 363 | } 364 | self.request_post(req_data) 365 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 366 | 367 | def test_get_bitasset_data(self): 368 | req_data = { 369 | "jsonrpc": "2.0", 370 | "method": "list_assets", 371 | "params": ["", 10], 372 | "id":1 373 | } 374 | assets = self.request_post(req_data)['result'] 375 | for asset in assets: 376 | if 'bitasset_data_id' in asset: 377 | req_data = { 378 | "jsonrpc": "2.0", 379 | "method": "get_bitasset_data", 380 | "params": [asset['symbol']], 381 | "id":1 382 | } 383 | self.request_post(req_data) 384 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 385 | 386 | # (get_limit_orders)(get_call_orders)(get_settle_orders) 387 | # (get_market_history) (get_order_book) 388 | # (list_assets)(list_asset_restricted_objects) 389 | # (get_asset)(get_bitasset_data) 390 | # (create_asset)(update_asset)(update_bitasset)(issue_asset)(reserve_asset) 391 | #(borrow_asset)(update_asset_feed_producers)(publish_asset_feed)(global_settle_asset) 392 | 393 | 394 | # (asset_update_restricted_list) 395 | 396 | # (sell_asset)(sell)(buy)(cancel_order) 397 | 398 | # (settle_asset)(bid_collateral) 399 | 400 | # update_asset(symbol, new_issuer, new_options, broadcast) 401 | # update_asset 1.3.4 test1 {"core_exchange_rate":{"base":{"amount":1,"asset_id":"1.3.4"},"quote":{"amount":1,"asset_id":"1.3.0"}}} true 402 | @unittest.skipIf(True, 'test other') 403 | def test_update_asset(self): 404 | asset = get_asset_if_not_create(test_default_asset) 405 | # print('###### asset: {}'.format(asset)) 406 | asset_opts = asset['options'] 407 | asset_opts['core_exchange_rate']['quote']['amount'] = 8 408 | req_data = { 409 | "jsonrpc": "2.0", 410 | "method": "update_asset", 411 | "params": [asset['symbol'], None, asset_opts, 'true'], 412 | "id":1 413 | } 414 | self.request_post(req_data) 415 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 416 | 417 | # update_bitasset(symbol, new_options, broadcast) 418 | @unittest.skipIf(True, 'test other') 419 | def test_update_bitasset(self): 420 | asset = get_asset_if_not_create(test_default_bitasset, True) 421 | print('###### asset: {}'.format(asset)) 422 | req_data = { 423 | "jsonrpc": "2.0", 424 | "method": "get_object", 425 | "params": [asset['bitasset_data_id']], 426 | "id":1 427 | } 428 | response = self.request_post(req_data) 429 | bitasset_data = response['result'] 430 | # print('##### bitasset_data: {}'.format(bitasset_data)) 431 | bitasset_opts = bitasset_data[0]['options'] 432 | # print('##### bitasset_opts: {}'.format(bitasset_opts)) 433 | bitasset_opts["feed_lifetime_sec"] = bitasset_opts["feed_lifetime_sec"] + 30 434 | req_data = { 435 | "jsonrpc": "2.0", 436 | "method": "update_bitasset", 437 | "params": [asset['symbol'], bitasset_opts, 'true'], 438 | "id":1 439 | } 440 | self.request_post(req_data) 441 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 442 | 443 | #issue_asset nicotest 10000 NODE "test issue asset" true 444 | def test_issue_asset(self): 445 | req_data = { 446 | "jsonrpc": "2.0", 447 | "method": "issue_asset", 448 | "params": [test_account, 100, test_default_asset, "issue_asset test", 'true'], 449 | "id":1 450 | } 451 | self.request_post(req_data) 452 | 453 | req_data = { 454 | "jsonrpc": "2.0", 455 | "method": "list_account_balances", 456 | "params": [test_account], 457 | "id":1 458 | } 459 | self.request_post(req_data) 460 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 461 | 462 | @unittest.skipIf(True, 'test other') 463 | def test_reserve_asset(self): 464 | req_data = { 465 | "jsonrpc": "2.0", 466 | "method": "reserve_asset", 467 | "params": [test_account, 20, test_default_asset, 'true'], 468 | "id":1 469 | } 470 | self.request_post(req_data) 471 | 472 | req_data = { 473 | "jsonrpc": "2.0", 474 | "method": "list_account_balances", 475 | "params": [test_account], 476 | "id":1 477 | } 478 | self.request_post(req_data) 479 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 480 | 481 | @unittest.skipIf(True, 'need feed price') 482 | def test_borrow_asset(self): 483 | req_data = { 484 | "jsonrpc": "2.0", 485 | "method": "borrow_asset", 486 | "params": [test_account, 20, test_default_bitasset, 'true'], 487 | "id":1 488 | } 489 | self.request_post(req_data) 490 | 491 | req_data = { 492 | "jsonrpc": "2.0", 493 | "method": "list_account_balances", 494 | "params": [test_account], 495 | "id":1 496 | } 497 | self.request_post(req_data) 498 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 499 | 500 | # sell_asset nicotest 100 NODE 1000 COCOS 1800 false true 501 | @unittest.skipIf(False, 'test other') 502 | def test_sell_asset(self): 503 | amount = 20 504 | timeout = 3600 505 | fill_or_kill = 'false' 506 | req_data = { 507 | "jsonrpc": "2.0", 508 | "method": "sell_asset", 509 | "params": [test_account, amount, test_default_asset, amount*2, core_asset, timeout, fill_or_kill, 'true'], 510 | "id":1 511 | } 512 | self.request_post(req_data) 513 | 514 | req_data = { 515 | "jsonrpc": "2.0", 516 | "method": "get_limit_orders", 517 | "params": [test_default_asset, core_asset, 20], 518 | "id":1 519 | } 520 | orders = self.request_post(req_data)['result'] 521 | 522 | index = 0 523 | for order in orders: 524 | if index % 2 == 0: 525 | # print('### settle_asset: {}'.format(order)) 526 | # req_data = { 527 | # "jsonrpc": "2.0", 528 | # "method": "settle_asset", 529 | # "params": [order['id'], 'true'], 530 | # "id":1 531 | # } 532 | # self.request_post(req_data) 533 | pass 534 | else: 535 | print("### cancel_order: {}".format(order)) 536 | req_data = { 537 | "jsonrpc": "2.0", 538 | "method": "cancel_order", 539 | "params": [order['id'], 'true'], 540 | "id":1 541 | } 542 | self.request_post(req_data) 543 | index = index+1 544 | 545 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 546 | 547 | @unittest.skipIf(True, 'test other') 548 | def test_feed(self): 549 | #update_asset_feed_producers 1.3.10 ["feeder"] true 550 | req_data = { 551 | "jsonrpc": "2.0", 552 | "method": "update_asset_feed_producers", 553 | "params": [self.feed_asset_id, [self.feeder], 'true'], 554 | "id":1 555 | } 556 | self.request_post(req_data) 557 | 558 | feed_price = { 559 | "settlement_price":{ 560 | "base":{"amount":5,"asset_id": self.feed_asset_id}, 561 | "quote":{"amount":10,"asset_id":"1.3.0"} 562 | }, 563 | "core_exchange_rate":{ 564 | "base":{"amount":100,"asset_id":self.feed_asset_id}, 565 | "quote":{"amount":2,"asset_id":"1.3.0"} 566 | } 567 | } 568 | req_data = { 569 | "jsonrpc": "2.0", 570 | "method": "publish_asset_feed", 571 | "params": [self.feeder, self.feed_asset_id, feed_price, 'true'], 572 | "id":1 573 | } 574 | self.request_post(req_data) 575 | 576 | req_data = { 577 | "jsonrpc": "2.0", 578 | "method": "get_bitasset_data", 579 | "params": [self.feed_asset], 580 | "id":1 581 | } 582 | self.request_post(req_data) 583 | 584 | req_data = { 585 | "jsonrpc": "2.0", 586 | "method": "get_object", 587 | "params": [self.feed_asset_dynamic_asset_data_id], 588 | "id":1 589 | } 590 | self.request_post(req_data) 591 | 592 | # borrow_asset nicotest 50 STEEM 1500 true 593 | req_data = { 594 | "jsonrpc": "2.0", 595 | "method": "borrow_asset", 596 | "params": [test_witness_account, 100, self.feed_asset, 1000, 'true'], 597 | "id":1 598 | } 599 | self.request_post(req_data) 600 | 601 | req_data = { 602 | "jsonrpc": "2.0", 603 | "method": "get_object", 604 | "params": [self.feed_asset_dynamic_asset_data_id], 605 | "id":1 606 | } 607 | self.request_post(req_data) 608 | 609 | settle_price = { 610 | "base":{"amount":5,"asset_id": self.feed_asset_id}, 611 | "quote":{"amount":20,"asset_id":"1.3.0"} 612 | } 613 | req_data = { 614 | "jsonrpc": "2.0", 615 | "method": "global_settle_asset", 616 | "params": [self.feed_asset, settle_price, 'true'], 617 | "id":1 618 | } 619 | self.request_post(req_data) 620 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 621 | 622 | if __name__ == "__main__": 623 | unittest.main() 624 | 625 | 626 | ''' 627 | ##### test_feed的一次测试数据: 628 | 629 | root@7ef1cba5083e:~/data/repo/scripts/chain/wallet_api_test# python t06_asset.py 630 | >> unlock ['123456'] 631 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 632 | 633 | >> import_key ['nicotest', '5J2SChqa9QxrCkdMor9VC2k9NT4R4ctRrJA6odQCPkb3yL89vxo'] 634 | {u'jsonrpc': u'2.0', u'id': 1, u'result': True} 635 | 636 | >> import_key ['init1', '5K5fqjvMrH5UtUisCgSZHQjiQf9BvtZ5vsKPhCErDy7P2gnLQmw'] 637 | {u'jsonrpc': u'2.0', u'id': 1, u'result': True} 638 | 639 | new_asset_symbol: BALE, new_bitasset_symbol: BASIFY 640 | >> get_account ['feeder'] 641 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'statistics': u'2.6.65', u'name': u'feeder', u'options': {u'memo_key': u'COCOS56a5dTnfGpuPoWACnYj65dahcXMpTrNQkV3hHWCFkLxMF5mXpx', u'extensions': [], u'votes': []}, u'active': {u'weight_threshold': 1, u'account_auths': [], u'key_auths': [[u'COCOS56a5dTnfGpuPoWACnYj65dahcXMpTrNQkV3hHWCFkLxMF5mXpx', 1]], u'address_auths': []}, u'registrar': u'1.2.16', u'asset_locked': {u'contract_lock_details': [], u'locked_total': []}, u'owner': {u'weight_threshold': 1, u'account_auths': [], u'key_auths': [[u'COCOS56a5dTnfGpuPoWACnYj65dahcXMpTrNQkV3hHWCFkLxMF5mXpx', 1]], u'address_auths': []}, u'membership_expiration_date': u'1970-01-01T00:00:00', u'id': u'1.2.65'}} 642 | 643 | [get_asset_if_not_create] symbol: STEEM 644 | >> get_asset ['STEEM'] 645 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'symbol': u'STEEM', u'precision': 5, u'id': u'1.3.6', u'bitasset_data_id': u'2.4.2', u'options': {u'issuer_permissions': 511, u'description': u'', u'max_market_fee': u'1000000000000000000', u'max_supply': u'1000000000000000000', u'flags': 0, u'extensions': [], u'market_fee_percent': 0, u'core_exchange_rate': {u'quote': {u'asset_id': u'1.3.0', u'amount': 1}, u'base': {u'asset_id': u'1.3.6', u'amount': 1}}}, u'dynamic_asset_data_id': u'2.3.6', u'issuer': u'1.2.16'}} 646 | 647 | >> get_asset ['STEEM'] 648 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'symbol': u'STEEM', u'precision': 5, u'id': u'1.3.6', u'bitasset_data_id': u'2.4.2', u'options': {u'issuer_permissions': 511, u'description': u'', u'max_market_fee': u'1000000000000000000', u'max_supply': u'1000000000000000000', u'flags': 0, u'extensions': [], u'market_fee_percent': 0, u'core_exchange_rate': {u'quote': {u'asset_id': u'1.3.0', u'amount': 1}, u'base': {u'asset_id': u'1.3.6', u'amount': 1}}}, u'dynamic_asset_data_id': u'2.3.6', u'issuer': u'1.2.16'}} 649 | 650 | ####feed asset| symbol: STEEM, asset_id: 1.3.6, dynamic_asset_data_id: 2.3.6 bitasset_data_id: 2.4.2 651 | setUpClass done. 652 | sss>> update_asset_feed_producers [u'1.3.6', ['feeder'], 'true'] 653 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'98b82b99ec399e3467b875d9f3008b090130e241e442626c02eb9661abec012a', {u'ref_block_prefix': 3918618374, u'operations': [[12, {u'new_feed_producers': [u'1.2.65'], u'asset_to_update': u'1.3.6', u'extensions': [], u'issuer': u'1.2.16'}]], u'signatures': [u'2011b60de6cf691bc72a9b97bcc71c55cc0f53f9cd274a110908539c8ba348d24d0a83050cc23e4f871e67bcfd7ed012d641dfab2eeb3d85df43cb96a6f04c1061'], u'ref_block_num': 42951, u'extensions': [], u'expiration': u'2019-11-29T12:10:26'}]} 654 | 655 | >> publish_asset_feed ['feeder', u'1.3.6', {'settlement_price': {'quote': {'asset_id': '1.3.0', 'amount': 10}, 'base': {'asset_id': u'1.3.6', 'amount': 5}}, 'core_exchange_rate': {'quote': {'asset_id': '1.3.0', 'amount': 2}, 'base': {'asset_id': u'1.3.6', 'amount': 100}}}, 'true'] 656 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'2240c914ddbce1b1c86ef1c641f9ce970877a786b9b7719c4ff49728f67e3816', {u'ref_block_prefix': 3918618374, u'operations': [[17, {u'asset_id': u'1.3.6', u'publisher': u'1.2.65', u'extensions': [], u'feed': {u'maximum_short_squeeze_ratio': 1500, u'settlement_price': {u'quote': {u'asset_id': u'1.3.0', u'amount': 10}, u'base': {u'asset_id': u'1.3.6', u'amount': 5}}, u'maintenance_collateral_ratio': 1750}}]], u'signatures': [u'1f4a2d759d08c1b3b982e585e814e94cca03ddf4fb6f58c9a01ad36022c7763d7379d2803b14085ede9406c931c2971d9011f93aeb572d455fa1a9c191e20103a2'], u'ref_block_num': 42951, u'extensions': [], u'expiration': u'2019-11-29T12:10:26'}]} 657 | 658 | >> get_bitasset_data ['STEEM'] 659 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'current_feed_publication_time': u'2019-11-29T11:49:56', u'settlement_price': {u'quote': {u'asset_id': u'1.3.0', u'amount': 0}, u'base': {u'asset_id': u'1.3.0', u'amount': 0}}, u'force_settled_volume': 0, u'settlement_fund': 0, u'options': {u'minimum_feeds': 1, u'force_settlement_delay_sec': 86400, u'force_settlement_offset_percent': 0, u'extensions': [], u'feed_lifetime_sec': 120, u'maximum_force_settlement_volume': 2000, u'short_backing_asset': u'1.3.0'}, u'feeds': [[u'1.2.65', [u'2019-11-29T11:49:56', {u'maximum_short_squeeze_ratio': 1500, u'settlement_price': {u'quote': {u'asset_id': u'1.3.0', u'amount': 10}, u'base': {u'asset_id': u'1.3.6', u'amount': 5}}, u'maintenance_collateral_ratio': 1750}]]], u'id': u'2.4.2', u'current_feed': {u'maximum_short_squeeze_ratio': 1500, u'settlement_price': {u'quote': {u'asset_id': u'1.3.0', u'amount': 10}, u'base': {u'asset_id': u'1.3.6', u'amount': 5}}, u'maintenance_collateral_ratio': 1750}}} 660 | 661 | >> get_object [u'2.3.6'] 662 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [{u'current_supply': 10000000, u'accumulated_fees': 0, u'id': u'2.3.6'}]} 663 | 664 | >> borrow_asset ['init1', 100, 'STEEM', 1000, 'true'] 665 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'4cb2bc9725b79a5c3cfc648510d2994feb9ff420ea01377da85055d001579a5a', {u'ref_block_prefix': 3918618374, u'operations': [[3, {u'funding_account': u'1.2.6', u'delta_debt': {u'asset_id': u'1.3.6', u'amount': 10000000}, u'extensions': [], u'delta_collateral': {u'asset_id': u'1.3.0', u'amount': 100000000}}]], u'signatures': [u'207311002d80981a208128dee5c66aa533f66ae720006a8c2ef7ea18df654d75927cb4135d94cc6d731493b19f5435d2102c11dbddd9df20e3f0506dd32a0ee9f7'], u'ref_block_num': 42951, u'extensions': [], u'expiration': u'2019-11-29T12:10:26'}]} 666 | 667 | >> get_object [u'2.3.6'] 668 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [{u'current_supply': 20000000, u'accumulated_fees': 0, u'id': u'2.3.6'}]} 669 | 670 | >> global_settle_asset ['STEEM', {'quote': {'asset_id': '1.3.0', 'amount': 20}, 'base': {'asset_id': u'1.3.6', 'amount': 5}}, 'true'] 671 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'282a9b75558dfd596f15559f8772b3bb096c2e5b3d815a54826d56bdaa87f54d', {u'ref_block_prefix': 3918618374, u'operations': [[16, {u'settle_price': {u'quote': {u'asset_id': u'1.3.0', u'amount': 20}, u'base': {u'asset_id': u'1.3.6', u'amount': 5}}, u'extensions': [], u'asset_to_settle': u'1.3.6', u'issuer': u'1.2.16'}]], u'signatures': [u'1f6366c7b25fb85dde073024239d4a76ca6485eabeac6160d8a6d6a5b7591c4a0b047e0a03981833c08c9c83f868839b308e6c2a139262eb103d6a8aec70ee75ea'], u'ref_block_num': 42951, u'extensions': [], u'expiration': u'2019-11-29T12:10:26'}]} 672 | ''' 673 | 674 | -------------------------------------------------------------------------------- /t07_nh_asset.py: -------------------------------------------------------------------------------- 1 | #-*- coding: utf-8 -*- 2 | 3 | import unittest 4 | from config import * 5 | from utils import * 6 | # import os 7 | import sys 8 | from chain_param import * 9 | 10 | class test_wallet_nh_asset_api(request_unittest): 11 | @classmethod 12 | def setUpClass(self): 13 | req_data = { 14 | "jsonrpc": "2.0", 15 | "method": "unlock", 16 | "params": [wallet_password], 17 | "id":1 18 | } 19 | request_post(req_data) 20 | 21 | req_data = { 22 | "jsonrpc": "2.0", 23 | "method": "import_key", 24 | "params": [test_account, test_account_private_key], 25 | "id":1 26 | } 27 | request_post(req_data) 28 | 29 | req_data = { 30 | "jsonrpc": "2.0", 31 | "method": "upgrade_account", 32 | "params": [test_account, 'true'], 33 | "id":1 34 | } 35 | # request_post(req_data) 36 | response = request_post(req_data, False) 37 | 38 | req_data = { 39 | "jsonrpc": "2.0", 40 | "method": "load_wallet_file", 41 | "params": [""], 42 | "id":1 43 | } 44 | request_post(req_data) 45 | 46 | req_data = { 47 | "jsonrpc": "2.0", 48 | "method": "import_key", 49 | "params": [test_witness_account, test_witness_account_private_key], 50 | "id":1 51 | } 52 | request_post(req_data) 53 | 54 | #get_nh_creator 55 | req_data = { 56 | "jsonrpc": "2.0", 57 | "method": "get_nh_creator", 58 | "params": [test_account], 59 | "id":1 60 | } 61 | response = request_post(req_data, False) 62 | if 'error' in response: 63 | #register nh creator 64 | req_data = { 65 | "jsonrpc": "2.0", 66 | "method": "register_nh_asset_creator", 67 | "params": [test_account, 'true'], 68 | "id":1 69 | } 70 | request_post(req_data) 71 | self.nh_creator = test_account 72 | self.nh_creator_account_id = response['result']['creator'] 73 | print('creator_account_id: {}'.format(self.nh_creator_account_id)) 74 | 75 | req_data = { 76 | "jsonrpc": "2.0", 77 | "method": "get_account", 78 | "params": [test_nh_creator], 79 | "id":1 80 | } 81 | response = request_post(req_data, False) 82 | if 'error' in response: 83 | #register account 84 | req_data = { 85 | "jsonrpc": "2.0", 86 | "method": "register_account", 87 | "params": [test_nh_creator, test_account_public_key, test_account_public_key, test_account, 'true'], 88 | "id":1 89 | } 90 | request_post(req_data) 91 | req_data = { 92 | "jsonrpc": "2.0", 93 | "method": "import_key", 94 | "params": [test_nh_creator, test_account_private_key], 95 | "id":1 96 | } 97 | request_post(req_data) 98 | 99 | req_data = { 100 | "jsonrpc": "2.0", 101 | "method": "transfer", 102 | "params": [test_account, test_nh_creator, 1000000, "COCOS", ["nh asset api test", "false"], 'true'], 103 | "id":1 104 | } 105 | request_post(req_data) 106 | 107 | req_data = { 108 | "jsonrpc": "2.0", 109 | "method": "upgrade_account", 110 | "params": [test_nh_creator, 'true'], 111 | "id":1 112 | } 113 | request_post(req_data) 114 | 115 | req_data = { 116 | "jsonrpc": "2.0", 117 | "method": "get_nh_creator", 118 | "params": [test_nh_creator], 119 | "id":1 120 | } 121 | response = request_post(req_data, False) 122 | if 'error' in response: 123 | #register nh creator 124 | req_data = { 125 | "jsonrpc": "2.0", 126 | "method": "register_nh_asset_creator", 127 | "params": [test_nh_creator, 'true'], 128 | "id":1 129 | } 130 | request_post(req_data) 131 | 132 | # create world view 133 | tokens = generate_random_words() 134 | world_view = 'test_' + tokens[0].lower() 135 | req_data = { 136 | "jsonrpc": "2.0", 137 | "method": "create_world_view", 138 | "params": [test_account, world_view, 'true'], 139 | "id":1 140 | } 141 | request_post(req_data) 142 | self.world_view = world_view 143 | self.relate_world_view = 'test_' + tokens[1].lower() 144 | 145 | self.core_asset = core_asset 146 | self.core_asset_id = "1.3.0" 147 | 148 | # create world view 149 | tokens = generate_random_words() 150 | world_view = 'test_common' 151 | req_data = { 152 | "jsonrpc": "2.0", 153 | "method": "create_world_view", 154 | "params": [test_account, world_view, 'true'], 155 | "id":1 156 | } 157 | request_post(req_data, False) 158 | self.test_world_view_common = world_view 159 | 160 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 161 | 162 | @classmethod 163 | def tearDownClass(self): 164 | req_data = { 165 | "jsonrpc": "2.0", 166 | "method": "lock", 167 | "params": [], 168 | "id":1 169 | } 170 | request_post(req_data) 171 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 172 | 173 | 174 | # signed_transaction propose_relate_world_view( 175 | # const string &proposing_account, fc::time_point_sec expiration_time, 176 | # const string &world_view_owner, const string &world_view, bool broadcast = false) 177 | @unittest.skipIf(True, 'test other') 178 | def test_propose_relate_world_view(self): 179 | expiration_time = datetime_N_ago(-1).strftime("%Y-%m-%dT%H:%M:%S") 180 | req_data = { 181 | "jsonrpc": "2.0", 182 | "method": "propose_relate_world_view", 183 | "params": [test_nh_creator, expiration_time, test_account, self.world_view, 'true'], 184 | "id":1 185 | } 186 | info = self.request_post(req_data)['result'] 187 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 188 | 189 | 190 | # signed_transaction create_nh_asset( 191 | # const string &creator, const string &owner, 192 | # const string &asset_id, const string &world_view, 193 | # const string &base_describe, bool broadcast = false) 194 | def test_create_nh_asset(self): 195 | base_describe = "{k1:v1, k2:v2}" 196 | req_data = { 197 | "jsonrpc": "2.0", 198 | "method": "create_nh_asset", 199 | "params": [self.nh_creator, test_account, self.core_asset_id, 200 | self.test_world_view_common, base_describe, 'true'], 201 | "id":1 202 | } 203 | self.request_post(req_data) 204 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 205 | 206 | # std::pair, uint32_t> wallet_api::list_nh_asset_by_creator( 207 | # const string &nh_asset_creator, 208 | # uint32_t pagesize, 209 | # uint32_t page) 210 | 211 | @unittest.skipIf(True, "test other") 212 | def test_list_nh_asset_by_creator(self): 213 | pagesize = 5 214 | page = 1 215 | req_data = { 216 | "jsonrpc": "2.0", 217 | "method": "list_nh_asset_by_creator", 218 | "params": [self.nh_creator, self.test_world_view_common, pagesize, page], 219 | "id":1 220 | } 221 | self.request_post(req_data) 222 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 223 | 224 | # std::pair, uint32_t> wallet_api::list_account_nh_asset( 225 | # const string &nh_asset_owner, 226 | # const vector &world_view_name_or_ids, 227 | # uint32_t pagesize, 228 | # uint32_t page, 229 | # nh_asset_list_type list_type) 230 | @unittest.skipIf(True, "test other") 231 | def test_list_account_nh_asset(self): 232 | pagesize = 5 233 | page = 1 234 | # list_type = nh_asset_list_type['owner_and_active'] 235 | for index in range(0, len(nh_asset_list_type)): 236 | req_data = { 237 | "jsonrpc": "2.0", 238 | "method": "list_account_nh_asset", 239 | "params": [test_account, [self.world_view], pagesize, page, index], 240 | "id":1 241 | } 242 | self.request_post(req_data) 243 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 244 | 245 | # pair wallet_api::transfer_nh_asset( 246 | # const string &from, 247 | # const string &to, 248 | # const string &nh_asset, 249 | # bool broadcast) 250 | @unittest.skipIf(True, "test other") 251 | def test_transfer_nh_asset(self): 252 | base_describe = "{k1:v1, k2:v2}" 253 | req_data = { 254 | "jsonrpc": "2.0", 255 | "method": "create_nh_asset", 256 | "params": [self.nh_creator, test_account, self.core_asset_id, 257 | self.test_world_view_common, base_describe, 'true'], 258 | "id":1 259 | } 260 | for _ in range(0, 3): 261 | self.request_post(req_data) 262 | 263 | pagesize = 5 264 | page = 1 265 | index = 4 # owner_and_active 266 | req_data = { 267 | "jsonrpc": "2.0", 268 | "method": "list_account_nh_asset", 269 | "params": [test_account, [self.test_world_view_common], pagesize, page, index], 270 | "id":1 271 | } 272 | page_nh_assets = self.request_post(req_data)['result'] 273 | # page_nh_assets: [[obj1, obj2, obj3...], size] 274 | index = 0 275 | for nh_asset in page_nh_assets[0]: 276 | # print('nh_asset: {}'.format(nh_asset)) 277 | asset_id = nh_asset['id'] 278 | if index == 0: 279 | #transfer 280 | req_data = { 281 | "jsonrpc": "2.0", 282 | "method": "transfer_nh_asset", 283 | "params": [nh_asset['nh_asset_owner'], test_witness_account, asset_id, 'true'], 284 | "id":1 285 | } 286 | request_post(req_data) 287 | # elif index == 1: 288 | elif index % 100 == 1: 289 | #delete 290 | req_data = { 291 | "jsonrpc": "2.0", 292 | "method": "delete_nh_asset", 293 | "params": [self.nh_creator, asset_id, 'true'], 294 | "id":1 295 | } 296 | self.request_post(req_data) 297 | index = index + 1 298 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 299 | 300 | @unittest.skipIf(True, "test other") 301 | def test_list_account_nh_asset_order(self): 302 | pagesize = 5 303 | page = 1 304 | req_data = { 305 | "jsonrpc": "2.0", 306 | "method": "list_account_nh_asset_order", 307 | "params": [self.nh_creator, pagesize, page], 308 | "id":1 309 | } 310 | self.request_post(req_data) 311 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 312 | 313 | # std::pair, uint32_t> wallet_api::list_nh_asset_order( 314 | # const string &asset_symbols_or_id, 315 | # const string &world_view_name_or_id, 316 | # const string &base_describe, 317 | # uint32_t pagesize, 318 | # uint32_t page, 319 | # bool is_ascending_order) 320 | def test_list_nh_asset_order(self): 321 | base_describe = "{k1:v1, k2:v2}" 322 | pagesize = 5 323 | page = 1 324 | req_data = { 325 | "jsonrpc": "2.0", 326 | "method": "list_nh_asset_order", 327 | "params": [self.core_asset_id, self.test_world_view_common, 328 | base_describe, pagesize, page, 'true'], 329 | "id":1 330 | } 331 | self.request_post(req_data) 332 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 333 | 334 | # pair wallet_api::create_nh_asset_order( 335 | # const string &seller, 336 | # const string &otcaccount, 337 | # const string &pending_fee_amount, 338 | # const string &pending_fee_symbol, 339 | # const string &nh_asset, 340 | # const string &price_amount, 341 | # const string &price_symbol, 342 | # const string &memo, 343 | # fc::time_point_sec expiration_time, 344 | # bool broadcast) 345 | 346 | def test_nh_assert_order(self): 347 | pagesize = 5 348 | page = 1 349 | index = 4 # owner_and_active 350 | req_data = { 351 | "jsonrpc": "2.0", 352 | "method": "list_account_nh_asset", 353 | "params": [test_account, [self.test_world_view_common], pagesize, page, index], 354 | "id":1 355 | } 356 | page_nh_assets = self.request_post(req_data)['result'] 357 | # page_nh_assets: [[obj1, obj2, obj3...], size] 358 | index = 0 359 | for nh_asset in page_nh_assets[0]: 360 | # asset_id = nh_asset['id'] 361 | # if index % 2 == 0: 362 | seller = nh_asset['nh_asset_owner'] 363 | otcaccount = test_witness_account 364 | pending_fee_amount = "500" 365 | pending_fee_symbol = core_asset 366 | nh_asset_id = nh_asset['id'] 367 | price_amount = "1500" 368 | price_symbol = core_asset 369 | memo = "create_nh_asset_order test" 370 | expiration_time = datetime_N_ago(-1).strftime("%Y-%m-%dT%H:%M:%S") 371 | req_data = { 372 | "jsonrpc": "2.0", 373 | "method": "create_nh_asset_order", 374 | "params": [seller, otcaccount, pending_fee_amount, pending_fee_symbol, 375 | nh_asset_id, price_amount, price_symbol, memo, expiration_time, 'true'], 376 | "id":1 377 | } 378 | request_post(req_data) 379 | index = index + 1 380 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 381 | 382 | 383 | # pair wallet_api::cancel_nh_asset_order( 384 | # object_id_type order_id, bool broadcast) 385 | def test_cancel_nh_asset_order(self): 386 | pagesize = 5 387 | page = 1 388 | req_data = { 389 | "jsonrpc": "2.0", 390 | "method": "list_account_nh_asset_order", 391 | "params": [self.nh_creator, pagesize, page], 392 | "id":1 393 | } 394 | nh_asset_orders = self.request_post(req_data)['result'] 395 | index = 0 396 | for order in nh_asset_orders[0]: 397 | if index == 0: 398 | req_data = { 399 | "jsonrpc": "2.0", 400 | "method": "cancel_nh_asset_order", 401 | "params": [order['id'], 'true'], 402 | "id":1 403 | } 404 | request_post(req_data) 405 | index = index + 1 406 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 407 | 408 | # pair wallet_api::fill_nh_asset_order( 409 | # const string &fee_paying_account, 410 | # nh_asset_order_id_type order_id, 411 | # bool broadcast) 412 | def test_fill_nh_asset_order(self): 413 | pagesize = 5 414 | page = 1 415 | req_data = { 416 | "jsonrpc": "2.0", 417 | "method": "list_account_nh_asset_order", 418 | "params": [self.nh_creator, pagesize, page], 419 | "id":1 420 | } 421 | nh_asset_orders = self.request_post(req_data)['result'] 422 | index = 0 423 | for order in nh_asset_orders[0]: 424 | if index == 0: 425 | req_data = { 426 | "jsonrpc": "2.0", 427 | "method": "fill_nh_asset_order", 428 | "params": [test_account, order['id'], 'true'], 429 | "id":1 430 | } 431 | request_post(req_data) 432 | index = index + 1 433 | print('{} done\n'.format(sys._getframe().f_code.co_name)) 434 | 435 | if __name__ == "__main__": 436 | unittest.main() 437 | 438 | ''' 439 | >> unlock ['123456'] 440 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 441 | 442 | >> import_key ['nicotest', '5J2SChqa9QxrCkdMor9VC2k9NT4R4ctRrJA6odQCPkb3yL89vxo'] 443 | {u'jsonrpc': u'2.0', u'id': 1, u'result': True} 444 | 445 | >> upgrade_account ['nicotest', 'true'] 446 | {u'jsonrpc': u'2.0', u'id': 1, u'error': {u'message': u'Assert Exception: !account_obj.is_lifetime_member(): ', u'code': 1}} 447 | 448 | >> load_wallet_file [''] 449 | {u'jsonrpc': u'2.0', u'id': 1, u'result': True} 450 | 451 | >> import_key ['init1', '5K5fqjvMrH5UtUisCgSZHQjiQf9BvtZ5vsKPhCErDy7P2gnLQmw'] 452 | {u'jsonrpc': u'2.0', u'id': 1, u'result': True} 453 | 454 | >> get_nh_creator ['nicotest'] 455 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'id': u'4.0.0', u'world_view': [u'test_veruled', u'test_stew', u'test_hushel', u'test_quizzer', u'test_mallow', u'test_katydid', 456 | u'test_aition', u'test_aflaunt', u'test_common', u'test_chordal', u'test_privily', u'test_uncheck', u'test_undry', u'test_closure', u'test_unrhyme', u'test_glaver', u'test 457 | _cig', u'test_page', u'test_pipy', u'test_limbeck', u'test_foamer', u'test_roughet', u'test_freak', u'test_logman', u'test_drab', u'test_excite', u'test_pyrexia', u'test_re 458 | gimen', u'test_sicsac', u'test_askance', u'test_cursus', u'test_grobian', u'test_alchimy', u'test_nuzzle', u'test_courlan', u'test_revend', u'test_unfiber', u'test_unionic' 459 | , u'test_sorroa', u'test_feower', u'test_disturb', u'test_smeary', u'test_verve', u'test_tutoyer', u'test_unfar', u'test_infidel', u'test_shyly', u'test_midwise', u'test_jo 460 | bber'], u'creator': u'1.2.16'}} 461 | 462 | creator_account_id: 1.2.16 463 | >> get_account ['creator2'] 464 | {u'jsonrpc': u'2.0', u'id': 1, u'result': {u'statistics': u'2.6.17', u'name': u'creator2', u'options': {u'memo_key': u'COCOS56a5dTnfGpuPoWACnYj65dahcXMpTrNQkV3hHWCFkLxMF5mX 465 | px', u'extensions': [], u'votes': []}, u'active': {u'weight_threshold': 1, u'account_auths': [], u'key_auths': [[u'COCOS56a5dTnfGpuPoWACnYj65dahcXMpTrNQkV3hHWCFkLxMF5mXpx', 466 | 1]], u'address_auths': []}, u'registrar': u'1.2.16', u'asset_locked': {u'contract_lock_details': [], u'locked_total': []}, u'owner': {u'weight_threshold': 1, u'account_aut 467 | hs': [], u'key_auths': [[u'COCOS56a5dTnfGpuPoWACnYj65dahcXMpTrNQkV3hHWCFkLxMF5mXpx', 1]], u'address_auths': []}, u'membership_expiration_date': u'1969-12-31T23:59:59', u'id 468 | ': u'1.2.17'}} 469 | 470 | >> create_world_view ['nicotest', u'test_slung', 'true'] 471 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'a474eda2f5ab902ee0eca85e4e01d07980aba2af4590dae7e546dea8f834b406', {u'ref_block_prefix': 294711135, u'operations': [[38, {u'wor 472 | ld_view': u'test_slung', u'fee_paying_account': u'1.2.16'}]], u'signatures': [u'1f59e869de1ccac5d2b2cffde6b0929e7a60b4c2c321bec86ce6c65546dd7a7f01758d7616293c704746a82e2dea 473 | ae079ab12c32e95932b427199b5cf7b00c009e'], u'ref_block_num': 9472, u'extensions': [], u'expiration': u'2019-12-01T04:12:58'}]} 474 | 475 | >> create_world_view ['nicotest', 'test_common', 'true'] 476 | {u'jsonrpc': u'2.0', u'id': 1, u'error': {u'message': u'unspecified: Assert Exception: insert_result.second: Could not create object! Most likely a uniqueness constraint is 477 | violated.', u'code': 1}} 478 | 479 | setUpClass done 480 | 481 | >> list_account_nh_asset_order ['nicotest', 5, 1] 482 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [[{u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.38', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo 483 | ': u'create_nh_asset_order test', u'nh_hash': u'2600000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'exp 484 | iration': u'2019-12-02T03:52:22', u'otcaccount': u'1.2.6', u'id': u'4.3.9', u'world_view': u'test_common'}, {u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.36', 485 | u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo': u'create_nh_asset_order test', u'nh_hash': u'2400000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5 486 | f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'expiration': u'2019-12-02T03:52:22', u'otcaccount': u'1.2.6', u'id': u'4.3.8', u'world_view': u'test_common'}, 487 | {u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.34', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo': u'create_nh_asset_order test', u'nh_hash' 488 | : u'2200000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'expiration': u'2019-12-02T03:52:22', u'otcaccou 489 | nt': u'1.2.6', u'id': u'4.3.7', u'world_view': u'test_common'}, {u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.31', u'price': {u'asset_id': u'1.3.0', u'amount' 490 | : 150000000}, u'memo': u'create_nh_asset_order test', u'nh_hash': u'1f00000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'seller': u'1.2.16', u'asset_qualifi 491 | er': u'COCOS', u'expiration': u'2019-12-02T03:52:22', u'otcaccount': u'1.2.6', u'id': u'4.3.6', u'world_view': u'test_common'}, {u'base_describe': u'{k1:v1, k2:v2}', u'nh_a 492 | sset_id': u'4.2.29', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo': u'create_nh_asset_order test', u'nh_hash': u'1d00000000000000274c0c8a9173c4f7c282a31a 493 | 790ca301e4f954c163f5f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'expiration': u'2019-12-02T03:52:22', u'otcaccount': u'1.2.6', u'id': u'4.3.5', u'world_view 494 | ': u'test_common'}], 5]} 495 | 496 | >> cancel_nh_asset_order [u'4.3.9', 'true'] 497 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'b59bc6146d9d1be9dd399177e1d80a10ba40a543e4af81c6bc06f6b761ad6174', {u'ref_block_prefix': 294711135, u'operations': [[44, {u'ext 498 | ensions': [], u'order': u'4.3.9', u'fee_paying_account': u'1.2.16'}]], u'signatures': [u'1f258fba634e1ab9d11891097592ddd39523e4fe74dddb8f08d7fe4213c0970cfd7a200d4acdf641f2b 499 | 8022130123dffd93a3595b02c025aa832ec5b1deeef2bb9'], u'ref_block_num': 9472, u'extensions': [], u'expiration': u'2019-12-01T04:12:58'}]} 500 | 501 | test_cancel_nh_asset_order done 502 | 503 | .>> create_nh_asset ['nicotest', 'nicotest', '1.3.0', 'test_common', '{k1:v1, k2:v2}', 'true'] 504 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'7815698ebd5e5db2a4f86c386bc856f8f91aaa34b26353943978c2d992f6aefe', {u'ref_block_prefix': 294711135, u'operations': [[40, {u'own 505 | er': u'1.2.16', u'asset_id': u'COCOS', u'base_describe': u'{k1:v1, k2:v2}', u'world_view': u'test_common', u'fee_paying_account': u'1.2.16'}]], u'signatures': [u'1f3913b992 506 | e448b97d8382a02c1adf94d9111e6f803203a101883e60f31291e562465b62aaae170efac986856b67f94c55a02561c233f546a7fc3f69b8066c5638'], u'ref_block_num': 9472, u'extensions': [], u'exp 507 | iration': u'2019-12-01T04:12:58'}]} 508 | 509 | test_create_nh_asset done 510 | 511 | .>> list_account_nh_asset_order ['nicotest', 5, 1] 512 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [[{u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.36', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo 513 | ': u'create_nh_asset_order test', u'nh_hash': u'2400000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'exp 514 | iration': u'2019-12-02T03:52:22', u'otcaccount': u'1.2.6', u'id': u'4.3.8', u'world_view': u'test_common'}, {u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.34', 515 | u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo': u'create_nh_asset_order test', u'nh_hash': u'2200000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5 516 | f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'expiration': u'2019-12-02T03:52:22', u'otcaccount': u'1.2.6', u'id': u'4.3.7', u'world_view': u'test_common'}, 517 | {u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.31', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo': u'create_nh_asset_order test', u'nh_hash' 518 | : u'1f00000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'expiration': u'2019-12-02T03:52:22', u'otcaccou 519 | nt': u'1.2.6', u'id': u'4.3.6', u'world_view': u'test_common'}, {u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.29', u'price': {u'asset_id': u'1.3.0', u'amount' 520 | : 150000000}, u'memo': u'create_nh_asset_order test', u'nh_hash': u'1d00000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'seller': u'1.2.16', u'asset_qualifi 521 | er': u'COCOS', u'expiration': u'2019-12-02T03:52:22', u'otcaccount': u'1.2.6', u'id': u'4.3.5', u'world_view': u'test_common'}], 4]} 522 | 523 | >> fill_nh_asset_order ['nicotest', u'4.3.8', 'true'] 524 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'ce20cd706f2907c9cf6058db5bfa1f7e1aac925e622c4045c517506c5416f6d7', {u'ref_block_prefix': 294711135, u'operations': [[45, {u'pri 525 | ce_amount': u'1500', u'fee_paying_account': u'1.2.16', u'price_asset_symbol': u'COCOS', u'seller': u'1.2.16', u'price_asset_id': u'1.3.0', u'extensions': [], u'nh_asset': u 526 | '4.2.36', u'order': u'4.3.8'}]], u'signatures': [u'20534850da054cf3d8f2d9750ec29c6c653a304f00906a809901ab0c9db8671179503ab6f64b09e4627aa1f9c38f2b2d38614cd902bb6e7af18784f79 527 | 9027eff09'], u'ref_block_num': 9472, u'extensions': [], u'expiration': u'2019-12-01T04:12:58'}]} 528 | 529 | test_fill_nh_asset_order done 530 | 531 | .sss>> list_nh_asset_order ['1.3.0', 'test_common', '{k1:v1, k2:v2}', 5, 1, 'true'] 532 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [[{u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.29', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo 533 | ': u'create_nh_asset_order test', u'nh_hash': u'1d00000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'exp 534 | iration': u'2019-12-02T03:52:22', u'otcaccount': u'1.2.6', u'id': u'4.3.5', u'world_view': u'test_common'}, {u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.31', 535 | u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo': u'create_nh_asset_order test', u'nh_hash': u'1f00000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5 536 | f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'expiration': u'2019-12-02T03:52:22', u'otcaccount': u'1.2.6', u'id': u'4.3.6', u'world_view': u'test_common'}, 537 | {u'base_describe': u'{k1:v1, k2:v2}', u'nh_asset_id': u'4.2.34', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}, u'memo': u'create_nh_asset_order test', u'nh_hash' 538 | : u'2200000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'seller': u'1.2.16', u'asset_qualifier': u'COCOS', u'expiration': u'2019-12-02T03:52:22', u'otcaccou 539 | nt': u'1.2.6', u'id': u'4.3.7', u'world_view': u'test_common'}], 3]} 540 | 541 | test_list_nh_asset_order done 542 | 543 | .>> list_account_nh_asset ['nicotest', ['test_common'], 5, 1, 4] 544 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [[{u'base_describe': u'{k1:v1, k2:v2}', u'parent': [], u'limit_type': u'black_list', u'nh_asset_owner': u'1.2.16', u'nh_hash': u'2 545 | 800000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'nh_asset_active': u'1.2.16', u'asset_qualifier': u'COCOS', u'dealership': u'1.2.16', u'create_time': u'2 546 | 019-12-01T03:00:08', u'limit_list': [], u'nh_asset_creator': u'1.2.16', u'child': [], u'describe_with_contract': [], u'id': u'4.2.40', u'world_view': u'test_common'}, {u'ba 547 | se_describe': u'{k1:v1, k2:v2}', u'parent': [], u'limit_type': u'black_list', u'nh_asset_owner': u'1.2.16', u'nh_hash': u'2a00000000000000274c0c8a9173c4f7c282a31a790ca301e4 548 | f954c163f5f305', u'nh_asset_active': u'1.2.16', u'asset_qualifier': u'COCOS', u'dealership': u'1.2.16', u'create_time': u'2019-12-01T03:00:52', u'limit_list': [], u'nh_asse 549 | t_creator': u'1.2.16', u'child': [], u'describe_with_contract': [], u'id': u'4.2.42', u'world_view': u'test_common'}, {u'base_describe': u'{k1:v1, k2:v2}', u'parent': [], u 550 | 'limit_type': u'black_list', u'nh_asset_owner': u'1.2.16', u'nh_hash': u'2c00000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'nh_asset_active': u'1.2.16', u 551 | 'asset_qualifier': u'COCOS', u'dealership': u'1.2.16', u'create_time': u'2019-12-01T03:04:52', u'limit_list': [], u'nh_asset_creator': u'1.2.16', u'child': [], u'describe_w 552 | ith_contract': [], u'id': u'4.2.44', u'world_view': u'test_common'}, {u'base_describe': u'{k1:v1, k2:v2}', u'parent': [], u'limit_type': u'black_list', u'nh_asset_owner': u 553 | '1.2.16', u'nh_hash': u'2e00000000000000274c0c8a9173c4f7c282a31a790ca301e4f954c163f5f305', u'nh_asset_active': u'1.2.16', u'asset_qualifier': u'COCOS', u'dealership': u'1.2 554 | .16', u'create_time': u'2019-12-01T03:05:36', u'limit_list': [], u'nh_asset_creator': u'1.2.16', u'child': [], u'describe_with_contract': [], u'id': u'4.2.46', u'world_view 555 | ': u'test_common'}, {u'base_describe': u'{k1:v1, k2:v2}', u'parent': [], u'limit_type': u'black_list', u'nh_asset_owner': u'1.2.16', u'nh_hash': u'3000000000000000274c0c8a9 556 | 173c4f7c282a31a790ca301e4f954c163f5f305', u'nh_asset_active': u'1.2.16', u'asset_qualifier': u'COCOS', u'dealership': u'1.2.16', u'create_time': u'2019-12-01T03:13:58', u'l 557 | imit_list': [], u'nh_asset_creator': u'1.2.16', u'child': [], u'describe_with_contract': [], u'id': u'4.2.48', u'world_view': u'test_common'}], 33]} 558 | 559 | >> create_nh_asset_order [u'1.2.16', 'init1', '500', 'COCOS', u'4.2.40', '1500', 'COCOS', 'create_nh_asset_order test', '2019-12-02T03:52:29', 'true'] 560 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'a34b30cb740844083ffcdba603017ac4f921a68156790b3f88aa46911d9cfd12', {u'ref_block_prefix': 294711135, u'operations': [[43, {u'pen 561 | ding_orders_fee': {u'asset_id': u'1.3.0', u'amount': 50000000}, u'memo': u'create_nh_asset_order test', u'nh_asset': u'4.2.40', u'seller': u'1.2.16', u'expiration': u'2019- 562 | 12-02T03:52:29', u'otcaccount': u'1.2.6', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}}]], u'signatures': [u'1f6e78bc300f805aa0b8cfd6f6976054f1a394cf2e646d91c7af 563 | f3e4f925c38c742a96f9750cfb389379446f1d9fbbcab8302a899547b60c08d5a7bf2c5ea5484d'], u'ref_block_num': 9472, u'extensions': [], u'expiration': u'2019-12-01T04:12:58'}]} 564 | 565 | >> create_nh_asset_order [u'1.2.16', 'init1', '500', 'COCOS', u'4.2.42', '1500', 'COCOS', 'create_nh_asset_order test', '2019-12-02T03:52:29', 'true'] 566 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'd957d945c355205622984e14010a9cfc7cd698cbb50d36cbf50ab7f2bf5beeed', {u'ref_block_prefix': 294711135, u'operations': [[43, {u'pen 567 | ding_orders_fee': {u'asset_id': u'1.3.0', u'amount': 50000000}, u'memo': u'create_nh_asset_order test', u'nh_asset': u'4.2.42', u'seller': u'1.2.16', u'expiration': u'2019- 568 | 12-02T03:52:29', u'otcaccount': u'1.2.6', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}}]], u'signatures': [u'20278be23667dc749376db130fcd07322b3e2b8bcfdd7749e0fe 569 | 4a488a46d7e9fe136e4980a106f6125fa4af32017d42e0f5a0965946e582f19e71912dd061efee'], u'ref_block_num': 9472, u'extensions': [], u'expiration': u'2019-12-01T04:12:58'}]} 570 | 571 | >> create_nh_asset_order [u'1.2.16', 'init1', '500', 'COCOS', u'4.2.44', '1500', 'COCOS', 'create_nh_asset_order test', '2019-12-02T03:52:29', 'true'] 572 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'7c087865aae362db6a6d7d69982915b95e1a7a6090e4c68adddd9ee5cf1f0cb1', {u'ref_block_prefix': 294711135, u'operations': [[43, {u'pen 573 | ding_orders_fee': {u'asset_id': u'1.3.0', u'amount': 50000000}, u'memo': u'create_nh_asset_order test', u'nh_asset': u'4.2.44', u'seller': u'1.2.16', u'expiration': u'2019- 574 | 12-02T03:52:29', u'otcaccount': u'1.2.6', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}}]], u'signatures': [u'2046df088ce2c5d93664c4ca6315b0594790a35a92f7564afae4 575 | 7fda75c58cd86416c95b139d13b0d7064b267f1571862b08901acc8164211d711e8fbff05a3b73'], u'ref_block_num': 9472, u'extensions': [], u'expiration': u'2019-12-01T04:12:58'}]} 576 | 577 | >> create_nh_asset_order [u'1.2.16', 'init1', '500', 'COCOS', u'4.2.46', '1500', 'COCOS', 'create_nh_asset_order test', '2019-12-02T03:52:29', 'true'] 578 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'767346864fd58bfd70cdd71e55ee6787ad2bb8095381f0618ca12420713f7b80', {u'ref_block_prefix': 294711135, u'operations': [[43, {u'pen 579 | ding_orders_fee': {u'asset_id': u'1.3.0', u'amount': 50000000}, u'memo': u'create_nh_asset_order test', u'nh_asset': u'4.2.46', u'seller': u'1.2.16', u'expiration': u'2019- 580 | 12-02T03:52:29', u'otcaccount': u'1.2.6', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}}]], u'signatures': [u'2019607b49c1498bf1b84f2170e1477dc75542417717c7e57e8e 581 | f2c8d422b97e3206f68883b838de4f93daf333e10bce097c8cc290b623747ae4ef11390104b867'], u'ref_block_num': 9472, u'extensions': [], u'expiration': u'2019-12-01T04:12:58'}]} 582 | 583 | >> create_nh_asset_order [u'1.2.16', 'init1', '500', 'COCOS', u'4.2.48', '1500', 'COCOS', 'create_nh_asset_order test', '2019-12-02T03:52:29', 'true'] 584 | {u'jsonrpc': u'2.0', u'id': 1, u'result': [u'edc52fdf6d4cf1588f8503e2405a8aa7985ad6e26ef91fc46728fc3bc14cd0ca', {u'ref_block_prefix': 294711135, u'operations': [[43, {u'pen 585 | ding_orders_fee': {u'asset_id': u'1.3.0', u'amount': 50000000}, u'memo': u'create_nh_asset_order test', u'nh_asset': u'4.2.48', u'seller': u'1.2.16', u'expiration': u'2019- 586 | 12-02T03:52:29', u'otcaccount': u'1.2.6', u'price': {u'asset_id': u'1.3.0', u'amount': 150000000}}]], u'signatures': [u'202234f5f63f78edfd78be4839d960d3c9c85c9274780b165ce2 587 | 52043cb6c5237850880bc088c71db6e52aaf5670c47d846b16a6da4453228f42425ae837c2667e'], u'ref_block_num': 9472, u'extensions': [], u'expiration': u'2019-12-01T04:12:58'}]} 588 | 589 | test_nh_assert_order done 590 | 591 | .ss>> lock [] 592 | {u'jsonrpc': u'2.0', u'id': 1, u'result': None} 593 | 594 | tearDownClass done 595 | 596 | 597 | ---------------------------------------------------------------------- 598 | Ran 10 tests in 0.331s 599 | 600 | OK (skipped=5) 601 | 602 | ''' --------------------------------------------------------------------------------