mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
Sample apps should exit code 1 upon failure (#1003)
Ensure that all sample applications return exit code 1 upon failure so that github actions can report the failure. Signed-off-by: David Enyeart <enyeart@us.ibm.com>
This commit is contained in:
parent
00c561457f
commit
75b8419113
6 changed files with 22 additions and 10 deletions
4
.github/workflows/test-network-gateway.yaml
vendored
4
.github/workflows/test-network-gateway.yaml
vendored
|
|
@ -28,8 +28,8 @@ jobs:
|
|||
- name: Set up the test network runtime
|
||||
uses: ./.github/actions/test-network-setup
|
||||
|
||||
- name: Run Test Network Off Chain
|
||||
- name: Run Test
|
||||
working-directory: test-network
|
||||
env:
|
||||
CHAINCODE_LANGUAGE: ${{ matrix.chaincode-language }}
|
||||
run: ../ci/scripts/run-test-network-gateway.sh
|
||||
run: ../ci/scripts/run-test-network-gateway.sh
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ public class App {
|
|||
}
|
||||
catch(Exception e){
|
||||
System.err.println(e);
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,6 +242,7 @@ async function main() {
|
|||
}
|
||||
} catch (error) {
|
||||
console.error(`******** FAILED to run the application: ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('*** application ending');
|
||||
|
|
|
|||
|
|
@ -192,6 +192,7 @@ async function main() {
|
|||
console.log('*** Result: committed, now asset will only require Org1 to endorse');
|
||||
} catch (createError) {
|
||||
console.log(`*** Failed: create - ${createError}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await readAssetByBothOrgs(assetKey, 100, org1, contractOrg1, contractOrg2);
|
||||
|
|
@ -207,6 +208,7 @@ async function main() {
|
|||
console.log('*** Result: committed');
|
||||
} catch (updateError) {
|
||||
console.log(`*** Failed: update - ${updateError}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await readAssetByBothOrgs(assetKey, 200, org1, contractOrg1, contractOrg2);
|
||||
|
|
@ -223,6 +225,7 @@ async function main() {
|
|||
console.log('*** Result: committed - because Org1 and Org2 both endorsed, while only the Org1 endorsement was required and checked');
|
||||
} catch (updateError) {
|
||||
console.log(`*** Failed: update - ${updateError}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await readAssetByBothOrgs(assetKey, 300, org1, contractOrg1, contractOrg2);
|
||||
|
|
@ -236,6 +239,7 @@ async function main() {
|
|||
console.log('*** Result: committed - because Org1 was on the discovery list, Org2 did not endorse');
|
||||
} catch (updateError) {
|
||||
console.log(`*** Failed: update - ${updateError}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await readAssetByBothOrgs(assetKey, 400, org1, contractOrg1, contractOrg2);
|
||||
|
|
@ -263,6 +267,7 @@ async function main() {
|
|||
console.log('*** Result: committed');
|
||||
} catch (transferError) {
|
||||
console.log(`*** Failed: transfer - ${transferError}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await readAssetByBothOrgs(assetKey, 400, org2, contractOrg1, contractOrg2);
|
||||
|
|
@ -277,6 +282,7 @@ async function main() {
|
|||
console.log('*** Result: committed');
|
||||
} catch (updateError) {
|
||||
console.log(`*** Failed: update - ${updateError}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await readAssetByBothOrgs(assetKey, 600, org2, contractOrg1, contractOrg2);
|
||||
|
|
@ -317,6 +323,7 @@ async function main() {
|
|||
console.log('*** Result: committed');
|
||||
} catch (deleteError) {
|
||||
console.log(`*** Failed: delete - ${deleteError}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// The asset should now be deleted, both orgs should not be able to read it
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ async function main(): Promise<void> {
|
|||
try {
|
||||
await contractWrapperOrg2.getAssetPrivateProperties(assetKey, mspIdOrg1);
|
||||
} catch(e) {
|
||||
console.log(`${RED}*** Failed: getAssetPrivateProperties - ${e}${RESET}`);
|
||||
console.log(`${RED}*** Successfully caught the failure: getAssetPrivateProperties - ${e}${RESET}`);
|
||||
}
|
||||
|
||||
// Org1 updates the assets public description.
|
||||
|
|
@ -94,7 +94,7 @@ async function main(): Promise<void> {
|
|||
ownerOrg: mspIdOrg1,
|
||||
publicDescription: `Asset ${assetKey} owned by ${mspIdOrg2} is NOT for sale`});
|
||||
} catch(e) {
|
||||
console.log(`${RED}*** Failed: changePublicDescription - ${e}${RESET}`);
|
||||
console.log(`${RED}*** Successfully caught the failure: changePublicDescription - ${e}${RESET}`);
|
||||
}
|
||||
|
||||
// Read the public details by org1.
|
||||
|
|
@ -126,14 +126,14 @@ async function main(): Promise<void> {
|
|||
try{
|
||||
await contractWrapperOrg2.getAssetSalesPrice(assetKey, mspIdOrg1);
|
||||
} catch(e) {
|
||||
console.log(`${RED}*** Failed: getAssetSalesPrice - ${e}${RESET}`);
|
||||
console.log(`${RED}*** Successfully caught the failure: getAssetSalesPrice - ${e}${RESET}`);
|
||||
}
|
||||
|
||||
// Org1 has not agreed to buy so this should fail.
|
||||
try{
|
||||
await contractWrapperOrg1.getAssetBidPrice(assetKey, mspIdOrg2);
|
||||
} catch(e) {
|
||||
console.log(`${RED}*** Failed: getAssetBidPrice - ${e}${RESET}`);
|
||||
console.log(`${RED}*** Successfully caught the failure: getAssetBidPrice - ${e}${RESET}`);
|
||||
}
|
||||
// Org2 should be able to see the price it has agreed.
|
||||
await contractWrapperOrg2.getAssetBidPrice(assetKey, mspIdOrg2);
|
||||
|
|
@ -143,7 +143,7 @@ async function main(): Promise<void> {
|
|||
try{
|
||||
await contractWrapperOrg1.transferAsset({ assetId: assetKey, price: 110, tradeId: now}, [ mspIdOrg1, mspIdOrg2 ], mspIdOrg1, mspIdOrg2);
|
||||
} catch(e) {
|
||||
console.log(`${RED}*** Failed: transferAsset - ${e}${RESET}`);
|
||||
console.log(`${RED}*** Successfully caught the failure: transferAsset - ${e}${RESET}`);
|
||||
}
|
||||
// Agree to a sell by Org1, the seller will agree to the bid price of Org2.
|
||||
await contractWrapperOrg1.agreeToSell({assetId:assetKey, price:100, tradeId:now});
|
||||
|
|
@ -168,7 +168,7 @@ async function main(): Promise<void> {
|
|||
try{
|
||||
await contractWrapperOrg2.transferAsset({ assetId: assetKey, price: 100, tradeId: now}, [ mspIdOrg1, mspIdOrg2 ], mspIdOrg1, mspIdOrg2);
|
||||
} catch(e) {
|
||||
console.log(`${RED}*** Failed: transferAsset - ${e}${RESET}`);
|
||||
console.log(`${RED}*** Successfully caught the failure: transferAsset - ${e}${RESET}`);
|
||||
}
|
||||
|
||||
// Org1 will transfer the asset to Org2.
|
||||
|
|
@ -188,7 +188,7 @@ async function main(): Promise<void> {
|
|||
try{
|
||||
await contractWrapperOrg1.getAssetPrivateProperties(assetKey, mspIdOrg2);
|
||||
} catch(e) {
|
||||
console.log(`${RED}*** Failed: getAssetPrivateProperties - ${e}${RESET}`);
|
||||
console.log(`${RED}*** Successfully caught the failure: getAssetPrivateProperties - ${e}${RESET}`);
|
||||
}
|
||||
|
||||
// This is an update to the public state and requires only the owner to endorse.
|
||||
|
|
|
|||
|
|
@ -165,4 +165,7 @@ function envOrDefault(key: string, defaultValue: string): string {
|
|||
return process.env[key] || defaultValue;
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
main().catch(error => {
|
||||
console.error('******** FAILED to run the application:', error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue