forked from hyperledger-cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 2
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): getTransaction method
Signed-off-by: Jeffrey Ushry <jeffrey.ushry@accenture.com>
- Loading branch information
1 parent
cacb7bc
commit d470540
Showing
5 changed files
with
266 additions
and
0 deletions.
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
99 changes: 99 additions & 0 deletions
99
...src/test/typescript/integration/plugin-ledger-connector-besu/besu-get-transaction.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,99 @@ | ||
import test, { Test } from "tape"; | ||
import { v4 as uuidv4 } from "uuid"; | ||
import { PluginRegistry } from "@hyperledger/cactus-core"; | ||
import { | ||
PluginLedgerConnectorBesu, | ||
PluginFactoryLedgerConnector, | ||
ReceiptType, | ||
Web3SigningCredentialType, | ||
} 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 { GetTransactionV1Request } from "../../../../main/typescript/generated/openapi/typescript-axios/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 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); | ||
t.comment(JSON.stringify(response.transaction)); | ||
t.ok(response.transaction, "getTransaction response is OK :-)"); | ||
t.equal( | ||
typeof response.transaction, | ||
"object", | ||
"getTransaction response type is OK :-)", | ||
); | ||
t.end(); | ||
}); |