| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- import * as dotevnv from "dotenv"
- import {toUtf8String,parseUnits,ContractFactory, parseEther,JsonRpcProvider, Contract, JsonRpcSigner, Wallet,ContractTransactionResponse, MaxInt256
- ,Transaction,formatEther,
- ZeroHash,ethers,keccak256
- } from 'ethers'
- import {Calulator} from "../inc/calc";
- import { TokenIssuer } from "../inc/TokenIssuer";
- import {
- SecurityToken,
- SecurityToken__factory,
- } from '../typechain'
- // import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
- import {checkReceipt,checkReceipt2, setProvider,getDeploymentAddresses,
- getElapsed, sleep,getBlockInfo} from '../inc/util'
- dotevnv.config();
- if (!process.env.RPCURL) {
- console.log(`No rpcur value specified...`)
- }
-
-
- console.log(`목적 서버 : ${process.env.RPCURL}`);
-
- async function getNonce(addr: string): Promise<number> {
- const nonce = await provider.getTransactionCount(addr);
- return nonce;
- }
-
- async function transfer(symbol:string, count: number = 10) {
-
- 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;
- await token.connect(admin);
- // const ops = await token.operators();
- // console.log(ops);
-
- let balance1= await token.balanceOf(holder1);
- let balance2 = await token.balanceOf(holder2);
- const b = await token.isTokenHolderKYC(holder1);
- if(!b) {
- console.log('holder kyc error');
- return;
- }
- const partitions = await token.getDefaultPartitions();
- console.log(`holder1(sender) = ${balance1}, holder2(receiver) = ${balance2}`);
- // token.on(token.filters.Transfer, async (...args) => {
- // const lastArg = args[args.length - 1];
- // console.log(lastArg);
- // console.log('on transfer by partition');
- // })
-
-
- let nonce = await getNonce(issuer.address);
- let txids = [];
- let proms = [];
- let firstTx:string = null;
- let lastTx:string = null;
- const start = Date.now();
-
- console.log(`sending ${count} transactions`);
- for(let i = 0; i < count; i++) {
- const tx = await token.operatorTransferByPartition.populateTransaction(
- partitions[0],
- holder1.address,
- holder2.address,
- 1,
- ZeroHash,
- ZeroHash,
- {
- // gasPrice: 0,
- gasLimit: 2100000,
- nonce: nonce,
- type: 2,
- chainId: 1337
- }
- );
- ++nonce;
- // console.log(tx);
-
- const signed = await issuer.signTransaction(tx);
- const pm = provider.send('eth_sendRawTransaction',[signed]);
-
- if(i == 0) {
- firstTx = keccak256(signed);
- }
- if (i == count -1) {
- lastTx = keccak256(signed);
- }
- proms.push(pm);
- }
-
- let txs = await Promise.all(proms);
-
- const elapsed = getElapsed(start,1000);
- console.log(`all tx sent in ${elapsed} seconds`);
-
- console.log(`first Tx = ${firstTx}`);
- console.log(`last Tx = ${lastTx}`);
-
- let txMap = new Map<string,boolean>();
- txs.forEach(txid => {
- // txids.push({txid: txid});
- txMap.set(txid,false);
- });
- const blockHashes = await checkReceipt2(txMap,[firstTx as string, lastTx as string], 'wait for receipt...');
-
- const firstBlockHash = blockHashes.get(firstTx);
- const lastBlockHash = blockHashes.get(lastTx);
- console.log(`firstBlockHash = ${firstBlockHash} , lastBlockHash = ${lastBlockHash}`);
-
- const lastB = await getBlockInfo(lastBlockHash);
- console.log(lastB.timestamp);
- const lastTimeStamp = parseInt(lastB.timestamp,16);
-
- balance1= await token.balanceOf(holder1);
- balance2 = await token.balanceOf(holder2);
- console.log(`holder1 = ${balance1}, holder2 = ${balance2}`);
-
-
- const d = new Date(lastTimeStamp * 1000);
- console.log(d);
-
- console.log(start);
- console.log(lastTimeStamp * 1000);
-
- const tps = calc.CTPS_NUM(count,start,lastTimeStamp * 1000);
- console.log(tps);
-
- }
-
- const calc = new Calulator();
- const rpcUrl = process.env.RPCURL;
- const provider = new JsonRpcProvider(rpcUrl);
- setProvider(provider);
-
- async function main() {
- transfer('test001',1000);
- // for(let i = 13489; i < 13492; i++ ) {
- // try {
- // await send(i);
- // } catch(ex) {
- // console.log(ex);
- // }
- // await sleep(10);
- // }
-
- }
-
- main();
|