Skip to content

Commit 308e7bf

Browse files
authored
Merge pull request #74 from algorandfoundation/chore/api-client-snapshots
chore: commit algod api clients
2 parents 2eea8b4 + a246c32 commit 308e7bf

File tree

285 files changed

+57831
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

285 files changed

+57831
-223
lines changed

.github/workflows/api_clients_ci.yml

+24-27
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,30 @@ jobs:
2626
working-directory: api
2727
run: bun install
2828

29-
- name: Generate TypeScript client
29+
- name: Generate algod clients
3030
working-directory: api
31-
run: bun run scripts/generate-algod-clients.ts --target typescript
31+
run: bun run generate:algod:all
3232

33-
- name: Upload TypeScript client
33+
- name: Check generated clients have been reviewed
34+
shell: bash
35+
run: |
36+
# Add untracked files as empty so they come up in diff
37+
git add -N ./packages/**/algod_api
38+
# Look for changes in generated templates and error if there are any
39+
git diff --exit-code --minimal ./packages/**/algod_api
40+
41+
- name: Upload algod TypeScript client
3442
uses: actions/upload-artifact@v4
3543
with:
3644
name: algokit-algod-api-ts
37-
path: api/api_clients/typescript
45+
path: packages/typescript/algod_api
3846
retention-days: 1
3947

40-
- name: Generate Python client
41-
working-directory: api
42-
run: bun run scripts/generate-algod-clients.ts --target python
43-
44-
- name: Upload Python client
48+
- name: Upload algod Python client
4549
uses: actions/upload-artifact@v4
4650
with:
4751
name: algokit-algod-api-py
48-
path: api/api_clients/python
52+
path: packages/python/algod_api
4953
retention-days: 1
5054

5155
algokit-algod-api-ts:
@@ -63,33 +67,26 @@ jobs:
6367
with:
6468
bun-version: latest
6569

66-
- name: Download TypeScript client
70+
- name: Download algod TypeScript client
6771
uses: actions/download-artifact@v4
6872
with:
6973
name: algokit-algod-api-ts
70-
path: api/api_clients/typescript
74+
path: packages/typescript/algod_api
7175

7276
- name: Install AlgoKit
7377
run: pipx install algokit
7478

7579
- name: Start localnet
7680
run: algokit localnet start
7781

78-
- name: Setup Node.js
79-
uses: actions/setup-node@v4
80-
with:
81-
node-version: 20
82-
cache: "npm"
83-
cache-dependency-path: "api/api_clients/typescript/package.json"
84-
8582
- name: Build TypeScript ffi package
8683
run: bun scripts/build ${{ env.CRATE }} typescript
8784

88-
- name: Test TypeScript client
89-
working-directory: api/api_clients/typescript
85+
- name: Test algod TypeScript client
86+
working-directory: packages/typescript/algod_api
9087
run: |
91-
npm install
92-
npm run test
88+
bun install
89+
bun run test
9390
9491
algokit-algod-api-py:
9592
needs: setup
@@ -101,11 +98,11 @@ jobs:
10198
with:
10299
toolchain: 1.85.0
103100

104-
- name: Download Python client
101+
- name: Download algod Python client
105102
uses: actions/download-artifact@v4
106103
with:
107104
name: algokit-algod-api-py
108-
path: api/api_clients/python
105+
path: packages/typescript/algod_api
109106

110107
- name: Install AlgoKit
111108
run: pipx install algokit
@@ -121,8 +118,8 @@ jobs:
121118
with:
122119
python-version: "3.10"
123120

124-
- name: Test Python client
125-
working-directory: api/api_clients/python
121+
- name: Test algod Python client
122+
working-directory: packages/python/algod_api
126123
run: |
127124
poetry install
128125
poetry run pytest

api/.gitignore

-2
This file was deleted.

api/README.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,13 @@ The converted spec will be available at `specs/algod.oas3.json`.
3131
Generates TypeScript and Python API clients based on the OpenAPI spec:
3232

3333
```bash
34-
bun run generate-algod-clients
35-
# or
36-
bun run scripts/generate-algod-clients.ts --target {python|typescript}
34+
bun run generate:{algod}:{py|ts}
3735
```
3836

39-
The generated clients will be available in the `../generated/` directory:
37+
The generated API clients will be available in the `./packages/` directory:
4038

