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

Commit

Permalink
Finished Test Case #1.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianjohnson5972 committed Apr 23, 2021
1 parent 7f3ca45 commit 40adba0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 67 deletions.
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ add_test(NAME light_validation_sync_test COMMAND tests/light_validation_sync_tes
set_property(TEST light_validation_sync_test PROPERTY LABELS nonparallelizable_tests)
add_test(NAME eosio_blocklog_prune_test COMMAND tests/eosio_blocklog_prune_test.py -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST eosio_blocklog_prune_test PROPERTY LABELS nonparallelizable_tests)
add_test(NAME privacy_startup_network COMMAND tests/privacy_startup_network.py -p 1 -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
add_test(NAME privacy_startup_network COMMAND tests/privacy_startup_network.py -p 2 -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST privacy_startup_network PROPERTY LABELS nonparallelizable_tests)
add_test(NAME privacy_simple_network COMMAND tests/privacy_simple_network.py -p 2 -n 3 -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_property(TEST privacy_simple_network PROPERTY LABELS nonparallelizable_tests)
Expand Down
3 changes: 2 additions & 1 deletion tests/SecurityGroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def __init__(self, nonParticipants, contractAccount, defaultNode=None, minAddRem
self.participants = []
self.contractAccount = contractAccount
assert len(nonParticipants) > 0
self.nonParticipants = copy.copy(nonParticipants)
# copy over all the running processes
self.nonParticipants = [x for x in nonParticipants if x.pid]
if Utils.Debug: Utils.Print("Creating SecurityGroup with the following nonParticipants: []".format(SecurityGroup.createAction(self.nonParticipants)))
self.defaultNode = defaultNode if defaultNode else nonParticipants[0]
self.publishProcessNum = minAddRemEntriesToPublish
Expand Down
93 changes: 28 additions & 65 deletions tests/privacy_startup_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from Node import ReturnType
from TestHelper import TestHelper

import copy
import decimal
import re
import signal
Expand Down Expand Up @@ -36,8 +37,10 @@
apiNodes=2 # minimum number of apiNodes that will be used in this test
minTotalNodes=pnodes+relayNodes+apiNodes
totalNodes=args.n if args.n >= minTotalNodes else minTotalNodes
if totalNodes > minTotalNodes:
if totalNodes >= minTotalNodes:
apiNodes += totalNodes - minTotalNodes
else:
Utils.Print("Requested {} total nodes, but since the minumum number of API nodes is {}, there will be {} total nodes".format(args.n, apiNodes, totalNodes))

Utils.Debug=args.v
dumpErrorDetails=args.dump_error_details
Expand Down Expand Up @@ -74,8 +77,12 @@
apiNodeNums = [x for x in range(firstApiNodeNum, totalNodes)]
for producerNum in range(pnodes):
pairedRelayNodeNum = pnodes + producerNum
# p2p connection between producer and relay
topo[producerNum] = [pairedRelayNodeNum]
topo[pairedRelayNodeNum] = apiNodeNums
# p2p connections between relays
topo[pairedRelayNodeNum] = [x + producerNum for x in range(pnodes) if x != producerNum]
# p2p connections between relay and all api nodes
topo[pairedRelayNodeNum].extend(apiNodeNums)
Utils.Print("topo: {}".format(json.dumps(topo, indent=4, sort_keys=True)))

# adjust prodCount to ensure that lib trails more than 1 block behind head
Expand All @@ -94,69 +101,25 @@
relays = [cluster.getNode(pnodes + x) for x in range(pnodes) ]
apiNodes = [cluster.getNode(x) for x in apiNodeNums]

def createAccount(newAcc):
producers[0].createInitializeAccount(newAcc, cluster.eosioAccount)
ignWallet = cluster.walletMgr.create("ignition") # will actually just look up the wallet
cluster.walletMgr.importKey(newAcc, ignWallet)

numAccounts = 4
testAccounts = Cluster.createAccountKeys(numAccounts)
accountPrefix = "testaccount"
for i in range(numAccounts):
testAccount = testAccounts[i]
testAccount.name = accountPrefix + str(i + 1)
createAccount(testAccount)

blockProducer = None

def verifyInSync(producerNum):
Utils.Print("Ensure all nodes are in-sync")
lib = producers[producerNum].getInfo()["last_irreversible_block_num"]
headBlockNum = producers[producerNum].getBlockNum()
headBlock = producers[producerNum].getBlock(headBlockNum)
global blockProducer
if blockProducer is None:
blockProducer = headBlock["producer"]
Utils.Print("headBlock: {}".format(json.dumps(headBlock, indent=4, sort_keys=True)))
headBlockId = headBlock["id"]
for prod in producers:
if prod == producers[producerNum]:
continue

assert prod.waitForBlock(headBlockNum, timeout = 10, reportInterval = 1) != None, "Producer node failed to get block number {}".format(headBlockNum)
prod.getBlock(headBlockId) # if it isn't there it will throw an exception
assert prod.waitForBlock(lib, blockType=BlockType.lib), \
"Producer node is failing to advance its lib ({}) with producer {} ({})".format(node.getInfo()["last_irreversible_block_num"], producerNum, lib)
for node in apiNodes:
assert node.waitForBlock(headBlockNum, timeout = 10, reportInterval = 1) != None, "API node failed to get block number {}".format(headBlockNum)
node.getBlock(headBlockId) # if it isn't there it will throw an exception
assert node.waitForBlock(lib, blockType=BlockType.lib), \
"API node is failing to advance its lib ({}) with producer {} ({})".format(node.getInfo()["last_irreversible_block_num"], producerNum, lib)

Utils.Print("Ensure all nodes are in-sync")
assert node.waitForBlock(lib + 1, blockType=BlockType.lib, reportInterval = 1) != None, "Producer node failed to advance lib ahead one block to: {}".format(lib + 1)

verifyInSync(producerNum=0)

featureDict = producers[0].getSupportedProtocolFeatureDict()
Utils.Print("feature dict: {}".format(json.dumps(featureDict, indent=4, sort_keys=True)))

Utils.Print("act feature dict: {}".format(json.dumps(producers[0].getActivatedProtocolFeatures(), indent=4, sort_keys=True)))
timeout = ( pnodes * 12 / 2 ) * 2 # (number of producers * blocks produced / 0.5 blocks per second) * 2 rounds
producers[0].waitUntilBeginningOfProdTurn(blockProducer, timeout=timeout)
feature = "SECURITY_GROUP"
producers[0].activateFeatures([feature])
assert producers[0].containsFeatures([feature]), "{} feature was not activated".format(feature)

if sanityTest:
testSuccessful=True
exit(0)

def publishContract(account, wasmFile, waitForTransBlock=False):
Print("Publish contract")
return producers[0].publishContract(account, "unittests/test-contracts/security_group_test/", wasmFile, abiFile=None, waitForTransBlock=waitForTransBlock)

publishContract(testAccounts[0], 'security_group_test.wasm', waitForTransBlock=True)
securityGroup = cluster.getSecurityGroup()
cluster.reportInfo()

Utils.Print("Add all producers and relay nodes to security group")
prodsAndRelays = copy.copy(producers)
prodsAndRelays.extend(relays)
securityGroup.editSecurityGroup(prodsAndRelays)
securityGroup.verifySecurityGroup()

allButLastApiNodes = apiNodes[:-1]
lastApiNode = [apiNodes[-1]]

Utils.Print("Add all but last API node and verify they receive blocks and the last API node does not")
securityGroup.editSecurityGroup(addNodes=allButLastApiNodes)
securityGroup.verifySecurityGroup()

Utils.Print("Add the last API node and verify it receives blocks")
securityGroup.editSecurityGroup(addNodes=lastApiNode)
securityGroup.verifySecurityGroup()

testSuccessful=True
finally:
Expand Down

0 comments on commit 40adba0

Please sign in to comment.