Skip to content

Commit

Permalink
feat(besu): support besu v21.1.6 #982
Browse files Browse the repository at this point in the history
Signed-off-by: AzaharaC <a.castano.benito@accenture.com>
  • Loading branch information
AzaharaC authored and petermetz committed Sep 8, 2021
1 parent beefcef commit d715c67
Show file tree
Hide file tree
Showing 14 changed files with 2,468 additions and 4 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import test, { Test } from "tape";
import { v4 as uuidv4 } from "uuid";
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";

test("can get balance of an account", async (t: Test) => {
const logLevel: LogLevelDesc = "TRACE";
const containerImageVersion = "2021-08-24--feat-1244";
const containerImageName =
"ghcr.io/hyperledger/cactus-besu-21-1-6-all-in-one";
const besuOptions = { containerImageName, containerImageVersion };
const besuTestLedger = new BesuTestLedger(besuOptions);
await besuTestLedger.start();

test.onFinish(async () => {
await besuTestLedger.stop();
await besuTestLedger.destroy();
});

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 = { address: firstHighNetWorthAccount };
const currentBalance = await connector.getBalance(req);
t.comment(JSON.stringify(currentBalance));
//makes the information in to string
t.ok(currentBalance, " Balance response is OK :-)");
t.equal(typeof currentBalance, "object", "Balance response type is OK :-)");
t.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import test, { Test } from "tape";
import { v4 as uuidv4 } from "uuid";
import { PluginRegistry } from "@hyperledger/cactus-core";
import {
PluginLedgerConnectorBesu,
PluginFactoryLedgerConnector,
GetBlockV1Request,
} 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";

test("can get block from blockchain", async (t: Test) => {
const logLevel: LogLevelDesc = "TRACE";
const containerImageVersion = "2021-08-24--feat-1244";
const containerImageName =
"ghcr.io/hyperledger/cactus-besu-21-1-6-all-in-one";
const besuOptions = { containerImageName, containerImageVersion };
const besuTestLedger = new BesuTestLedger(besuOptions);
await besuTestLedger.start();

test.onFinish(async () => {
await besuTestLedger.stop();
await besuTestLedger.destroy();
});

const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost();
const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost();
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 request: GetBlockV1Request = { blockHashOrBlockNumber: 0 };
const currentBlock = await connector.getBlock(request);
t.comment(JSON.stringify(currentBlock));
//makes the information in to string
t.ok(currentBlock, " Block response is OK :-)");
t.equal(typeof currentBlock, "object", "Block response type is OK :-)");
t.end();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import test, { Test } from "tape";
import { v4 as uuidv4 } from "uuid";
import { PluginRegistry } from "@hyperledger/cactus-core";
import {
PluginLedgerConnectorBesu,
PluginFactoryLedgerConnector,
GetPastLogsV1Request,
} 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";

test("can get past logs of an account", async (t: Test) => {
const logLevel: LogLevelDesc = "TRACE";
const containerImageVersion = "2021-08-24--feat-1244";
const containerImageName =
"ghcr.io/hyperledger/cactus-besu-21-1-6-all-in-one";
const besuOptions = { containerImageName, containerImageVersion };
const besuTestLedger = new BesuTestLedger(besuOptions);
await besuTestLedger.start();

test.onFinish(async () => {
await besuTestLedger.stop();
await besuTestLedger.destroy();
});

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: GetPastLogsV1Request = { address: firstHighNetWorthAccount };
const pastLogs = await connector.getPastLogs(req);
t.comment(JSON.stringify(pastLogs));
t.ok(pastLogs, "Past logs response is OK :-)");
t.equal(typeof pastLogs, "object", "Past logs response type is OK :-)");
t.end();
});
Loading

0 comments on commit d715c67

Please sign in to comment.