github.com/platonnetwork/platon-go@v0.7.6/cases/tests/cmd/account/test_account.py (about) 1 import time 2 3 import allure 4 import pytest 5 from client_sdk_python.eth import Eth 6 from eth_utils import is_integer 7 8 from common.log import log 9 from common.connect import run_ssh_cmd 10 from client_sdk_python.admin import Admin 11 12 from conf.settings import NODE_FILE 13 # from environment import t1est_env_impl 14 15 16 # py.test tests/cmd/account/t1est_account.py -s --nodeFile "deploy/4_node.yml" --accountFile "deploy/accounts.yml" --initChain --startAll 17 from environment import Node 18 19 20 class AccountEnv: 21 __slots__ = ('remote_pwd_file', 'remote_account_address', 'remote_account_file', 'remote_key_file') 22 23 24 @pytest.fixture(scope='module', autouse=False) 25 def account_env(global_test_env) -> (Node, AccountEnv): 26 log.info("module account begin.................................") 27 28 env = global_test_env 29 node = env.get_rand_node() 30 log.info("Node::::::::::::::::::::::::::::::{}".format(node)) 31 32 remote_pwd_file = node.remote_node_path + "/password.txt" 33 node.upload_file("./deploy/keystore/password.txt", remote_pwd_file) 34 35 remote_account_file = node.remote_keystore_dir + "/UTC--2019-10-15T10-27-31.520865283Z--c198603d3793c11e5362c8564a65d3880bae341b" 36 node.upload_file("./deploy/keystore/UTC--2019-10-15T10-27-31.520865283Z--c198603d3793c11e5362c8564a65d3880bae341b", remote_account_file) 37 38 remote_key_file = node.remote_keystore_dir + "/key.pri" 39 node.upload_file("./deploy/key.pri", remote_key_file) 40 41 account_env = AccountEnv() 42 account_env.remote_pwd_file = remote_pwd_file 43 account_env.remote_account_file = remote_account_file 44 account_env.remote_key_file = remote_key_file 45 account_env.remote_account_address = "c198603d3793c11e5362c8564a65d3880bae341b" 46 47 yield node, account_env 48 49 log.info("module account end.................................") 50 # node.deleteRemoteFile(remote_pwd_file) 51 # node.deleteRemoteFile(remote_pwd_file) 52 # node.deleteRemoteFile(remote_pwd_file) 53 54 55 @allure.title("Specify the datadir and keystore paths and create a new account by entering a password.") 56 @pytest.mark.P1 57 @pytest.mark.SYNC 58 def test_CMD_002(account_env): 59 node, env = account_env 60 return_list = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 61 old_counts = len(return_list) - 1 62 63 run_ssh_cmd(node.ssh, "{} account new --datadir {} --keystore {}".format(node.remote_bin_file, node.remote_data_dir, node.remote_keystore_dir), "88888888", "88888888") 64 time.sleep(0.2) 65 return_list2 = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 66 new_counts = len(return_list2) - 1 67 assert old_counts + 1 == new_counts 68 69 70 @allure.title("Specify datadir. In the default datadir/keystore, create a new account by entering a password.") 71 @pytest.mark.P1 72 @pytest.mark.SYNC 73 def test_CMD_003(account_env): 74 node, env = account_env 75 return_list = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 76 old_counts = len(return_list) - 1 77 78 run_ssh_cmd(node.ssh, "{} account new --datadir {}".format(node.remote_bin_file, node.remote_data_dir), "88888888", "88888888") 79 time.sleep(0.2) 80 return_list2 = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 81 new_counts = len(return_list2) - 1 82 assert old_counts + 1 == new_counts 83 84 85 @allure.title("Specify a keystore and create a new account by entering a password.") 86 @pytest.mark.P1 87 @pytest.mark.SYNC 88 def test_CMD_004(account_env): 89 node, env = account_env 90 return_list = run_ssh_cmd(node.ssh, "{} account list --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir)) 91 old_counts = len(return_list) - 1 92 93 run_ssh_cmd(node.ssh, "{} account new --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir), "88888888", "88888888") 94 time.sleep(0.2) 95 return_list2 = run_ssh_cmd(node.ssh, "{} account list --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir)) 96 new_counts = len(return_list2) - 1 97 assert old_counts + 1 == new_counts 98 99 100 @allure.title("Specify the datadir and keystore paths to create a new account with a password file.") 101 @pytest.mark.P1 102 @pytest.mark.SYNC 103 def test_CMD_001(account_env): 104 node, env = account_env 105 return_list = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 106 old_counts = len(return_list) - 1 107 108 run_ssh_cmd(node.ssh, "{} account new --datadir {} --keystore {} --password {}".format(node.remote_bin_file, 109 node.remote_data_dir, 110 node.remote_keystore_dir, 111 env.remote_pwd_file)) 112 time.sleep(0.2) 113 return_list2 = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 114 new_counts = len(return_list2) - 1 115 assert old_counts + 1 == new_counts 116 117 118 @allure.title("Specify datadir, create a new account with the password file in the default datadir/keystore") 119 @pytest.mark.P1 120 @pytest.mark.SYNC 121 def test_CMD_003_2(account_env): 122 node, env = account_env 123 return_list = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 124 old_counts = len(return_list) - 1 125 126 run_ssh_cmd(node.ssh, "{} account new --datadir {} --password {}".format(node.remote_bin_file, 127 node.remote_data_dir, 128 env.remote_pwd_file)) 129 time.sleep(0.2) 130 return_list2 = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 131 new_counts = len(return_list2) - 1 132 assert old_counts + 1 == new_counts 133 134 135 @allure.title("Specify a keystore and create a new account by entering a password.") 136 @pytest.mark.P1 137 @pytest.mark.SYNC 138 def test_CMD_004_2(account_env): 139 node, env = account_env 140 return_list = run_ssh_cmd(node.ssh, "{} account list --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir)) 141 old_counts = len(return_list) - 1 142 143 run_ssh_cmd(node.ssh, "{} account new --keystore {} --password {}".format(node.remote_bin_file, node.remote_keystore_dir, env.remote_pwd_file)) 144 time.sleep(0.2) 145 return_list2 = run_ssh_cmd(node.ssh, "{} account list --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir)) 146 new_counts = len(return_list2) - 1 147 assert old_counts + 1 == new_counts 148 149 150 @allure.title("Change account password, specify datadir") 151 @pytest.mark.P1 152 @pytest.mark.SYNC 153 def test_CMD_005(account_env): 154 node, env = account_env 155 returnList = run_ssh_cmd(node.ssh, "{} account update {} --datadir {}".format(node.remote_bin_file, env.remote_account_address, node.remote_data_dir), "88888888", "88888888", "88888888") 156 157 assert len(returnList) == 6 158 assert returnList[5].strip() == "Repeat passphrase:" 159 160 161 @allure.title("Change account password, specify keystore") 162 @pytest.mark.P1 163 @pytest.mark.SYNC 164 def test_CMD_006(account_env): 165 node, env = account_env 166 returnList = run_ssh_cmd(node.ssh, "{} account update {} --keystore {}".format(node.remote_bin_file, env.remote_account_address, node.remote_keystore_dir), "88888888", "88888888", "88888888") 167 168 assert len(returnList) == 6 169 assert returnList[5].strip() == "Repeat passphrase:" 170 171 172 @allure.title("Import account, do not specify password file, specify datadir") 173 @pytest.mark.P1 174 @pytest.mark.SYNC 175 def test_CMD_007(account_env): 176 node, env = account_env 177 178 return_list = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 179 old_counts = len(return_list) - 1 180 181 remote_key_file = node.remote_keystore_dir + "/key.pri" 182 node.upload_file("./deploy/key.pri", remote_key_file) 183 184 run_ssh_cmd(node.ssh, "{} account import {} --datadir {}".format(node.remote_bin_file, remote_key_file, node.remote_data_dir), "88888888", "88888888") 185 time.sleep(0.2) 186 return_list2 = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 187 188 new_counts = len(return_list2) - 1 189 190 assert old_counts + 1 == new_counts 191 192 193 @allure.title("Import account, do not specify password file, specify keystore") 194 @pytest.mark.P1 195 @pytest.mark.SYNC 196 def test_CMD_010_CMD_034(account_env): 197 node, env = account_env 198 199 return_list = run_ssh_cmd(node.ssh, "{} account list --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir)) 200 old_counts = len(return_list) - 1 201 202 remote_key_file = node.remote_keystore_dir + "/key.pri_2" 203 node.upload_file("./deploy/key.pri_2", remote_key_file) 204 205 run_ssh_cmd(node.ssh, "{} account import {} --keystore {}".format(node.remote_bin_file, remote_key_file, node.remote_keystore_dir), "88888888", "88888888") 206 time.sleep(0.2) 207 return_list2 = run_ssh_cmd(node.ssh, "{} account list --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir)) 208 209 new_counts = len(return_list2) - 1 210 211 assert old_counts + 1 == new_counts 212 213 214 @allure.title("Import account, specify password file, specify datadir") 215 @pytest.mark.P1 216 @pytest.mark.SYNC 217 def test_CMD_009(account_env): 218 node, env = account_env 219 220 return_list = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 221 old_counts = len(return_list) - 1 222 223 remote_key_file = node.remote_keystore_dir + "/key.pri_3" 224 node.upload_file("./deploy/key.pri_3", remote_key_file) 225 226 run_ssh_cmd(node.ssh, "{} account import {} --datadir {} --password {}".format(node.remote_bin_file, remote_key_file, node.remote_data_dir, env.remote_pwd_file)) 227 time.sleep(0.2) 228 return_list2 = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 229 230 new_counts = len(return_list2) - 1 231 232 assert old_counts + 1 == new_counts 233 234 235 @allure.title("Import account, specify password file, specify keystore") 236 @pytest.mark.P1 237 @pytest.mark.SYNC 238 def test_CMD_008(account_env): 239 node, env = account_env 240 241 return_list = run_ssh_cmd(node.ssh, "{} account list --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir)) 242 old_counts = len(return_list) - 1 243 244 remote_key_file = node.remote_keystore_dir + "/key.pri_4" 245 node.upload_file("./deploy/key.pri_4", remote_key_file) 246 247 run_ssh_cmd(node.ssh, "{} account import {} --keystore {} --password {}".format(node.remote_bin_file, remote_key_file, node.remote_keystore_dir, env.remote_pwd_file)) 248 time.sleep(0.2) 249 return_list2 = run_ssh_cmd(node.ssh, "{} account list --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir)) 250 251 new_counts = len(return_list2) - 1 252 253 assert old_counts + 1 == new_counts 254 255 256 @allure.title("List account") 257 @pytest.mark.P1 258 @pytest.mark.SYNC 259 def test_CMD_011(account_env): 260 node, env = account_env 261 262 return_list1 = run_ssh_cmd(node.ssh, "{} account list --datadir {}".format(node.remote_bin_file, node.remote_data_dir)) 263 264 counts1 = len(return_list1) - 1 265 266 return_list2 = run_ssh_cmd(node.ssh, "{} account list --keystore {}".format(node.remote_bin_file, node.remote_keystore_dir)) 267 counts2 = len(return_list2) - 1 268 269 assert counts1 == counts2 270 271 272 ''' 273 platon attach http / ws 274 ''' 275 276 277 @allure.title("Connect the node and open the js interactive console") 278 @pytest.mark.P3 279 def test_CMD_015(account_env): 280 node, env = account_env 281 282 print("node.remote_bin_file:::", node.remote_bin_file) 283 print("node.url:::", node.url) 284 285 blockNumber = node.run_ssh("{} attach {} --exec platon.blockNumber".format(node.remote_bin_file, node.url)) 286 287 bn = int(blockNumber[0]) 288 289 assert is_integer(bn) 290 assert bn > 0 291 292 293 ''' 294 platon attach http / ws 295 ''' 296 @allure.title("Copy chain data") 297 @pytest.mark.P3 298 def test_CMD_016(global_test_env): 299 global_env = global_test_env 300 301 node = global_env.consensus_node_list[0] 302 303 log.info("test copydb on host: {}".format(node.host)) 304 305 node.stop() 306 307 # copy deploy data to bak 308 bakremote_data_dir = node.remote_node_path + "/data_bak" 309 310 run_ssh_cmd(node.ssh, "sudo -S -p '' cp -r {} {}".format(node.remote_data_dir, bakremote_data_dir), node.password) 311 312 run_ssh_cmd(node.ssh, "sudo -S -p '' rm -rf {}/platon".format(node.remote_data_dir), node.password) 313 # run_ssh_cmd(node.ssh, "sudo -S -p '' rm -rf {}/platon/chaindata".format(node.remote_data_dir), node.password) 314 315 # re-init 316 run_ssh_cmd(node.ssh, "sudo -S -p '' {} init {} --datadir {}".format(node.remote_bin_file, node.remote_genesis_file, node.remote_data_dir), node.password) 317 318 time.sleep(10) 319 320 # copyDb from bak 321 run_ssh_cmd(node.ssh, "sudo -S -p '' {} copydb {}/platon/chaindata/ {}/platon/snapshotdb/ --datadir {}".format(node.remote_bin_file, bakremote_data_dir, bakremote_data_dir, node.remote_data_dir), node.password) 322 time.sleep(10) 323 324 node.start(False) 325 326 time.sleep(5) 327 328 blockNumber = node.run_ssh("{} attach {} --exec platon.blockNumber".format(node.remote_bin_file, node.url)) 329 330 for i in range(len(blockNumber)): 331 print("Serial number:{}".format(i), "result:{}".format(blockNumber[i])) 332 333 bn = int(blockNumber[0]) 334 335 assert is_integer(bn) 336 assert bn > 0 337 # pass 338 339 340 @allure.title("Analyze a specific block") 341 @pytest.mark.P3 342 def test_CMD_017(global_test_env): 343 global_env = global_test_env 344 345 node = global_env.consensus_node_list[0] 346 node.stop() 347 348 # dump 349 return_list = run_ssh_cmd(node.ssh, "sudo -S -p '' {} --datadir {} dump 0".format(node.remote_bin_file, node.remote_data_dir), node.password) 350 351 node.start(False) 352 353 assert len(return_list) > 0 and "root" in return_list[1] 354 355 356 @allure.title("Display configuration values(you can view the default configuration information of the node)") 357 @pytest.mark.P3 358 def test_CMD_018(global_test_env): 359 global_env = global_test_env 360 361 node = global_env.consensus_node_list[0] 362 # dump 363 returnList = run_ssh_cmd(node.ssh, "{} --nodekey {} --cbft.blskey {} dumpconfig".format(node.remote_bin_file, node.remote_nodekey_file, node.remote_blskey_file)) 364 assert returnList[0].strip() == '[Eth]' 365 366 367 @allure.title("Modify the exported value when exporting") 368 @pytest.mark.P3 369 def test_CMD_019(global_test_env): 370 global_env = global_test_env 371 372 node = global_env.consensus_node_list[0] 373 # dump 374 return_list = run_ssh_cmd(node.ssh, "{} --nodekey {} --cbft.blskey {} dumpconfig --networkid 1500".format(node.remote_bin_file, node.remote_nodekey_file, node.remote_blskey_file)) 375 376 assert return_list[1].strip() == 'NetworkId = 1500' 377 378 379 @allure.title("Import blocks from the hash image file") 380 @pytest.mark.P3 381 def test_CMD_025(global_test_env): 382 global_env = global_test_env 383 384 node = global_env.consensus_node_list[0] 385 node.stop() 386 387 # dump 388 export_list = run_ssh_cmd(node.ssh, "sudo -S -p '' {} export-preimages exportPreImage --datadir {}".format(node.remote_bin_file, node.remote_data_dir), node.password) 389 for i in range(len(export_list)): 390 log.info("Serial number:{} result:{}".format(i, export_list[i])) 391 392 time.sleep(1) 393 394 import_list = run_ssh_cmd(node.ssh, "sudo -S -p '' {} import-preimages exportPreImage --datadir {}".format(node.remote_bin_file, node.remote_data_dir), node.password) 395 node.start(False) 396 397 for i in range(len(import_list)): 398 log.info("Serial number:{} result:{}".format(i, import_list[i])) 399 400 assert len(export_list) == 1 401 assert len(import_list) == 1 402 403 404 @allure.title("Display version information") 405 @pytest.mark.P3 406 def test_CMD_026(global_test_env): 407 global_env = global_test_env 408 409 node = global_env.consensus_node_list[0] 410 411 return_list = run_ssh_cmd(node.ssh, "{} license".format(node.remote_bin_file)) 412 # for i in range(len(returnList)): 413 # log.info("Serial number:{} result:{}".format(i, returnList[i])) 414 415 assert return_list[0].strip() == "platon is free software: you can redistribute it and/or modify" 416 417 418 @allure.title("Display chain version") 419 @pytest.mark.P3 420 def test_CMD_029(global_test_env): 421 global_env = global_test_env 422 423 node = global_env.consensus_node_list[0] 424 425 return_list = run_ssh_cmd(node.ssh, "{} version".format(node.remote_bin_file)) 426 # for i in range(len(returnList)): 427 # log.info("Serial number:{} Result: {}".format(i, returnList[i])) 428 429 assert return_list[0].strip() == "PlatON" 430 assert "Version:" in return_list[1] 431 432 433 @allure.title("Load configuration file") 434 @pytest.mark.P3 435 def test_CMD_033_CMD_034(global_test_env): 436 global_env = global_test_env 437 438 node = global_env.consensus_node_list[0] 439 node.stop() 440 441 run_ssh_cmd(node.ssh, "sed -i 's/\"NetworkId\": 1/\"NetworkId\": 111/g' {}".format(node.remote_config_file)) 442 443 node.start(False) 444 445 time.sleep(2) 446 447 ret = node.admin.nodeInfo 448 # print(ret) 449 assert ret["protocols"]["platon"]["network"] == 111 450 451 # Todo: use case without assertion 452 # def no_t1est_removedb(global_test_env): 453 # globalEnv = global_test_env 454 # 455 # node = globalEnv.consensus_node_list[0] 456 # node.stop() 457 # 458 # returnList = run_ssh_cmd(node.ssh, "{} removedb --datadir {}".format(node.remote_bin_file, node.remote_data_dir, "y", "y")) 459 # for i in range(len(returnList)): 460 # log.info("Serial number:{} result".format(i, returnList[i])) 461 # 462 # node.start(False) 463 #assert returnList[0].strip()=="platon is free software: you can redistribute it and/or modify"