()
| 318 | |
| 319 | |
| 320 | def test_case_8(): |
| 321 | print("test rnode refund all") |
| 322 | cf = Web3(Web3.HTTPProvider("http://127.0.0.1:8521")) |
| 323 | owner = cf.toChecksumAddress("b3801b8743dea10c30b0c21cae8b1923d9625f84") |
| 324 | cf.personal.unlockAccount(owner, "password") |
| 325 | rnodes = [] |
| 326 | print("================generate 15 rnodes======================") |
| 327 | for i in range(100): |
| 328 | rnode = cf.toChecksumAddress(cf.personal.newAccount("password")) |
| 329 | rnodes.append(rnode) |
| 330 | cf.cpc.sendTransaction({"from": owner, "to": rnode, "value": cf.toWei(300000, "ether")}) |
| 331 | print("wait for tx confirmation...") |
| 332 | time.sleep(15) |
| 333 | for rnode in rnodes: |
| 334 | balance = cf.fromWei(cf.cpc.getBalance(rnode), "ether") |
| 335 | print("address: ", rnode) |
| 336 | print("balance: ", balance) |
| 337 | print("=================deploy contract====================") |
| 338 | config = compile_file() |
| 339 | contract = cf.cpc.contract(abi=config["abi"], bytecode=config["bin"]) |
| 340 | cf.cpc.defaultAccount = owner |
| 341 | cf.personal.unlockAccount(owner, "password") |
| 342 | estimated_gas = contract.constructor().estimateGas() |
| 343 | tx_hash = contract.constructor().transact(dict(gas=estimated_gas)) |
| 344 | tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash) |
| 345 | address = tx_receipt['contractAddress'] |
| 346 | rnode_ins = cf.cpc.contract(abi=config["abi"], address=address) |
| 347 | |
| 348 | print("=============nodes tries to join rnodes=========") |
| 349 | for rnode in rnodes: |
| 350 | cf.personal.unlockAccount(rnode, "password") |
| 351 | print("address: ", rnode) |
| 352 | cf.cpc.defaultAccount = rnode |
| 353 | tx_hash = rnode_ins.functions.joinRnode(1).transact({"gas": 829776, "from": rnode, "value": cf.toWei(210000, "ether")}) |
| 354 | tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash) |
| 355 | print("result: ", tx_receipt["status"]) |
| 356 | is_rnode = rnode_ins.functions.isRnode(rnode).call() |
| 357 | print("is rnode: ", is_rnode) |
| 358 | rnode_num = rnode_ins.functions.getRnodeNum().call() |
| 359 | print("number of rnode: ", rnode_num) |
| 360 | |
| 361 | print("===============check rnode=====================") |
| 362 | rnodes_from_contract = rnode_ins.functions.getRnodes().call() |
| 363 | rnode_num = rnode_ins.functions.getRnodeNum().call() |
| 364 | print("number of rnodes: ", rnode_num) |
| 365 | print("all rnodes from contract:") |
| 366 | print(rnodes_from_contract) |
| 367 | |
| 368 | # print("===============quit rnode=======================") |
| 369 | # print("owner set period") |
| 370 | # cf.cpc.defaultAccount = owner |
| 371 | # tx_hash = rnode_ins.functions.setPeriod(1).transact({"gas": 829776, "from": owner, "value": 0}) |
| 372 | # tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash) |
| 373 | # print("result: ", tx_receipt["status"]) |
| 374 | # for rnode in rnodes: |
| 375 | # cf.personal.unlockAccount(rnode, "password") |
| 376 | # print("address: ", rnode) |
| 377 | # cf.cpc.defaultAccount = rnode |
no test coverage detected