Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • hive/workerbee
1 result
Show changes
Commits on Source (7)
......@@ -11,7 +11,7 @@ variables:
include:
- project: 'hive/common-ci-configuration'
ref: 5806284d3c6feb2ce52bdb6077c20a9a578bb643
ref: 590bfd88a491efba5a39571bc2c82ffbabda2ec8
file:
- '/templates/npm_projects.gitlab-ci.yml'
......
// We only want to import types here!
import type beekeeperFactoryType from "@hiveio/beekeeper/web";
import type Wax from "@hiveio/wax";
import type WorkerBee from "../../dist/bundle/index";
export type TEnvType = "web" | "node";
......@@ -8,6 +10,7 @@ export type TEnvType = "web" | "node";
export interface IWorkerBeeGlobals {
beekeeperFactory: typeof beekeeperFactoryType;
WorkerBee: typeof WorkerBee;
wax: typeof Wax;
}
declare global {
......
......@@ -2,15 +2,18 @@
globalThis.createTestFor = async function createTestFor(env) {
const locWorkerBee = env === "web" ? "../../dist/bundle/index.js" : "../../dist/bundle/index.js";
const locBeekeeper = env === "web" ? "@hiveio/beekeeper/web" : "@hiveio/beekeeper/node";
const locWax = env === "web" ? "@hiveio/wax/web" : "@hiveio/wax/node";
// Import required libraries env-dependent
const wb = await import(locWorkerBee);
const beekeeper = await import(locBeekeeper);
const wax = await import(locWax);
// Provide results
return {
beekeeperFactory: beekeeper.default,
WorkerBee: wb.default
WorkerBee: wb.default,
wax
};
};
......
......@@ -10,6 +10,7 @@
{
"imports": {
"@hiveio/wax": "/node_modules/@hiveio/wax/wasm/dist/bundle/web.js",
"@hiveio/wax/web": "/node_modules/@hiveio/wax/wasm/dist/bundle/web.js",
"@hiveio/beekeeper/web": "/node_modules/@hiveio/beekeeper/dist/bundle/web.js"
}
}
......
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { ApiAccount } from "@hiveio/wax";
import type { ReplyOperation, ApiAccount } from "@hiveio/wax";
import { expect } from "@playwright/test";
import { ChromiumBrowser, ConsoleMessage, chromium } from "playwright";
import type { IStartConfiguration } from "../../src/bot";
import type { IBroadcastData, ITransactionData } from "../../src/index";
import { test } from "../assets/jest-helper";
......@@ -37,6 +38,81 @@ test.describe("WorkerBee Bot events test", () => {
});
});
test("Allow to broadcast to mirronet chain", async({ workerbeeTest }) => {
const broadcastTest = await workerbeeTest(async({ WorkerBee, wax, beekeeperFactory }) => {
/*
* Prepare helper WorkerBee instance just to provide IHiveChainInterface instance.
* It is a problem in PW tests to reference whole wax, since its dependencies need to be declared at importmap in test.html
*/
const customWaxConfig = { apiEndpoint: "https://api.fake.openhive.network", chainId: "42" };
const customConfig: IStartConfiguration = { chainOptions: customWaxConfig };
const chainOwner = new WorkerBee(customConfig);
// Call start just to initialize chain member in WorkerBee object.
await chainOwner.start();
// Stop does not affect chain property, so we can avoid making ineffective api calls.
chainOwner.stop();
const localChain = chainOwner.chain!;
const bot = new WorkerBee({ explicitChain: localChain });
const newTx = await localChain.createTransaction();
newTx.pushOperation(new wax.ReplyOperation({author: "gtg", permlink: `re-${Date.now()}`, parentAuthor: "hbd.funder",
parentPermlink: "re-upvote-this-post-to-fund-hbdstabilizer-20250312t045515z", title: "test", body: "Awesome test!",
maxAcceptedPayout: localChain.hbdCoins(1000000), percentHbd: 9000, allowVotes: true, allowCurationRewards: true}));
const bkInstance = await beekeeperFactory({inMemory: true});
const bkSession = bkInstance.createSession("salt and pepper");
const {wallet} = await bkSession.createWallet("temp", "pass", true);
const publicKey = await wallet.importKey("5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n");
/// Intentionally sign using legacy method
const legacySigDigest = newTx.legacy_sigDigest;
const signature = await wallet.signDigest(publicKey, legacySigDigest);
newTx.sign(signature);
let signatureIsMatching: boolean = false;
await Promise.race([
/* eslint-disable-next-line no-async-promise-executor */
new Promise<void>(async res => {
await bot.start();
const broadcastResultObserver = await bot.broadcast(newTx, { throwAfter: "+20s"});
const txObserver = broadcastResultObserver.subscribe({
next (data: IBroadcastData) {
console.log(`Received broadcast data: ${JSON.stringify(data.transaction)}`);
if(data.transaction.signatures[0] !== signature)
throw new Error("Invalid signature in broadcast result");
signatureIsMatching = true;
txObserver.unsubscribe();
res();
},
error(err) {
console.error(err);
throw new Error("Transaction broadcast failure");
}
});
}),
new Promise(res => { setTimeout(res, 15000); })
]);
bot.delete();
chainOwner.delete();
return signatureIsMatching;
});
expect(broadcastTest).toEqual(true);
});
test("Allow to pass explicit chain", async({ workerbeeTest }) => {
const explicitChainTest = await workerbeeTest(async({ WorkerBee }) => {
......
Subproject commit 5806284d3c6feb2ce52bdb6077c20a9a578bb643
Subproject commit 590bfd88a491efba5a39571bc2c82ffbabda2ec8
......@@ -4,7 +4,7 @@
"description": "Hive automation library based on the wax and beekeeper",
"main": "dist/bundle/index.js",
"types": "dist/bundle/index.d.ts",
"packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0",
"packageManager": "pnpm@10.0.0+sha512.b8fef5494bd3fe4cbd4edabd0745df2ee5be3e4b0b8b08fa643aa3e4c6702ccc0f00d68fa8a8c9858a735a0032485a44990ed2810526c875e416f001b17df12b",
"exports": {
".": {
"default": {
......@@ -77,8 +77,8 @@
"typescript": "catalog:typescript-toolset"
},
"dependencies": {
"@hiveio/beekeeper": "1.27.8-stable.250131103618",
"@hiveio/wax": "1.27.6-rc7-stable.250131113706"
"@hiveio/beekeeper": "1.27.10-stable.250310202833",
"@hiveio/wax": "1.27.6-rc7-stable.250314180436"
},
"repository": {
"type": "git",
......
......@@ -69,11 +69,11 @@ importers:
.:
dependencies:
'@hiveio/beekeeper':
specifier: 1.27.8-stable.250131103618
version: 1.27.8-stable.250131103618
specifier: 1.27.10-stable.250310202833
version: 1.27.10-stable.250310202833
'@hiveio/wax':
specifier: 1.27.6-rc7-stable.250131113706
version: 1.27.6-rc7-stable.250131113706
specifier: 1.27.6-rc7-stable.250314180436
version: 1.27.6-rc7-stable.250314180436
devDependencies:
'@eslint/compat':
specifier: ^1.2.7
......@@ -377,12 +377,16 @@ packages:
'@gerrit0/mini-shiki@1.27.2':
resolution: {integrity: sha512-GeWyHz8ao2gBiUW4OJnQDxXQnFgZQwwQk05t/CVVgNBN7/rK8XZ7xY6YhLVv9tH3VppWWmr9DCl3MwemB/i+Og==}
'@hiveio/beekeeper@1.27.8-stable.250131103618':
resolution: {integrity: sha1-0IYuFBbxIIKfRTrI6ZZc7Jf+qLA=, tarball: https://gitlab.syncad.com/api/v4/projects/198/packages/npm/@hiveio/beekeeper/-/@hiveio/beekeeper-1.27.8-stable.250131103618.tgz}
'@hiveio/beekeeper@1.27.10-stable.250305202831':
resolution: {integrity: sha1-mPx0QrDh3NSPSOYGyR1SUyi3lyA=, tarball: https://gitlab.syncad.com/api/v4/projects/198/packages/npm/@hiveio/beekeeper/-/@hiveio/beekeeper-1.27.10-stable.250305202831.tgz}
engines: {node: ^20.11 || >= 21.2}
'@hiveio/wax@1.27.6-rc7-stable.250131113706':
resolution: {integrity: sha1-Xi2VV8y9T6MdBHOBSzxZNpmGnF8=, tarball: https://gitlab.syncad.com/api/v4/projects/419/packages/npm/@hiveio/wax/-/@hiveio/wax-1.27.6-rc7-stable.250131113706.tgz}
'@hiveio/beekeeper@1.27.10-stable.250310202833':
resolution: {integrity: sha1-RIuA9M6LrJkf/2HuNmiavT9bUyI=, tarball: https://gitlab.syncad.com/api/v4/projects/198/packages/npm/@hiveio/beekeeper/-/@hiveio/beekeeper-1.27.10-stable.250310202833.tgz}
engines: {node: ^20.11 || >= 21.2}
'@hiveio/wax@1.27.6-rc7-stable.250314180436':
resolution: {integrity: sha1-/NkHF9IjJixN2LUTiUo/6KeQxUY=, tarball: https://gitlab.syncad.com/api/v4/projects/419/packages/npm/@hiveio/wax/-/@hiveio/wax-1.27.6-rc7-stable.250314180436.tgz}
engines: {node: ^20.11 || >= 21.2}
'@humanfs/core@0.19.1':
......@@ -2886,11 +2890,13 @@ snapshots:
'@shikijs/types': 1.29.2
'@shikijs/vscode-textmate': 10.0.1
'@hiveio/beekeeper@1.27.8-stable.250131103618': {}
'@hiveio/beekeeper@1.27.10-stable.250305202831': {}
'@hiveio/beekeeper@1.27.10-stable.250310202833': {}
'@hiveio/wax@1.27.6-rc7-stable.250131113706':
'@hiveio/wax@1.27.6-rc7-stable.250314180436':
dependencies:
'@hiveio/beekeeper': 1.27.8-stable.250131103618
'@hiveio/beekeeper': 1.27.10-stable.250305202831
events: 3.3.0
long: 5.2.3
......
......@@ -103,10 +103,14 @@ export class WorkerBee implements IWorkerBee {
const listener = txObserver.provideBlockHeaderData().subscribe({
next(val) {
observer.next?.({
transaction: val.transactions[apiTx.id]!,
block: val.block
});
const transaction = val.transactions[txId] ?? val.transactions[legacyId]!;
if( transaction!== undefined) {
listener.unsubscribe();
observer.next?.({
transaction,
block: val.block
});
}
},
error(val) {
observer.error?.(val);
......