From 4dfe361372306dd57de2e3d22d24c6d6c4f3db8f Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Sat, 6 Apr 2024 16:55:00 -0700 Subject: [PATCH] test(connector-besu): migrate v21-besu-get-transaction.test.ts to Jest Signed-off-by: Peter Somogyvari --- .github/workflows/ci.yaml | 2 +- .taprc | 1 - jest.config.js | 1 - .../v21-besu-get-transaction.test.ts | 146 +++++++++--------- 4 files changed, 76 insertions(+), 74 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 546dbb6807..780604dd5a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -983,7 +983,7 @@ jobs: JEST_TEST_PATTERN: packages/cactus-plugin-ledger-connector-besu/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts JEST_TEST_RUNNER_DISABLED: false TAPE_TEST_PATTERN: >- - --files={./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-block.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-web3-eea.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/v21-besu-get-transaction.test.ts} + --files={./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-block.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-web3-eea.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts,./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts} TAPE_TEST_RUNNER_DISABLED: false runs-on: ubuntu-22.04 steps: diff --git a/.taprc b/.taprc index f0b8d5f2dd..a8cd162f3d 100644 --- a/.taprc +++ b/.taprc @@ -54,7 +54,6 @@ files: - ./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts - ./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts - ./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-block.test.ts - - ./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/v21-besu-get-transaction.test.ts - ./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai-json-object.test.ts - ./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai-json-object.test.ts - ./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts diff --git a/jest.config.js b/jest.config.js index 3171e824ec..7425b9a2a1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -63,7 +63,6 @@ module.exports = { `./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts`, `./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts`, `./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-block.test.ts`, - `./packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/v21-besu-get-transaction.test.ts`, `./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/deploy-contract-from-json-xdai-json-object.test.ts`, `./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai-json-object.test.ts`, `./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts`, diff --git a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/v21-besu-get-transaction.test.ts b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/v21-besu-get-transaction.test.ts index 4c5dd715c4..ff90302359 100644 --- a/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/v21-besu-get-transaction.test.ts +++ b/packages/cactus-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-ledger-connector-besu/v21-besu-get-transaction.test.ts @@ -1,4 +1,4 @@ -import test, { Test } from "tape"; +import "jest-extended"; import { v4 as uuidv4 } from "uuid"; import { PluginRegistry } from "@hyperledger/cactus-core"; import { @@ -9,96 +9,100 @@ import { } from "../../../../main/typescript/public-api"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; import { BesuTestLedger } from "@hyperledger/cactus-test-tooling"; -import { LogLevelDesc } from "@hyperledger/cactus-common"; +import { LogLevelDesc, LoggerProvider } from "@hyperledger/cactus-common"; import HelloWorldContractJson from "../../../solidity/hello-world-contract/HelloWorld.json"; import Web3 from "web3"; import { PluginImportType } from "@hyperledger/cactus-core-api"; import { GetTransactionV1Request } from "../../../../main/typescript/generated/openapi/typescript-axios/api"; -test("can get past logs of an account", async (t: Test) => { +describe("PluginLedgerConnectorBesu", () => { const logLevel: LogLevelDesc = "TRACE"; const containerImageVersion = "2021-08-24--feat-1244"; const containerImageName = "ghcr.io/hyperledger/cactus-besu-21-1-6-all-in-one"; + const besuOptions = { containerImageName, containerImageVersion }; const besuTestLedger = new BesuTestLedger(besuOptions); - await besuTestLedger.start(); + const log = LoggerProvider.getOrCreate({ + label: "v21-besu-get-transaction.test.ts", + level: logLevel, + }); + + let rpcApiHttpHost: string; + let rpcApiWsHost: string; + let firstHighNetWorthAccount: string; + + beforeAll(async () => { + await besuTestLedger.start(); + rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost(); + rpcApiWsHost = await besuTestLedger.getRpcApiWsHost(); + firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey(); + }); - test.onFinish(async () => { + afterAll(async () => { await besuTestLedger.stop(); await besuTestLedger.destroy(); }); - const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost(); - const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost(); + test("can get past logs of an account", async () => { + const web3 = new Web3(rpcApiHttpHost); + const testEthAccount = web3.eth.accounts.create(uuidv4()); - /** - * Constant defining the standard 'dev' Besu genesis.json contents. - * - * @see https://github.com/hyperledger/besu/blob/21.1.6/config/src/main/resources/dev.json - */ + const keychainEntryKey = uuidv4(); + const keychainEntryValue = testEthAccount.privateKey; + const keychainPlugin = new PluginKeychainMemory({ + instanceId: uuidv4(), + keychainId: uuidv4(), + // pre-provision keychain with mock backend holding the private key of the + // test account that we'll reference while sending requests with the + // signing credential pointing to this keychain entry. + backend: new Map([[keychainEntryKey, keychainEntryValue]]), + logLevel, + }); + keychainPlugin.set( + HelloWorldContractJson.contractName, + JSON.stringify(HelloWorldContractJson), + ); + const factory = new PluginFactoryLedgerConnector({ + pluginImportType: PluginImportType.Local, + }); - const firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey(); + const connector: PluginLedgerConnectorBesu = await factory.create({ + rpcApiHttpHost, + rpcApiWsHost, + instanceId: uuidv4(), + pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }), + }); - const web3 = new Web3(rpcApiHttpHost); - const testEthAccount = web3.eth.accounts.create(uuidv4()); + const privateKey = await besuTestLedger.getGenesisAccountPrivKey(); + const { transactionReceipt } = await connector.transact({ + web3SigningCredential: { + ethAccount: firstHighNetWorthAccount, + secret: privateKey, + type: Web3SigningCredentialType.PrivateKeyHex, + }, + consistencyStrategy: { + blockConfirmations: 0, + receiptType: ReceiptType.LedgerBlockAck, + timeoutMs: 60000, + }, + transactionConfig: { + from: firstHighNetWorthAccount, + to: testEthAccount.address, + value: 10e9, + gas: 1000000, + }, + }); - const keychainEntryKey = uuidv4(); - const keychainEntryValue = testEthAccount.privateKey; - const keychainPlugin = new PluginKeychainMemory({ - instanceId: uuidv4(), - keychainId: uuidv4(), - // pre-provision keychain with mock backend holding the private key of the - // test account that we'll reference while sending requests with the - // signing credential pointing to this keychain entry. - backend: new Map([[keychainEntryKey, keychainEntryValue]]), - logLevel, - }); - keychainPlugin.set( - HelloWorldContractJson.contractName, - JSON.stringify(HelloWorldContractJson), - ); - const factory = new PluginFactoryLedgerConnector({ - pluginImportType: PluginImportType.Local, - }); + const req: GetTransactionV1Request = { + transactionHash: transactionReceipt.transactionHash, + }; + const response = await connector.getTransaction(req); + log.debug("Transaction in HTTP response: %o", response.transaction); + expect(response).toBeTruthy(); + expect(response.transaction).toBeTruthy(); - const connector: PluginLedgerConnectorBesu = await factory.create({ - rpcApiHttpHost, - rpcApiWsHost, - instanceId: uuidv4(), - pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }), + expect(response.transaction).toBeObject(); + expect(response.transaction).not.toBeEmptyObject(); }); - - const privateKey = await besuTestLedger.getGenesisAccountPrivKey(); - const { transactionReceipt } = await connector.transact({ - web3SigningCredential: { - ethAccount: firstHighNetWorthAccount, - secret: privateKey, - type: Web3SigningCredentialType.PrivateKeyHex, - }, - consistencyStrategy: { - blockConfirmations: 0, - receiptType: ReceiptType.LedgerBlockAck, - timeoutMs: 60000, - }, - transactionConfig: { - from: firstHighNetWorthAccount, - to: testEthAccount.address, - value: 10e9, - gas: 1000000, - }, - }); - - const req: GetTransactionV1Request = { - transactionHash: transactionReceipt.transactionHash, - }; - const response = await connector.getTransaction(req); - t.comment(JSON.stringify(response.transaction)); - t.ok(response.transaction, "getTransaction response is OK :-)"); - t.equal( - typeof response.transaction, - "object", - "getTransaction response type is OK :-)", - ); - t.end(); });