Simon Lee 1 year ago
parent
commit
6caabbcd9e
1 changed files with 49 additions and 29 deletions
  1. 49
    29
      TC3/start.ts

+ 49
- 29
TC3/start.ts View File

FetchRequest,JsonRpcApiProviderOptions FetchRequest,JsonRpcApiProviderOptions
} from 'ethers' } from 'ethers'
import {Calulator} from "../inc/calc"; import {Calulator} from "../inc/calc";
import chalk from "chalk";
import { TokenIssuer } from "../inc/TokenIssuer"; import { TokenIssuer } from "../inc/TokenIssuer";
import { import {
SecurityToken, SecurityToken,
if (!process.env.RPCURL) { if (!process.env.RPCURL) {
console.log(`No rpcur value specified...`) console.log(`No rpcur value specified...`)
} }
import axios from "axios";


async function getBalance(symbol: string, address: string ): Promise<number> {
const path = `holders/${address}/tokens/${symbol}/balance`;
const ret = await axios.get(gateWay + path, getAuthHeader(authToken));
return ret.data;
}


async function getBalanceAsc(symbol: string, address: string ): Promise<any> {
const path = `holders/${address}/tokens/${symbol}/balance`;
return axios.get(gateWay + path, getAuthHeader(authToken));
// const ret = await axios.get(gateWay + path, getAuthHeader(authToken));
// return ret.data;
}


async function readTest(symbol:string, count: number = 100): Promise<any> {

const proxy = getDeploymentAddresses(symbol).address;
console.log(`토큰 주소 : ${proxy}`);

const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);
const token = new SecurityToken__factory(issuer).attach(proxy) as SecurityToken;


let balance1= await token.balanceOf(holder1);
let balance2 = await token.balanceOf(holder2);
function getAuthHeader(token: string) : any{
return {
headers: {
'Content-Type': 'application/json;charset=UTF-8',
'Access-Control-Allow-Origin': '*',
'Authorization': `Bearer ${token}`
}
};
}




async function readTest(symbol:string, holder: Wallet, count: number = 100): Promise<any> {


console.log(new Date());
const proxy = getDeploymentAddresses(symbol).address;
console.log(`토큰 주소 : ${proxy}`);
const balance = await getBalance(symbol,holder.address);
console.log(chalk.blue(`잔고(${holder.address}) = ${balance}`));
const start = Date.now(); const start = Date.now();
console.log(chalk.cyan(`조회시작 시간 : ${new Date(start).toUTCString()}`));
console.log(chalk.yellow(`reading balance ${count} times`));

let proms = []; let proms = [];
for(let i = 0; i < count; i++) { for(let i = 0; i < count; i++) {
proms.push(token.balanceOf(holder1));
proms.push(getBalanceAsc(symbol,holder.address));
} }
let resolved = await Promise.all(proms); let resolved = await Promise.all(proms);

console.log(resolved.length);
assert(count == resolved.length); assert(count == resolved.length);

resolved.forEach(balance => {
// console.log(balance);
if(balance != balance1) {
console.log(balance);
resolved.forEach(b => {
// console.log(b.data);
if(b.data != balance) {
console.log('balance mismatch!!!!!!!!!!!!!!!!!!!!!!!!!!');
} }
}); });


const end = Date.now(); const end = Date.now();
const elapsed = getElapsed(start,1000); const elapsed = getElapsed(start,1000);
console.log(`all tx sent in ${elapsed} seconds`);
console.log(`request finished in ${elapsed} seconds`);


const CEPS = calc.CQPS(count,start,end); const CEPS = calc.CQPS(count,start,end);
console.log(`CQPS = ${CEPS}`); console.log(`CQPS = ${CEPS}`);


const calc = new Calulator(); const calc = new Calulator();
const rpcUrl = process.env.RPCURL; const rpcUrl = process.env.RPCURL;
const gateWay = process.env.GATE_WAY;
const authToken=process.env.AUTHTOKEN;
const fetchRequest = new FetchRequest(rpcUrl); const fetchRequest = new FetchRequest(rpcUrl);
console.log(rpcUrl) console.log(rpcUrl)
fetchRequest.timeout = 10000; fetchRequest.timeout = 10000;
// const provider = new JsonRpcProvider(fetchRequest,null,{batchMaxSize: 5, batchMaxCount: 100});
const provider = new JsonRpcProvider(fetchRequest); const provider = new JsonRpcProvider(fetchRequest);

setProvider(provider); setProvider(provider);
const admin = new Wallet('0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3',provider);
const issuer = new Wallet('0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63',provider);
const holder1 = new Wallet('0xae6ae8e5ccbfb04590405997ee2d52d2b330726137b875053c36d94e974d162f',provider);
const holder2 = new Wallet('0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',provider);


console.log(`목적 서버 : ${rpcUrl}`); console.log(`목적 서버 : ${rpcUrl}`);


async function main() { async function main() {
await readTest('test001',4000);

await readTest('BCG_TEST',holder1,1000);
// const b = await getBalance('BCG_TEST',holder1.address);
// console.log(b);
} }


main(); main();

Loading…
Cancel
Save