()
| 226 | |
| 227 | |
| 228 | def test_case_7(): |
| 229 | cf = Web3(Web3.HTTPProvider("http://127.0.0.1:8521")) |
| 230 | |
| 231 | print("========config account=========") |
| 232 | rnode = "0x6c95FEb59EF0281b3f9fD8Ec5628E1Da1d3Cc6E8" |
| 233 | civilian = "0x970c18A634B23c95a61746d172C48356DB58D8EC" |
| 234 | owner = "0xb3801b8743DEA10c30b0c21CAe8b1923d9625F84" |
| 235 | password = "password" |
| 236 | cf.personal.unlockAccount(rnode, password) |
| 237 | cf.personal.unlockAccount(civilian, password) |
| 238 | cf.personal.unlockAccount(owner, password) |
| 239 | print("balance of rnode: ", cf.fromWei(cf.cpc.getBalance(rnode), "ether")) |
| 240 | print("balance of civilian: ", cf.fromWei(cf.cpc.getBalance(civilian), "ether")) |
| 241 | print("balance of owner: ", cf.fromWei(cf.cpc.getBalance(owner), "ether")) |
| 242 | |
| 243 | print("========deploy rnode contract============") |
| 244 | config = compile_file() |
| 245 | contract = cf.cpc.contract(abi=config["abi"], bytecode=config["bin"]) |
| 246 | cf.cpc.defaultAccount = owner |
| 247 | estimated_gas = contract.constructor().estimateGas() |
| 248 | tx_hash = contract.constructor().transact(dict(gas=estimated_gas)) |
| 249 | tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash) |
| 250 | address = tx_receipt['contractAddress'] |
| 251 | |
| 252 | print("========test owner control===============") |
| 253 | rnode_ins = cf.cpc.contract(abi=config["abi"], address=address) |
| 254 | print("before set") |
| 255 | period = rnode_ins.functions.period().call() |
| 256 | print("period: ", period) |
| 257 | print("civilian tries to set period") |
| 258 | cf.cpc.defaultAccount = civilian |
| 259 | tx_hash = rnode_ins.functions.setPeriod(2).transact({"gas": 829776, "from": civilian, "value": 0}) |
| 260 | tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash) |
| 261 | print("result: ", tx_receipt["status"]) |
| 262 | period = rnode_ins.functions.period().call() |
| 263 | print("period after civilian set: ", period) |
| 264 | print("owner tries to set period") |
| 265 | cf.cpc.defaultAccount = owner |
| 266 | tx_hash = rnode_ins.functions.setPeriod(2).transact({"gas": 829776, "from": owner, "value": 0}) |
| 267 | tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash) |
| 268 | print("result: ", tx_receipt["status"]) |
| 269 | period = rnode_ins.functions.period().call() |
| 270 | print("period after owner set: ", period) |
| 271 | |
| 272 | print("============test version control============") |
| 273 | print("rnode tries to join rnode with old version") |
| 274 | cf.cpc.defaultAccount = rnode |
| 275 | tx_hash = rnode_ins.functions.joinRnode(0).transact({"gas": 829776, "from": rnode, "value": cf.toWei(200001, "ether")}) |
| 276 | tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash) |
| 277 | print("result: ", tx_receipt["status"]) |
| 278 | result = rnode_ins.functions.isRnode(rnode).call() |
| 279 | print("is rnode: ", result) |
| 280 | print("rnode tries to join rnode with new version") |
| 281 | tx_hash = rnode_ins.functions.joinRnode(3).transact({"gas": 829776, "from": rnode, "value": cf.toWei(200001, "ether")}) |
| 282 | tx_receipt = cf.cpc.waitForTransactionReceipt(tx_hash) |
| 283 | print("result: ", tx_receipt["status"]) |
| 284 | result = rnode_ins.functions.isRnode(rnode).call() |
| 285 | print("is rnode: ", result) |
nothing calls this directly
no test coverage detected