|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import signal |
| 3 | +import platform |
| 4 | + |
| 5 | +from TestHarness import Account, Cluster, TestHelper, Utils, WalletMgr |
| 6 | + |
| 7 | +############################################################### |
| 8 | +# sync_call_restart |
| 9 | +# |
| 10 | +# Tests restart of a node with sync_call protocol feature already activated. |
| 11 | +# |
| 12 | +# We had a bug that resources required by sync calls (in particular for OC) were |
| 13 | +# not allocated on restart if sync_call protocol feature had already been activated |
| 14 | +# https://github.com/AntelopeIO/spring/issues/1847 |
| 15 | +# |
| 16 | +# This test activates sync_call protocol feature, does a snapshot, kills the node, |
| 17 | +# restarts the node, pushes a transaction containing 2-levels of nested sync calls, |
| 18 | +# and verifies node not crashed. |
| 19 | +############################################################### |
| 20 | + |
| 21 | +Print=Utils.Print |
| 22 | +errorExit=Utils.errorExit |
| 23 | + |
| 24 | +args=TestHelper.parse_args({"--keep-logs","--dump-error-details","-v","--leave-running","--unshared"}) |
| 25 | +pnodes=1 |
| 26 | +debug=args.v |
| 27 | +total_nodes=pnodes |
| 28 | +dumpErrorDetails=args.dump_error_details |
| 29 | + |
| 30 | +Utils.Debug=debug |
| 31 | +testSuccessful=False |
| 32 | + |
| 33 | +cluster=Cluster(unshared=args.unshared, keepRunning=args.leave_running, keepLogs=args.keep_logs) |
| 34 | +walletMgr=WalletMgr(True, keepRunning=args.leave_running, keepLogs=args.keep_logs) |
| 35 | + |
| 36 | +try: |
| 37 | + if platform.system() != "Linux": |
| 38 | + Print("OC not run on Linux. Skip the test") |
| 39 | + exit(True) # Do not fail the test |
| 40 | + |
| 41 | + TestHelper.printSystemInfo("BEGIN") |
| 42 | + |
| 43 | + cluster.setWalletMgr(walletMgr) |
| 44 | + |
| 45 | + # Enable OC so that the test can execute paths invloved OC reources |
| 46 | + specificExtraNodeosArgs={0: " --eos-vm-oc-enable all "} |
| 47 | + |
| 48 | + Print("Stand up cluster") |
| 49 | + if cluster.launch(pnodes=pnodes, totalNodes=total_nodes, activateIF=True, specificExtraNodeosArgs=specificExtraNodeosArgs) is False: |
| 50 | + errorExit("Failed to stand up cluster.") |
| 51 | + |
| 52 | + cluster.waitOnClusterSync(blockAdvancing=5) |
| 53 | + |
| 54 | + node=cluster.getNode(0) |
| 55 | + |
| 56 | + def deployContract(account_name, contract_name): |
| 57 | + acct=Account(account_name) |
| 58 | + acct.ownerPublicKey="PUB_K1_6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5BoDq63" |
| 59 | + acct.activePublicKey="PUB_K1_6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5BoDq63" |
| 60 | + cluster.createAccountAndVerify(acct, cluster.eosioAccount) |
| 61 | + node.publishContract(acct, f"unittests/test-contracts/{contract_name}", f"{contract_name}.wasm", f"{contract_name}.abi", waitForTransBlock=True) |
| 62 | + |
| 63 | + Print("Create accounts and publish contracts") |
| 64 | + deployContract("caller", "sync_caller"); |
| 65 | + deployContract("callee", "sync_callee"); |
| 66 | + deployContract("callee1", "sync_callee1"); |
| 67 | + |
| 68 | + Print("Create snapshot"); |
| 69 | + ret=node.createSnapshot() |
| 70 | + assert ret is not None, "Snapshot creation failed" |
| 71 | + |
| 72 | + Print("Stopping snapshot"); |
| 73 | + node.kill(signal.SIGTERM) |
| 74 | + assert not node.verifyAlive(), "Node did not shutdown" |
| 75 | + |
| 76 | + node.removeState() |
| 77 | + node.removeReversibleBlks() |
| 78 | + |
| 79 | + Print("Restart from snapshot"); |
| 80 | + isRelaunchSuccess=node.relaunch(chainArg=f"--snapshot {node.getLatestSnapshot()}") |
| 81 | + assert isRelaunchSuccess, "node relaunch from snapshot failed" |
| 82 | + |
| 83 | + Print("Push a transaction containing 2-levels of a nested sync call"); |
| 84 | + trx={"actions": [{"account": "caller", "name": "nestedcalls", "authorization": [{"actor": "caller","permission": "active"}], "data": {}}]} |
| 85 | + results=node.pushTransaction(trx) |
| 86 | + assert results[0], "pushTransaction failed" |
| 87 | + |
| 88 | + testSuccessful=True |
| 89 | +finally: |
| 90 | + TestHelper.shutdown(cluster, walletMgr, testSuccessful=testSuccessful, dumpErrorDetails=dumpErrorDetails) |
| 91 | + |
| 92 | +exitCode=0 if testSuccessful else 1 |
| 93 | +exit(exitCode) |
0 commit comments