You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import * as dotevnv from "dotenv"
  2. import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
  3. ,Transaction,formatEther,
  4. ZeroHash,ethers,keccak256,
  5. FetchRequest,JsonRpcApiProviderOptions
  6. } from 'ethers'
  7. import {Calulator} from "../inc/calc";
  8. import chalk from "chalk";
  9. import { TokenIssuer } from "../inc/TokenIssuer";
  10. import {
  11. SecurityToken,
  12. SecurityToken__factory,
  13. } from '../typechain'
  14. // import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
  15. import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses,
  16. getElapsed, sleep,getBlockInfo,getNonce} from '../inc/util'
  17. import { assert } from "console";
  18. dotevnv.config();
  19. if (!process.env.RPCURL) {
  20. console.log(`No rpcur value specified...`)
  21. }
  22. import axios from "axios";
  23. async function getBalance(symbol: string, address: string ): Promise<number> {
  24. const path = `holders/${address}/tokens/${symbol}/balance`;
  25. const ret = await axios.get(gateWay + path, getAuthHeader(authToken));
  26. return ret.data;
  27. }
  28. async function getBalanceAsc(symbol: string, address: string ): Promise<any> {
  29. const path = `holders/${address}/tokens/${symbol}/balance`;
  30. return axios.get(gateWay + path, getAuthHeader(authToken));
  31. }
  32. async function health() : Promise<any> {
  33. const path = `health`;
  34. return axios.get(gateWayRaw + path, getAuthHeader(authToken));
  35. }
  36. function getAuthHeader(token: string) : any{
  37. return {
  38. headers: {
  39. 'Content-Type': 'application/json;charset=UTF-8',
  40. 'Access-Control-Allow-Origin': '*',
  41. 'Authorization': `Bearer ${token}`
  42. }
  43. };
  44. }
  45. async function readHealth(symbol:string, holder: Wallet, count: number = 100): Promise<any> {
  46. const proxy = getDeploymentAddresses(symbol).address;
  47. console.log(`토큰 주소 : ${proxy}`);
  48. // const balance = await getBalance(symbol,holder.address);
  49. // console.log(chalk.blue(`잔고(${holder.address}) = ${balance}`));
  50. const start = Date.now();
  51. console.log(chalk.cyan(`조회시작 시간 : ${new Date(start).toUTCString()}`));
  52. console.log(chalk.yellow(`reading balance ${count} times`));
  53. let proms = [];
  54. for(let i = 0; i < count; i++) {
  55. proms.push(health());
  56. }
  57. let resolved = await Promise.all(proms);
  58. assert(count == resolved.length);
  59. resolved.forEach(b => {
  60. //console.log(b.data);
  61. //console.log(b);
  62. });
  63. const end = Date.now();
  64. const elapsed = getElapsed(start,1000);
  65. console.log(`request finished in ${elapsed} seconds`);
  66. const CEPS = calc.CQPS(count,start,end);
  67. console.log(`CQPS = ${CEPS}`);
  68. return 0;
  69. }
  70. async function readTest(symbol:string, holder: Wallet, count: number = 100): Promise<any> {
  71. const proxy = getDeploymentAddresses(symbol).address;
  72. console.log(`토큰 주소 : ${proxy}`);
  73. const balance = await getBalance(symbol,holder.address);
  74. console.log(chalk.blue(`잔고(${holder.address}) = ${balance}`));
  75. const start = Date.now();
  76. console.log(chalk.cyan(`조회시작 시간 : ${new Date(start).toUTCString()}`));
  77. console.log(chalk.yellow(`reading balance ${count} times`));
  78. let proms = [];
  79. for(let i = 0; i < count; i++) {
  80. proms.push(getBalanceAsc(symbol,holder.address));
  81. }
  82. let resolved = await Promise.all(proms);
  83. assert(count == resolved.length);
  84. resolved.forEach(b => {
  85. // console.log(b.data);
  86. if(b.data != balance) {
  87. console.log('balance mismatch!!!!!!!!!!!!!!!!!!!!!!!!!!');
  88. }
  89. });
  90. const end = Date.now();
  91. const elapsed = getElapsed(start,1000);
  92. console.log(`request finished in ${elapsed} seconds`);
  93. const CEPS = calc.CQPS(count,start,end);
  94. console.log(`CQPS = ${CEPS}`);
  95. return 0;
  96. }
  97. const calc = new Calulator();
  98. const rpcUrl = process.env.RPCURL;
  99. const gateWay = process.env.GATE_WAY;
  100. const gateWayRaw=process.env.GATE_WAY_RAW;
  101. const authToken=process.env.AUTHTOKEN;
  102. const fetchRequest = new FetchRequest(rpcUrl);
  103. console.log(rpcUrl)
  104. fetchRequest.timeout = 10000;
  105. const provider = new JsonRpcProvider(fetchRequest);
  106. setProvider(provider);
  107. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  108. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  109. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  110. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  111. console.log(`목적 서버 : ${gateWay}`);
  112. async function main() {
  113. // await readHealth('BCG_TEST',holder1,1000);
  114. await readTest('BCG_TEST',holder1,1000);
  115. }
  116. main();