Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

start.ts 3.7KB

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