src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 228:2 - Line 241:5), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 178:2 - Line 191:2)
Show code Hide code {
const parameters = {
keychainId: keychainIdForUnsigned,
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
constructorArgs: [],
web3SigningCredential: {
ethAccount: testEthAccount1.address,
secret: testEthAccount1.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
bytecode: HelloWorldContractJson.bytecode,
gas: 1000000,
fake
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 303:2 - Line 315:5), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 255:2 - Line 267:2)
Show code Hide code {
const parameters = {
contractName: "HelloWorld",
keychainId: keychainIdForUnsigned,
invocationType: EthContractInvocationType.Call,
methodName: "sayHello",
params: [],
signingCredential: {
ethAccount: testEthAccount1.address,
secret: testEthAccount1.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
fake
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 317:24 - Line 327:5), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 214:7 - Line 255:8)
Show code Hide code );
} catch (e) {
expect(e.response.status).toEqual(400);
const fields = e.response.data.map((param: { readonly path: string }) =>
param.path.replace("/body/", ""),
);
expect(fields.includes("fake")).toBeTrue();
}
});
test(`${testCase} - ${fRun
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 356:2 - Line 369:2), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 327:2 - Line 340:20)
Show code Hide code {
const parameters = {
web3SigningCredential: {
ethAccount: testEthAccount1.address,
secret: testEthAccount1.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
transactionConfig: {
from: testEthAccount1.address,
to: testEthAccount2.address,
value: 10e7,
gas: 1000000,
},
}
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 380:15 - Line 399:5), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 355:15 - Line 345:2)
Show code Hide code }`, async () => {
try {
const parameters = {
web3SigningCredential: {
ethAccount: testEthAccount1.address,
secret: testEthAccount1.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
transactionConfig: {
from: testEthAccount1.address,
to: testEthAccount2.address,
value: 10e7,
gas: 1000000,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
timeoutMs: 5000,
},
fake
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 399:2 - Line 411:6), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 368:2 - Line 255:8)
Show code Hide code ,
};
await apiClient.runTransactionV1(parameters as RunTransactionRequest);
} catch (e) {
expect(e.response.status).toEqual(400);
const fields = e.response.data.map((param: { readonly path: string }) =>
param.path.replace("/body/", ""),
);
expect(fields.includes("fake")).toBeTrue();
}
});
test(`${testCase} - ${fSign
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 461:15 - Line 481:2), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 411:4 - Line 432:2)
Show code Hide code }`, async () => {
const runTxRes = await apiClient.runTransactionV1({
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.LedgerBlockAck,
timeoutMs: 5000,
},
transactionConfig: {
from: testEthAccount1.address,
to: testEthAccount2.address,
value: 1,
gas: 10000000,
},
web3SigningCredential: {
ethAccount: testEthAccount1.address,
secret: testEthAccount1.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(runTxRes).toBeTruthy();
expect(runTxRes.
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 502:15 - Line 528:11), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 411:4 - Line 487:12)
Show code Hide code }`, async () => {
const runTxRes = await apiClient.runTransactionV1({
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.LedgerBlockAck,
timeoutMs: 5000,
},
transactionConfig: {
from: testEthAccount1.address,
to: testEthAccount2.address,
value: 1,
gas: 10000000,
},
web3SigningCredential: {
ethAccount: testEthAccount1.address,
secret: testEthAccount1.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(runTxRes).toBeTruthy();
expect(runTxRes.status).toEqual(200);
expect(runTxRes.data).toBeTruthy();
expect((runTxRes.data as any).data.transactionReceipt).toBeTruthy();
try {
const parameters = {
keychainId
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 535:23 - Line 545:9), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 214:7 - Line 255:8)
Show code Hide code );
} catch (e) {
expect(e.response.status).toEqual(400);
const fields = e.response.data.map((param: { readonly path: string }) =>
param.path.replace("/body/", ""),
);
expect(fields.includes("fake")).toBeTrue();
}
});
test(`${testCase} - ${fBalance
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 570:7 - Line 581:7), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 554:2 - Line 255:8)
Show code Hide code };
await apiClient.getBalanceV1(parameters as GetBalanceV1Request);
} catch (e) {
expect(e.response.status).toEqual(400);
const fields = e.response.data.map((param: { readonly path: string }) =>
param.path.replace("/body/", ""),
);
expect(fields.includes("fake")).toBeTrue();
}
});
test(`${testCase} - ${fBlock
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 606:7 - Line 617:10), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 590:2 - Line 255:8)
Show code Hide code };
await apiClient.getBlockV1(parameters as GetBlockV1Request);
} catch (e) {
expect(e.response.status).toEqual(400);
const fields = e.response.data.map((param: { readonly path: string }) =>
param.path.replace("/body/", ""),
);
expect(fields.includes("fake")).toBeTrue();
}
});
test(`${testCase} - ${fPastLogs
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 629:21 - Line 639:10), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 214:7 - Line 565:9)
Show code Hide code );
} catch (e) {
expect(e.response.status).toEqual(400);
const fields = e.response.data.map((param: { readonly path: string }) =>
param.path.replace("/body/", ""),
);
expect(fields.includes("address")).toBeTrue();
}
});
test(`${testCase} - ${fPastLogs
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 644:7 - Line 655:8), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 628:2 - Line 255:8)
Show code Hide code };
await apiClient.getPastLogsV1(parameters as GetPastLogsV1Request);
} catch (e) {
expect(e.response.status).toEqual(400);
const fields = e.response.data.map((param: { readonly path: string }) =>
param.path.replace("/body/", ""),
);
expect(fields.includes("fake")).toBeTrue();
}
});
test(`${testCase} - ${fRecord
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 655:8 - Line 676:11), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 411:6 - Line 481:8)
Show code Hide code } - ${cOk}`, async () => {
const runTxRes = await apiClient.runTransactionV1({
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.LedgerBlockAck,
timeoutMs: 5000,
},
transactionConfig: {
from: testEthAccount1.address,
to: testEthAccount2.address,
value: 1,
gas: 10000000,
},
web3SigningCredential: {
ethAccount: testEthAccount1.address,
secret: testEthAccount1.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(runTxRes).toBeTruthy();
expect(runTxRes.status).toBeNumber
src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 711:23 - Line 721:9), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 214:7 - Line 255:5)
Show code Hide code );
} catch (e) {
expect(e.response.status).toEqual(400);
const fields = e.response.data.map((param: { readonly path: string }) =>
param.path.replace("/body/", ""),
);
expect(fields.includes("fake")).toBeTrue();
}
});
afterAll
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 316:2 - Line 328:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 216:5 - Line 228:2)
Show code Hide code expect(setNameOutInvalidTask).rejects.toThrowWithMessage(
Error,
"Returned error: Nonce too low",
);
const { callOutput: getNameOut } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 328:18 - Line 339:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 232:2 - Line 243:2)
Show code Hide code ,
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 339:18 - Line 350:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 247:2 - Line 258:2)
Show code Hide code ,
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 74:2 - Line 91:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 61:5 - Line 78:10)
Show code Hide code 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
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 151:5 - Line 165:3), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 113:2 - Line 127:7)
Show code Hide code ) => {
const deployOut = await connector.deployContract({
keychainId: keychainPlugin.getKeychainId(),
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
constructorArgs: [],
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
bytecode: HelloWorldContractJson.bytecode,
gas: 1000000,
});
t2
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 201:5 - Line 214:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 152:2 - Line 165:6)
Show code Hide code ) => {
const testEthAccount2 = web3.eth.accounts.create(uuidv4());
const { rawTransaction } = await web3.eth.accounts.signTransaction(
{
from: testEthAccount.address,
to: testEthAccount2.address,
value: 10e6,
gas: 1000000,
},
testEthAccount.privateKey,
);
const
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 257:16 - Line 269:3), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 203:2 - Line 216:7)
Show code Hide code ,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
t2
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 299:16 - Line 311:3), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 253:2 - Line 265:7)
Show code Hide code ,
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
value: 10,
});
t2
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts (Line 46:2 - Line 73:11), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 67:2 - Line 94:9)
Show code Hide code ;
const web3 = new Web3(rpcApiHttpHost);
const testEthAccount = web3.eth.accounts.create(uuidv4());
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 connector: PluginLedgerConnectorBesu = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
instanceId
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-block.test.ts (Line 7:18 - Line 30:19), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 11:12 - Line 34:16)
Show code Hide code ,
} 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 HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json";
import Web3 from "web3";
import { PluginImportType } from "@hyperledger/cactus-core-api";
import { Account } from "web3-core";
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);
const keychainEntryKey = uuidv4();
let rpcApiHttpHost: string;
let rpcApiWsHost: string;
let web3: Web3;
let testEthAccount: Account;
let keychainEntryValue
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-block.test.ts (Line 39:5 - Line 63:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 73:2 - Line 85:6)
Show code Hide code 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,
});
connector = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
instanceId: uuidv4(),
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
});
}
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-balance.test.ts (Line 17:8 - Line 33:36), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts (Line 21:2 - Line 37:34)
Show code Hide code ;
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);
beforeAll(async () => {
await besuTestLedger.start();
});
afterAll(async () => {
await besuTestLedger.stop();
await besuTestLedger.destroy();
});
test("can get balance of an ETH account"
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-balance.test.ts (Line 33:36 - Line 71:20), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts (Line 37:34 - Line 77:21)
Show code Hide code , async () => {
const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost();
const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost();
/**
* 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 firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey();
const web3 = new Web3(rpcApiHttpHost);
const testEthAccount = web3.eth.accounts.create(uuidv4());
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 connector: PluginLedgerConnectorBesu = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
instanceId: uuidv4(),
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
});
const req: GetBalanceV1Request
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 14:16 - Line 29:8), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 13:23 - Line 28:2)
Show code Hide code ,
} from "../../../../../main/typescript/public-api";
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
import {
BesuTestLedger,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
import {
LogLevelDesc,
IListenOptions,
Servers,
} from "@hyperledger/cactus-common";
import HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json";
import Web3 from "web3";
import { Constants, PluginImportType } from "@hyperledger/cactus-core-api";
import express
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 147:5 - Line 162:10), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 127:3 - Line 142:2)
Show code Hide code await connector.transact({
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
transactionConfig: {
from: firstHighNetWorthAccount,
to: testEthAccount.address,
value: 10e9,
gas: 1000000,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
timeoutMs
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 193:5 - Line 208:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 113:3 - Line 128:2)
Show code Hide code ("deploys contract via .json file", async () => {
const deployOut = await connector.deployContract({
keychainId: keychainPlugin.getKeychainId(),
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
constructorArgs: [],
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
bytecode: HelloWorldContractJson.bytecode,
gas: 1000000,
});
expect(deployOut).toBeTruthy();
expect(deployOut)
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 216:7 - Line 231:7), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 179:2 - Line 194:3)
Show code Hide code ;
const { callOutput: helloMsg } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "sayHello",
params: [],
signingCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 221:16 - Line 236:5), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 137:2 - Line 152:3)
Show code Hide code ,
invocationType: EthContractInvocationType.Call,
methodName: "sayHello",
params: [],
signingCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(helloMsg).toBeTruthy();
expect(helloMsg).toBeString();
expect(helloMsg).not.toBeEmpty();
});
test
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 236:40 - Line 253:18), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 152:56 - Line 169:20)
Show code Hide code , async () => {
const testEthAccount2 = web3.eth.accounts.create(uuidv4());
const { rawTransaction } = await web3.eth.accounts.signTransaction(
{
from: testEthAccount.address,
to: testEthAccount2.address,
value: 10e6,
gas: 1000000,
},
testEthAccount.privateKey,
);
await connector.transact({
web3SigningCredential: {
type: Web3SigningCredentialType.None,
},
transactionConfig
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 267:2 - Line 283:7), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 235:5 - Line 251:3)
Show code Hide code ) => {
const newName = `DrCactus${uuidv4()}`;
const setNameOut = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
expect
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 272:16 - Line 285:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 187:2 - Line 199:7)
Show code Hide code ,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
expect(setNameOut).toBeTruthy();
const
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 285:2 - Line 301:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 254:2 - Line 216:7)
Show code Hide code connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
await
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 305:2 - Line 318:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 277:2 - Line 290:2)
Show code Hide code {
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
})
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 308:16 - Line 323:12), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 223:2 - Line 238:11)
Show code Hide code ,
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 324:16 - Line 339:12), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 238:2 - Line 253:11)
Show code Hide code ,
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 335:2 - Line 356:12), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 294:42 - Line 269:11)
Show code Hide code );
const response = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
value: 10,
});
expect(response).toBeTruthy();
const { callOutput } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 354:2 - Line 367:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 313:2 - Line 326:2)
Show code Hide code {
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getNameByIndex",
params: [0],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
})
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 357:16 - Line 372:5), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 269:2 - Line 283:3)
Show code Hide code ,
invocationType: EthContractInvocationType.Call,
methodName: "getNameByIndex",
params: [0],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(callOutput).toEqual(newName);
});
test
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 372:53 - Line 384:12), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 283:69 - Line 294:11)
Show code Hide code , async () => {
const newName = `DrCactus${uuidv4()}`;
const signingCredential: Web3SigningCredentialCactusKeychainRef = {
ethAccount: testEthAccount.address,
keychainEntryKey,
keychainId: keychainPlugin.getKeychainId(),
type: Web3SigningCredentialType.CactusKeychainRef,
};
const setNameOut = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 407:19 - Line 419:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 301:19 - Line 313:2)
Show code Hide code ).rejects.toMatchObject<Partial<Error>>({
message: expect.stringContaining("Nonce too low"),
});
const { callOutput: getNameOut } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 414:16 - Line 425:12), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 323:2 - Line 334:11)
Show code Hide code ,
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 419:18 - Line 431:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 317:2 - Line 329:2)
Show code Hide code ,
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 431:18 - Line 444:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 333:2 - Line 345:2)
Show code Hide code ,
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 444:18 - Line 456:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 349:2 - Line 360:2)
Show code Hide code ,
value: 10,
});
expect(response).toBeTruthy();
const { callOutput } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getNameByIndex",
params: [1
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json-no-keychain.test.ts (Line 1:1 - Line 70:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 1:1 - Line 70:15)
Show code Hide code import "jest-extended";
import { v4 as uuidv4 } from "uuid";
import { Server as SocketIoServer } from "socket.io";
import { PluginRegistry } from "@hyperledger/cactus-core";
import {
EthContractInvocationType,
Web3SigningCredentialType,
PluginLedgerConnectorBesu,
PluginFactoryLedgerConnector,
Web3SigningCredentialCactusKeychainRef,
ReceiptType,
BesuApiClient,
WatchBlocksV1Progress,
Web3BlockHeader,
} from "../../../../../main/typescript/public-api";
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
import {
BesuTestLedger,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
import {
LogLevelDesc,
IListenOptions,
Servers,
} from "@hyperledger/cactus-common";
import HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json";
import Web3 from "web3";
import { Constants, PluginImportType } from "@hyperledger/cactus-core-api";
import express from "express";
import bodyParser from "body-parser";
import http from "http";
import { AddressInfo } from "net";
import { K_CACTUS_BESU_TOTAL_TX_COUNT } from "../../../../../main/typescript/prometheus-exporter/metrics";
import { BesuApiClientOptions } from "../../../../../main/typescript/api-client/besu-api-client";
import { Account } from "web3-core";
describe("PluginLedgerConnectorBesu", () => {
const testCase = "deploys contract via .json file";
const logLevel: LogLevelDesc = "INFO";
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);
const besuKeyPair = {
privateKey: besuTestLedger.getGenesisAccountPrivKey(),
};
const keychainEntryKey = uuidv4();
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(),
logLevel,
});
const factory = new PluginFactoryLedgerConnector({
pluginImportType: PluginImportType.Local,
});
const expressApp = express();
expressApp.use(bodyParser.json({ limit: "250mb" }));
const server = http.createServer(expressApp);
const pluginRegistry = new PluginRegistry({ plugins: [keychainPlugin] });
const
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json-no-keychain.test.ts (Line 68:2 - Line 189:19), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 73:3 - Line 194:10)
Show code Hide code );
const wsApi = new SocketIoServer(server, {
path: Constants.SocketIoConnectionPathV1,
});
const listenOptions: IListenOptions = {
hostname: "127.0.0.1",
port: 0,
server,
};
let rpcApiHttpHost: string;
let rpcApiWsHost: string;
let firstHighNetWorthAccount: string;
let web3: Web3;
let testEthAccount: Account;
let keychainEntryValue: string;
let connector: PluginLedgerConnectorBesu;
let addressInfo: AddressInfo;
let apiClient: BesuApiClient;
let apiHost: string;
let contractAddress: string;
beforeAll(async () => {
await pruneDockerAllIfGithubAction({ logLevel });
});
beforeAll(async () => {
await besuTestLedger.start();
rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost();
rpcApiWsHost = await besuTestLedger.getRpcApiWsHost();
firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey();
web3 = new Web3(rpcApiHttpHost);
testEthAccount = web3.eth.accounts.create(uuidv4());
keychainEntryValue = testEthAccount.privateKey;
keychainPlugin.set(keychainEntryKey, keychainEntryValue);
addressInfo = await Servers.listen(listenOptions);
connector = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
logLevel,
instanceId: uuidv4(),
pluginRegistry,
});
const { address, port } = addressInfo;
apiHost = `http://${address}:${port}`;
const besuApiClientOptions = new BesuApiClientOptions({
basePath: apiHost,
});
apiClient = new BesuApiClient(besuApiClientOptions);
await connector.getOrCreateWebServices();
await connector.registerWebServices(expressApp, wsApi);
});
afterAll(async () => {
await Servers.shutdown(server);
});
afterAll(async () => {
await besuTestLedger.stop();
await besuTestLedger.destroy();
});
afterAll(async () => {
await pruneDockerAllIfGithubAction({ logLevel });
});
test(testCase, async () => {
await connector.transact({
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
transactionConfig: {
from: firstHighNetWorthAccount,
to: testEthAccount.address,
value: 10e9,
gas: 1000000,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
timeoutMs: 60000,
},
});
const blocks = await apiClient.watchBlocksV1();
const aBlockHeader = await new Promise<Web3BlockHeader>(
(resolve, reject) => {
let done = false;
const timerId = setTimeout(() => {
if (!done) {
reject("Waiting for block header notification to arrive timed out");
}
}, 10000);
const subscription = blocks.subscribe((res: WatchBlocksV1Progress) => {
subscription.unsubscribe();
done = true;
clearTimeout(timerId);
resolve(res.blockHeader);
});
},
);
expect(aBlockHeader).toBeTruthy();
expect(aBlockHeader).toBeObject();
expect(aBlockHeader).not.toBeEmptyObject();
const balance = await web3.eth.getBalance(testEthAccount.address);
expect(balance).toBeTruthy();
expect(parseInt(balance, 10)).toEqual(10e9);
});
test("deploys contract via .json file", async () => {
const contractJSONString
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json-no-keychain.test.ts (Line 193:19 - Line 479:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 117:4 - Line 483:2)
Show code Hide code ,
constructorArgs: [],
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
bytecode: HelloWorldContractJson.bytecode,
gas: 1000000,
});
expect(deployOut).toBeTruthy();
expect(deployOut).toBeObject();
expect(deployOut.transactionReceipt).toBeTruthy();
expect(deployOut.transactionReceipt).toBeObject();
expect(deployOut.transactionReceipt.contractAddress).toBeTruthy();
expect(deployOut.transactionReceipt.contractAddress).toBeString();
contractAddress = deployOut.transactionReceipt.contractAddress as string;
const { callOutput: helloMsg } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "sayHello",
params: [],
signingCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(helloMsg).toBeTruthy();
expect(helloMsg).toBeString();
expect(helloMsg).not.toBeEmpty();
});
test("invoke Web3SigningCredentialType.NONE", async () => {
const testEthAccount2 = web3.eth.accounts.create(uuidv4());
const { rawTransaction } = await web3.eth.accounts.signTransaction(
{
from: testEthAccount.address,
to: testEthAccount2.address,
value: 10e6,
gas: 1000000,
},
testEthAccount.privateKey,
);
await connector.transact({
web3SigningCredential: {
type: Web3SigningCredentialType.None,
},
transactionConfig: {
rawTransaction,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
timeoutMs: 60000,
},
});
const balance2 = await web3.eth.getBalance(testEthAccount2.address);
expect(parseInt(balance2, 10)).toEqual(10e6);
});
test("invoke Web3SigningCredentialType.PrivateKeyHex", async () => {
const newName = `DrCactus${uuidv4()}`;
const setNameOut = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
expect(setNameOut).toBeTruthy();
const setNameOutPromise1 = connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
await expect(setNameOutPromise1).rejects.toMatchObject<Partial<Error>>({
message: expect.stringContaining("Nonce too low"),
});
const { callOutput: getNameOut } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
value: 10,
});
expect(response).toBeTruthy();
const { callOutput } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getNameByIndex",
params: [0],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(callOutput).toEqual(newName);
});
test("invoke Web3SigningCredentialType.CactusKeychainRef", async () => {
const newName = `DrCactus${uuidv4()}`;
const signingCredential: Web3SigningCredentialCactusKeychainRef = {
ethAccount: testEthAccount.address,
keychainEntryKey,
keychainId: keychainPlugin.getKeychainId(),
type: Web3SigningCredentialType.CactusKeychainRef,
};
const setNameOut = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential,
nonce: 4,
});
expect(setNameOut).toBeTruthy();
const setNameOutPromise2 = connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential,
nonce: 4,
});
await expect(setNameOutPromise2).rejects.toMatchObject<Partial<Error>>({
message: expect.stringContaining("Nonce too low"),
});
const { callOutput: getNameOut } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential,
value: 10,
});
expect(response).toBeTruthy();
const { callOutput } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getNameByIndex",
params: [1],
gas: 1000000,
signingCredential,
});
expect(callOutput).toEqual(newName);
});
test("get prometheus exporter metrics", async () => {
const res = await apiClient.getPrometheusMetricsV1();
const promMetricsOutput =
"# HELP " +
K_CACTUS_BESU_TOTAL_TX_COUNT +
" Total transactions executed\n" +
"# TYPE " +
K_CACTUS_BESU_TOTAL_TX_COUNT +
" gauge\n" +
K_CACTUS_BESU_TOTAL_TX_COUNT +
'{type="' +
K_CACTUS_BESU_TOTAL_TX_COUNT +
'"} 9';
expect(res).toBeTruthy();
expect(res.data).toBeTruthy();
expect(res.status).toEqual(200);
expect(res.data.includes(promMetricsOutput)).toBeTrue();
});
});
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 25:197 - Line 66:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-web3-eea.test.ts (Line 13:8 - Line 54:5)
Show code Hide code ;
// WARNING: the keys here are demo purposes ONLY. Please use a tool like Orchestrate or EthSigner for production, rather than hard coding private keys
const keysStatic = {
tessera: {
member1: {
publicKey: "BULeR8JyUWhiuuCMU/HLA0Q5pzkYT+cHII3ZKBey3Bo=",
},
member2: {
publicKey: "QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc=",
},
member3: {
publicKey: "1iTZde/ndBHvzhcl7V68x44Vx7pl8nwx9LqnM/AfJUg=",
},
},
besu: {
member1: {
url: "http://127.0.0.1:20000",
wsUrl: "ws://127.0.0.1:20001",
privateKey:
"8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63",
},
member2: {
url: "http://127.0.0.1:20002",
wsUrl: "ws://127.0.0.1:20003",
privateKey:
"c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
},
member3: {
url: "http://127.0.0.1:20004",
wsUrl: "ws://127.0.0.1:20005",
privateKey:
"ae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f",
},
ethsignerProxy: {
url: "http://127.0.0.1:18545",
accountAddress: "9b790656b9ec0db1936ed84b3bea605873558198",
},
},
};
const
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 74:2 - Line 95:23), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-web3-eea.test.ts (Line 54:5 - Line 74:5)
Show code Hide code ) => {
// At development time one can specify this environment variable if there is
// a multi-party network already running, which is doable with something like
// this on the terminal:
// docker run --rm --privileged --publish 2222:22 --publish 3000:3000 --publish 8545:8545 --publish 8546:8546 --publish 9001:9001 --publish 9081:9081 --publish 9082:9082 --publish 9083:9083 --publish 9090:9090 --publish 18545:18545 --publish 20000:20000 --publish 20001:20001 --publish 20002:20002 --publish 20003:20003 --publish 20004:20004 --publish 20005:20005 --publish 25000:25000 petermetz/cactus-besu-multi-party-all-in-one:0.1.2
//
// The upside of this approach is that a new container is not launched from
// scratch for every test execution which enables faster iteration.
const preWarmedLedger =
process.env.CACTUS_TEST_PRE_WARMED_LEDGER === "true";
let keys: any;
if (preWarmedLedger) {
keys = keysStatic;
} else {
const ledger = new BesuMpTestLedger({
logLevel,
imageName: containerImageName,
imageTag: containerImageTag,
emitContainerLogs: false,
});
infrastructureElements
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 229:8 - Line 241:7), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 205:8 - Line 216:16)
Show code Hide code ,
});
expect(deployOut).toBeTruthy();
expect(deployOut).toBeObject();
expect(deployOut.transactionReceipt).toBeTruthy();
expect(deployOut.transactionReceipt).toBeObject();
expect(deployOut.transactionReceipt.contractAddress).toBeTruthy();
expect(deployOut.transactionReceipt.contractAddress).toBeString();
expect
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 325:5 - Line 337:7), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-web3-eea.test.ts (Line 201:13 - Line 213:2)
Show code Hide code ,
privateFrom: keys.tessera.member1.publicKey,
privateFor: [keys.tessera.member2.publicKey],
privateKey: keys.besu.member1.privateKey,
};
const privacyGroupId =
web3QuorumMember1.utils.generatePrivacyGroup(fnParams);
const callOutput = await web3QuorumMember1.priv.call(privacyGroupId, {
to: contractDeployReceipt.contractAddress,
data: contract.methods.getName().encodeABI(),
});
expect
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 348:5 - Line 358:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-web3-eea.test.ts (Line 225:2 - Line 235:2)
Show code Hide code ,
privateFrom: keys.tessera.member1.publicKey,
privateFor: [keys.tessera.member2.publicKey],
privateKey: keys.besu.member3.privateKey,
};
const privacyGroupId =
web3QuorumMember3.utils.generatePrivacyGroup(fnParams);
const callOutput = await web3QuorumMember3.priv.call(privacyGroupId, {
to: contractDeployReceipt.contractAddress,
data,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 452:2 - Line 463:11), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 430:16 - Line 441:8)
Show code Hide code ],
privateTransactionConfig: {
privateFrom: keys.tessera.member1.publicKey,
privateFor: [keys.tessera.member2.publicKey],
},
signingCredential: {
secret: keys.besu.member1.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(res.callOutput
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 467:11 - Line 489:11), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 445:11 - Line 467:11)
Show code Hide code .invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress: contractDeployReceipt.contractAddress,
invocationType: EthContractInvocationType.Call,
gas: 3000000,
methodName: "getName",
params: [],
privateTransactionConfig: {
privateFrom: keys.tessera.member1.publicKey,
privateFor: [keys.tessera.member2.publicKey],
},
signingCredential: {
secret: keys.besu.member1.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(res.callOutput).toEqual(doctorCactusHex);
}
{
const res = await connector3
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 489:11 - Line 502:8), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/private-deploy-contract-from-json-cactus.test.ts (Line 445:11 - Line 458:8)
Show code Hide code .invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress: contractDeployReceipt.contractAddress,
invocationType: EthContractInvocationType.Call,
gas: 3000000,
methodName: "getName",
params: [],
privateTransactionConfig: {
privateFrom: keys.tessera.member1.publicKey,
privateFor: [keys.tessera.member2.publicKey],
},
signingCredential: {
secret: keys.besu.member3
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 1:1 - Line 19:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 1:1 - Line 19:7)
Show code Hide code import "jest-extended";
import { v4 as uuidv4 } from "uuid";
import { PluginRegistry } from "@hyperledger/cactus-core";
import {
EthContractInvocationType,
Web3SigningCredentialType,
PluginLedgerConnectorBesu,
PluginFactoryLedgerConnector,
Web3SigningCredentialCactusKeychainRef,
ReceiptType,
} 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 HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json";
import Web3 from "web3";
import { PluginImportType } from "@hyperledger/cactus-core-api";
const
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 45:13 - Line 75:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 67:2 - Line 77:6)
Show code Hide code ;
const web3 = new Web3(rpcApiHttpHost);
const testEthAccount = web3.eth.accounts.create(uuidv4());
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 connector: PluginLedgerConnectorBesu = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
instanceId: uuidv4(),
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
});
await
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 75:2 - Line 99:4), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 83:2 - Line 106:2)
Show code Hide code );
await connector.transact({
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
},
transactionConfig: {
from: firstHighNetWorthAccount,
to: testEthAccount.address,
value: 10e9,
gas: 1000000,
},
});
const balance = await web3.eth.getBalance(testEthAccount.address);
expect(balance).toBeTruthy();
expect(parseInt(balance, 10)).toEqual(10e9);
let
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 101:5 - Line 120:7), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 113:2 - Line 132:16)
Show code Hide code {
const deployOut = await connector.deployContract({
keychainId: keychainPlugin.getKeychainId(),
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
constructorArgs: [],
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
bytecode: HelloWorldContractJson.bytecode,
gas: 1000000,
});
expect(deployOut).toBeTruthy();
expect(deployOut.transactionReceipt).toBeTruthy();
expect(deployOut.transactionReceipt.contractAddress).toBeTruthy();
contractAddress = deployOut.transactionReceipt.contractAddress as string;
expect(typeof
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 123:9 - Line 135:7), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 136:2 - Line 148:9)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Call,
methodName: "sayHello",
params: [],
signingCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(helloMsg).toBeTruthy();
expect(typeof
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 138:5 - Line 169:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 152:2 - Line 181:2)
Show code Hide code {
const testEthAccount2 = web3.eth.accounts.create(uuidv4());
const { rawTransaction } = await web3.eth.accounts.signTransaction(
{
from: testEthAccount.address,
to: testEthAccount2.address,
value: 10e6,
gas: 1000000,
},
testEthAccount.privateKey,
);
await connector.transact({
web3SigningCredential: {
type: Web3SigningCredentialType.None,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
},
transactionConfig: {
rawTransaction,
},
});
const balance2 = await web3.eth.getBalance(testEthAccount2.address);
expect(balance2).toBeTruthy();
expect(parseInt(balance2, 10)).toEqual(10e6);
}
{
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 172:9 - Line 186:4), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 186:2 - Line 199:7)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
expect(setNameOut).toBeTruthy();
try
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 188:11 - Line 201:18), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 202:2 - Line 216:22)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
expect(setNameOutInvalid
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 207:9 - Line 222:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 222:2 - Line 237:2)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 222:9 - Line 237:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 237:2 - Line 252:2)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 237:9 - Line 253:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 252:2 - Line 268:2)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
value: 10,
});
expect(response).toBeTruthy();
const { callOutput } = await connector.invokeContract({
contractName,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 253:9 - Line 268:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 268:2 - Line 281:2)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Call,
methodName: "getNameByIndex",
params: [0],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(callOutput).toEqual(newName);
}
{
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 268:5 - Line 278:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 283:2 - Line 293:2)
Show code Hide code {
const newName = `DrCactus${uuidv4()}`;
const signingCredential: Web3SigningCredentialCactusKeychainRef = {
ethAccount: testEthAccount.address,
keychainEntryKey,
keychainId: keychainPlugin.getKeychainId(),
type: Web3SigningCredentialType.CactusKeychainRef,
};
const setNameOut = await connector.invokeContract({
contractName,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 285:2 - Line 297:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 182:2 - Line 194:2)
Show code Hide code ,
});
expect(setNameOut).toBeTruthy();
try {
const setNameOutInvalid = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 298:2 - Line 312:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 199:2 - Line 213:2)
Show code Hide code ,
});
expect(setNameOutInvalid.transactionReceipt).toBeFalsy();
} catch (error) {
expect(error.message).toMatch("Nonce too low");
}
const { callOutput: getNameOut } = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 306:9 - Line 317:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 322:2 - Line 333:2)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 312:18 - Line 323:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 217:2 - Line 228:2)
Show code Hide code ,
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 317:9 - Line 328:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 333:2 - Line 344:2)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 323:18 - Line 334:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 232:2 - Line 243:2)
Show code Hide code ,
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/invoke-contract.test.ts (Line 328:9 - Line 340:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 344:2 - Line 357:2)
Show code Hide code contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential,
value: 10,
});
expect(response).toBeTruthy();
const { callOutput: callOut } = await connector.invokeContract({
contractName,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 9:12 - Line 32:15), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 2:7 - Line 24:2)
Show code Hide code ;
import { PluginRegistry } from "@hyperledger/cactus-core";
import {
EthContractInvocationType,
Web3SigningCredentialType,
PluginLedgerConnectorBesu,
PluginFactoryLedgerConnector,
ReceiptType,
InvokeContractV1Request,
BesuApiClientOptions,
BesuApiClient,
GetBesuRecordV1Request,
} from "../../../../../main/typescript/public-api";
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
import {
BesuTestLedger,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
import {
LogLevelDesc,
IListenOptions,
Servers,
LoggerProvider
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 94:2 - Line 116:9), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 58:2 - Line 81:11)
Show code Hide code ;
const keychainEntryValue = testEthAccount.privateKey;
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,
});
connector = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
logLevel
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 125:5 - Line 136:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 101:2 - Line 112:5)
Show code Hide code server = http.createServer(expressApp);
const wsApi = new SocketIoServer(server, {
path: Constants.SocketIoConnectionPathV1,
});
const listenOptions: IListenOptions = {
hostname: "127.0.0.1",
port: 0,
server,
};
const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo;
const
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 153:42 - Line 173:7), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 146:9 - Line 146:2)
Show code Hide code , async () => {
await connector.transact({
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
transactionConfig: {
from: firstHighNetWorthAccount,
to: testEthAccount.address,
value: 10e9,
gas: 1000000,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
},
});
const balance = await web3.eth.getBalance(testEthAccount.address);
expect
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 177:19 - Line 201:12), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 113:34 - Line 137:11)
Show code Hide code , async () => {
const deployOut = await connector.deployContract({
keychainId: keychainPlugin.getKeychainId(),
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
constructorArgs: [],
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
bytecode: HelloWorldContractJson.bytecode,
gas: 1000000,
});
expect(deployOut).toBeTruthy();
expect(deployOut.transactionReceipt).toBeTruthy();
expect(deployOut.transactionReceipt.contractAddress).toBeTruthy();
contractAddress = deployOut.transactionReceipt.contractAddress as string;
expect(contractAddress).toBeString();
expect(contractAddress).not.toBeEmpty();
const { callOutput: helloMsg } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 197:2 - Line 217:23), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 179:5 - Line 236:40)
Show code Hide code );
const { callOutput: helloMsg } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "sayHello",
params: [],
signingCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(helloMsg).toBeTruthy();
expect(helloMsg).toBeString();
expect(helloMsg).not.toBeEmpty();
});
test("getBesuRecord test 1"
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 217:23 - Line 247:7), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 152:56 - Line 231:3)
Show code Hide code , async () => {
const testEthAccount2 = web3.eth.accounts.create(uuidv4());
const { rawTransaction } = await web3.eth.accounts.signTransaction(
{
from: testEthAccount.address,
to: testEthAccount2.address,
value: 10e6,
gas: 1000000,
},
testEthAccount.privateKey,
);
const transactionReceipt = await connector.transact({
web3SigningCredential: {
type: Web3SigningCredentialType.None,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
},
transactionConfig: {
rawTransaction,
},
});
const request: GetBesuRecordV1Request = {
transactionHash: transactionReceipt.transactionReceipt.transactionHash,
};
const getInputData = await api.getBesuRecordV1(request);
expect
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 250:23 - Line 269:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 267:49 - Line 187:6)
Show code Hide code , async () => {
const newName = `DrCactus${uuidv4()}`;
const setNameOut = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
expect(setNameOut).toBeTruthy();
try {
await
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 269:7 - Line 284:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 254:2 - Line 216:7)
Show code Hide code await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
throw
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 293:2 - Line 313:7), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 274:42 - Line 294:3)
Show code Hide code ,
);
}
const req: InvokeContractV1Request = {
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
};
const { callOutput: getNameOut } = await connector.getBesuRecord({
invokeCall: req,
});
expect
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 313:8 - Line 332:5), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 294:42 - Line 267:2)
Show code Hide code );
const response = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
value: 10,
});
expect(response).toBeTruthy();
const req2
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 330:2 - Line 348:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 311:51 - Line 328:2)
Show code Hide code );
const req2: InvokeContractV1Request = {
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getNameByIndex",
params: [0],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
};
const { callOutput } = await connector.getBesuRecord({
invokeCall: req2,
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-past-logs.test.ts (Line 19:2 - Line 36:8), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts (Line 26:12 - Line 45:8)
Show code Hide code );
beforeAll(async () => {
await besuTestLedger.start();
});
afterAll(async () => {
await besuTestLedger.stop();
await besuTestLedger.destroy();
});
test("can get past logs of an account", async () => {
const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost();
const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost();
/**
* Constant defining the standard 'dev' Besu genesis.json contents.
*
* @see https://github.com/hyperledger/besu/blob/1.5.1/config/src/main/resources/dev.json
*/
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-past-logs.test.ts (Line 37:5 - Line 69:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts (Line 46:5 - Line 77:6)
Show code Hide code const firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey();
const web3 = new Web3(rpcApiHttpHost);
const testEthAccount = web3.eth.accounts.create(uuidv4());
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 connector: PluginLedgerConnectorBesu = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
instanceId: uuidv4(),
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
});
await connector.onPluginInit();
const
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-block.test.ts (Line 30:16 - Line 58:13), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts (Line 46:24 - Line 85:9)
Show code Hide code ();
const web3 = new Web3(rpcApiHttpHost);
const testEthAccount = web3.eth.accounts.create(uuidv4());
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,
});
connector = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
instanceId: uuidv4(),
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
});
await connector.onPluginInit
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-balance.test.ts (Line 3:12 - Line 17:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-balance.test.ts (Line 2:7 - Line 16:9)
Show code Hide code ;
import { PluginRegistry } from "@hyperledger/cactus-core";
import {
PluginLedgerConnectorBesu,
PluginFactoryLedgerConnector,
GetBalanceV1Request,
} 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 HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json";
import Web3 from "web3";
import { PluginImportType } from "@hyperledger/cactus-core-api";
const
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-balance.test.ts (Line 62:5 - Line 77:20), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts (Line 62:5 - Line 69:21)
Show code Hide code keychainPlugin.set(
HelloWorldContractJson.contractName,
JSON.stringify(HelloWorldContractJson),
);
const factory = new PluginFactoryLedgerConnector({
pluginImportType: PluginImportType.Local,
});
const connector: PluginLedgerConnectorBesu = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
instanceId: uuidv4(),
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
});
await connector.onPluginInit();
const req: GetBalanceV1Request
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts (Line 1:1 - Line 40:15), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 1:1 - Line 40:22)
Show code Hide code import "jest-extended";
import { v4 as uuidv4 } from "uuid";
import { Server as SocketIoServer } from "socket.io";
import { PluginRegistry } from "@hyperledger/cactus-core";
import {
EthContractInvocationType,
Web3SigningCredentialType,
PluginLedgerConnectorBesu,
PluginFactoryLedgerConnector,
Web3SigningCredentialCactusKeychainRef,
ReceiptType,
BesuApiClient,
WatchBlocksV1Progress,
Web3BlockHeader,
} from "../../../../../main/typescript/public-api";
import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory";
import {
BesuTestLedger,
pruneDockerAllIfGithubAction,
} from "@hyperledger/cactus-test-tooling";
import {
LogLevelDesc,
IListenOptions,
Servers,
} from "@hyperledger/cactus-common";
import HelloWorldContractJson from "../../../../solidity/hello-world-contract/HelloWorld.json";
import Web3 from "web3";
import { Constants, PluginImportType } from "@hyperledger/cactus-core-api";
import express from "express";
import bodyParser from "body-parser";
import http from "http";
import { AddressInfo } from "net";
import { K_CACTUS_BESU_TOTAL_TX_COUNT } from "../../../../../main/typescript/prometheus-exporter/metrics";
import { BesuApiClientOptions } from "../../../../../main/typescript/api-client/besu-api-client";
import { Account } from "web3-core";
describe("PluginLedgerConnectorBesu", () => {
const testCase = "deploys contract via .json file";
const logLevel: LogLevelDesc = "INFO";
const besuTestLedger
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/deploy-contract-from-json.test.ts (Line 40:2 - Line 476:2), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts (Line 44:12 - Line 483:2)
Show code Hide code );
const besuKeyPair = {
privateKey: besuTestLedger.getGenesisAccountPrivKey(),
};
const keychainEntryKey = uuidv4();
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(),
logLevel,
});
const factory = new PluginFactoryLedgerConnector({
pluginImportType: PluginImportType.Local,
});
const expressApp = express();
expressApp.use(bodyParser.json({ limit: "250mb" }));
const server = http.createServer(expressApp);
const pluginRegistry = new PluginRegistry({ plugins: [keychainPlugin] });
keychainPlugin.set(
HelloWorldContractJson.contractName,
JSON.stringify(HelloWorldContractJson),
);
const wsApi = new SocketIoServer(server, {
path: Constants.SocketIoConnectionPathV1,
});
const listenOptions: IListenOptions = {
hostname: "127.0.0.1",
port: 0,
server,
};
let rpcApiHttpHost: string;
let rpcApiWsHost: string;
let firstHighNetWorthAccount: string;
let web3: Web3;
let testEthAccount: Account;
let keychainEntryValue: string;
let connector: PluginLedgerConnectorBesu;
let addressInfo: AddressInfo;
let apiClient: BesuApiClient;
let apiHost: string;
let contractAddress: string;
beforeAll(async () => {
await pruneDockerAllIfGithubAction({ logLevel });
});
beforeAll(async () => {
await besuTestLedger.start();
rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost();
rpcApiWsHost = await besuTestLedger.getRpcApiWsHost();
firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey();
web3 = new Web3(rpcApiHttpHost);
testEthAccount = web3.eth.accounts.create(uuidv4());
keychainEntryValue = testEthAccount.privateKey;
keychainPlugin.set(keychainEntryKey, keychainEntryValue);
addressInfo = await Servers.listen(listenOptions);
connector = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
logLevel,
instanceId: uuidv4(),
pluginRegistry,
});
const { address, port } = addressInfo;
apiHost = `http://${address}:${port}`;
const besuApiClientOptions = new BesuApiClientOptions({
basePath: apiHost,
});
apiClient = new BesuApiClient(besuApiClientOptions);
await connector.getOrCreateWebServices();
await connector.registerWebServices(expressApp, wsApi);
});
afterAll(async () => {
await Servers.shutdown(server);
});
afterAll(async () => {
await besuTestLedger.stop();
await besuTestLedger.destroy();
});
afterAll(async () => {
await pruneDockerAllIfGithubAction({ logLevel });
});
test(testCase, async () => {
await connector.transact({
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
transactionConfig: {
from: firstHighNetWorthAccount,
to: testEthAccount.address,
value: 10e9,
gas: 1000000,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
timeoutMs: 60000,
},
});
const blocks = await apiClient.watchBlocksV1();
const aBlockHeader = await new Promise<Web3BlockHeader>(
(resolve, reject) => {
let done = false;
const timerId = setTimeout(() => {
if (!done) {
reject("Waiting for block header notification to arrive timed out");
}
}, 10000);
const subscription = blocks.subscribe((res: WatchBlocksV1Progress) => {
subscription.unsubscribe();
done = true;
clearTimeout(timerId);
resolve(res.blockHeader);
});
},
);
expect(aBlockHeader).toBeTruthy();
expect(aBlockHeader).toBeObject();
expect(aBlockHeader).not.toBeEmptyObject();
const balance = await web3.eth.getBalance(testEthAccount.address);
expect(balance).toBeTruthy();
expect(parseInt(balance, 10)).toEqual(10e9);
});
test("deploys contract via .json file", async () => {
const deployOut = await connector.deployContract({
keychainId: keychainPlugin.getKeychainId(),
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
constructorArgs: [],
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
bytecode: HelloWorldContractJson.bytecode,
gas: 1000000,
});
expect(deployOut).toBeTruthy();
expect(deployOut).toBeObject();
expect(deployOut.transactionReceipt).toBeTruthy();
expect(deployOut.transactionReceipt).toBeObject();
expect(deployOut.transactionReceipt.contractAddress).toBeTruthy();
expect(deployOut.transactionReceipt.contractAddress).toBeString();
contractAddress = deployOut.transactionReceipt.contractAddress as string;
const { callOutput: helloMsg } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "sayHello",
params: [],
signingCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(helloMsg).toBeTruthy();
expect(helloMsg).toBeString();
expect(helloMsg).not.toBeEmpty();
});
test("invoke Web3SigningCredentialType.NONE", async () => {
const testEthAccount2 = web3.eth.accounts.create(uuidv4());
const { rawTransaction } = await web3.eth.accounts.signTransaction(
{
from: testEthAccount.address,
to: testEthAccount2.address,
value: 10e6,
gas: 1000000,
},
testEthAccount.privateKey,
);
await connector.transact({
web3SigningCredential: {
type: Web3SigningCredentialType.None,
},
transactionConfig: {
rawTransaction,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
timeoutMs: 60000,
},
});
const balance2 = await web3.eth.getBalance(testEthAccount2.address);
expect(parseInt(balance2, 10)).toEqual(10e6);
});
test("invoke Web3SigningCredentialType.PrivateKeyHex", async () => {
const newName = `DrCactus${uuidv4()}`;
const setNameOut = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
expect(setNameOut).toBeTruthy();
const setNameOutPromise1 = connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
nonce: 1,
});
await expect(setNameOutPromise1).rejects.toMatchObject<Partial<Error>>({
message: expect.stringContaining("Nonce too low"),
});
const { callOutput: getNameOut } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
value: 10,
});
expect(response).toBeTruthy();
const { callOutput } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getNameByIndex",
params: [0],
gas: 1000000,
signingCredential: {
ethAccount: testEthAccount.address,
secret: testEthAccount.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
});
expect(callOutput).toEqual(newName);
});
test("invoke Web3SigningCredentialType.CactusKeychainRef", async () => {
const newName = `DrCactus${uuidv4()}`;
const signingCredential: Web3SigningCredentialCactusKeychainRef = {
ethAccount: testEthAccount.address,
keychainEntryKey,
keychainId: keychainPlugin.getKeychainId(),
type: Web3SigningCredentialType.CactusKeychainRef,
};
const setNameOut = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential,
nonce: 4,
});
expect(setNameOut).toBeTruthy();
const setNameOutPromise2 = connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "setName",
params: [newName],
gas: 1000000,
signingCredential,
nonce: 4,
});
await expect(setNameOutPromise2).rejects.toMatchObject<Partial<Error>>({
message: expect.stringContaining("Nonce too low"),
});
const { callOutput: getNameOut } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
});
expect(getNameOut).toEqual(newName);
const getNameOut2 = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "getName",
params: [],
gas: 1000000,
signingCredential,
});
expect(getNameOut2).toBeTruthy();
const response = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Send,
methodName: "deposit",
params: [],
gas: 1000000,
signingCredential,
value: 10,
});
expect(response).toBeTruthy();
const { callOutput } = await connector.invokeContract({
contractName: HelloWorldContractJson.contractName,
contractAbi: HelloWorldContractJson.abi,
contractAddress,
invocationType: EthContractInvocationType.Call,
methodName: "getNameByIndex",
params: [1],
gas: 1000000,
signingCredential,
});
expect(callOutput).toEqual(newName);
});
test("get prometheus exporter metrics", async () => {
const res = await apiClient.getPrometheusMetricsV1();
const promMetricsOutput =
"# HELP " +
K_CACTUS_BESU_TOTAL_TX_COUNT +
" Total transactions executed\n" +
"# TYPE " +
K_CACTUS_BESU_TOTAL_TX_COUNT +
" gauge\n" +
K_CACTUS_BESU_TOTAL_TX_COUNT +
'{type="' +
K_CACTUS_BESU_TOTAL_TX_COUNT +
'"} 9';
expect(res).toBeTruthy();
expect(res.data).toBeTruthy();
expect(res.status).toEqual(200);
expect(res.data.includes(promMetricsOutput)).toBeTrue();
});
});
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/besu-test-ledger-parameters.test.ts (Line 57:23 - Line 71:44), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/besu-test-ledger-parameters.test.ts (Line 36:23 - Line 50:45)
Show code Hide code ,
"BESU_MIN_GAS_PRICE=0",
"BESU_TARGET=/var/lib/besu hyperledger/besu:latest",
];
const besuOptions = {
envVars: rinkebyNetworkEnvVars,
};
const besuTestLedger = new BesuTestLedger(besuOptions);
expect(besuTestLedger.envVars).toEqual(rinkebyNetworkEnvVars);
expect(besuTestLedger).toBeTruthy();
});
test("deploys a Besu Node on the Goerli network"
src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/besu-test-ledger-parameters.test.ts (Line 78:22 - Line 92:51), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/besu-test-ledger-parameters.test.ts (Line 36:23 - Line 50:45)
Show code Hide code ,
"BESU_MIN_GAS_PRICE=0",
"BESU_TARGET=/var/lib/besu hyperledger/besu:latest",
];
const besuOptions = {
envVars: rinkebyNetworkEnvVars,
};
const besuTestLedger = new BesuTestLedger(besuOptions);
expect(besuTestLedger.envVars).toEqual(rinkebyNetworkEnvVars);
expect(besuTestLedger).toBeTruthy();
});
test("deploys a Besu Node on the Ethereum main network"
src/test/typescript/integration/plugin-ledger-connector-besu/v21-besu-get-transaction.test.ts (Line 48:5 - Line 77:11), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 69:3 - Line 77:4)
Show code Hide code const web3 = new Web3(rpcApiHttpHost);
const testEthAccount = web3.eth.accounts.create(uuidv4());
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 connector: PluginLedgerConnectorBesu = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
instanceId: uuidv4(),
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
});
const privateKey
src/test/typescript/integration/plugin-ledger-connector-besu/lock-contract.test.ts (Line 59:2 - Line 74:22), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 91:5 - Line 71:23)
Show code Hide code web3 = new Web3(rpcApiHttpHost);
testEthAccount = web3.eth.accounts.create(uuidv4());
const keychainEntryKey = uuidv4();
const keychainEntryValue = testEthAccount.privateKey;
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(
LockAssetContractJson
src/test/typescript/integration/plugin-ledger-connector-besu/lock-contract.test.ts (Line 84:9 - Line 112:3), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-invoke-contract.test.ts (Line 81:2 - Line 108:9)
Show code Hide code ,
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
});
await connector.transact({
web3SigningCredential: {
ethAccount: firstHighNetWorthAccount,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
},
transactionConfig: {
from: firstHighNetWorthAccount,
to: testEthAccount.address,
value: 10e9,
gas: 1000000,
},
});
const balance = await web3.eth.getBalance(testEthAccount.address);
expect(balance).toBeTruthy();
expect(parseInt(balance, 10)).toEqual(10e9);
});
it
src/test/typescript/integration/plugin-ledger-connector-besu/lock-contract.test.ts (Line 102:8 - Line 112:60), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 168:14 - Line 177:19)
Show code Hide code ,
},
});
const balance = await web3.eth.getBalance(testEthAccount.address);
expect(balance).toBeTruthy();
expect(parseInt(balance, 10)).toEqual(10e9);
});
it("deploys contract via .json file, verifies lock/unlock ops"
src/test/typescript/integration/plugin-ledger-connector-besu/lock-contract.test.ts (Line 184:2 - Line 198:9), src/test/typescript/integration/plugin-ledger-connector-besu/lock-contract.test.ts (Line 150:2 - Line 164:8)
Show code Hide code } = await connector.invokeContract({
contractName: LockAssetContractJson.contractName,
keychainId: keychainPlugin.getKeychainId(),
invocationType: EthContractInvocationType.Send,
methodName: "lockAsset",
params: ["asset1"],
signingCredential: {
ethAccount: testEthAccount.address,
secret: besuKeyPair.privateKey,
type: Web3SigningCredentialType.PrivateKeyHex,
},
gas: 1000000,
});
expect(lockRes2
src/test/typescript/integration/plugin-ledger-connector-besu/besu-get-transaction.test.ts (Line 32:5 - Line 74:11), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-past-logs.test.ts (Line 29:5 - Line 69:4)
Show code Hide code const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost();
const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost();
/**
* Constant defining the standard 'dev' Besu genesis.json contents.
*
* @see https://github.com/hyperledger/besu/blob/1.5.1/config/src/main/resources/dev.json
*/
const firstHighNetWorthAccount = besuTestLedger.getGenesisAccountPubKey();
const web3 = new Web3(rpcApiHttpHost);
const testEthAccount = web3.eth.accounts.create(uuidv4());
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 connector: PluginLedgerConnectorBesu = await factory.create({
rpcApiHttpHost,
rpcApiWsHost,
instanceId: uuidv4(),
pluginRegistry: new PluginRegistry({ plugins: [keychainPlugin] }),
});
await connector.onPluginInit();
const privateKey
src/test/typescript/integration/plugin-ledger-connector-besu/besu-get-transaction.test.ts (Line 72:2 - Line 98:7), src/test/typescript/integration/plugin-ledger-connector-besu/v21-besu-get-transaction.test.ts (Line 75:2 - Line 101:4)
Show code Hide code );
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);
expect
src/main/typescript/impl/deploy-contract-v1/deploy-contract-v1-keychain.ts (Line 73:3 - Line 110:23), src/main/typescript/impl/deploy-contract-v1/deploy-contract-v1-no-keychain.ts (Line 49:3 - Line 86:14)
Show code Hide code const networkId = await ctx.web3.eth.net.getId();
const tmpContract = new ctx.web3.eth.Contract(req.contractAbi);
const deployment = tmpContract.deploy({
data: req.bytecode,
arguments: req.constructorArgs,
});
const abi = deployment.encodeABI();
const data = abi.startsWith("0x") ? abi : `0x${abi}`;
log.debug(`Deploying "${req.contractName}" with data %o`, data);
const web3SigningCredential = req.web3SigningCredential as
| Web3SigningCredentialPrivateKeyHex
| Web3SigningCredentialCactusKeychainRef;
const transactV1ImplCtx = {
prometheusExporter: ctx.prometheusExporter,
pluginRegistry: ctx.pluginRegistry,
logLevel: ctx.logLevel,
web3: ctx.web3,
};
const transactV1ImplReq = {
transactionConfig: {
data,
from: web3SigningCredential.ethAccount,
gas: req.gas,
gasPrice: req.gasPrice,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
timeoutMs: req.timeoutMs || 60000,
},
web3SigningCredential,
privateTransactionConfig: req.privateTransactionConfig,
};
const runTransactionResponse
src/test/typescript/unit/get-open-api-spec-v1-connector-besu.test.ts (Line 60:6 - Line 71:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/get-record-locator.test.ts (Line 129:2 - Line 138:4)
Show code Hide code );
const listenOptions: IListenOptions = {
hostname: "127.0.0.1",
port: 0,
server,
};
const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo;
const { address, port } = addressInfo;
const apiHost = `http://${address}:${port}`;
const
src/test/typescript/benchmark/run-plugin-ledger-connector-besu-benchmark.ts (Line 56:21 - Line 98:6), src/test/typescript/integration/plugin-ledger-connector-besu/openapi/openapi-validation.test.ts (Line 102:24 - Line 144:11)
Show code Hide code ();
// keychainPlugin for signed transactions
const { privateKey } = Secp256k1Keys.generateKeyPairsBuffer();
const keyHex = privateKey.toString("hex");
const pem = keyEncoder.encodePrivate(keyHex, KeyFormat.Raw, KeyFormat.PEM);
const signedKeychainPlugin = new PluginKeychainMemory({
instanceId: uuidv4(),
keychainId: keychainIdForSigned,
backend: new Map([[keychainRefForSigned, pem]]),
logLevel,
});
// keychainPlugin for unsigned transactions
const keychainEntryValue = testEthAccount1.privateKey;
const unsignedKeychainPlugin = new PluginKeychainMemory({
instanceId: uuidv4(),
keychainId: keychainIdForUnsigned,
backend: new Map([[keychainRefForUnsigned, keychainEntryValue]]),
logLevel,
});
unsignedKeychainPlugin.set(
HelloWorldContractJson.contractName,
JSON.stringify(HelloWorldContractJson),
);
const pluginRegistry = new PluginRegistry({
plugins: [signedKeychainPlugin, unsignedKeychainPlugin],
});
const options: IPluginLedgerConnectorBesuOptions = {
instanceId: uuidv4(),
rpcApiHttpHost,
rpcApiWsHost,
pluginRegistry,
logLevel,
};
const connector = new PluginLedgerConnectorBesu(options);
pluginRegistry.add(connector);
const expressApp = express();
expressApp.use(bodyParser.json({ limit: "250mb" }));
const
src/test/typescript/benchmark/run-plugin-ledger-connector-besu-benchmark.ts (Line 94:10 - Line 116:6), src/test/typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-record-locator.test.ts (Line 97:2 - Line 74:10)
Show code Hide code );
const expressApp = express();
expressApp.use(bodyParser.json({ limit: "250mb" }));
const server = http.createServer(expressApp);
const wsApi = new SocketIoServer(server, {
path: Constants.SocketIoConnectionPathV1,
});
const listenOptions: IListenOptions = {
hostname: "127.0.0.1",
port: 0,
server,
};
const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo;
const { address, port } = addressInfo;
const apiHost = `http://${address}:${port}`;
const besuApiClientOptions = new BesuApiClientOptions({
basePath: apiHost,
});
const
src/main/typescript/web-services/invoke-contract-endpoint.ts (Line 1:1 - Line 20:24), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 1:1 - Line 20:22)
Show code Hide code import { Express, Request, Response } from "express";
import {
Logger,
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IEndpointAuthzOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
import { registerWebServiceEndpoint } from "@hyperledger/cactus-core";
import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu";
import OAS from "../../json/openapi.json";
import { InvokeContractV1Request
src/main/typescript/web-services/invoke-contract-endpoint.ts (Line 36:31 - Line 46:83), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 36:31 - Line 46:83)
Show code Hide code ) {
const fnTag = `${this.className}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);
Checks.truthy(options.connector, `${fnTag} arg options.connector`);
const level = this.options.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });
}
public get oasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/invoke-contract"
src/main/typescript/web-services/invoke-contract-endpoint.ts (Line 49:5 - Line 88:24), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 49:5 - Line 88:22)
Show code Hide code ];
}
public getPath(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.path;
}
public getVerbLowerCase(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.verbLowerCase;
}
public getOperationId(): string {
return this.oasPath.post.operationId;
}
getAuthorizationOptionsProvider(): IAsyncProvider<IEndpointAuthzOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isProtected: true,
requiredRoles: [],
}),
};
}
public async registerExpress(
expressApp: Express,
): Promise<IWebServiceEndpoint> {
await registerWebServiceEndpoint(expressApp, this);
return this;
}
public getExpressRequestHandler(): IExpressRequestHandler {
return this.handleRequest.bind(this);
}
public async handleRequest(req: Request, res: Response): Promise<void> {
const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`;
this.log.debug(reqTag);
const reqBody: InvokeContractV1Request
src/main/typescript/web-services/get-transaction-endpoint.ts (Line 1:1 - Line 21:7), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 1:1 - Line 20:7)
Show code Hide code import { Express, Request, Response } from "express";
import {
Logger,
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IEndpointAuthzOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
import { registerWebServiceEndpoint } from "@hyperledger/cactus-core";
import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu";
import OAS from "../../json/openapi.json";
export
src/main/typescript/web-services/get-transaction-endpoint.ts (Line 35:31 - Line 45:83), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 36:31 - Line 46:83)
Show code Hide code ) {
const fnTag = `${this.className}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);
Checks.truthy(options.connector, `${fnTag} arg options.connector`);
const level = this.options.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });
}
public get oasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-transaction"
src/main/typescript/web-services/get-transaction-endpoint.ts (Line 48:5 - Line 87:2), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 49:5 - Line 88:2)
Show code Hide code ];
}
public getPath(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.path;
}
public getVerbLowerCase(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.verbLowerCase;
}
public getOperationId(): string {
return this.oasPath.post.operationId;
}
getAuthorizationOptionsProvider(): IAsyncProvider<IEndpointAuthzOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isProtected: true,
requiredRoles: [],
}),
};
}
public async registerExpress(
expressApp: Express,
): Promise<IWebServiceEndpoint> {
await registerWebServiceEndpoint(expressApp, this);
return this;
}
public getExpressRequestHandler(): IExpressRequestHandler {
return this.handleRequest.bind(this);
}
public async handleRequest(req: Request, res: Response): Promise<void> {
const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`;
this.log.debug(reqTag);
const reqBody =
src/main/typescript/web-services/get-transaction-endpoint.ts (Line 89:15 - Line 99:2), src/main/typescript/web-services/invoke-contract-endpoint.ts (Line 90:15 - Line 100:2)
Show code Hide code (reqBody);
res.json(resBody);
} catch (ex) {
this.log.error(`Crash while serving ${reqTag}`, ex);
res.status(500).json({
message: "Internal Server Error",
error: ex?.stack || ex?.message,
});
}
}
}
src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts (Line 41:43 - Line 60:99), src/main/typescript/web-services/sign-transaction-endpoint-v1.ts (Line 38:33 - Line 57:84)
Show code Hide code ;
const level = options.logLevel || "INFO";
this.log = LoggerProvider.getOrCreate({ label, level });
}
getAuthorizationOptionsProvider(): IAsyncProvider<IEndpointAuthzOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isProtected: true,
requiredRoles: [],
}),
};
}
public getExpressRequestHandler(): IExpressRequestHandler {
return this.handleRequest.bind(this);
}
public get oasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-prometheus-exporter-metrics"
src/main/typescript/web-services/get-prometheus-exporter-metrics-endpoint-v1.ts (Line 75:4 - Line 86:47), src/main/typescript/web-services/sign-transaction-endpoint-v1.ts (Line 72:5 - Line 83:48)
Show code Hide code .operationId;
}
public async registerExpress(
expressApp: Express,
): Promise<IWebServiceEndpoint> {
await registerWebServiceEndpoint(expressApp, this);
return this;
}
async handleRequest(req: Request, res: Response): Promise<void> {
const fnTag = "GetPrometheusExporterMetrics#handleRequest()"
src/main/typescript/web-services/get-past-logs-endpoint.ts (Line 1:1 - Line 21:28), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 1:1 - Line 21:31)
Show code Hide code import { Express, Request, Response } from "express";
import {
Logger,
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IEndpointAuthzOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
import { registerWebServiceEndpoint } from "@hyperledger/cactus-core";
import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu";
import OAS from "../../json/openapi.json";
export interface IGetPastLogsEndpointOptions
src/main/typescript/web-services/get-past-logs-endpoint.ts (Line 35:28 - Line 45:81), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 36:31 - Line 46:83)
Show code Hide code ) {
const fnTag = `${this.className}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);
Checks.truthy(options.connector, `${fnTag} arg options.connector`);
const level = this.options.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });
}
public get oasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-past-logs"
src/main/typescript/web-services/get-past-logs-endpoint.ts (Line 48:5 - Line 89:12), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 49:5 - Line 89:15)
Show code Hide code ];
}
public getPath(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.path;
}
public getVerbLowerCase(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.verbLowerCase;
}
public getOperationId(): string {
return this.oasPath.post.operationId;
}
getAuthorizationOptionsProvider(): IAsyncProvider<IEndpointAuthzOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isProtected: true,
requiredRoles: [],
}),
};
}
public async registerExpress(
expressApp: Express,
): Promise<IWebServiceEndpoint> {
await registerWebServiceEndpoint(expressApp, this);
return this;
}
public getExpressRequestHandler(): IExpressRequestHandler {
return this.handleRequest.bind(this);
}
public async handleRequest(req: Request, res: Response): Promise<void> {
const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`;
this.log.debug(reqTag);
const reqBody = req.body;
try {
const resBody = await this.options.connector.getPastLogs
src/main/typescript/web-services/get-past-logs-endpoint.ts (Line 89:12 - Line 99:2), src/main/typescript/web-services/invoke-contract-endpoint.ts (Line 90:15 - Line 100:2)
Show code Hide code (reqBody);
res.json(resBody);
} catch (ex) {
this.log.error(`Crash while serving ${reqTag}`, ex);
res.status(500).json({
message: "Internal Server Error",
error: ex?.stack || ex?.message,
});
}
}
}
src/main/typescript/web-services/get-block-v1-endpoint-.ts (Line 1:1 - Line 21:25), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 1:1 - Line 21:31)
Show code Hide code import { Express, Request, Response } from "express";
import {
Logger,
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IEndpointAuthzOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
import { registerWebServiceEndpoint } from "@hyperledger/cactus-core";
import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu";
import OAS from "../../json/openapi.json";
export interface IGetBlockEndpointOptions
src/main/typescript/web-services/get-block-v1-endpoint-.ts (Line 35:25 - Line 45:77), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 36:31 - Line 46:83)
Show code Hide code ) {
const fnTag = `${this.className}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);
Checks.truthy(options.connector, `${fnTag} arg options.connector`);
const level = this.options.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });
}
public get oasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-block"
src/main/typescript/web-services/get-block-v1-endpoint-.ts (Line 48:5 - Line 89:9), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 49:5 - Line 89:15)
Show code Hide code ];
}
public getPath(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.path;
}
public getVerbLowerCase(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.verbLowerCase;
}
public getOperationId(): string {
return this.oasPath.post.operationId;
}
getAuthorizationOptionsProvider(): IAsyncProvider<IEndpointAuthzOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isProtected: true,
requiredRoles: [],
}),
};
}
public async registerExpress(
expressApp: Express,
): Promise<IWebServiceEndpoint> {
await registerWebServiceEndpoint(expressApp, this);
return this;
}
public getExpressRequestHandler(): IExpressRequestHandler {
return this.handleRequest.bind(this);
}
public async handleRequest(req: Request, res: Response): Promise<void> {
const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`;
this.log.debug(reqTag);
const reqBody = req.body;
try {
const resBody = await this.options.connector.getBlock
src/main/typescript/web-services/get-block-v1-endpoint-.ts (Line 89:9 - Line 99:2), src/main/typescript/web-services/invoke-contract-endpoint.ts (Line 90:15 - Line 100:2)
Show code Hide code (reqBody);
res.json(resBody);
} catch (ex) {
this.log.error(`Crash while serving ${reqTag}`, ex);
res.status(500).json({
message: "Internal Server Error",
error: ex?.stack || ex?.message,
});
}
}
}
src/main/typescript/web-services/get-besu-record-endpoint-v1.ts (Line 1:1 - Line 18:2), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 1:1 - Line 19:4)
Show code Hide code import { Express, Request, Response } from "express";
import {
Logger,
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IEndpointAuthzOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
import { registerWebServiceEndpoint } from "@hyperledger/cactus-core";
import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu";
import {
src/main/typescript/web-services/get-besu-record-endpoint-v1.ts (Line 36:32 - Line 46:11), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 36:31 - Line 46:4)
Show code Hide code ) {
const fnTag = `${this.className}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);
Checks.truthy(options.connector, `${fnTag} arg options.connector`);
const level = this.options.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });
}
public getOasPath
src/main/typescript/web-services/get-besu-record-endpoint-v1.ts (Line 63:2 - Line 90:4), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 61:8 - Line 88:6)
Show code Hide code .post.operationId;
}
getAuthorizationOptionsProvider(): IAsyncProvider<IEndpointAuthzOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isProtected: true,
requiredRoles: [],
}),
};
}
public async registerExpress(
expressApp: Express,
): Promise<IWebServiceEndpoint> {
await registerWebServiceEndpoint(expressApp, this);
return this;
}
public getExpressRequestHandler(): IExpressRequestHandler {
return this.handleRequest.bind(this);
}
public async handleRequest(req: Request, res: Response): Promise<void> {
const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`;
this.log.debug(reqTag);
try
src/main/typescript/web-services/get-besu-record-endpoint-v1.ts (Line 93:14 - Line 103:2), src/main/typescript/web-services/invoke-contract-endpoint.ts (Line 90:15 - Line 100:2)
Show code Hide code (reqBody);
res.json(resBody);
} catch (ex) {
this.log.error(`Crash while serving ${reqTag}`, ex);
res.status(500).json({
message: "Internal Server Error",
error: ex?.stack || ex?.message,
});
}
}
}
src/main/typescript/web-services/get-balance-endpoint.ts (Line 1:1 - Line 21:27), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 1:1 - Line 21:31)
Show code Hide code import { Express, Request, Response } from "express";
import {
Logger,
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
IEndpointAuthzOptions,
IExpressRequestHandler,
IWebServiceEndpoint,
} from "@hyperledger/cactus-core-api";
import { registerWebServiceEndpoint } from "@hyperledger/cactus-core";
import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu";
import OAS from "../../json/openapi.json";
export interface IGetBalanceEndpointOptions
src/main/typescript/web-services/get-balance-endpoint.ts (Line 35:27 - Line 45:79), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 36:31 - Line 46:83)
Show code Hide code ) {
const fnTag = `${this.className}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);
Checks.truthy(options.connector, `${fnTag} arg options.connector`);
const level = this.options.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });
}
public get oasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/get-balance"
src/main/typescript/web-services/get-balance-endpoint.ts (Line 48:5 - Line 89:11), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 49:5 - Line 89:15)
Show code Hide code ];
}
public getPath(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.path;
}
public getVerbLowerCase(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.verbLowerCase;
}
public getOperationId(): string {
return this.oasPath.post.operationId;
}
getAuthorizationOptionsProvider(): IAsyncProvider<IEndpointAuthzOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isProtected: true,
requiredRoles: [],
}),
};
}
public async registerExpress(
expressApp: Express,
): Promise<IWebServiceEndpoint> {
await registerWebServiceEndpoint(expressApp, this);
return this;
}
public getExpressRequestHandler(): IExpressRequestHandler {
return this.handleRequest.bind(this);
}
public async handleRequest(req: Request, res: Response): Promise<void> {
const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`;
this.log.debug(reqTag);
const reqBody = req.body;
try {
const resBody = await this.options.connector.getBalance
src/main/typescript/web-services/get-balance-endpoint.ts (Line 89:11 - Line 99:2), src/main/typescript/web-services/invoke-contract-endpoint.ts (Line 90:15 - Line 100:2)
Show code Hide code (reqBody);
res.json(resBody);
} catch (ex) {
this.log.error(`Crash while serving ${reqTag}`, ex);
res.status(500).json({
message: "Internal Server Error",
error: ex?.stack || ex?.message,
});
}
}
}
src/main/typescript/web-services/deploy-contract-solidity-bytecode-no-keychain-endpoint.ts (Line 45:3 - Line 55:113), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 36:31 - Line 46:83)
Show code Hide code ) {
const fnTag = `${this.className}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);
Checks.truthy(options.connector, `${fnTag} arg options.connector`);
const level = this.options.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });
}
public get oasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/deploy-contract-solidity-bytecode-no-keychain"
src/main/typescript/web-services/deploy-contract-solidity-bytecode-no-keychain-endpoint.ts (Line 58:5 - Line 95:2), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 49:5 - Line 86:7)
Show code Hide code ];
}
public getPath(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.path;
}
public getVerbLowerCase(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.verbLowerCase;
}
public getOperationId(): string {
return this.oasPath.post.operationId;
}
getAuthorizationOptionsProvider(): IAsyncProvider<IEndpointAuthzOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isProtected: true,
requiredRoles: [],
}),
};
}
public async registerExpress(
expressApp: Express,
): Promise<IWebServiceEndpoint> {
await registerWebServiceEndpoint(expressApp, this);
return this;
}
public getExpressRequestHandler(): IExpressRequestHandler {
return this.handleRequest.bind(this);
}
public async handleRequest(req: Request, res: Response): Promise<void> {
const {
src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint.ts (Line 1:1 - Line 26:39), src/main/typescript/web-services/deploy-contract-solidity-bytecode-no-keychain-endpoint.ts (Line 1:1 - Line 26:49)
Show code Hide code import type { Express, Request, Response } from "express";
import {
IWebServiceEndpoint,
IExpressRequestHandler,
IEndpointAuthzOptions,
} from "@hyperledger/cactus-core-api";
import {
Logger,
Checks,
LogLevelDesc,
LoggerProvider,
IAsyncProvider,
} from "@hyperledger/cactus-common";
import {
handleRestEndpointException,
registerWebServiceEndpoint,
} from "@hyperledger/cactus-core";
import { PluginLedgerConnectorBesu } from "../plugin-ledger-connector-besu";
import { DeployContractSolidityBytecodeV1Request } from "../generated/openapi/typescript-axios";
import OAS from "../../json/openapi.json";
export interface IDeployContractSolidityBytecodeOptions
src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint.ts (Line 42:39 - Line 52:101), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 36:31 - Line 46:83)
Show code Hide code ) {
const fnTag = `${this.className}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);
Checks.truthy(options.connector, `${fnTag} arg options.connector`);
const level = this.options.logLevel || "INFO";
const label = this.className;
this.log = LoggerProvider.getOrCreate({ level, label });
}
public get oasPath(): (typeof OAS.paths)["/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-besu/deploy-contract-solidity-bytecode"
src/main/typescript/web-services/deploy-contract-solidity-bytecode-endpoint.ts (Line 55:5 - Line 98:15), src/main/typescript/web-services/run-transaction-endpoint.ts (Line 49:5 - Line 102:25)
Show code Hide code ];
}
public getPath(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.path;
}
public getVerbLowerCase(): string {
return this.oasPath.post["x-hyperledger-cacti"].http.verbLowerCase;
}
public getOperationId(): string {
return this.oasPath.post.operationId;
}
getAuthorizationOptionsProvider(): IAsyncProvider<IEndpointAuthzOptions> {
// TODO: make this an injectable dependency in the constructor
return {
get: async () => ({
isProtected: true,
requiredRoles: [],
}),
};
}
public async registerExpress(
expressApp: Express,
): Promise<IWebServiceEndpoint> {
await registerWebServiceEndpoint(expressApp, this);
return this;
}
public getExpressRequestHandler(): IExpressRequestHandler {
return this.handleRequest.bind(this);
}
public async handleRequest(req: Request, res: Response): Promise<void> {
const { log } = this;
const fnTag = `${this.className}#handleRequest()`;
const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`;
this.log.debug(reqTag);
const reqBody: DeployContractSolidityBytecodeV1Request = req.body;
try {
const resBody = await this.options.connector.deployContract
src/main/typescript/grpc-services/besu-grpc-svc-open-api.ts (Line 78:45 - Line 90:13), src/main/typescript/grpc-services/besu-grpc-svc-open-api.ts (Line 64:35 - Line 76:38)
Show code Hide code ,
deploy_contract_solidity_bytecode_v1_response_pb.org.hyperledger.cacti.plugin.ledger.connector.besu.DeployContractSolidityBytecodeV1ResponsePB
>,
callback: sendUnaryData<deploy_contract_solidity_bytecode_v1_response_pb.org.hyperledger.cacti.plugin.ledger.connector.besu.DeployContractSolidityBytecodeV1ResponsePB>,
): void {
return callback({
message: "Status.UNIMPLEMENTED",
code: status.UNIMPLEMENTED,
details: "Service endpoint not yet implemented.",
});
}
public GetBalanceV1
src/main/typescript/plugin-ledger-connector-besu.ts (Line 469:2 - Line 481:2), src/main/typescript/impl/deploy-contract-v1/deploy-contract-v1-no-keychain.ts (Line 73:5 - Line 85:2)
Show code Hide code ,
from: web3SigningCredential.ethAccount,
gas: req.gas,
gasPrice: req.gasPrice,
},
consistencyStrategy: {
blockConfirmations: 0,
receiptType: ReceiptType.NodeTxPoolAck,
timeoutMs: req.timeoutMs || 60000,
},
web3SigningCredential,
privateTransactionConfig: req.privateTransactionConfig,
})