41-
- `../generated/typescript/` - TypeScript client
42-
- `../generated/python/` - Python client
39+
- `./packages/typescript/algod_api/` - algod TypeScript client
40+
- `./packages/python/algod_api/` - algod Python client
4341

4442
## OpenAPI Specs for algorand apis
4543

@@ -53,14 +51,14 @@ The client generation is configured with the following options:
5351

5452
### TypeScript Client
5553

56-
- Package name: `@algorandfoundation/algokit-algod-api-ts`
54+
- Package name: `@algorandfoundation/algokit-algod-api`
5755
- ES6 support: true
5856
- Manually refined tsconfig setup to build cjs, esm clients along with browser support.
5957
- Custom tests defined in `oas_templates/typescript/custom-tests/` that implement tests for initial batch of transaction endpoints. More endpoint tests are to be added in the future.
6058

6159
### Python Client
6260

63-
- Package name: `algokit_algod_api_py`
61+
- Package name: `algokit_algod_api`
6462
- Ignoring various unneeded supporting files like tox.ini, git_push.sh, etc.
6563
- Various improvements to make auto generated code compatible with poetry and more modern python conventions and practices.
6664
- Custom tests defined in `oas_templates/python/custom-tests/` that implement tests for initial batch of transaction endpoints. More endpoint tests are to be added in the future.

api/oas_templates/python/custom_tests/test_transactions.mustache

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import base64
1010
from algosdk.encoding import msgpack_decode
1111
from algosdk.transaction import SignedTransaction
1212

