Skip to content

Commit abc81af

Browse files
[FAB-3934] Daily Test Runs for Auction App
Client Driver: testAuctionChainCode.py, api_driver.sh. Following transactions are performed on Auction App --Post Users --Get Users --Download Images --Get Items --Post Auction --Open Auction For Bids --Submit Bids --Transfer Item Change-Id: I8c5967588d87f1a4507288a0e6a694c26fc70e99 Signed-off-by: sandp125 <[email protected]>
1 parent 897ca82 commit abc81af

File tree

6 files changed

+718
-511
lines changed

6 files changed

+718
-511
lines changed

test/envsetup/channel-artifacts/.gitkeep

Whitespace-only changes.

test/envsetup/docker-compose.yaml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#
2+
# Copyright IBM Corp. All Rights Reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
version: '2'
8+
9+
services:
10+
11+
orderer.example.com:
12+
extends:
13+
file: base/docker-compose-base.yaml
14+
service: orderer.example.com
15+
container_name: orderer.example.com
16+
17+
peer0.org1.example.com:
18+
container_name: peer0.org1.example.com
19+
extends:
20+
file: base/docker-compose-base.yaml
21+
service: peer0.org1.example.com
22+
23+
peer1.org1.example.com:
24+
container_name: peer1.org1.example.com
25+
extends:
26+
file: base/docker-compose-base.yaml
27+
service: peer1.org1.example.com
28+
29+
peer0.org2.example.com:
30+
container_name: peer0.org2.example.com
31+
extends:
32+
file: base/docker-compose-base.yaml
33+
service: peer0.org2.example.com
34+
35+
peer1.org2.example.com:
36+
container_name: peer1.org2.example.com
37+
extends:
38+
file: base/docker-compose-base.yaml
39+
service: peer1.org2.example.com
40+
41+
cli:
42+
container_name: cli
43+
image: hyperledger/fabric-tools
44+
tty: true
45+
environment:
46+
- GOPATH=/opt/gopath
47+
- CORE_VM_ENDPOINT=unix:///host/var/run/docker.sock
48+
- CORE_LOGGING_LEVEL=DEBUG
49+
- CORE_PEER_ID=cli
50+
- CORE_PEER_ADDRESS=peer0.org1.example.com:7051
51+
- CORE_PEER_LOCALMSPID=Org1MSP
52+
- CORE_PEER_TLS_ENABLED=true
53+
- CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
54+
- CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
55+
- CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
56+
- CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp
57+
working_dir: /opt/gopath/src/github.com/hyperledger/fabric/peer
58+
command: /bin/bash -c 'apt-get update && apt-get install -y jq; sleep 600000000000'
59+
volumes:
60+
- /var/run/:/host/var/run/
61+
- ../../../../../examples/chaincode/go:/opt/gopath/src/github.com/hyperledger/fabric/examples/chaincode/go
62+
- ./channel-artifacts:/opt/gopath/src/github.com/hyperledger/fabric/peer/channel-artifacts
63+
- ./crypto-config:/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto
64+
- ./logs:/opt/gopath/src/github.com/hyperledger/fabric/test/envsetup/logs
65+
- ../tools:/opt/gopath/src/github.com/hyperledger/fabric/test/tools
66+
- ../chaincodes:/opt/gopath/src/github.com/hyperledger/fabric/test/chaincodes
67+
depends_on:
68+
- orderer.example.com
69+
- peer0.org1.example.com
70+
- peer1.org1.example.com
71+
- peer0.org2.example.com
72+
- peer1.org2.example.com

