Skip to content

Commit

Permalink
Error handling and other small improvements.
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Lebedev <[email protected]>
  • Loading branch information
thenswan committed Oct 18, 2023
1 parent 382a322 commit 7185d80
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Compile SDK
- name: Assemble SDK
run: ./gradlew :sdk:assemble
- name: Compile Examples
- name: Assemble Examples
run: ./gradlew :examples:assemble

- name: Start the local node
Expand All @@ -128,3 +128,6 @@ jobs:
- name: Run Examples
run: |
./gradlew :examples:runAllExamples
- name: Stop the local node
run: npx @hashgraph/hedera-local stop
2 changes: 1 addition & 1 deletion examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ task runAllExamples {
.filter { it.name.endsWith('Example.java') }
.map { it.name.replaceAll('\\.java$', '') }
.filter { !it.equals('ValidateChecksumExample') } // disabled this example, because it needs user input (but it WORKS)
.filter { !it.equals('ZeroTokenOperationsExample') } // doesn't work with hedera-local-node
.filter { !it.equals('ZeroTokenOperationsExample') } // doesn't work
.filter { !it.equals('SolidityPrecompileExample') } // doesn't work with hedera-local-node
.filter { !it.equals('ConsensusPubSubChunkedExample') } // doesn't work on CI
.toList()
Expand Down
12 changes: 6 additions & 6 deletions examples/src/main/java/AccountCreateWithHtsExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class AccountCreateWithHtsExample {
private AccountCreateWithHtsExample() {
}

public static void main(String[] args) throws NullPointerException, PrecheckStatusException, ReceiptStatusException, InterruptedException, TimeoutException {
public static void main(String[] args) throws Exception {
Client client = ClientHelper.forName(HEDERA_NETWORK);

// Defaults the operator account ID and key such that all generated transactions will be paid for
Expand Down Expand Up @@ -149,11 +149,11 @@ public static void main(String[] args) throws NullPointerException, PrecheckStat

System.out.println("The normal account ID of the given alias: " + accountId);

if (nftOwnerAccountId.equals(accountId))
if (nftOwnerAccountId.equals(accountId)) {
System.out.println("The NFT owner accountId matches the accountId created with the HTS");
else
System.out.println("The two account IDs does not match");

} else {
throw new Exception("The two account IDs does not match");
}

System.out.println("Example 2");

Expand Down Expand Up @@ -224,7 +224,7 @@ public static void main(String[] args) throws NullPointerException, PrecheckStat
if (tokenBalanceAccountId2 == 10)
System.out.println("Account is created successfully using HTS 'TransferTransaction'");
else
System.out.println("Creating account with HTS using public key alias failed");
throw new Exception("Creating account with HTS using public key alias failed");

client.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private AutoCreateAccountTransferTransactionExample() {
- Sign with the private key that corresponds to the public key on the hollow account
- Get the `AccountInfo` for the account and return the public key on the account to show it is a complete account
*/
public static void main(String[] args) throws PrecheckStatusException, TimeoutException, ReceiptStatusException, InterruptedException, IOException {
public static void main(String[] args) throws Exception {
Client client = ClientHelper.forName(HEDERA_NETWORK);

// Defaults the operator account ID and key such that all generated transactions will be paid for
Expand Down Expand Up @@ -111,7 +111,7 @@ public static void main(String[] args) throws PrecheckStatusException, TimeoutEx
if (((KeyList) accountInfo.key).isEmpty()) {
System.out.println("The newly created account is a hollow account");
} else {
System.out.println("Not a hollow account");
throw new Exception("Not a hollow account");
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private CreateAccountWithAliasAndReceiverSignatureRequiredExample() {
- Get the `AccountInfo` and show that the account has contractAccountId
*/
public static void main(String[] args)
throws PrecheckStatusException, TimeoutException, ReceiptStatusException, InterruptedException {
throws Exception {
Client client = ClientHelper.forName(HEDERA_NETWORK);

// Defaults the operator account ID and key such that all generated transactions will be paid for
Expand Down Expand Up @@ -84,7 +84,7 @@ public static void main(String[] args)
if (accountInfo.contractAccountId != null) {
System.out.println("The new account has alias " + accountInfo.contractAccountId);
} else {
System.out.println("The new account doesn't have alias");
throw new Exception("The new account doesn't have alias");
}
}
}
3 changes: 1 addition & 2 deletions examples/src/main/java/CreateSimpleContractExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ public static void main(String[] args)
.execute(client);

if (contractCallResult.errorMessage != null) {
System.out.println("error calling contract: " + contractCallResult.errorMessage);
return;
throw new Exception("error calling contract: " + contractCallResult.errorMessage);
}

String message = contractCallResult.getString(0);
Expand Down

0 comments on commit 7185d80

Please sign in to comment.