13-
from algokit_algod_api_py.api.algod_api import AlgodApi
14-
from algokit_algod_api_py.exceptions import ApiException
15-
from algokit_algod_api_py.models.transaction_params200_response import TransactionParams200Response
13+
from algokit_algod_api.api.algod_api import AlgodApi
14+
from algokit_algod_api.exceptions import ApiException
15+
from algokit_algod_api.models.transaction_params200_response import TransactionParams200Response
1616
from algokit_transact import (
1717
encode_transaction,
1818
TransactionType,

api/oas_templates/python/openapi-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
templateDir: oas_templates/python
22
additionalProperties:
33
packageVersion: 0.1.0
4-
packageName: algokit_algod_api_py
4+
packageName: algokit_algod_api
55

66
openapiNormalizer:
77
SET_TAGS_FOR_ALL_OPERATIONS: Algod
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
import { describe, test, expect, beforeAll } from 'vitest';
2-
import { algorandFixture } from '@algorandfoundation/algokit-utils/testing';
3-
import * as algosdk from 'algosdk';
4-
import * as algodPackage from '@algorandfoundation/algokit-algod-api-ts';
5-
import { encodeTransaction, Transaction, Address } from 'algokit_transact';
6-
import { Blob } from 'buffer';
7-
import { HttpFile } from '../http/http';
8-
import { TransactionSignerAccount } from '@algorandfoundation/algokit-utils/types/account';
1+
import { describe, test, expect, beforeAll } from "vitest";
2+
import { algorandFixture } from "@algorandfoundation/algokit-utils/testing";
3+
import * as algosdk from "algosdk";
4+
import * as algodPackage from "@algorandfoundation/algokit-algod-api";
5+
import { encodeTransaction, Transaction, Address } from "algokit_transact";
6+
import { Blob } from "buffer";
7+
import { HttpFile } from "../http/http";
8+
import { TransactionSignerAccount } from "@algorandfoundation/algokit-utils/types/account";
99

1010
// Helper function to create and sign a transaction, then return it as an HttpFile
1111
const createSignedTxnHttpFile = (
1212
sender: algosdk.Address & TransactionSignerAccount & algosdk.Account,
1313
receiver: Address,
1414
amount: number | bigint,
1515
apiSuggestedParams: algodPackage.TransactionParams200Response,
16-
note?: Uint8Array
16+
note?: Uint8Array,
1717
): HttpFile => {
1818
const transactionHeaderParams = {
1919
fee: BigInt(apiSuggestedParams.minFee || apiSuggestedParams.fee),
2020
firstValid: BigInt(apiSuggestedParams.lastRound),
2121
lastValid: BigInt(apiSuggestedParams.lastRound) + BigInt(1000),
22-
genesisHash: new Uint8Array(Buffer.from(apiSuggestedParams.genesisHash, 'base64')),
22+
genesisHash: new Uint8Array(Buffer.from(apiSuggestedParams.genesisHash, "base64")),
2323
genesisId: apiSuggestedParams.genesisId,
24-
}
24+
};
2525

2626
const txn: Transaction = {
27-
transactionType: 'Payment',
27+
transactionType: "Payment",
2828
payment: {
2929
amount: BigInt(amount),
3030
receiver: receiver,
@@ -38,81 +38,76 @@ const createSignedTxnHttpFile = (
3838
const algosdkTxn = algosdk.decodeUnsignedTransaction(Buffer.from(encodedTxn.slice(2)));
3939
const signedTxnBytes = algosdkTxn.signTxn(sender.sk);
4040

41-
const binaryData = new Blob([signedTxnBytes], { type: 'application/x-binary' });
41+
const binaryData = new Blob([signedTxnBytes], { type: "application/x-binary" });
4242
// @ts-ignore - we know this matches the HttpFile structure
4343
// TODO: find more elegant way to do this
44-
const httpFile: HttpFile = Object.assign(binaryData, { name: 'transaction.txn' });
44+
const httpFile: HttpFile = Object.assign(binaryData, { name: "transaction.txn" });
4545
return httpFile;
4646
};
4747

48-
describe('Transaction API Tests', () => {
48+
describe("Transaction API Tests", () => {
4949
const fixture = algorandFixture();
5050
let algodApi: algodPackage.AlgodApi;
5151
5252
beforeAll(async () => {
5353
await fixture.newScope();
5454
const authConfig: algodPackage.AuthMethodsConfiguration = {
55-
"api_key": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
56-
}
57-
const serverConfig = new algodPackage.ServerConfiguration('http://localhost:4001', {})
55+
api_key: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
56+
};
57+
const serverConfig = new algodPackage.ServerConfiguration("http://localhost:4001", {});
5858
const configurationParameters = {
59-
httpApi: new algodPackage.IsomorphicFetchHttpLibrary(),
60-
baseServer: serverConfig,
61-
authMethods: authConfig,
62-
promiseMiddleware: [],
63-
}
59+
httpApi: new algodPackage.IsomorphicFetchHttpLibrary(),
60+
baseServer: serverConfig,
61+
authMethods: authConfig,
62+
promiseMiddleware: [],
63+
};
6464
const config = algodPackage.createConfiguration(configurationParameters);
6565
algodApi = new algodPackage.AlgodApi(config);
6666
});
6767

68-
test('should get transaction parameters', async () => {
68+
test("should get transaction parameters", async () => {
6969
const params = await algodApi.transactionParams();
7070
expect(params).toBeDefined();
71-
expect(params.consensusVersion).toBeTypeOf('string');
72-
expect(params.fee).toBeTypeOf('number');
73-
expect(params.genesisHash).toBeTypeOf('string');
74-
expect(params.genesisId).toBeTypeOf('string');
75-
expect(params.lastRound).toBeTypeOf('number');
76-
expect(params.minFee).toBeTypeOf('number');
71+
expect(params.consensusVersion).toBeTypeOf("string");
72+
expect(params.fee).toBeTypeOf("number");
73+
expect(params.genesisHash).toBeTypeOf("string");
74+
expect(params.genesisId).toBeTypeOf("string");
75+
expect(params.lastRound).toBeTypeOf("number");
76+
expect(params.minFee).toBeTypeOf("number");
7777
});
7878

79-
test('should submit a raw transaction', async () => {
79+
test("should submit a raw transaction", async () => {
8080
const { testAccount: sender } = fixture.context;
8181
const suggestedParams = await algodApi.transactionParams();
8282

83-
const httpFile = createSignedTxnHttpFile(
84-
sender,
85-
{ address: String(sender.addr), pubKey: sender.publicKey },
86-
100000,
87-
suggestedParams
88-
);
83+
const httpFile = createSignedTxnHttpFile(sender, { address: String(sender.addr), pubKey: sender.publicKey }, 100000, suggestedParams);
8984

9085
const result = await algodApi.rawTransaction(httpFile);
9186
expect(result).not.toBeNull();
9287
expect(result?.txId).toBeDefined();
9388
});
9489

95-
test('should get pending transaction info', async () => {
96-
const { testAccount: sender } = fixture.context;
97-
const suggestedParams = await algodApi.transactionParams();
98-
const note = new Uint8Array(Buffer.from('pending test'));
90+
test("should get pending transaction info", async () => {
91+
const { testAccount: sender } = fixture.context;
92+
const suggestedParams = await algodApi.transactionParams();
93+
const note = new Uint8Array(Buffer.from("pending test"));
9994

100-
const httpFile = createSignedTxnHttpFile(
101-
sender,
102-
{ address: String(sender.addr), pubKey: sender.publicKey },
103-
100000,
104-
suggestedParams,
105-
note
106-
);
95+
const httpFile = createSignedTxnHttpFile(
96+
sender,
97+
{ address: String(sender.addr), pubKey: sender.publicKey },
98+
100000,
99+
suggestedParams,
100+
note,
101+
);
107102

108-
const submitResult = await algodApi.rawTransaction(httpFile);
109-
expect(submitResult.txId).toBeDefined();
103+
const submitResult = await algodApi.rawTransaction(httpFile);
104+
expect(submitResult.txId).toBeDefined();
110105

111-
await new Promise(resolve => setTimeout(resolve, 100));
106+
await new Promise((resolve) => setTimeout(resolve, 100));
112107

113-
const pendingTxnsResult = await algodApi.getPendingTransactions(10);
114-
expect(pendingTxnsResult).toBeDefined();
108+
const pendingTxnsResult = await algodApi.getPendingTransactions(10);
109+
expect(pendingTxnsResult).toBeDefined();
115110
});
116111

117112
// TODO: Add more tests based on other endpoints in AlgodApi related to transactions
118-
});
113+
});

api/oas_templates/typescript/openapi-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
templateDir: oas_templates/typescript
22
additionalProperties:
33
npmVersion: 0.0.1
4-
npmName: "@algorandfoundation/algokit-algod-api-ts"
4+
npmName: "@algorandfoundation/algokit-algod-api"
55
supportsES6: true
66
useRxJS: false
77
platform: browser

api/oas_templates/typescript/package.mustache

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "OpenAPI-Generator Contributors",
66
"repository": {
77
"type": "git",
8-
"url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
8+
"url": "https://github.com/algorandfoundation/algokit-core.git"
99
},
1010
"keywords": [
1111
"fetch",
@@ -45,19 +45,19 @@
4545
],
4646
"scripts": {
4747
"test": "vitest",
48-
"build": "npm run clean && npm run build:esm && npm run build:cjs",
48+
"build": "bun run clean && bun run build:esm && bun run build:cjs",
4949
"build:esm": "tsc -p tsconfig.esm.json",
5050
"build:cjs": "tsc -p tsconfig.cjs.json",
5151
"clean": "rimraf dist",
52-
"prepare": "npm run build"
52+
"prepare": "bun run build"
5353
},
5454
"dependencies": {
5555
"whatwg-fetch": "^3.0.0",
5656
"es6-promise": "^4.2.4"
5757
},
5858
"devDependencies": {
5959
"@algorandfoundation/algokit-utils": "^9.0.1",
60-
"algokit_transact": "file:../../../packages/typescript/algokit_transact",
60+
"algokit_transact": "file:../algokit_transact",
6161
"algosdk": "^3.2.0",
6262
"rimraf": "^6.0.1",
6363
"typescript": "^5.0.0",

api/package.json

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
"private": true,
66
"scripts": {
77
"generate": "openapi-generator-cli generate",
8-
"generate-algod-clients": "bun run scripts/generate-algod-clients.ts",
9-
"convert-openapi": "bun run scripts/convert-openapi.ts"
8+
"generate:algod": "bun generate:algod:all",
9+
"generate:algod:all": "bun scripts/generate-clients.ts algod all",
10+
"generate:algod:ts": "bun scripts/generate-clients.ts algod typescript",
11+
"generate:algod:py": "bun scripts/generate-clients.ts algod python",
12+
"convert-openapi": "bun scripts/convert-openapi.ts"
1013
},
1114
"devDependencies": {
1215
"@openapitools/openapi-generator-cli": "2.19.1",
@@ -17,4 +20,4 @@
1720
"peerDependencies": {
1821
"typescript": "^5"
1922
}
20-
}
23+
}

0 commit comments

Comments
 (0)