test/envsetup/generateCfgTrx.sh

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/bin/bash
2+
#
3+
# Copyright IBM Corp. All Rights Reserved.
4+
#
5+
# SPDX-License-Identifier: Apache-2.0
6+
#
7+
8+
set -e
9+
10+
CHANNEL_NAME=$1
11+
CHANNEL_COUNT=$2
12+
13+
: ${CHANNEL_NAME:="mychannel"}
14+
: ${CHANNEL_COUNT:="1"}
15+
16+
export FABRIC_ROOT=$GOPATH/src/github.com/hyperledger/fabric
17+
export E2E_CLI_PATH=$FABRIC_ROOT/examples/e2e_cli/
18+
cp $E2E_CLI_PATH/configtx.yaml $PWD
19+
cp $E2E_CLI_PATH/crypto-config.yaml ./crypto-config.yaml
20+
cp -r $E2E_CLI_PATH/base $PWD/
21+
sed -i 's/e2ecli/envsetup/g' base/peer-base.yaml
22+
export FABRIC_CFG_PATH=$PWD
23+
24+
ARTIFACTS=./channel-artifacts
25+
OS_ARCH=$(echo "$(uname -s)-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
26+
27+
echo "Channel name - "$CHANNEL_NAME
28+
echo "Total channels - "$CHANNEL_COUNT
29+
echo
30+
31+
CONFIGTXGEN=$(which configtxgen || /bin/true)
32+
33+
## Generates Org certs using cryptogen tool
34+
function generateCerts() {
35+
CRYPTOGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/cryptogen
36+
37+
if [ -f "$CRYPTOGEN" ]; then
38+
echo "Using cryptogen -> $CRYPTOGEN"
39+
else
40+
echo "Building cryptogen"
41+
make -C $FABRIC_ROOT release-all
42+
fi
43+
44+
echo
45+
echo "**** Generate certificates using cryptogen tool ****"
46+
$CRYPTOGEN generate --config=./crypto-config.yaml
47+
echo
48+
}
49+
50+
## Generate orderer genesis block , channel configuration transaction and anchor peer update transactions
51+
function generateChannelArtifacts() {
52+
53+
CONFIGTXGEN=$FABRIC_ROOT/release/$OS_ARCH/bin/configtxgen
54+
if [ -f "$CONFIGTXGEN" ]; then
55+
echo "Using configtxgen -> $CONFIGTXGEN"
56+
else
57+
echo "Building configtxgen"
58+
make -C $FABRIC_ROOT release-all
59+
fi
60+
61+
echo "Generating genesis block"
62+
$CONFIGTXGEN -profile TwoOrgsOrdererGenesis -outputBlock $ARTIFACTS/genesis.block
63+
64+
for ((i = 0; $i < $CHANNEL_COUNT; i++)); do
65+
echo "Generating channel configuration transaction for channel '$CHANNEL_NAME$i'"
66+
$CONFIGTXGEN -profile TwoOrgsChannel -outputCreateChannelTx $ARTIFACTS/channel$i.tx -channelID $CHANNEL_NAME$i
67+
68+
echo "Generating anchor peer update for Org1MSP"
69+
$CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate $ARTIFACTS/Org1MSPanchors$i.tx -channelID $CHANNEL_NAME$i -asOrg Org1MSP
70+
71+
echo "Generating anchor peer update for Org2MSP"
72+
$CONFIGTXGEN -profile TwoOrgsChannel -outputAnchorPeersUpdate $ARTIFACTS/Org2MSPanchors$i.tx -channelID $CHANNEL_NAME$i -asOrg Org2MSP
73+
done
74+
}
75+
76+
generateCerts
77+
generateChannelArtifacts
78+
79+
echo "######################### DONE ######################"

test/regression/daily/runDailyTestSuite.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# SPDX-License-Identifier: Apache-2.0
66
#
77

8-
98
DAILYDIR="$GOPATH/src/github.com/hyperledger/fabric/test/regression/daily"
109

1110
#echo "========== Sample Tests..."
@@ -21,3 +20,6 @@ cd -
2120

2221
echo "========== Ledger component performance tests..."
2322
py.test -v --junitxml results_ledger_lte.xml ledger_lte.py
23+
24+
echo "========== Test Auction Chaincode ..."
25+
py.test -v --junitxml results_auction_daily.xml testAuctionChaincode.py
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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)

0 commit comments

Comments
 (0)