diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 878572c..a54fb94 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,3 +12,21 @@ jobs: name: Test uses: ./.github/workflows/test-reusable.yml secrets: inherit + + # integration-tests: + # name: Integration Tests + # runs-on: ubuntu-latest + # steps: + # - name: Checkout + # uses: actions/checkout@v4 + + # - name: Setup Node.js + # uses: actions/setup-node@v2 + # with: + # node-version: '14' + + # - name: Install dependencies + # run: npm install + + # - name: Run integration tests + # run: npm test diff --git a/examples/README.md b/examples/README.md index 046dc7b..2024a42 100644 --- a/examples/README.md +++ b/examples/README.md @@ -282,4 +282,14 @@ To run an example, you need to make the required changes to the code and use typ ```bash cd examples ts-node -r tsconfig-paths/register create_deployment.ts -``` \ No newline at end of file +``` + +## Running Integration Tests + +To verify the functionality of the examples, integration tests have been added. You can run these tests using the following command: + +```bash +npm test +``` + +The integration tests will execute each example and verify their output to ensure they are valid and functional. diff --git a/examples/get_deployments.ts b/examples/get_deployments.ts index 50f1a2c..9bf58d0 100644 --- a/examples/get_deployments.ts +++ b/examples/get_deployments.ts @@ -4,15 +4,19 @@ import { getRpc } from "@akashnetwork/akashjs/build/rpc"; async function main() { const request = QueryDeploymentsRequest.fromJSON({ filters: { - owner: "akashSomeOwnerAddress" + owner: "akash1qqzwc5d7hynl67nsmn9jukvwqp3vzdl6j2t7lk" } }); - const client = new QueryClientImpl(await getRpc("http://your.rpc.node")); - const response = await client.Deployments(request); - const data = QueryDeploymentsResponse.toJSON(response); + const client = new QueryClientImpl(await getRpc("https://rpc.akashnet.net:443")); - console.log(data); + try { + const response = await client.Deployments(request); + const data = QueryDeploymentsResponse.toJSON(response); + console.log(data); + } catch (error) { + console.error("Error fetching deployments:", error); + } } main(); diff --git a/examples/get_lease_status.ts b/examples/get_lease_status.ts index 119b231..20c9385 100644 --- a/examples/get_lease_status.ts +++ b/examples/get_lease_status.ts @@ -2,22 +2,25 @@ import { QueryClientImpl, QueryLeaseRequest, QueryLeaseResponse } from "@akashne import { getRpc } from "@akashnetwork/akashjs/build/rpc"; async function main() { - const client = new QueryClientImpl(await getRpc("http://your.rpc.node")); + const client = new QueryClientImpl(await getRpc("https://rpc.akashnet.net:443")); const getLeaseStatusRequest = QueryLeaseRequest.fromPartial({ id: { - owner: "akashSomeOwnerAddress", - provider: "akashSomeProviderAddress", - dseq: 1111, // deployment dseq + owner: "akash1qqzwc5d7hynl67nsmn9jukvwqp3vzdl6j2t7lk", + provider: "akash1t6r5v7h8j9k0l1m2n3p4q5r6s7t8u9v0w1x2y3", + dseq: 123456, // deployment dseq gseq: 1, // most of the time the value is 1 oseq: 1 // most of the time the value is 1 } }); - const leaseStatusResponse = await client.Lease(getLeaseStatusRequest); - const data = QueryLeaseResponse.toJSON(leaseStatusResponse); - - console.log(data); + try { + const leaseStatusResponse = await client.Lease(getLeaseStatusRequest); + const data = QueryLeaseResponse.toJSON(leaseStatusResponse); + console.log(data); + } catch (error) { + console.error("Error fetching lease status:", error); + } } main(); diff --git a/tests/test_examples.ts b/tests/test_examples.ts new file mode 100644 index 0000000..7152831 --- /dev/null +++ b/tests/test_examples.ts @@ -0,0 +1,77 @@ +import tap from "tap"; +import { exec } from "child_process"; +import path from "path"; + +const examplesDir = path.resolve(__dirname, "../examples"); + +const runExample = (exampleFile: string) => { + return new Promise((resolve, reject) => { + exec(`ts-node -r tsconfig-paths/register ${exampleFile}`, { cwd: examplesDir }, (error, stdout, stderr) => { + if (error) { + reject(stderr); + } else { + resolve(stdout); + } + }); + }); +}; + +tap.test("should run create_deployment example without errors", async t => { + t.plan(1); + const output = await runExample("create_deployment.ts"); + t.has(output, "Service tetris is available at:"); +}); + +tap.test("should run create_wallet example without errors", async t => { + t.plan(1); + const output = await runExample("create_wallet.ts"); + t.has(output, "akash"); +}); + +tap.test("should run details_of_single_provider example without errors", async t => { + t.plan(1); + const output = await runExample("details_of_single_provider.ts"); + t.has(output, "owner"); +}); + +tap.test("should run estimate_gas example without errors", async t => { + t.plan(1); + const output = await runExample("estimate_gas.ts"); + t.has(output, "gas"); +}); + +tap.test("should run get_deployments example without errors", async t => { + t.plan(1); + const output = await runExample("get_deployments.ts"); + t.has(output, "deployments"); +}); + +tap.test("should run get_lease_status example without errors", async t => { + t.plan(1); + const output = await runExample("get_lease_status.ts"); + t.has(output, "lease"); +}); + +tap.test("should run list_all_providers example without errors", async t => { + t.plan(1); + const output = await runExample("list_all_providers.ts"); + t.has(output, "providers"); +}); + +tap.test("should run signed_message example without errors", async t => { + t.plan(1); + const output = await runExample("signed_message.ts"); + t.has(output, "test message"); +}); + +tap.test("should run signed_msg_send example without errors", async t => { + t.plan(1); + const output = await runExample("signed_msg_send.ts"); + t.has(output, "send funds with akashjs"); +}); + +tap.test("should run take_down_deployment example without errors", async t => { + t.plan(1); + const output = await runExample("take_down_deployment.ts"); + t.has(output, "take down deployment"); +});