From 3827001fba07f3de30690b12653205242132379b Mon Sep 17 00:00:00 2001 From: Michal Bajer Date: Fri, 24 Nov 2023 15:50:29 +0000 Subject: [PATCH] test(geth-test-ledger): add basic tests - Add test suite for geth-test-ledger package. - Add new test suit to CI - It was initially proposed in #2588, I've added some cleanups and improvements. - Run codegen, update missing deps, sort package.json, fix type in socketio-test-setup-helpers, to fix some CI. Closes: #2579 Co-authored-by: Tomasz Awramski Signed-off-by: Michal Bajer --- .github/workflows/ci.yaml | 25 ++ .../odap-extension/client-helper.ts | 2 +- .../client/models/GetKeychainEntryRequest.kt | 36 -- .../client/models/GetKeychainEntryResponse.kt | 41 -- .../client/models/SetKeychainEntryRequest.kt | 41 -- .../client/models/SetKeychainEntryResponse.kt | 36 -- .../package.json | 2 +- .../hello-world-contract/HelloWorld.json | 409 ++++++++++++++++++ .../hello-world-contract/HelloWorld.sol | 24 + .../integration/geth-test-ledger.test.ts | 85 +++- .../cactus-test-geth-ledger/tsconfig.json | 6 +- .../socketio-test-setup-helpers.ts | 11 +- .../cactus-test-verifier-client/package.json | 2 + packages/cactus-verifier-client/package.json | 2 +- yarn.lock | 2 + 15 files changed, 549 insertions(+), 175 deletions(-) delete mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequest.kt delete mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponse.kt delete mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequest.kt delete mode 100644 packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponse.kt create mode 100644 packages/cactus-test-geth-ledger/src/test/solidity/hello-world-contract/HelloWorld.json create mode 100644 packages/cactus-test-geth-ledger/src/test/solidity/hello-world-contract/HelloWorld.sol diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1e49be10dc..6ec30b551c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1545,6 +1545,31 @@ jobs: node-version: ${{ env.NODEJS_VERSION }} - uses: actions/checkout@v3.5.2 + - id: yarn-cache + name: Restore Yarn Cache + uses: actions/cache@v3.3.1 + with: + key: ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }} + path: ./.yarn/ + restore-keys: | + ${{ runner.os }}-yarn-${{ hashFiles('./yarn.lock') }} + - run: ./tools/ci.sh + cactus-test-geth-ledger: + continue-on-error: false + env: + FULL_BUILD_DISABLED: true + JEST_TEST_PATTERN: packages/cactus-test-geth-ledger/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts + JEST_TEST_RUNNER_DISABLED: false + TAPE_TEST_RUNNER_DISABLED: true + needs: build-dev + runs-on: ubuntu-20.04 + steps: + - name: Use Node.js ${{ env.NODEJS_VERSION }} + uses: actions/setup-node@v3.6.0 + with: + node-version: ${{ env.NODEJS_VERSION }} + - uses: actions/checkout@v3.5.2 + - id: yarn-cache name: Restore Yarn Cache uses: actions/cache@v3.3.1 diff --git a/examples/cactus-example-cbdc-bridging-backend/src/main/typescript/odap-extension/client-helper.ts b/examples/cactus-example-cbdc-bridging-backend/src/main/typescript/odap-extension/client-helper.ts index 2377840009..62430f33f2 100644 --- a/examples/cactus-example-cbdc-bridging-backend/src/main/typescript/odap-extension/client-helper.ts +++ b/examples/cactus-example-cbdc-bridging-backend/src/main/typescript/odap-extension/client-helper.ts @@ -2,7 +2,7 @@ import { SHA256 } from "crypto-js"; import { PluginOdapGateway, TransferInitializationV1Request, - ClientGatewayHelper + ClientGatewayHelper, } from "@hyperledger/cactus-plugin-odap-hermes"; import { OdapMessageType } from "@hyperledger/cactus-plugin-odap-hermes"; import { FabricOdapGateway } from "./fabric-odap-gateway"; diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequest.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequest.kt deleted file mode 100644 index e40ba72fb5..0000000000 --- a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryRequest.kt +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - * Please note: - * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * Do not edit this file manually. - * - */ - -@file:Suppress( - "ArrayInDataClass", - "EnumEntryName", - "RemoveRedundantQualifierName", - "UnusedImport" -) - -package org.openapitools.client.models - - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -/** - * - * - * @param key The key for the entry to get from the keychain. - */ - - -data class GetKeychainEntryRequest ( - - /* The key for the entry to get from the keychain. */ - @Json(name = "key") - val key: kotlin.String - -) - diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponse.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponse.kt deleted file mode 100644 index 91b92b3f6d..0000000000 --- a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/GetKeychainEntryResponse.kt +++ /dev/null @@ -1,41 +0,0 @@ -/** - * - * Please note: - * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * Do not edit this file manually. - * - */ - -@file:Suppress( - "ArrayInDataClass", - "EnumEntryName", - "RemoveRedundantQualifierName", - "UnusedImport" -) - -package org.openapitools.client.models - - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -/** - * - * - * @param key The key that was used to retrieve the value from the keychain. - * @param `value` The value associated with the requested key on the keychain. - */ - - -data class GetKeychainEntryResponse ( - - /* The key that was used to retrieve the value from the keychain. */ - @Json(name = "key") - val key: kotlin.String, - - /* The value associated with the requested key on the keychain. */ - @Json(name = "value") - val `value`: kotlin.String - -) - diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequest.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequest.kt deleted file mode 100644 index b0b685e857..0000000000 --- a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryRequest.kt +++ /dev/null @@ -1,41 +0,0 @@ -/** - * - * Please note: - * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * Do not edit this file manually. - * - */ - -@file:Suppress( - "ArrayInDataClass", - "EnumEntryName", - "RemoveRedundantQualifierName", - "UnusedImport" -) - -package org.openapitools.client.models - - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -/** - * - * - * @param key The key for the entry to set on the keychain. - * @param `value` The value that will be associated with the key on the keychain. - */ - - -data class SetKeychainEntryRequest ( - - /* The key for the entry to set on the keychain. */ - @Json(name = "key") - val key: kotlin.String, - - /* The value that will be associated with the key on the keychain. */ - @Json(name = "value") - val `value`: kotlin.String - -) - diff --git a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponse.kt b/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponse.kt deleted file mode 100644 index 329b850d2e..0000000000 --- a/packages/cactus-plugin-keychain-memory/src/main/kotlin/generated/openapi/kotlin-client/src/main/kotlin/org/openapitools/client/models/SetKeychainEntryResponse.kt +++ /dev/null @@ -1,36 +0,0 @@ -/** - * - * Please note: - * This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). - * Do not edit this file manually. - * - */ - -@file:Suppress( - "ArrayInDataClass", - "EnumEntryName", - "RemoveRedundantQualifierName", - "UnusedImport" -) - -package org.openapitools.client.models - - -import com.squareup.moshi.Json -import com.squareup.moshi.JsonClass - -/** - * - * - * @param key The key that was used to set the value on the keychain. - */ - - -data class SetKeychainEntryResponse ( - - /* The key that was used to set the value on the keychain. */ - @Json(name = "key") - val key: kotlin.String - -) - diff --git a/packages/cactus-plugin-ledger-connector-sawtooth/package.json b/packages/cactus-plugin-ledger-connector-sawtooth/package.json index 30abacea90..96734d916d 100644 --- a/packages/cactus-plugin-ledger-connector-sawtooth/package.json +++ b/packages/cactus-plugin-ledger-connector-sawtooth/package.json @@ -47,8 +47,8 @@ "codegen": "run-p 'codegen:*'", "codegen:openapi": "npm run generate-sdk", "generate-sdk": "run-p 'generate-sdk:*'", - "generate-sdk:typescript-axios": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore", "generate-sdk:sawtooth-axios": "openapi-generator-cli generate -i ./src/main/json/sawtooth-openapi.json -g typescript-axios -o ./src/main/typescript/sawtooth-api/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore", + "generate-sdk:typescript-axios": "openapi-generator-cli generate -i ./src/main/json/openapi.json -g typescript-axios -o ./src/main/typescript/generated/openapi/typescript-axios/ --reserved-words-mappings protected=protected --ignore-file-override ../../openapi-generator-ignore", "webpack": "npm-run-all webpack:dev", "webpack:dev": "npm-run-all webpack:dev:node webpack:dev:web", "webpack:dev:node": "webpack --env=dev --target=node --config ../../webpack.config.js", diff --git a/packages/cactus-test-geth-ledger/src/test/solidity/hello-world-contract/HelloWorld.json b/packages/cactus-test-geth-ledger/src/test/solidity/hello-world-contract/HelloWorld.json new file mode 100644 index 0000000000..4cd84064e1 --- /dev/null +++ b/packages/cactus-test-geth-ledger/src/test/solidity/hello-world-contract/HelloWorld.json @@ -0,0 +1,409 @@ +{ + "contractName": "HelloWorld", + "abi": [ + { + "inputs": [], + "name": "getName", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "sayHello", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "newName", + "type": "string" + } + ], + "name": "setName", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ], + "metadata": "{\"compiler\":{\"version\":\"0.7.2+commit.51b20bc0\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"getName\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"sayHello\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"pure\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"string\",\"name\":\"newName\",\"type\":\"string\"}],\"name\":\"setName\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"/home/peter/a/blockchain/blockchain-integration-framework/packages/cactus-plugin-ledger-connector-quorum/src/test/solidity/hello-world-contract/HelloWorld.sol\":\"HelloWorld\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"/home/peter/a/blockchain/blockchain-integration-framework/packages/cactus-plugin-ledger-connector-quorum/src/test/solidity/hello-world-contract/HelloWorld.sol\":{\"keccak256\":\"0x0b78fa11f33f7936a80da194c49f04198e38947e3f98f3a7b765b4adb4c455c1\",\"urls\":[\"bzz-raw://12697aa12341c70ed7a411a27a17398dcb2d4336a14dac51845e2123acf174c7\",\"dweb:/ipfs/QmPhH1UbHtUeeen9W2qMDwEVVWAtVJSMN29Nch5q8Gax1D\"]}},\"version\":1}", + "bytecode": "60c0604052600d60808190526c4361707461696e43616374757360981b60a090815261002e9160009190610041565b5034801561003b57600080fd5b506100d4565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061008257805160ff19168380011785556100af565b828001600101855582156100af579182015b828111156100af578251825591602001919060010190610094565b506100bb9291506100bf565b5090565b5b808211156100bb57600081556001016100c0565b61030f806100e36000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806317d7de7c14610046578063c47f0027146100c3578063ef5fb05b1461016b575b600080fd5b61004e610173565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610088578181015183820152602001610070565b50505050905090810190601f1680156100b55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610169600480360360208110156100d957600080fd5b8101906020810181356401000000008111156100f457600080fd5b82018360208201111561010657600080fd5b8035906020019184600183028401116401000000008311171561012857600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610209945050505050565b005b61004e610220565b60008054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156101ff5780601f106101d4576101008083540402835291602001916101ff565b820191906000526020600020905b8154815290600101906020018083116101e257829003601f168201915b5050505050905090565b805161021c906000906020840190610246565b5050565b60408051808201909152600c81526b48656c6c6f20576f726c642160a01b602082015290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061028757805160ff19168380011785556102b4565b828001600101855582156102b4579182015b828111156102b4578251825591602001919060010190610299565b506102c09291506102c4565b5090565b5b808211156102c057600081556001016102c556fea2646970667358221220965216915797db694e698c024753d560e1989f2aebb14463f9225b2297003b2c64736f6c63430007020033", + "deployedBytecode": "608060405234801561001057600080fd5b50600436106100415760003560e01c806317d7de7c14610046578063c47f0027146100c3578063ef5fb05b1461016b575b600080fd5b61004e610173565b6040805160208082528351818301528351919283929083019185019080838360005b83811015610088578181015183820152602001610070565b50505050905090810190601f1680156100b55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b610169600480360360208110156100d957600080fd5b8101906020810181356401000000008111156100f457600080fd5b82018360208201111561010657600080fd5b8035906020019184600183028401116401000000008311171561012857600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550610209945050505050565b005b61004e610220565b60008054604080516020601f60026000196101006001881615020190951694909404938401819004810282018101909252828152606093909290918301828280156101ff5780601f106101d4576101008083540402835291602001916101ff565b820191906000526020600020905b8154815290600101906020018083116101e257829003601f168201915b5050505050905090565b805161021c906000906020840190610246565b5050565b60408051808201909152600c81526b48656c6c6f20576f726c642160a01b602082015290565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061028757805160ff19168380011785556102b4565b828001600101855582156102b4579182015b828111156102b4578251825591602001919060010190610299565b506102c09291506102c4565b5090565b5b808211156102c057600081556001016102c556fea2646970667358221220965216915797db694e698c024753d560e1989f2aebb14463f9225b2297003b2c64736f6c63430007020033", + "sourceMap": "463:37:0:-:0;439:322;463:37;;439:322;463:37;;;-1:-1:-1;;;463:37:0;;;;;;-1:-1:-1;;463:37:0;;:::i;:::-;;439:322;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;439:322:0;;;-1:-1:-1;439:322:0;:::i;:::-;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;", + "deployedSourceMap": "439:322:0:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;598:81;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;683:76;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;683:76:0;;-1:-1:-1;683:76:0;;-1:-1:-1;;;;;683:76:0:i;:::-;;505:89;;;:::i;598:81::-;670:4;663:11;;;;;;;;-1:-1:-1;;663:11:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;638:13;;663:11;;670:4;;663:11;;670:4;663:11;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;598:81;:::o;683:76::-;740:14;;;;:4;;:14;;;;;:::i;:::-;;683:76;:::o;505:89::-;568:21;;;;;;;;;;;;-1:-1:-1;;;568:21:0;;;;505:89;:::o;-1:-1:-1:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;:::o;:::-;;;;;;;;;;;;;;", + "sourcePath": "/home/peter/a/blockchain/blockchain-integration-framework/packages/cactus-plugin-ledger-connector-quorum/src/test/solidity/hello-world-contract/HelloWorld.sol", + "compiler": { + "name": "solc", + "version": "0.7.2+commit.51b20bc0" + }, + "networks": {}, + "ast": { + "absolutePath": "/home/peter/a/blockchain/blockchain-integration-framework/packages/cactus-plugin-ledger-connector-quorum/src/test/solidity/hello-world-contract/HelloWorld.sol", + "exportedSymbols": { + "HelloWorld": [31] + }, + "id": 32, + "nodeType": "SourceUnit", + "nodes": [ + { + "id": 1, + "literals": ["solidity", ">=", "0.7", ".0"], + "nodeType": "PragmaDirective", + "src": "413:24:0" + }, + { + "abstract": false, + "baseContracts": [], + "contractDependencies": [], + "contractKind": "contract", + "fullyImplemented": true, + "id": 31, + "linearizedBaseContracts": [31], + "name": "HelloWorld", + "nodeType": "ContractDefinition", + "nodes": [ + { + "constant": false, + "id": 4, + "mutability": "mutable", + "name": "name", + "nodeType": "VariableDeclaration", + "scope": 31, + "src": "463:37:0", + "stateVariable": true, + "storageLocation": "default", + "typeDescriptions": { + "typeIdentifier": "t_string_storage", + "typeString": "string" + }, + "typeName": { + "id": 2, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "463:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "value": { + "hexValue": "4361707461696e436163747573", + "id": 3, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "string", + "lValueRequested": false, + "nodeType": "Literal", + "src": "485:15:0", + "typeDescriptions": { + "typeIdentifier": "t_stringliteral_bdd2f21877c99489ddcc32737686677f40d460368c7982ce22ce4f72b41b0312", + "typeString": "literal_string \"CaptainCactus\"" + }, + "value": "CaptainCactus" + }, + "visibility": "private" + }, + { + "body": { + "id": 11, + "nodeType": "Block", + "src": "562:32:0", + "statements": [ + { + "expression": { + "hexValue": "48656c6c6f20576f726c6421", + "id": 9, + "isConstant": false, + "isLValue": false, + "isPure": true, + "kind": "string", + "lValueRequested": false, + "nodeType": "Literal", + "src": "575:14:0", + "typeDescriptions": { + "typeIdentifier": "t_stringliteral_3ea2f1d0abf3fc66cf29eebb70cbd4e7fe762ef8a09bcc06c8edf641230afec0", + "typeString": "literal_string \"Hello World!\"" + }, + "value": "Hello World!" + }, + "functionReturnParameters": 8, + "id": 10, + "nodeType": "Return", + "src": "568:21:0" + } + ] + }, + "functionSelector": "ef5fb05b", + "id": 12, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "sayHello", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 5, + "nodeType": "ParameterList", + "parameters": [], + "src": "523:2:0" + }, + "returnParameters": { + "id": 8, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 7, + "mutability": "mutable", + "name": "", + "nodeType": "VariableDeclaration", + "scope": 12, + "src": "547:13:0", + "stateVariable": false, + "storageLocation": "memory", + "typeDescriptions": { + "typeIdentifier": "t_string_memory_ptr", + "typeString": "string" + }, + "typeName": { + "id": 6, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "547:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + } + ], + "src": "546:15:0" + }, + "scope": 31, + "src": "505:89:0", + "stateMutability": "pure", + "virtual": false, + "visibility": "public" + }, + { + "body": { + "id": 19, + "nodeType": "Block", + "src": "655:24:0", + "statements": [ + { + "expression": { + "id": 17, + "name": "name", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 4, + "src": "670:4:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage", + "typeString": "string storage ref" + } + }, + "functionReturnParameters": 16, + "id": 18, + "nodeType": "Return", + "src": "663:11:0" + } + ] + }, + "functionSelector": "17d7de7c", + "id": 20, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "getName", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 13, + "nodeType": "ParameterList", + "parameters": [], + "src": "614:2:0" + }, + "returnParameters": { + "id": 16, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 15, + "mutability": "mutable", + "name": "", + "nodeType": "VariableDeclaration", + "scope": 20, + "src": "638:13:0", + "stateVariable": false, + "storageLocation": "memory", + "typeDescriptions": { + "typeIdentifier": "t_string_memory_ptr", + "typeString": "string" + }, + "typeName": { + "id": 14, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "638:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + } + ], + "src": "637:15:0" + }, + "scope": 31, + "src": "598:81:0", + "stateMutability": "view", + "virtual": false, + "visibility": "public" + }, + { + "body": { + "id": 29, + "nodeType": "Block", + "src": "732:27:0", + "statements": [ + { + "expression": { + "id": 27, + "isConstant": false, + "isLValue": false, + "isPure": false, + "lValueRequested": false, + "leftHandSide": { + "id": 25, + "name": "name", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 4, + "src": "740:4:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage", + "typeString": "string storage ref" + } + }, + "nodeType": "Assignment", + "operator": "=", + "rightHandSide": { + "id": 26, + "name": "newName", + "nodeType": "Identifier", + "overloadedDeclarations": [], + "referencedDeclaration": 22, + "src": "747:7:0", + "typeDescriptions": { + "typeIdentifier": "t_string_memory_ptr", + "typeString": "string memory" + } + }, + "src": "740:14:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage", + "typeString": "string storage ref" + } + }, + "id": 28, + "nodeType": "ExpressionStatement", + "src": "740:14:0" + } + ] + }, + "functionSelector": "c47f0027", + "id": 30, + "implemented": true, + "kind": "function", + "modifiers": [], + "name": "setName", + "nodeType": "FunctionDefinition", + "parameters": { + "id": 23, + "nodeType": "ParameterList", + "parameters": [ + { + "constant": false, + "id": 22, + "mutability": "mutable", + "name": "newName", + "nodeType": "VariableDeclaration", + "scope": 30, + "src": "700:21:0", + "stateVariable": false, + "storageLocation": "memory", + "typeDescriptions": { + "typeIdentifier": "t_string_memory_ptr", + "typeString": "string" + }, + "typeName": { + "id": 21, + "name": "string", + "nodeType": "ElementaryTypeName", + "src": "700:6:0", + "typeDescriptions": { + "typeIdentifier": "t_string_storage_ptr", + "typeString": "string" + } + }, + "visibility": "internal" + } + ], + "src": "699:23:0" + }, + "returnParameters": { + "id": 24, + "nodeType": "ParameterList", + "parameters": [], + "src": "732:0:0" + }, + "scope": 31, + "src": "683:76:0", + "stateMutability": "nonpayable", + "virtual": false, + "visibility": "public" + } + ], + "scope": 32, + "src": "439:322:0" + } + ], + "src": "413:349:0" + }, + "functionHashes": { + "getName()": "17d7de7c", + "sayHello()": "ef5fb05b", + "setName(string)": "c47f0027" + }, + "gasEstimates": { + "creation": { + "codeDepositCost": "156600", + "executionCost": "infinite", + "totalCost": "infinite" + }, + "external": { + "getName()": "infinite", + "sayHello()": "infinite", + "setName(string)": "infinite" + } + } +} diff --git a/packages/cactus-test-geth-ledger/src/test/solidity/hello-world-contract/HelloWorld.sol b/packages/cactus-test-geth-ledger/src/test/solidity/hello-world-contract/HelloWorld.sol new file mode 100644 index 0000000000..201fddd6fc --- /dev/null +++ b/packages/cactus-test-geth-ledger/src/test/solidity/hello-world-contract/HelloWorld.sol @@ -0,0 +1,24 @@ +// ***************************************************************************** +// IMPORTANT: If you update this code then make sure to recompile +// it and update the .json file as well so that they +// remain in sync for consistent test executions. +// With that said, there shouldn't be any reason to recompile this, like ever... +// ***************************************************************************** + +pragma solidity >=0.7.0; + +contract HelloWorld { + string private name = "CaptainCactus"; + + function sayHello() public pure returns (string memory) { + return "Hello World!"; + } + + function getName() public view returns (string memory) { + return name; + } + + function setName(string memory newName) public { + name = newName; + } +} diff --git a/packages/cactus-test-geth-ledger/src/test/typescript/integration/geth-test-ledger.test.ts b/packages/cactus-test-geth-ledger/src/test/typescript/integration/geth-test-ledger.test.ts index 9cae4bb245..3289183a93 100644 --- a/packages/cactus-test-geth-ledger/src/test/typescript/integration/geth-test-ledger.test.ts +++ b/packages/cactus-test-geth-ledger/src/test/typescript/integration/geth-test-ledger.test.ts @@ -6,15 +6,11 @@ // Constants ////////////////////////////////// -// Ledger settings -// const containerImageName = "ghcr.io/hyperledger/cactus-geth-all-in-one"; -// const containerImageVersion = "2022-10-18-06770b6c"; -// const useRunningLedger = false; - // Log settings const testLogLevel: LogLevelDesc = "info"; import { GethTestLedger } from "../../../main/typescript/index"; +import contractData from "../../solidity/hello-world-contract/HelloWorld.json"; import { LogLevelDesc, @@ -37,6 +33,7 @@ const log: Logger = LoggerProvider.getOrCreate({ */ describe("Geth Test Ledger checks", () => { let ledger: GethTestLedger; + let web3Instance: Web3; ////////////////////////////////// // Environment Setup @@ -51,10 +48,12 @@ describe("Geth Test Ledger checks", () => { emitContainerLogs: true, logLevel: testLogLevel, }); - log.debug("Geth image:", ledger.fullContainerImageName); expect(ledger).toBeTruthy(); + log.debug("Geth image:", ledger.fullContainerImageName); await ledger.start(); + web3Instance = new Web3(await ledger.getRpcApiHttpHost()); + expect(web3Instance).toBeTruthy; }); afterAll(async () => { @@ -99,4 +98,78 @@ describe("Geth Test Ledger checks", () => { wsWeb3.provider?.disconnect(); } }); + + test("Class name is correct", async () => { + const className = ledger.className; + expect(className).toEqual("GethTestLedger"); + }); + + test("Method createEthTestAccount works", async () => { + const testEthAcc = await ledger.createEthTestAccount(); + + expect(testEthAcc).toBeTruthy(); + expect(testEthAcc.address).toHaveLength(42); + expect(testEthAcc.address).toStartWith("0x"); + }); + + test("Method newEthPersonalAccount works", async () => { + const testEthAccount = await ledger.newEthPersonalAccount(); + + expect(testEthAccount).toBeTruthy(); + expect(testEthAccount).toHaveLength(42); + expect(testEthAccount).toStartWith("0x"); + }); + + test("Method transferAssetFromCoinbase works", async () => { + const testEthAcc = await ledger.createEthTestAccount(); + + const txReceipt = await ledger.transferAssetFromCoinbase( + testEthAcc.address, + 1000, + ); + + expect(txReceipt).toBeTruthy(); + expect(web3Instance.utils.toChecksumAddress(txReceipt.to)).toEqual( + testEthAcc.address, + ); + expect(await web3Instance.eth.getBalance(testEthAcc.address)).toEqual( + BigInt("10000000000000001000"), + ); + }); + + test("Method deployContract works and returns contract address", async () => { + const deployedData = await ledger.deployContract( + contractData.abi, + contractData.bytecode, + [], + ); + expect(deployedData).toBeTruthy(); + expect(deployedData.contractAddress).toStartWith("0x"); + expect(deployedData.contractAddress).toHaveLength(42); + + const contract = new web3Instance.eth.Contract( + contractData.abi, + deployedData.contractAddress, + ); + expect(contract).toBeTruthy(); + + const contractCallResult = await contract.methods.sayHello().call(); + expect(contractCallResult).toEqual("Hello World!"); + }); + + test("Method getRpcApiHttpHost returns valid URL", async () => { + const httpHostAddress = await ledger.getRpcApiHttpHost(); + const httpPort = await ledger.getHostPortHttp(); + expect(httpHostAddress).toBeTruthy(); + expect(httpHostAddress).toStartWith("http://"); + expect(httpHostAddress).toContain(`${httpPort}`); + }); + + test("Method getRpcApiWebSocketHost returns valid URL", async () => { + const wsHostAddress = await ledger.getRpcApiWebSocketHost(); + const wsPort = await ledger.getHostPortWs(); + expect(wsHostAddress).toBeTruthy(); + expect(wsHostAddress).toStartWith("ws://"); + expect(wsHostAddress).toContain(`${wsPort}`); + }); }); diff --git a/packages/cactus-test-geth-ledger/tsconfig.json b/packages/cactus-test-geth-ledger/tsconfig.json index 95cf4429f7..ea14a1f425 100644 --- a/packages/cactus-test-geth-ledger/tsconfig.json +++ b/packages/cactus-test-geth-ledger/tsconfig.json @@ -7,9 +7,7 @@ "rootDir": "./src", "tsBuildInfoFile": "../../.build-cache/cactus-test-geth-ledger.tsbuildinfo" }, - "include": [ - "./src" - ], + "include": ["./src", "src/**/*.json"], "references": [ { "path": "../cactus-common/tsconfig.json" @@ -18,4 +16,4 @@ "path": "../cactus-test-tooling/tsconfig.json" } ] -} \ No newline at end of file +} diff --git a/packages/cactus-test-tooling/src/main/typescript/socketio-test-setup-helpers/socketio-test-setup-helpers.ts b/packages/cactus-test-tooling/src/main/typescript/socketio-test-setup-helpers/socketio-test-setup-helpers.ts index d2483aa1e6..dfbb33ac09 100644 --- a/packages/cactus-test-tooling/src/main/typescript/socketio-test-setup-helpers/socketio-test-setup-helpers.ts +++ b/packages/cactus-test-tooling/src/main/typescript/socketio-test-setup-helpers/socketio-test-setup-helpers.ts @@ -7,12 +7,7 @@ import { ServerOptions as SocketServerOptions, Socket as ServerSocket, } from "socket.io"; -import { - io, - Socket as ClientSocket, - ManagerOptions, - SocketOptions, -} from "socket.io-client-fixed-types"; +import { io, Socket as ClientSocket } from "socket.io-client-fixed-types"; import { createServer } from "http"; export { Server, ServerSocket, ClientSocket }; @@ -53,13 +48,13 @@ export function createListeningMockServer(): Promise<[Server, string]> { * @port - Localhost port to connect to. */ export function createClientSocket(port: string): ClientSocket { - const clientSocketOpts: Partial = { + const clientSocketOpts = { reconnectionAttempts: 10, reconnectionDelay: 1000, transports: ["websocket"], }; - return io(`http://127.0.0.1:${port}`, clientSocketOpts as any); + return io(`http://127.0.0.1:${port}`, clientSocketOpts); } /** diff --git a/packages/cactus-test-verifier-client/package.json b/packages/cactus-test-verifier-client/package.json index 97cabe0e71..84c07e127a 100644 --- a/packages/cactus-test-verifier-client/package.json +++ b/packages/cactus-test-verifier-client/package.json @@ -62,6 +62,8 @@ "@types/body-parser": "1.19.4", "@types/express": "4.17.19", "@types/node": "14.18.54", + "@types/uuid": "9.0.6", + "uuid": "9.0.1", "web3-eth-accounts": "4.0.3" }, "engines": { diff --git a/packages/cactus-verifier-client/package.json b/packages/cactus-verifier-client/package.json index bef5a4ccd3..abaf84db67 100644 --- a/packages/cactus-verifier-client/package.json +++ b/packages/cactus-verifier-client/package.json @@ -96,7 +96,7 @@ } }, "engines": { - "node": ">=10", + "node": ">=18", "npm": ">=8" }, "publishConfig": { diff --git a/yarn.lock b/yarn.lock index 5caf879cb7..0f17b6cc47 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8259,10 +8259,12 @@ __metadata: "@types/body-parser": 1.19.4 "@types/express": 4.17.19 "@types/node": 14.18.54 + "@types/uuid": 9.0.6 body-parser: 1.20.2 express: 4.18.2 log4js: 6.4.1 socket.io: 4.5.4 + uuid: 9.0.1 web3-eth-accounts: 4.0.3 languageName: unknown linkType: soft