Skip to content

Commit 4f5093e

Browse files
author
Junha Yang0
committed
WIP
1 parent 3559d7f commit 4f5093e

File tree

3 files changed

+147
-1
lines changed

3 files changed

+147
-1
lines changed

test/src/tendermint.test/norpc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ import CodeChain from "../helper/spawn";
5656
additionalKeysPath: "tendermint/keys"
5757
});
5858
});
59-
await Promise.all(nodes.map(node => node.start()));
59+
await Promise.all(nodes.map(node => node.start({ argv: ["--no-tx-relay"] })));
6060

6161
await Promise.all([
6262
nodes[0].connect(nodes[1]),

test/src/tendermint.test/txgen.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright 2018-2019 Kodebox, Inc.
2+
// This file is part of CodeChain.
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Affero General Public License as
6+
// published by the Free Software Foundation, either version 3 of the
7+
// License, or (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Affero General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Affero General Public License
15+
// along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
17+
import {
18+
faucetAddress,
19+
faucetSecret,
20+
validator0Address,
21+
validator1Address,
22+
validator2Address,
23+
validator3Address,
24+
validator0Secret,
25+
validator1Secret,
26+
validator2Secret,
27+
validator3Secret
28+
} from "../helper/constants";
29+
import { makeRandomH256 } from "../helper/random";
30+
import CodeChain from "../helper/spawn";
31+
const {
32+
Worker,
33+
isMainThread,
34+
parentPort,
35+
workerData
36+
} = require("worker_threads");
37+
const path = require("path");
38+
39+
const RLP = require("rlp");
40+
41+
(async () => {
42+
let nodes: CodeChain[];
43+
44+
const validatorAddresses = [
45+
validator0Address,
46+
validator1Address,
47+
validator2Address,
48+
validator3Address
49+
];
50+
let promises = [];
51+
const validatorSecrets = [
52+
validator0Secret,
53+
validator1Secret,
54+
validator2Secret,
55+
validator3Secret
56+
];
57+
58+
for (let index = 0; index < 4; index += 1) {
59+
const worker = new Worker(
60+
path.resolve(__dirname, "./txgen_worker.js"),
61+
{
62+
workerData: {
63+
wname: `${index}`,
64+
secret: validatorSecrets[index],
65+
seqStart: 0,
66+
seqEnd: 10000,
67+
filePrefix: `${index}`
68+
}
69+
}
70+
);
71+
72+
let workerPromise = new Promise((resolve, reject) => {
73+
worker.on("error", reject);
74+
worker.on("exit", (code: any) => {
75+
if (code !== 0) {
76+
reject(new Error(`Worker stopped with exit code ${code}`));
77+
}
78+
});
79+
});
80+
promises.push(workerPromise);
81+
}
82+
await Promise.all(promises);
83+
})().catch(console.error);
84+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const {
2+
Worker,
3+
isMainThread,
4+
parentPort,
5+
workerData
6+
} = require("worker_threads");
7+
const { SDK } = require("codechain-sdk");
8+
const { existsSync , readFileSync, writeFileSync} = require("fs")
9+
10+
async function main() {
11+
console.log("Hello");
12+
console.log("Bye");
13+
await wait(100);
14+
15+
const { wname, secret, seqStart, seqEnd, filePrefix } = workerData;
16+
console.log(`${wname} // ${secret} // ${seqStart} // ${seqEnd} // ${filePrefix}`);
17+
18+
const sdk = new SDK({
19+
server: `http://localhost:${8080}`,
20+
networkId: "tc"
21+
});
22+
let seqCount = seqStart;
23+
while (seqCount < seqEnd) {
24+
const transactions = [];
25+
let chunkStart = seqCount;
26+
for (let i = 0; i < 50000; i++) {
27+
28+
const value = makeRandomH256();
29+
const accountId = sdk.util.getAccountIdFromPrivate(value);
30+
const recipient = sdk.core.classes.PlatformAddress.fromAccountId(accountId, {
31+
networkId: "tc"
32+
});
33+
if (seqCount % 1000 === 0) {
34+
await console.log(`[tx prepared] Worker ${wname}: ${i}`);
35+
}
36+
const transaction = sdk.core
37+
.createPayTransaction({
38+
recipient,
39+
quantity: 1
40+
})
41+
.sign({
42+
secret: secret,
43+
seq: seqCount,
44+
fee: 10
45+
});
46+
transactions.push(transaction.rlpBytes().toString("hex"));
47+
seqCount++;
48+
}
49+
writeFileSync(`./tx/${filePrefix}_${chunkStart}_${seqCount}.json`, JSON.stringify(transactions));
50+
}
51+
}
52+
53+
main().catch(console.error);
54+
55+
function makeRandomH256() {
56+
let text = "";
57+
const possible = "0123456789abcdef";
58+
for (let i = 0; i < 64; i++) {
59+
text += possible.charAt(Math.floor(Math.random() * possible.length));
60+
}
61+
return text;
62+
}

0 commit comments

Comments
 (0)