-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from subspace/3-setup-basic-function-to-connect…
…-to-the-rpc-consensus Setup basic function to connect to the rpc consensus
- Loading branch information
Showing
25 changed files
with
5,373 additions
and
725 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Build | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
name: Build all packages and run tests | ||
steps: | ||
- name: Checkout 🛎️ | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '18' | ||
|
||
- name: Enable Corepack | ||
run: corepack enable | ||
|
||
- name: Set Yarn version to Berry | ||
run: corepack prepare [email protected] --activate | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Build auto-utils package 🔧 | ||
run: yarn workspace @autonomys/auto-utils build | ||
|
||
- name: Build all packages 🔧 | ||
run: yarn build | ||
|
||
- name: Run tests 🧪 | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Autonomys Auto SDK Monorepo | ||
|
||
This monorepo contains multiple packages for the Autonomys Auto SDK, including utility, consensus and identity functions. | ||
|
||
## Structure | ||
|
||
The repository is organized as follows: | ||
|
||
- `packages/auto-utils`: Utility functions for the SDK. | ||
- `packages/auto-consensus`: Consensus functions. | ||
- `packages/auto-id`: Identity functions. | ||
|
||
## Requirements | ||
|
||
- Node.js | ||
- Yarn 2 (Berry) or later | ||
|
||
## Setup | ||
|
||
1. **Clone the repository:** | ||
|
||
`git clone https://github.com/subspace/auto-sdk.git` | ||
|
||
2. **Navigate to the project directory:** | ||
|
||
`cd auto-sdk` | ||
|
||
3. **Set Yarn to use the Berry version:** | ||
|
||
`yarn set version berry` | ||
|
||
4. **Install dependencies:** | ||
|
||
`yarn install` | ||
|
||
## Scripts | ||
|
||
### Build | ||
|
||
To build all packages: | ||
|
||
`yarn build` | ||
|
||
### Test | ||
|
||
To run tests for all packages: | ||
|
||
`yarn test` | ||
|
||
## Workspaces | ||
|
||
This project uses Yarn workspaces. Packages are located in the `packages` directory. Each package can have its own dependencies and build scripts. | ||
|
||
## License | ||
|
||
This project is licensed under the MIT License. See the LICENSE file for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,12 +7,13 @@ | |
"packages/*" | ||
], | ||
"scripts": { | ||
"build": "yarn workspaces run build", | ||
"test": "yarn workspaces run test" | ||
"build": "yarn workspaces foreach --all run build", | ||
"test": "yarn workspaces foreach --all run test" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^8.57.0", | ||
"prettier": "^3.2.5", | ||
"typescript": "^5.4.5" | ||
} | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { activate, disconnect } from '@autonomys/auto-utils' | ||
import { totalIssuance } from '../src/balances' | ||
|
||
describe('Verify balances functions', () => { | ||
beforeAll(async () => { | ||
await activate() | ||
}) | ||
|
||
afterAll(async () => { | ||
await disconnect() | ||
}) | ||
|
||
test('Check totalIssuance return a number greater than zero', async () => { | ||
// totalIssuance is an async function that returns a hex number as a string | ||
const rawIssuance = await totalIssuance() | ||
// Convert the hex number to a BigInt | ||
const issuance = BigInt(rawIssuance.toString()) | ||
// Check if the issuance is greater than zero | ||
expect(issuance).toBeGreaterThan(BigInt(0)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { activate, disconnect } from '@autonomys/auto-utils' | ||
import { currentTimestamp } from '../src/info' | ||
|
||
describe('Verify info functions', () => { | ||
beforeAll(async () => { | ||
await activate() | ||
}) | ||
|
||
afterAll(async () => { | ||
await disconnect() | ||
}) | ||
|
||
test('Check timestamp return a number greater than zero', async () => { | ||
// totalIssuance is an async function that returns a hex number as a string | ||
const rawTimestamp = await currentTimestamp() | ||
// Convert the hex number to a BigInt | ||
const timestamp = BigInt(rawTimestamp.toString()) | ||
// Check if the issuance is greater than zero | ||
expect(timestamp).toBeGreaterThan(BigInt(0)) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { activate } from '@autonomys/auto-utils' | ||
|
||
export const totalIssuance = async (networkId?: string) => { | ||
// Get the api instance for the network | ||
const api = await activate({ networkId }) | ||
|
||
// Get the current total token issuance | ||
const totalIssuance = await api.query.balances.totalIssuance() | ||
|
||
return totalIssuance | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export const helloWorld = () => { | ||
console.log('Hello World'); | ||
}; | ||
export * from './balances' | ||
export * from './info' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { activate } from '@autonomys/auto-utils' | ||
|
||
export const currentTimestamp = async (networkId?: string) => { | ||
// Get the api instance for the network | ||
const api = await activate({ networkId }) | ||
|
||
// Get the current timestamp | ||
const timestamp = await api.query.timestamp.now() | ||
|
||
return timestamp | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": "./src" | ||
}, | ||
"include": ["src/**/*"], | ||
|
||
} | ||
|
||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"rootDir": "./src" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { defaultNetwork, networks } from '../src/constants/network' | ||
import { getNetworkDetails, getNetworkRpcUrls } from '../src/network' | ||
|
||
describe('Verify network functions', () => { | ||
const TEST_NETWORK = { networkId: networks[0].id } | ||
const TEST_INVALID_NETWORK = { networkId: 'invalid-network' } | ||
|
||
test('Check getNetworkDetails return all network detail', async () => { | ||
const network = getNetworkDetails() | ||
expect(network).toEqual(defaultNetwork) | ||
}) | ||
|
||
test('Check getNetworkRpcUrls return the network urls', async () => { | ||
const rpcUrls = getNetworkRpcUrls() | ||
expect(rpcUrls).toEqual(defaultNetwork.rpcUrls) | ||
}) | ||
|
||
test('Check getNetworkDetails return the network detail for a specific network', async () => { | ||
const rpcUrls = getNetworkDetails(TEST_NETWORK) | ||
expect(rpcUrls).toEqual(networks[0]) | ||
}) | ||
|
||
test('Check getNetworkRpcUrls return the network urls for a specific network', async () => { | ||
const rpcUrls = getNetworkRpcUrls(TEST_NETWORK) | ||
expect(rpcUrls).toEqual(networks[0].rpcUrls) | ||
}) | ||
|
||
test('Check getNetworkDetails return the network urls for an invalid network', async () => { | ||
expect(() => getNetworkDetails(TEST_INVALID_NETWORK)).toThrow( | ||
'Network with id invalid-network not found', | ||
) | ||
}) | ||
|
||
test('Check getNetworkRpcUrls return the network urls for an invalid network', async () => { | ||
expect(() => getNetworkRpcUrls(TEST_INVALID_NETWORK)).toThrow( | ||
'Network with id invalid-network not found', | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.