-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(connector-besu): add get past logs method
Signed-off-by: Hana Awad <[email protected]>
- Loading branch information
Showing
6 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
71 changes: 71 additions & 0 deletions
71
...typescript/integration/plugin-ledger-connector-besu/deploy-contract/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,71 @@ | ||
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 besuTestLedger = new BesuTestLedger(); | ||
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/1.5.1/config/src/main/resources/dev.json | ||
*/ | ||
const firstHighNetWorthAccount = "627306090abaB3A6e1400e9345bC60c78a8BEf57"; | ||
|
||
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, | ||
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(); | ||
}); |