Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated examples and add integration tests #103

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 11 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
```

## 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.
14 changes: 9 additions & 5 deletions examples/get_deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
19 changes: 11 additions & 8 deletions examples/get_lease_status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
77 changes: 77 additions & 0 deletions tests/test_examples.ts
Original file line number Diff line number Diff line change
@@ -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");
});