Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Add test for various chainbase objects which contain fields that require dynamic allocation #7320

Merged
merged 4 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nodeos_run_remote_test.py ${CMAKE_CUR
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nodeos_under_min_avail_ram.py ${CMAKE_CURRENT_BINARY_DIR}/nodeos_under_min_avail_ram.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nodeos_voting_test.py ${CMAKE_CURRENT_BINARY_DIR}/nodeos_voting_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nodeos_irreversible_mode_test.py ${CMAKE_CURRENT_BINARY_DIR}/nodeos_irreversible_mode_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nodeos_chainbase_allocation_test.py ${CMAKE_CURRENT_BINARY_DIR}/nodeos_chainbase_allocation_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nodeos_protocol_feature_test.py ${CMAKE_CURRENT_BINARY_DIR}/nodeos_protocol_feature_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/nodeos_multiple_version_protocol_feature_test.py ${CMAKE_CURRENT_BINARY_DIR}/nodeos_multiple_version_protocol_feature_test.py COPYONLY)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/consensus-validation-malicious-producers.py ${CMAKE_CURRENT_BINARY_DIR}/consensus-validation-malicious-producers.py COPYONLY)
Expand Down Expand Up @@ -111,6 +112,9 @@ set_property(TEST nodeos_under_min_avail_ram_lr_test PROPERTY LABELS long_runnin
add_test(NAME nodeos_irreversible_mode_lr_test COMMAND tests/nodeos_irreversible_mode_test.py -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST nodeos_irreversible_mode_lr_test PROPERTY LABELS long_running_tests)

add_test(NAME nodeos_chainbase_allocation_lr_test COMMAND tests/nodeos_chainbase_allocation_test.py -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST nodeos_chainbase_allocation_lr_test PROPERTY LABELS long_running_tests)

add_test(NAME nodeos_startup_catchup_lr_test COMMAND tests/nodeos_startup_catchup.py -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(nodeos_startup_catchup_lr_test PROPERTIES TIMEOUT 3000)
set_property(TEST nodeos_startup_catchup_lr_test PROPERTY LABELS long_running_tests)
Expand Down
5 changes: 5 additions & 0 deletions tests/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1570,3 +1570,8 @@ def modifyBuiltinPFSubjRestrictions(self, nodeId, featureCodename, subjectiveRes
protocolFeatureJson["subjective_restrictions"].update(subjectiveRestriction)
with open(jsonPath, "w") as f:
json.dump(protocolFeatureJson, f, indent=2)

# Require producer_api_plugin
def createSnapshot(self):
param = { }
return self.processCurlCmd("producer", "create_snapshot", json.dumps(param))
109 changes: 109 additions & 0 deletions tests/nodeos_chainbase_allocation_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/usr/bin/env python3

from testUtils import Utils, Account
from Cluster import Cluster
from TestHelper import TestHelper
from WalletMgr import WalletMgr
from Node import Node

import signal
import json
import time
import os
import filecmp

# Parse command line arguments
args = TestHelper.parse_args({"-v","--clean-run","--dump-error-details","--leave-running","--keep-logs"})
Utils.Debug = args.v
killAll=args.clean_run
dumpErrorDetails=args.dump_error_details
dontKill=args.leave_running
killEosInstances=not dontKill
killWallet=not dontKill
keepLogs=args.keep_logs

walletMgr=WalletMgr(True)
cluster=Cluster(walletd=True)
cluster.setWalletMgr(walletMgr)

testSuccessful = False
try:
TestHelper.printSystemInfo("BEGIN")
cluster.killall(allInstances=killAll)
cluster.cleanup()

# The following is the list of chainbase objects that need to be verified:
# - account_object (bootstrap)
# - code_object (bootstrap)
# - generated_transaction_object
# - global_property_object
# - key_value_object (bootstrap)
# - protocol_state_object (bootstrap)
# - permission_object (bootstrap)
# The bootstrap process has created account_object and code_object (by uploading the bios contract),
# key_value_object (token creation), protocol_state_object (preactivation feature), and permission_object
# (automatically taken care by the automatically generated eosio account)
assert cluster.launch(
pnodes=1,
prodCount=1,
totalProducers=1,
totalNodes=2,
useBiosBootFile=False,
loadSystemContract=False,
specificExtraNodeosArgs={
1:"--read-mode irreversible --plugin eosio::producer_api_plugin"})

producerNodeId = 0
irrNodeId = 1
producerNode = cluster.getNode(producerNodeId)
irrNode = cluster.getNode(irrNodeId)

# Create delayed transaction to create "generated_transaction_object"
cmd = "create account -j eosio sample EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV\
EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV --delay-sec 600 -p eosio"
trans = producerNode.processCleosCmd(cmd, cmd, silentErrors=False)
assert trans

# Schedule a new producer to trigger new producer schedule for "global_property_object"
newProducerAcc = Account("newprod")
newProducerAcc.ownerPublicKey = "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
newProducerAcc.activePublicKey = "EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV"
producerNode.createAccount(newProducerAcc, cluster.eosioAccount)

setProdsStr = '{"schedule": ['
setProdsStr += '{"producer_name":' + newProducerAcc.name + ',"block_signing_key":' + newProducerAcc.activePublicKey + '}'
setProdsStr += ']}'
cmd="push action -j eosio setprods '{}' -p eosio".format(setProdsStr)
trans = producerNode.processCleosCmd(cmd, cmd, silentErrors=False)
assert trans
setProdsBlockNum = int(trans["processed"]["block_num"])

# Wait until the block where set prods is executed become irreversible so the producer schedule
def isSetProdsBlockNumIrr():
return producerNode.getIrreversibleBlockNum() >= setProdsBlockNum
Utils.waitForBool(isSetProdsBlockNumIrr, timeout=30, sleepTime=0.1)
# Once it is irreversible, immediately pause the producer so the promoted producer schedule is not cleared
producerNode.processCurlCmd("producer", "pause", "")

producerNode.kill(signal.SIGTERM)

# Create the snapshot and rename it to avoid name conflict later on
res = irrNode.createSnapshot()
beforeShutdownSnapshotPath = res["snapshot_name"]
snapshotPathWithoutExt, snapshotExt = os.path.splitext(beforeShutdownSnapshotPath)
os.rename(beforeShutdownSnapshotPath, snapshotPathWithoutExt + "_before_shutdown" + snapshotExt)

# Restart irr node and ensure the snapshot is still identical
irrNode.kill(signal.SIGTERM)
isRelaunchSuccess = irrNode.relaunch(irrNodeId, "", timeout=5, cachePopen=True)
assert isRelaunchSuccess, "Fail to relaunch"
res = irrNode.createSnapshot()
afterShutdownSnapshotPath = res["snapshot_name"]
assert filecmp.cmp(beforeShutdownSnapshotPath, afterShutdownSnapshotPath), "snapshot is not identical"

testSuccessful = True
finally:
TestHelper.shutdown(cluster, walletMgr, testSuccessful, killEosInstances, killWallet, keepLogs, killAll, dumpErrorDetails)

exitCode = 0 if testSuccessful else 1
exit(exitCode)
7 changes: 1 addition & 6 deletions tests/nodeos_irreversible_mode_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from TestHelper import TestHelper
from testUtils import Account

import urllib.request
import re
import os
import time
Expand Down Expand Up @@ -46,10 +45,6 @@
cluster=Cluster(walletd=True)
cluster.setWalletMgr(walletMgr)

def makeSnapshot(nodeId):
req = urllib.request.Request("http://127.0.0.1:{}/v1/producer/create_snapshot".format(8888 + int(nodeId)))
urllib.request.urlopen(req)

def backupBlksDir(nodeId):
dataDir = Utils.getNodeDataDir(nodeId)
sourceDir = os.path.join(dataDir, "blocks")
Expand Down Expand Up @@ -353,7 +348,7 @@ def switchToSpecModeWithIrrModeSnapshot(nodeIdOfNodeToTest, nodeToTest):
# Relaunch in irreversible mode and create the snapshot
relaunchNode(nodeToTest, nodeIdOfNodeToTest, chainArg=" --read-mode irreversible")
confirmHeadLibAndForkDbHeadOfIrrMode(nodeToTest)
makeSnapshot(nodeIdOfNodeToTest)
nodeToTest.createSnapshot()
nodeToTest.kill(signal.SIGTERM)

# Start from clean data dir, recover back up blocks, and then relaunch with irreversible snapshot
Expand Down
1 change: 0 additions & 1 deletion tests/nodeos_protocol_feature_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def restartNode(node: Node, nodeId, chainArg=None, addOrSwapFlags=None):
cluster=Cluster(walletd=True)
cluster.setWalletMgr(walletMgr)

# List to contain the test result message
testSuccessful = False
try:
TestHelper.printSystemInfo("BEGIN")
Expand Down