-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSmokeBench.spec.ts
129 lines (117 loc) · 5.07 KB
/
SmokeBench.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { Blockchain, SandboxContract, TreasuryContract, internal } from '@ton/sandbox';
import { Cell, toNano } from '@ton/core';
import { MasterCounter } from '../wrappers/MasterCounter';
import { Retranslator, RetranslatorOptions } from '../wrappers/Retranslator';
import '@ton/test-utils';
import { compile } from '@ton/blueprint';
import { Counter } from '../wrappers/Counter';
import { KeyPair, getSecureRandomBytes, keyPairFromSeed } from '@ton/crypto';
import { setMasterCounter, printSpamChain, printTPSHistory, now } from '../wrappers/utils';
describe('MasterCounter', () => {
let blockchain: Blockchain;
let keypair: KeyPair;
let masterCounter: SandboxContract<MasterCounter>;
let retranslator0: SandboxContract<Retranslator>;
let counter0: SandboxContract<Counter>;
let deployer: SandboxContract<TreasuryContract>;
let spamConfig: RetranslatorOptions = {
amount: toNano(200),
hops: 10000,
threads: 1,
splitHops: 0,
sameShardProbability: 0.5,
};
let counterCode: Cell;
beforeAll(async () => {
blockchain = await Blockchain.create();
deployer = await blockchain.treasury('deployer');
keypair = keyPairFromSeed(await getSecureRandomBytes(32));
let masterCounterCode = await compile('MasterCounter');
masterCounter = blockchain.openContract(
MasterCounter.createFromConfig(
{ owner: deployer.address, publicKey: keypair.publicKey },
masterCounterCode,
-1 // workchain = masterchain
)
);
setMasterCounter(masterCounter.address);
let retranslatorCode = await compile('Retranslator');
counterCode = await compile('Counter');
retranslator0 = blockchain.openContract(
Retranslator.createFromConfig({ id: 0, keypair, counterCode }, retranslatorCode)
);
counter0 = blockchain.openContract(
Counter.createFromConfig({ id: 0, publicKey: keypair.publicKey }, counterCode)
);
const deployMasterResult = await masterCounter.sendCounterCode(deployer.getSender(), counterCode, toNano('1000'));
expect(deployMasterResult.transactions).toHaveTransaction({
from: deployer.address,
to: masterCounter.address,
deploy: true,
success: true,
});
});
it('should deploy master counter', async () => {
// checks the success of beforeAll
});
it('should deploy first retranslator and start flooding', async () => {
await deployer.send({
to: retranslator0.address, // topup
value: toNano('100000'),
bounce: false,
});
const startResult = await retranslator0.sendStart(spamConfig);
expect(startResult.transactions).toHaveTransaction({
from: undefined, // external
on: retranslator0.address,
deploy: true,
success: true,
});
printSpamChain(startResult.transactions, masterCounter.address);
});
const t = now();
it('should report to master from 0th', async () => {
const counterAmountB = await masterCounter.getCounter();
console.log("counter before 0th's 10:", counterAmountB);
const masterContract = await blockchain.getContract(masterCounter.address);
masterContract.receiveMessage(
internal({
from: counter0.address,
to: masterCounter.address,
value: toNano('0.4'),
body: MasterCounter.addMessageBody(0, 10, t, t + 10),
})
);
const counterAmountA = await masterCounter.getCounter();
console.log("counter after 0th's 10:", counterAmountA);
});
it('should report to master from 100th counter', async () => {
const counterAmountB = await masterCounter.getCounter();
console.log("counter before 100th's 20:", counterAmountB);
const masterContract = await blockchain.getContract(masterCounter.address);
const counter100 = blockchain.openContract(
Counter.createFromConfig({ id: 100, publicKey: keypair.publicKey }, counterCode)
);
masterContract.receiveMessage(
internal({
from: counter100.address,
to: masterCounter.address,
value: toNano('2'),
body: MasterCounter.addMessageBody(100, 20, t, t + 20),
})
);
const counterAmountA = await masterCounter.getCounter();
console.log("counter after 100th's 20:", counterAmountA);
});
it('should show counter', async () => {
const counterAmount = await masterCounter.getCounter();
console.log('Total counter:', counterAmount);
});
it('should show the result', async () => {
const history = await masterCounter.getHistory();
const secTxs = printTPSHistory(history);
const counterAmount = await masterCounter.getCounter();
console.log('Total counter:', counterAmount);
console.log('Avg TPS:', counterAmount / BigInt(secTxs.length));
});
});