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

bun experiment #56

Open
wants to merge 1 commit 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Options:
<html>
<head>
<title>Monitoring</title>
<script src="https://unpkg.com/moonbeam-tools@0.0.50/dist/index.umd.js" charset="UTF-8" integrity="sha384-YEu5UHBQ2fazqqXdsvej6Xr0mhCfqIEbmdkWeu8nszY7ZI1jQys6yQwxGrfThIew" crossorigin="anonymous"></script>
<script src="https://unpkg.com/moonbeam-tools@0.0.50/dist/index.umd.js" charset="UTF-8" integrity="sha384-2pLKPKO9pi/6scqDkLqHeLZGc1eLLlRXNnF+gOIlqHdd7tJAW+uNr9iWuPGW+wO5" crossorigin="anonymous"></script>
<style>
body {
padding: 2rem;
Expand Down
Binary file added bun.lockb
Binary file not shown.
71 changes: 35 additions & 36 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,60 @@
"browser": "dist/index.umd.js",
"types": "dist/index.d.ts",
"dependencies": {
"@moonbeam-network/api-augment": "^0.2902.0",
"@polkadot/api": "^12.4.2",
"@moonbeam-network/api-augment": "^0.3200.2",
"@polkadot/api": "^14.2.1",
"@polkadot/apps-config": "^0.138.1",
"@polkadot/util": "^13.1.1",
"@polkadot/util-crypto": "^13.1.1",
"@polkadot/util": "^13.2.2",
"@polkadot/util-crypto": "^13.2.2",
"chalk": "^4.1.2",
"cli-progress": "^3.11.2",
"debug": "^4.3.4",
"cli-progress": "^3.12.0",
"debug": "^4.3.7",
"esbuild": "^0.13.15",
"humanize-number": "^0.0.2",
"inquirer": "^8.2.5",
"knex": "^2.3.0",
"inquirer": "^8.2.6",
"knex": "^2.5.1",
"lodash.isobject": "^3.0.2",
"lodash.mergewith": "^4.6.2",
"moment": "^2.29.4",
"moment": "^2.30.1",
"moment-parseplus": "^2.0.3",
"moonbeam-types-bundle": "^2.0.9",
"node-fetch": "2",
"moonbeam-types-bundle": "^2.0.10",
"node-fetch": "^2.7.0",
"p-map": "^4.0.0",
"p-queue": "^6.6.2",
"pg": "^8.8.0",
"pg": "^8.13.1",
"prettier": "3.2.5",
"pretty-bytes": "^5.6.0",
"rollup-plugin-esbuild": "^4.6.0",
"rollup-plugin-esbuild": "^4.10.3",
"rollup-plugin-preserve-shebangs": "^0.2.0",
"semver": "^7.3.8",
"solc": "^0.8.10",
"sqlite": "^4.0.25",
"sqlite3": "^5.1.1",
"table": "^6.8.0",
"ts-node": "^10.8.1",
"undici": "^5.11.0",
"viem": "^0.3.40",
"web3": "^1.6.0",
"semver": "^7.6.3",
"solc": "^0.8.28",
"sqlite": "^4.2.1",
"sqlite3": "^5.1.7",
"table": "^6.8.2",
"ts-node": "^10.9.2",
"undici": "^5.28.4",
"viem": "^0.3.50",
"web3": "^1.10.4",
"yargs": "^15.4.1"
},
"devDependencies": {
"@babel/core": "^7.15.8",
"@rollup/plugin-commonjs": "^21.0.0",
"@babel/core": "^7.26.0",
"@rollup/plugin-commonjs": "^21.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.5",
"@types/axios": "^0.14.0",
"@types/jest": "^29.2.0",
"@types/lodash.isobject": "^3.0.7",
"@types/lodash.mergewith": "^4.6.7",
"@types/yargs": "^15.0.15",
"@rollup/plugin-node-resolve": "^13.3.0",
"@types/axios": "^0.14.4",
"@types/jest": "^29.5.14",
"@types/lodash.isobject": "^3.0.9",
"@types/lodash.mergewith": "^4.6.9",
"@types/yargs": "^15.0.19",
"eslint": "^7.32.0",
"jest": "^29.2.1",
"jest": "^29.7.0",
"pkg": "^5.8.1",
"rollup": "^2.58.0",
"rollup": "^2.79.2",
"rollup-plugin-dts": "^4.2.3",
"ts-jest": "^29.0.3",
"tslib": "^2.4.0",
"typescript": "^4.7.4"
"ts-jest": "^29.2.5",
"tslib": "^2.8.0",
"typescript": "^4.9.5"
},
"overrides": {
"@polkadot/api": "$@polkadot/api",
Expand All @@ -85,7 +85,6 @@
"ws@3": "8"
},
"scripts": {
"test": "jest",
"dev": "rollup -c -w",
"build": "npm run build:libs && npm run build:bins && npm run build:readme",
"build:libs": "tsc -p tsconfig.json --emitDeclarationOnly && rollup -c && ./scripts/update-readme.sh",
Expand Down
53 changes: 23 additions & 30 deletions src/tools/auction-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,11 @@ import yargs from "yargs";
import "@polkadot/api-augment";

import { getApiFor } from "../utils/networks";
import { getAccountIdentity } from "../utils/monitoring";
import { BN } from "@polkadot/util";
import {
isBigInt,
isBn,
isHex,
isNumber,
isU8a,
u8aConcat,
u8aToBn,
u8aToHex,
u8aToU8a,
} from "@polkadot/util";

const argv = yargs(process.argv.slice(2))
.usage("Usage: $0")
.version("1.0.0")
.options({
url: {
type: "string",
description: "Relay Websocket url",
string: true,
demandOption: true,
},
para: {
type: "number",
description: "Para for which a lease exists",
},
}).argv;

type AuctionInfo = {
duration: Number;
Expand All @@ -44,7 +20,7 @@ function addSeconds(date, seconds) {
return date;
}

async function calculateTimestamp(api, futureblock: number) {
export async function calculateTimestamp(api, futureblock: number) {
let currentBlock = (await api.rpc.chain.getHeader()).number.toNumber();
let timestamp = (await api.query.timestamp.now()).toNumber();

Expand All @@ -56,12 +32,12 @@ async function calculateTimestamp(api, futureblock: number) {
return [futureDate.getTime(), futureDate];
}

async function calculateCurrentLeasePeriod(api, leasePeriod, leaseOffset) {
export async function calculateCurrentLeasePeriod(api, leasePeriod, leaseOffset) {
let currentBlock = (await api.rpc.chain.getHeader()).number.toNumber();
return (currentBlock - leaseOffset) / leasePeriod;
}

const main = async () => {
const main = async (argv) => {
const api = await getApiFor(argv);

const scheduled = await api.query.scheduler.agenda.entries();
Expand Down Expand Up @@ -203,13 +179,30 @@ const main = async () => {
await api.disconnect();
};

async function start() {
if (require.main === module) {
const argv = yargs(process.argv.slice(2))
.usage("Usage: $0")
.version("1.0.0")
.options({
url: {
type: "string",
description: "Relay Websocket url",
string: true,
demandOption: true,
},
para: {
type: "number",
description: "Para for which a lease exists",
},
}).argv;

console.log("Starting auction info tool");

try {
await main();
main(argv);
} catch (e) {
console.error(e);
process.exit(1);
}
}

start();
1 change: 1 addition & 0 deletions src/tools/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const main = async () => {
} else {
getMonitoredApiFor(argv);
}
console.log("Listening to events...");
};

main();
42 changes: 42 additions & 0 deletions test/auction-info.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { jest } from '@jest/globals';
import { calculateTimestamp, calculateCurrentLeasePeriod } from '../src/tools/auction-info';

describe('Auction Info Tests', () => {

let api;

beforeAll(async () => {
api = {
rpc: {
chain: {
getHeader: jest.fn().mockReturnValue({
number: {
toNumber: jest.fn().mockReturnValue(100),
},
}) ,
},
},
query: {
timestamp: {
now: jest.fn().mockReturnValue({
toNumber: jest.fn().mockReturnValue(Date.now()),
}),
},
},
};
});

test('calculateTimestamp should return correct future date', async () => {
const futureBlock = 110;
const [timestamp, date] = await calculateTimestamp(api, futureBlock);
expect(date).toBeInstanceOf(Date);
expect(timestamp).toBeGreaterThan(Date.now());
});

test('calculateCurrentLeasePeriod should return correct lease period', async () => {
const leasePeriod = 10;
const leaseOffset = 5;
const currentLeasePeriod = await calculateCurrentLeasePeriod(api, leasePeriod, leaseOffset);
expect(currentLeasePeriod).toBe((100 - leaseOffset) / leasePeriod);
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"sourceMap": true,
"outDir": "build"
},
"include": ["src/**/*.ts", "test/**/*.spec.ts"],
"include": ["src/**/*.ts", "test/**/*.spec.ts", "test/auction-info.test.ts"],
"exclude": ["node_modules"]
}
Loading