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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. function getAuthHeader(token: string) : any{
  33. return {
  34. headers: {
  35. 'Content-Type': 'application/json;charset=UTF-8',
  36. 'Access-Control-Allow-Origin': '*',
  37. 'Authorization': `Bearer ${token}`
  38. }
  39. };
  40. }
  41. async function readTest(symbol:string, holder: Wallet, count: number = 100): Promise<any> {
  42. const proxy = getDeploymentAddresses(symbol).address;
  43. console.log(`토큰 주소 : ${proxy}`);
  44. const balance = await getBalance(symbol,holder.address);
  45. console.log(chalk.blue(`잔고(${holder.address}) = ${balance}`));
  46. const start = Date.now();
  47. console.log(chalk.cyan(`조회시작 시간 : ${new Date(start).toUTCString()}`));
  48. console.log(chalk.yellow(`reading balance ${count} times`));
  49. let proms = [];
  50. for(let i = 0; i < count; i++) {
  51. proms.push(getBalanceAsc(symbol,holder.address));
  52. }
  53. let resolved = await Promise.all(proms);
  54. assert(count == resolved.length);
  55. resolved.forEach(b => {
  56. // console.log(b.data);
  57. if(b.data != balance) {
  58. console.log('balance mismatch!!!!!!!!!!!!!!!!!!!!!!!!!!');
  59. }
  60. });
  61. const end = Date.now();
  62. const elapsed = getElapsed(start,1000);
  63. console.log(`request finished in ${elapsed} seconds`);
  64. const CEPS = calc.CQPS(count,start,end);
  65. console.log(`CQPS = ${CEPS}`);
  66. return 0;
  67. }
  68. const calc = new Calulator();
  69. const rpcUrl = process.env.RPCURL;
  70. const gateWay = process.env.GATE_WAY;
  71. const authToken=process.env.AUTHTOKEN;
  72. const fetchRequest = new FetchRequest(rpcUrl);
  73. console.log(rpcUrl)
  74. fetchRequest.timeout = 10000;
  75. const provider = new JsonRpcProvider(fetchRequest);
  76. setProvider(provider);
  77. const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
  78. const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
  79. const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
  80. const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
  81. console.log(`목적 서버 : ${gateWay}`);
  82. async function main() {
  83. await readTest('BCG_TEST',holder1,1000);
  84. }
  85. main();