-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(besu): support besu v21.1.6 #982
Signed-off-by: AzaharaC <a.castano.benito@accenture.com>
- Loading branch information
Showing
14 changed files
with
2,468 additions
and
4 deletions.
There are no files selected for viewing
496 changes: 496 additions & 0 deletions
496
...ration/plugin-ledger-connector-besu/deploy-contract/v21-deploy-contract-from-json.test.ts
Large diffs are not rendered by default.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
...pescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-balance.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
67 changes: 67 additions & 0 deletions
67
...typescript/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-block.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
75 changes: 75 additions & 0 deletions
75
...script/integration/plugin-ledger-connector-besu/deploy-contract/v21-get-past-logs.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |
Oops, something went wrong.