-
Notifications
You must be signed in to change notification settings - Fork 282
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 balance method
Signed-off-by: Youngone Lee <youngone.lee@accenture.com>
- Loading branch information
1 parent
d1f9560
commit db71c5c
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
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
78 changes: 78 additions & 0 deletions
78
...t/typescript/integration/plugin-ledger-connector-besu/deploy-contract/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,78 @@ | ||
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 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 besuKeyPair = { | ||
privateKey: | ||
"c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3", | ||
}; | ||
const contractName = "HelloWorld"; | ||
*/ | ||
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: 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(); | ||
}); |