diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4e934ea28..a4d7473da 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -173,3 +173,59 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} fail_ci_if_error: true + + examples: + name: Run examples using Node ${{ matrix.node }} + runs-on: hiero-client-sdk-linux-medium + strategy: + matrix: + node: [ "20" ] + steps: + - name: Harden Runner + uses: step-security/harden-runner@cb605e52c26070c328afc4562f0b4ada7618a84e # v2.10.4 + with: + egress-policy: audit + + - name: Checkout Code + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + submodules: recursive + + - name: Install Task + uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0 + with: + version: 3.35.1 + + - name: Install PNPM + uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0 + with: + version: 8.15.4 + + - name: Setup Node + uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + with: + node-version: ${{ matrix.node }} + cache: pnpm + + - name: Build @hashgraph/sdk + id: build-sdk + run: task build + + - name: Start the local node + id: start-local-node + if: ${{ !cancelled() && always() }} + run: | + ${{ env.CG_EXEC }} npx @hashgraph/hedera-local start -d -—network local --balance=100000 --network-tag=0.57.0 + sleep 30 + + - name: Install dependencies + run: | + cd examples + pnpm i + + - name: Run all еxamples + run: task run:examples + - name: Stop the local node + id: stop-local-node + if: ${{ steps.start-local-node.conclusion == 'success' && !cancelled() && always() }} + run: ${{ env.CG_EXEC }} npx @hashgraph/hedera-local stop diff --git a/examples/create-contract-with-value.js b/examples/create-contract-with-value.js index 58b871033..c293a505e 100644 --- a/examples/create-contract-with-value.js +++ b/examples/create-contract-with-value.js @@ -13,7 +13,7 @@ import dotenv from "dotenv"; dotenv.config(); // Import the compiled contract -import payableContract from "./payable.json" assert { type: "json" }; +import payableContract from "./payable.json" with { type: "json" }; async function main() { if ( @@ -126,7 +126,7 @@ async function main() { .freezeWithSigner(wallet); await contractDeleteTransaction.signWithSigner(wallet); const contractDeleteResult = - await transaction.executeWithSigner(wallet); + await contractDeleteTransaction.executeWithSigner(wallet); // Delete the contract // Note: The admin key of the contract needs to sign the transaction diff --git a/examples/create-simple-contract.js b/examples/create-simple-contract.js index 0d2afc15e..e7e74d943 100644 --- a/examples/create-simple-contract.js +++ b/examples/create-simple-contract.js @@ -13,7 +13,7 @@ import dotenv from "dotenv"; dotenv.config(); // Import the compiled contract -import helloWorld from "./hello_world.json" assert { type: "json" }; +import helloWorld from "./hello_world.json" with { type: "json" }; async function main() { if ( diff --git a/examples/create-stateful-contract.js b/examples/create-stateful-contract.js index 057238a81..16b3cedf0 100644 --- a/examples/create-stateful-contract.js +++ b/examples/create-stateful-contract.js @@ -14,7 +14,7 @@ import dotenv from "dotenv"; dotenv.config(); // Import the compiled contract -import stateful from "./stateful.json" assert { type: "json" }; +import stateful from "./stateful.json" with { type: "json" }; async function main() { if ( @@ -70,7 +70,7 @@ async function main() { ), ) // Set gas to create the contract - .setGas(100000) + .setGas(150000) // The contract bytecode must be set to the file ID containing the contract bytecode .setBytecodeFileId(fileId) // Set the admin key on the contract in case the contract should be deleted or @@ -150,7 +150,7 @@ async function main() { .freezeWithSigner(wallet); await contractExecuteTransaction.signWithSigner(wallet); const contractExecTransactionResponse = - await transaction.executeWithSigner(wallet); + await contractExecuteTransaction.executeWithSigner(wallet); await contractExecTransactionResponse.getReceiptWithSigner(wallet); diff --git a/examples/exempt-custom-fees.js b/examples/exempt-custom-fees.js index 75db4e55b..5351307b5 100644 --- a/examples/exempt-custom-fees.js +++ b/examples/exempt-custom-fees.js @@ -74,7 +74,7 @@ async function main() { const firstAccountWallet = new Wallet( firstAccountId, firstAccountPrivateKey, - new LocalProvider(), + provider, ); let secondAccountPrivateKey = PrivateKey.generateED25519(); @@ -93,7 +93,7 @@ async function main() { const secondAccountWallet = new Wallet( secondAccountId, secondAccountPrivateKey, - new LocalProvider(), + provider, ); let thirdAccountPrivateKey = PrivateKey.generateED25519(); @@ -112,7 +112,7 @@ async function main() { const thirdAccountWallet = new Wallet( thirdAccountId, thirdAccountPrivateKey, - new LocalProvider(), + provider, ); /** diff --git a/examples/long-term-schedule-transaction.js b/examples/long-term-schedule-transaction.js index 62aa27913..ec1d2f28c 100644 --- a/examples/long-term-schedule-transaction.js +++ b/examples/long-term-schedule-transaction.js @@ -204,6 +204,7 @@ async function main() { ); console.log("Long Term Scheduled Transaction Example Complete!"); + client.close(); } main().catch(console.error); diff --git a/examples/mint-big-number-of-units-of-token.js b/examples/mint-big-number-of-units-of-token.js index 40c0caf84..bf244fec6 100644 --- a/examples/mint-big-number-of-units-of-token.js +++ b/examples/mint-big-number-of-units-of-token.js @@ -14,7 +14,7 @@ import dotenv from "dotenv"; dotenv.config(); async function main() { - const operatorKey = PrivateKey.fromStringECDSA(process.env.OPERATOR_KEY); + const operatorKey = PrivateKey.fromStringED25519(process.env.OPERATOR_KEY); const operatorId = AccountId.fromString(process.env.OPERATOR_ID); const client = Client.forName(process.env.HEDERA_NETWORK).setOperator( diff --git a/examples/mirror-node-contract-queries-example.js b/examples/mirror-node-contract-queries-example.js index 0e3200685..8190cf793 100644 --- a/examples/mirror-node-contract-queries-example.js +++ b/examples/mirror-node-contract-queries-example.js @@ -93,6 +93,8 @@ async function main() { const decodedStringMessage = decodedSimulationResult[0]; console.log("Simulation result: " + decodedStringMessage); console.log("Contract call result: " + result.getString(0)); + + client.close(); } void main(); diff --git a/examples/run-all-examples.js b/examples/run-all-examples.js index da0182d71..a01be874b 100644 --- a/examples/run-all-examples.js +++ b/examples/run-all-examples.js @@ -12,7 +12,11 @@ const excludedDirectories = [ "./react-native-example", "./simple_rest_signature_provider", ]; -const excludedJSFile = "run-all-examples.js"; +const excludedJSFile = [ + "run-all-examples.js", + "consensus-pub-sub.js", + "create-update-delete-node.js", +]; const cmd = process.env.NODE_COMMAND; fs.readdir(examplesDirectory, (err, files) => { @@ -36,7 +40,7 @@ fs.readdir(examplesDirectory, (err, files) => { const examples = files.filter( (file) => file.endsWith(".js") && - file !== excludedJSFile && + !excludedJSFile.includes(file) && excludedDirectories.some( (directory) => !isPathStartsWith(directory, file), ), @@ -57,7 +61,7 @@ fs.readdir(examplesDirectory, (err, files) => { console.log(`✅ Successfully executed.`); } else { failed += 1; - console.error(`❌ Failed.`); + throw new Error("Task failed"); } }); diff --git a/examples/solidity-precompile-example.js b/examples/solidity-precompile-example.js index 90be64ef2..7e294f89e 100644 --- a/examples/solidity-precompile-example.js +++ b/examples/solidity-precompile-example.js @@ -1,6 +1,6 @@ import * as hashgraph from "@hashgraph/sdk"; import ContractHelper from "./ContractHelper.js"; -import contract from "./precompile-example/PrecompileExample.json" assert { type: "json" }; +import contract from "./precompile-example/PrecompileExample.json" with { type: "json" }; import dotenv from "dotenv"; dotenv.config(); @@ -24,7 +24,7 @@ async function main() { provider, ); - const operatorPrivateKey = hashgraph.PrivateKey.fromStringDer( + const operatorPrivateKey = hashgraph.PrivateKey.fromStringED25519( process.env.OPERATOR_KEY, ); const operatorPublicKey = operatorPrivateKey.publicKey; @@ -50,7 +50,7 @@ async function main() { const walletWithAlice = new hashgraph.Wallet( aliceAccountId, alicePrivateKey, - new hashgraph.LocalProvider(), + provider, ); // Instantiate ContractHelper @@ -207,9 +207,9 @@ async function main() { console.log("All steps completed with valid results."); } catch (error) { console.error(error); + } finally { + provider.close(); } - - provider.close(); } void main(); diff --git a/examples/zeroTokenOperations.js b/examples/zeroTokenOperations.js index 4f390a661..987029a9d 100644 --- a/examples/zeroTokenOperations.js +++ b/examples/zeroTokenOperations.js @@ -2,7 +2,7 @@ import * as hashgraph from "@hashgraph/sdk"; import ContractHelper from "./ContractHelper.js"; -import contract from "./precompile-example/ZeroTokenOperations.json" assert { type: "json" }; +import contract from "./precompile-example/ZeroTokenOperations.json" with { type: "json" }; import dotenv from "dotenv"; dotenv.config();