github.com/kchristidis/fabric@v1.0.4-0.20171028114726-837acd08cde1/test/regression/daily/testAuctionChaincode.py (about) 1 # 2 # Copyright IBM Corp. All Rights Reserved. 3 # 4 # SPDX-License-Identifier: Apache-2.0 5 # 6 7 #!/usr/bin/python 8 # -*- coding: utf-8 -*- 9 10 ###################################################################### 11 # To execute: 12 # Install: sudo apt-get install python python-pytest 13 # Run on command line: py.test -v --junitxml results_auction_daily.xml testAuctionChaincode.py 14 15 import subprocess 16 import unittest 17 from subprocess import check_output 18 import shutil 19 20 21 class ChaincodeAPI(unittest.TestCase): 22 23 @classmethod 24 def setUpClass(cls): 25 cls.CHANNEL_NAME = 'channel' 26 cls.CHANNELS = '2' 27 cls.CHAINCODES = '1' 28 cls.ENDORSERS = '4' 29 cls.RUN_TIME_HOURS = '1' 30 check_output(['./generateCfgTrx.sh {0} {1}'.format(cls.CHANNEL_NAME, cls.CHANNELS)], cwd='../../envsetup', shell=True) 31 check_output(['docker-compose -f docker-compose.yaml up -d'], cwd='../../envsetup', shell=True) 32 33 @classmethod 34 def tearDownClass(cls): 35 check_output(['docker-compose -f docker-compose.yaml down'], cwd='../../envsetup', shell=True) 36 delete_this = ['__pycache__', '.cache'] 37 for item in delete_this: 38 shutil.rmtree(item) 39 40 ################################################################################# 41 42 def runIt(self, command, scriptName): 43 cmd = \ 44 '/opt/gopath/src/github.com/hyperledger/fabric/test/tools/AuctionApp/%s %s %s %s %s %s %s' \ 45 % ( 46 scriptName, 47 self.CHANNEL_NAME, 48 self.CHANNELS, 49 self.CHAINCODES, 50 self.ENDORSERS, 51 self.RUN_TIME_HOURS, 52 command, 53 ) 54 output = \ 55 check_output(['docker exec cli bash -c "{0}"'.format(cmd)], 56 shell=True) 57 return output 58 59 def test_FAB3934_1_Create_Channel(self): 60 ''' 61 Network: 1 Ord, 2 Org, 4 Peers, 2 Chan, 1 CC 62 Description: This test is used to creates channels 63 Passing criteria: Creating Channel is successful 64 ''' 65 output = self.runIt('createChannel', 'api_driver.sh') 66 self.assertIn('Creating Channel is successful', output) 67 68 69 def test_FAB3934_2_Join_Channel(self): 70 ''' 71 Network: 1 Ord, 2 Org, 4 Peers, 2 Chan, 1 CC 72 Description: This test is used to join peers on all channels 73 Passing criteria: Join Channel is successful 74 ''' 75 output = self.runIt('joinChannel', 'api_driver.sh') 76 self.assertIn('Join Channel is successful', output) 77 78 79 def test_FAB3934_3_Install_Chaincode(self): 80 ''' 81 Network: 1 Ord, 2 Org, 4 Peers, 2 Chan, 1 CC 82 Description: This test is used to install all chaincodes on all peers 83 Passing criteria: Installing chaincode is successful 84 ''' 85 output = self.runIt('installChaincode', 'api_driver.sh') 86 self.assertIn('Installing chaincode is successful', output) 87 88 89 def test_FAB3934_4_Instantiate_Chaincode(self): 90 ''' 91 Network: 1 Ord, 2 Org, 4 Peers, 2 Chan, 1 CC 92 Description: This test is used to instantiate all chaincodes on all channels 93 Passing criteria: Instantiating chaincode is successful 94 ''' 95 output = self.runIt('instantiateChaincode', 'api_driver.sh') 96 self.assertIn('Instantiating chaincode is successful', output) 97 98 99 def test_FAB3934_5_Post_Users(self): 100 ''' 101 Network: 1 Ord, 2 Org, 4 Peers, 2 Chan, 1 CC 102 Description: This test is used to submit users to the auction application 103 Passing criteria: Posting Users transaction is successful 104 ''' 105 output = self.runIt('postUsers', 'api_driver.sh') 106 self.assertIn('Posting Users transaction is successful', output) 107 108 109 def test_FAB3934_6_Get_Users(self): 110 ''' 111 Network: 1 Ord, 2 Org, 4 Peers, 2 Chan, 1 CC 112 Description: This test is used to query users submitted to the auction application 113 Passing criteria: Get Users transaction is successful 114 ''' 115 output = self.runIt('getUsers', 'api_driver.sh') 116 self.assertIn('Get Users transaction is successful', output) 117 118 def test_FAB3934_7_Download_Images(self): 119 ''' 120 Network: 1 Ord, 2 Org, 4 Peers, 2 Chan, 1 CC 121 Description: This test is used to download auction images on all chaincode containers 122 Passing criteria: Download Images transaction is successful 123 ''' 124 output = self.runIt('downloadImages', 'api_driver.sh') 125 self.assertIn('Download Images transaction is successful', 126 output) 127 128 129 def test_FAB3934_8_Post_Items(self): 130 ''' 131 Network: 1 Ord, 2 Org, 4 Peers, 2 Chan, 1 CC 132 Description: This test is used to submit auction items for a user to the auction application 133 Passing criteria: Post Items transaction is successful 134 ''' 135 output = self.runIt('postItems', 'api_driver.sh') 136 self.assertIn('Post Items transaction is successful', output) 137 138 139 def test_FAB3934_9_Auction_Invoke(self): 140 ''' 141 Network: 1 Ord, 2 Org, 4 Peers, 2 Chan, 1 CC 142 Description: This test runs for 1 Hr. It is used to open auction on the submitted items, 143 submit bids to the auction, close auction and finally transfer item to a user. 144 Passing criteria: Open Auction/Submit Bids/Close Auction/Transfer Item transaction(s) are successful 145 ''' 146 output = self.runIt('auctionInvokes', 'api_driver.sh') 147 self.assertIn('Open Auction/Submit Bids/Close Auction/Transfer Item transaction(s) are successful' 148 , output)