diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 631b7fe3d2..7286c02e31 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2048,9 +2048,7 @@ jobs: JEST_TEST_RUNNER_DISABLED: false JEST_TEST_COVERAGE_PATH: ./code-coverage-ts/ctp-ledger-connector-besu JEST_TEST_CODE_COVERAGE_ENABLED: true - TAPE_TEST_PATTERN: >- - --files={./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts,./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts} - TAPE_TEST_RUNNER_DISABLED: false + TAPE_TEST_RUNNER_DISABLED: true runs-on: ubuntu-22.04 steps: - name: Use Node.js ${{ env.NODEJS_VERSION }} diff --git a/.taprc b/.taprc index 9ef42e7cca..67e6efca30 100644 --- a/.taprc +++ b/.taprc @@ -21,8 +21,6 @@ files: - ./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts - ./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation-no-keychain.test.ts - ./packages/cactus-common/src/test/typescript/unit/logging/logger.test.ts - - ./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts - - ./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts - ./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts - ./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/cactus-keychain-vault-server.test.ts - ./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/plugin-keychain-vault.test.ts diff --git a/jest.config.js b/jest.config.js index 3e3d311575..d2b50e9f9d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -34,8 +34,6 @@ module.exports = { `./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts`, `./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation-no-keychain.test.ts`, `./packages/cactus-common/src/test/typescript/unit/logging/logger.test.ts`, - `./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts`, - `./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts`, `./packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-sign-transaction-endpoint.test.ts`, `./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/cactus-keychain-vault-server.test.ts`, `./packages/cactus-plugin-keychain-vault/src/test/typescript/integration/plugin-keychain-vault.test.ts`, diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts index 169a489910..58b906bd64 100644 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts +++ b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/get-block-endpoint.test.ts @@ -1,4 +1,4 @@ -import test, { Test } from "tape-promise/tape"; +import "jest-extended"; import { v4 as uuidv4 } from "uuid"; import { createServer } from "http"; @@ -33,117 +33,119 @@ import { PluginRegistry } from "@hyperledger/cactus-core"; import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; -const testCase = "Test sign transaction endpoint"; -const logLevel: LogLevelDesc = "TRACE"; +const testCase = "Test get block endpoint"; +const logLevel: LogLevelDesc = "INFO"; -test("BEFORE " + testCase, async (t: Test) => { - const pruning = pruneDockerAllIfGithubAction({ logLevel }); - await t.doesNotReject(pruning, "Pruning didn't throw OK"); - t.end(); -}); - -test(testCase, async (t: Test) => { - const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); - const keychainId = uuidv4(); - const keychainRef = uuidv4(); - - const { privateKey } = Secp256k1Keys.generateKeyPairsBuffer(); - const keyHex = privateKey.toString("hex"); - const pem = keyEncoder.encodePrivate(keyHex, KeyFormat.Raw, KeyFormat.PEM); - - const keychain = new PluginKeychainMemory({ - backend: new Map([[keychainRef, pem]]), - keychainId, - logLevel, - instanceId: uuidv4(), - }); +describe(testCase, () => { + const besuTestLedger = new BesuTestLedger(); + let apiServer: ApiServer; - const httpServer1 = createServer(); - await new Promise((resolve, reject) => { - httpServer1.once("error", reject); - httpServer1.once("listening", resolve); - httpServer1.listen(0, "127.0.0.1"); + beforeAll(async () => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await expect(pruning).resolves.toBeTruthy(); + await besuTestLedger.start(); }); - const addressInfo1 = httpServer1.address() as AddressInfo; - t.comment(`HttpServer1 AddressInfo: ${JSON.stringify(addressInfo1)}`); - const node1Host = `http://${addressInfo1.address}:${addressInfo1.port}`; - t.comment(`Cactus Node 1 Host: ${node1Host}`); - - const besuTestLedger = new BesuTestLedger(); - await besuTestLedger.start(); - const tearDown = async () => { + afterAll(async () => { await besuTestLedger.stop(); await besuTestLedger.destroy(); - }; - - test.onFinish(tearDown); - - const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost(); - const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost(); - - // 2. Instantiate plugin registry which will provide the web service plugin with the key value storage plugin - const pluginRegistry = new PluginRegistry({ plugins: [keychain] }); - - // 3. Instantiate the web service consortium plugin - const options: IPluginLedgerConnectorBesuOptions = { - instanceId: uuidv4(), - rpcApiHttpHost, - rpcApiWsHost, - pluginRegistry, - logLevel, - }; - const pluginValidatorBesu = new PluginLedgerConnectorBesu(options); - - // 4. Create the API Server object that we embed in this test - const configService = new ConfigService(); - const apiServerOptions = await configService.newExampleConfig(); - apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE; - apiServerOptions.configFile = ""; - apiServerOptions.apiCorsDomainCsv = "*"; - apiServerOptions.apiPort = addressInfo1.port; - apiServerOptions.cockpitPort = 0; - apiServerOptions.grpcPort = 0; - apiServerOptions.crpcPort = 0; - apiServerOptions.apiTlsEnabled = false; - const config = await configService.newExampleConfigConvict(apiServerOptions); - - pluginRegistry.add(pluginValidatorBesu); - - const apiServer = new ApiServer({ - httpServerApi: httpServer1, - config: config.getProperties(), - pluginRegistry, + await apiServer.shutdown(); }); - // 5. make sure the API server is shut down when the testing if finished. - test.onFinish(() => apiServer.shutdown()); - - // 6. Start the API server which is now listening on port A and it's healthcheck works through the main SDK - await apiServer.start(); - - // 7. Instantiate the main SDK dynamically with whatever port the API server ended up bound to (port 0) - t.comment(`AddressInfo: ${JSON.stringify(addressInfo1)}`); - - const request: GetBlockV1Request = { - blockHashOrBlockNumber: 0, - }; - - const configuration = new BesuApiClientOptions({ basePath: node1Host }); - const api = new BesuApiClient(configuration); - - // Test for 200 valid response test case - const res = await api.getBlockV1(request); - - const { status, data } = res; - t.true(status >= 200, "status GTE 200 OK"); - t.true(status < 300, "status LT 300 OK"); - t.ok(data, "GetBlockResponse Truthy OK"); - t.true(typeof data.block === "object", "Response data is OK"); -}); + afterAll(async () => { + const pruning = pruneDockerAllIfGithubAction({ logLevel }); + await expect(pruning).resolves.toBeTruthy(); + }); -test("AFTER " + testCase, async (t: Test) => { - const pruning = pruneDockerAllIfGithubAction({ logLevel }); - await t.doesNotReject(pruning, "Pruning didn't throw OK"); - t.end(); + test(testCase, async () => { + const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); + const keychainId = uuidv4(); + const keychainRef = uuidv4(); + + const { privateKey } = Secp256k1Keys.generateKeyPairsBuffer(); + const keyHex = privateKey.toString("hex"); + const pem = keyEncoder.encodePrivate(keyHex, KeyFormat.Raw, KeyFormat.PEM); + + const keychain = new PluginKeychainMemory({ + backend: new Map([[keychainRef, pem]]), + keychainId, + logLevel, + instanceId: uuidv4(), + }); + + const httpServer1 = createServer(); + await new Promise((resolve, reject) => { + httpServer1.once("error", reject); + httpServer1.once("listening", resolve); + httpServer1.listen(0, "127.0.0.1"); + }); + const addressInfo1 = httpServer1.address() as AddressInfo; + console.log(`HttpServer1 AddressInfo: ${JSON.stringify(addressInfo1)}`); + + const node1Host = `http://${addressInfo1.address}:${addressInfo1.port}`; + console.log(`Cactus Node 1 Host: ${node1Host}`); + + const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost(); + const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost(); + + // 2. Instantiate plugin registry which will provide the web service plugin with the key value storage plugin + const pluginRegistry = new PluginRegistry({ plugins: [keychain] }); + + // 3. Instantiate the web service consortium plugin + const options: IPluginLedgerConnectorBesuOptions = { + instanceId: uuidv4(), + rpcApiHttpHost, + rpcApiWsHost, + pluginRegistry, + logLevel, + }; + const pluginValidatorBesu = new PluginLedgerConnectorBesu(options); + + // 4. Create the API Server object that we embed in this test + const configService = new ConfigService(); + const apiServerOptions = await configService.newExampleConfig(); + apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE; + apiServerOptions.configFile = ""; + apiServerOptions.apiCorsDomainCsv = "*"; + apiServerOptions.apiPort = addressInfo1.port; + apiServerOptions.cockpitPort = 0; + apiServerOptions.grpcPort = 0; + apiServerOptions.crpcPort = 0; + apiServerOptions.apiTlsEnabled = false; + const config = + await configService.newExampleConfigConvict(apiServerOptions); + + pluginRegistry.add(pluginValidatorBesu); + + apiServer = new ApiServer({ + httpServerApi: httpServer1, + config: config.getProperties(), + pluginRegistry, + }); + + // 5. make sure the API server is shut down when the testing if finished. + + // 6. Start the API server which is now listening on port A and it's healthcheck works through the main SDK + await apiServer.start(); + + // 7. Instantiate the main SDK dynamically with whatever port the API server ended up bound to (port 0) + console.log(`AddressInfo: ${JSON.stringify(addressInfo1)}`); + + const request: GetBlockV1Request = { + blockHashOrBlockNumber: 0, + }; + + const configuration = new BesuApiClientOptions({ basePath: node1Host }); + const api = new BesuApiClient(configuration); + + // Test for 200 valid response test case + const res = await api.getBlockV1(request); + + const { status, data } = res; + + expect(status).toBeGreaterThanOrEqual(200); + expect(status).toBeLessThan(300); + expect(data).toBeTruthy(); + expect(data.block).toBeObject(); + }); }); diff --git a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts b/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts deleted file mode 100644 index 85ea9965f7..0000000000 --- a/packages/cactus-test-plugin-ledger-connector-besu/src/test/typescript/integration/plugin-validator-besu/v21-get-block-endpoint.test.ts +++ /dev/null @@ -1,151 +0,0 @@ -import test, { Test } from "tape-promise/tape"; - -import { v4 as uuidv4 } from "uuid"; -import { createServer } from "http"; -import KeyEncoder from "key-encoder"; -import { AddressInfo } from "net"; - -import { - ApiServer, - AuthorizationProtocol, - ConfigService, -} from "@hyperledger/cactus-cmd-api-server"; -import { - Secp256k1Keys, - KeyFormat, - LogLevelDesc, -} from "@hyperledger/cactus-common"; - -import { - BesuTestLedger, - pruneDockerAllIfGithubAction, -} from "@hyperledger/cactus-test-tooling"; - -import { - BesuApiClientOptions, - BesuApiClient, - IPluginLedgerConnectorBesuOptions, - PluginLedgerConnectorBesu, - GetBlockV1Request, -} from "@hyperledger/cactus-plugin-ledger-connector-besu"; - -import { PluginRegistry } from "@hyperledger/cactus-core"; - -import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; - -const testCase = "Test sign transaction endpoint"; -const logLevel: LogLevelDesc = "TRACE"; - -test("BEFORE " + testCase, async (t: Test) => { - const pruning = pruneDockerAllIfGithubAction({ logLevel }); - await t.doesNotReject(pruning, "Pruning didn't throw OK"); - t.end(); -}); - -test(testCase, async (t: Test) => { - const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); - const keychainId = uuidv4(); - const keychainRef = uuidv4(); - - const { privateKey } = Secp256k1Keys.generateKeyPairsBuffer(); - const keyHex = privateKey.toString("hex"); - const pem = keyEncoder.encodePrivate(keyHex, KeyFormat.Raw, KeyFormat.PEM); - - const keychain = new PluginKeychainMemory({ - backend: new Map([[keychainRef, pem]]), - keychainId, - logLevel, - instanceId: uuidv4(), - }); - - const httpServer1 = createServer(); - await new Promise((resolve, reject) => { - httpServer1.once("error", reject); - httpServer1.once("listening", resolve); - httpServer1.listen(0, "127.0.0.1"); - }); - const addressInfo1 = httpServer1.address() as AddressInfo; - t.comment(`HttpServer1 AddressInfo: ${JSON.stringify(addressInfo1)}`); - const node1Host = `http://${addressInfo1.address}:${addressInfo1.port}`; - t.comment(`Cactus Node 1 Host: ${node1Host}`); - - 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 tearDown = async () => { - await besuTestLedger.stop(); - await besuTestLedger.destroy(); - }; - - test.onFinish(tearDown); - - const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost(); - const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost(); - - // 2. Instantiate plugin registry which will provide the web service plugin with the key value storage plugin - const pluginRegistry = new PluginRegistry({ plugins: [keychain] }); - - // 3. Instantiate the web service consortium plugin - const options: IPluginLedgerConnectorBesuOptions = { - instanceId: uuidv4(), - rpcApiHttpHost, - rpcApiWsHost, - pluginRegistry, - logLevel, - }; - const pluginValidatorBesu = new PluginLedgerConnectorBesu(options); - - // 4. Create the API Server object that we embed in this test - const configService = new ConfigService(); - const apiServerOptions = await configService.newExampleConfig(); - apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE; - apiServerOptions.configFile = ""; - apiServerOptions.apiCorsDomainCsv = "*"; - apiServerOptions.apiPort = addressInfo1.port; - apiServerOptions.cockpitPort = 0; - apiServerOptions.apiTlsEnabled = false; - const config = await configService.newExampleConfigConvict(apiServerOptions); - - pluginRegistry.add(pluginValidatorBesu); - - const apiServer = new ApiServer({ - httpServerApi: httpServer1, - config: config.getProperties(), - pluginRegistry, - }); - - // 5. make sure the API server is shut down when the testing if finished. - test.onFinish(() => apiServer.shutdown()); - - // 6. Start the API server which is now listening on port A and it's healthcheck works through the main SDK - await apiServer.start(); - - // 7. Instantiate the main SDK dynamically with whatever port the API server ended up bound to (port 0) - t.comment(`AddressInfo: ${JSON.stringify(addressInfo1)}`); - - const request: GetBlockV1Request = { - blockHashOrBlockNumber: 0, - }; - - const configuration = new BesuApiClientOptions({ basePath: node1Host }); - const api = new BesuApiClient(configuration); - - // Test for 200 valid response test case - const res = await api.getBlockV1(request); - - const { status, data } = res; - t.true(status >= 200, "status GTE 200 OK"); - t.true(status < 300, "status LT 300 OK"); - t.ok(data, "GetBlockResponse Truthy OK"); - t.true(typeof data.block === "object", "Response data is OK"); -}); - -test("AFTER " + testCase, async (t: Test) => { - const pruning = pruneDockerAllIfGithubAction({ logLevel }); - await t.doesNotReject(pruning, "Pruning didn't throw OK"); - t.end(); -});