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

test(connector-fabric): fix tests - package io/fs is not in GOROOT #2599

Merged
merged 1 commit into from
Aug 11, 2023
Merged
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 .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"version": "v0.18.0"
},
"ghcr.io/devcontainers-contrib/features/protoc:1": {
"version": "v3.23.4"
"version": "v3.20.3"
}
},
"customizations": {
Expand Down
2 changes: 1 addition & 1 deletion .taprc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ no-check-coverage: true
node-arg:
- --max-old-space-size=4096
jobs: 1
timeout: 900
timeout: 3600
ts: true
files:
- ./packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/openapi/openapi-validation.test.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"express-openapi-validator": "3.10.0",
"internal-ip": "6.2.0",
"joi": "17.9.1",
"node-ssh": "12.0.0",
"node-ssh": "13.1.0",
"prom-client": "13.2.0",
"rxjs": "7.8.1",
"temp": "0.9.4",
Expand All @@ -73,7 +73,6 @@
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.1",
"@types/express": "4.17.13",
"@types/multer": "1.4.7",
"@types/node-ssh": "7.0.1",
"@types/temp": "0.9.1",
"express": "4.17.3"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,10 @@
* More details: https://github.com/facebook/jest/pull/12789
*/

//////////////////////////////////
// Constants
//////////////////////////////////

// Ledger settings
const imageName = "ghcr.io/hyperledger/cactus-fabric2-all-in-one";
const imageVersion = "2021-09-02--fix-876-supervisord-retries";
const fabricEnvVersion = "2.2.0";
const fabricEnvCAVersion = "1.4.9";
const ledgerUserName = "appUser";
const ledgerChannelName = "mychannel";
const ledgerContractName = "basic";
const leaveLedgerRunning = false; // default: false
const useRunningLedger = false; // default: false

// Log settings
const testLogLevel: LogLevelDesc = "info"; // default: info
const sutLogLevel: LogLevelDesc = "info"; // default: info

import {
DEFAULT_FABRIC_2_AIO_FABRIC_VERSION,
DEFAULT_FABRIC_2_AIO_IMAGE_NAME,
DEFAULT_FABRIC_2_AIO_IMAGE_VERSION,
FabricTestLedgerV1,
pruneDockerAllIfGithubAction,
SelfSignedPkiGenerator,
Expand Down Expand Up @@ -61,6 +45,25 @@ import os from "os";
import "jest-extended";
import { Server as HttpsServer } from "https";

//////////////////////////////////
// Constants
//////////////////////////////////

// Ledger settings
const imageName = DEFAULT_FABRIC_2_AIO_IMAGE_NAME;
const imageVersion = DEFAULT_FABRIC_2_AIO_IMAGE_VERSION;
const fabricEnvVersion = DEFAULT_FABRIC_2_AIO_FABRIC_VERSION;
const fabricEnvCAVersion = "1.4.9";
const ledgerUserName = "appUser";
const ledgerChannelName = "mychannel";
const ledgerContractName = "basic";
const leaveLedgerRunning = false; // default: false
const useRunningLedger = false; // default: false

// Log settings
const testLogLevel: LogLevelDesc = "debug"; // default: info
const sutLogLevel: LogLevelDesc = "debug"; // default: info

// Logger setup
const log: Logger = LoggerProvider.getOrCreate({
label: "fabric-socketio-connector.test",
Expand Down Expand Up @@ -203,7 +206,7 @@ describe("Fabric-SocketIO connector tests", () => {
useRunningLedger,
});
log.debug("Fabric image:", ledger.getContainerImageName());
await ledger.start();
await ledger.start({ omitPull: false });

// Get connection profile
log.info("Get fabric connection profile for Org1...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"jsrsasign": "10.5.25",
"multer": "1.4.5-lts.1",
"ngo": "2.7.0",
"node-ssh": "12.0.0",
"node-ssh": "13.1.0",
"node-vault": "0.9.22",
"openapi-types": "9.1.0",
"prom-client": "13.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { SSHExecCommandResponse } from "node-ssh";
import { RuntimeError } from "run-time-error";

export function isSshExecOk(res: SSHExecCommandResponse): boolean {
const fnTag = "isSshExecOk()";
if (!res) {
throw new RuntimeError(`${fnTag} expected arg res to be truthy.`);
}
return res.code === null || res.code === 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "path";

import { Certificate } from "@fidm/x509";
import { Express } from "express";
import { RuntimeError } from "run-time-error";
import "multer";
import temp from "temp";
import {
Expand Down Expand Up @@ -123,6 +124,7 @@ import {
} from "./common/get-transaction-receipt-by-tx-id";
import { GetBlockEndpointV1 } from "./get-block/get-block-endpoint-v1";
import { querySystemChainCode } from "./common/query-system-chain-code";
import { isSshExecOk } from "./common/is-ssh-exec-ok";

/**
* Constant value holding the default $GOPATH in the Fabric CLI container as
Expand All @@ -148,6 +150,7 @@ export interface IPluginLedgerConnectorFabricOptions
cliContainerEnv: NodeJS.ProcessEnv;
pluginRegistry: PluginRegistry;
sshConfig: SshConfig;
readonly sshDebugOn?: boolean;
connectionProfile: ConnectionProfile;
prometheusExporter?: PrometheusExporter;
discoveryOptions?: GatewayDiscoveryOptions;
Expand Down Expand Up @@ -178,6 +181,7 @@ export class PluginLedgerConnectorFabric
private endpoints: IWebServiceEndpoint[] | undefined;
private readonly secureIdentity: SecureIdentityProviders;
private readonly certStore: CertDatastore;
private readonly sshDebugOn: boolean;
private runningWatchBlocksMonitors = new Set<WatchBlocksV1Endpoint>();

public get className(): string {
Expand Down Expand Up @@ -225,6 +229,11 @@ export class PluginLedgerConnectorFabric
webSocketConfig: opts.webSocketConfig,
});
this.certStore = new CertDatastore(opts.pluginRegistry);

this.sshDebugOn = opts.sshDebugOn === true;
if (this.sshDebugOn) {
this.opts.sshConfig = this.enableSshDebugLogs(this.opts.sshConfig);
}
}

public getOpenApiSpec(): unknown {
Expand Down Expand Up @@ -268,6 +277,16 @@ export class PluginLedgerConnectorFabric

return consensusHasTransactionFinality(currentConsensusAlgorithmFamily);
}

private enableSshDebugLogs(cfg: SshConfig): SshConfig {
const fnTag = `${this.className}#decorateSshConfigWithLogger()`;
Checks.truthy(cfg, `${fnTag} cfg must be truthy.`);
return {
...cfg,
debug: (msg: unknown) => this.log.debug(`[NodeSSH] %o`, msg),
};
}

private async sshExec(
cmd: string,
label: string,
Expand All @@ -276,8 +295,13 @@ export class PluginLedgerConnectorFabric
): Promise<SSHExecCommandResponse> {
this.log.debug(`${label} CMD: ${cmd}`);
const cmdRes = await ssh.execCommand(cmd, sshCmdOptions);
this.log.debug(`${label} CMD Response: %o`, cmdRes);
Checks.truthy(cmdRes.code === null, `${label} cmdRes.code === null`);
this.log.debug(`${label} CMD Response .code: %o`, cmdRes.code);
this.log.debug(`${label} CMD Response .signal: %o`, cmdRes.signal);
this.log.debug(`${label} CMD Response .stderr: %s`, cmdRes.stderr);
this.log.debug(`${label} CMD Response .stdout: %s`, cmdRes.stdout);
if (cmdRes.code !== null && cmdRes.code !== 0) {
throw new RuntimeError(`Expected ${label} cmdRes.code as null or 0`);
}
return cmdRes;
}

Expand All @@ -292,7 +316,10 @@ export class PluginLedgerConnectorFabric
const { log, opts } = this;

const ssh = new NodeSSH();
this.log.debug(`${fnTag} Establishing SSH connection to peer...`);
await ssh.connect(opts.sshConfig);
this.log.debug(`${fnTag} Established SSH connection to peer OK.`);

if (req.collectionsConfigFile) {
log.debug(`Has private data collection definition`);
}
Expand Down Expand Up @@ -569,7 +596,7 @@ export class PluginLedgerConnectorFabric
{
const res = await this.sshExec(commitCmd, "Commit", ssh, sshCmdOptions);
lifecycle.commit = res;
success = success && res.code === null;
success = success && isSshExecOk(res);
}

{
Expand Down Expand Up @@ -781,7 +808,7 @@ export class PluginLedgerConnectorFabric
);

log.debug(`Instantiate CMD Response:%o`, instantiationCommandResponse);
success = success && instantiationCommandResponse.code === null;
success = success && isSshExecOk(instantiationCommandResponse);

log.debug(`EXIT doDeploy()`);
const res: DeployContractGoSourceV1Response = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
module github.com/hyperledger/fabric-samples/asset-transfer-private-data/chaincode-go

go 1.13
go 1.18

require (
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
github.com/hyperledger/fabric-contract-api-go v1.1.0
)

require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/go-openapi/jsonpointer v0.19.3 // indirect
github.com/go-openapi/jsonreference v0.19.4 // indirect
github.com/go-openapi/spec v0.19.8 // indirect
github.com/go-openapi/swag v0.19.9 // indirect
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/hyperledger/fabric-chaincode-go v0.0.0-20200511190512-bcfeb58dd83a
github.com/hyperledger/fabric-contract-api-go v1.1.0
github.com/gobuffalo/packr v1.30.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hyperledger/fabric-protos-go v0.0.0-20200707132912-fee30f3ccd23 // indirect
github.com/joho/godotenv v1.3.0 // indirect
github.com/mailru/easyjson v0.7.1 // indirect
github.com/rogpeppe/go-internal v1.6.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
)
Loading
Loading