Skip to content

Commit 980250c

Browse files
committed
Change reward tests
1 parent 6f90ce2 commit 980250c

File tree

2 files changed

+201
-134
lines changed

2 files changed

+201
-134
lines changed

test/src/e2e/reward.test.ts

Lines changed: 171 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ import {
2323
bobAddress,
2424
carolAddress,
2525
daveAddress,
26+
faucetAccointId,
2627
faucetAddress
2728
} from "../helper/constants";
2829
import CodeChain from "../helper/spawn";
2930

3031
describe("Reward = 50, 1 miner", function() {
32+
// FIXME: Change Number to U64
3133
const MIN_FEE_PAY = 10;
3234
const BLOCK_REWARD = 50;
33-
const FAUCET_INITIAL_CCS = new U64("18000000000000000000");
35+
const FAUCET_INITIAL_CCS = 18000000000000000000;
3436

3537
let node: CodeChain;
3638

@@ -43,46 +45,66 @@ describe("Reward = 50, 1 miner", function() {
4345
});
4446

4547
it("Mining an empty block", async function() {
46-
await node.sdk.rpc.devel.startSealing();
48+
await node.rpc.devel!.startSealing();
4749
expect(
48-
await node.sdk.rpc.chain.getBalance(faucetAddress)
49-
).to.deep.equal(FAUCET_INITIAL_CCS);
50-
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
51-
new U64(BLOCK_REWARD)
52-
);
53-
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
54-
new U64(0)
55-
);
56-
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
57-
new U64(0)
58-
);
59-
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
60-
new U64(0)
61-
);
50+
+(await node.rpc.chain.getBalance({
51+
address: faucetAddress.toString()
52+
}))!
53+
).to.equal(FAUCET_INITIAL_CCS);
54+
expect(
55+
+(await node.rpc.chain.getBalance({
56+
address: aliceAddress.toString()
57+
}))!
58+
).to.equal(BLOCK_REWARD);
59+
expect(
60+
+(await node.rpc.chain.getBalance({
61+
address: bobAddress.toString()
62+
}))!
63+
).to.equal(0);
64+
expect(
65+
+(await node.rpc.chain.getBalance({
66+
address: carolAddress.toString()
67+
}))!
68+
).to.equal(0);
69+
expect(
70+
+(await node.rpc.chain.getBalance({
71+
address: daveAddress.toString()
72+
}))!
73+
).to.equal(0);
6274
});
6375

6476
it("Mining a block with 1 transaction", async function() {
6577
await node.sendPayTx({ fee: 10 });
6678

6779
expect(
68-
await node.sdk.rpc.chain.getBalance(faucetAddress)
69-
).to.deep.equal(FAUCET_INITIAL_CCS.minus(10 /* fee */));
70-
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
71-
new U64(4 /* share */).plus(BLOCK_REWARD)
72-
);
73-
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
74-
new U64(3 /* share */)
75-
);
76-
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
77-
new U64(2 /* share */)
78-
);
79-
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
80-
new U64(1 /* share */)
81-
);
80+
+(await node.rpc.chain.getBalance({
81+
address: faucetAddress.toString()
82+
}))!
83+
).to.equal(FAUCET_INITIAL_CCS - 10 /* fee */);
84+
expect(
85+
+(await node.rpc.chain.getBalance({
86+
address: aliceAddress.toString()
87+
}))!
88+
).to.equal(4 /* share */ + BLOCK_REWARD);
89+
expect(
90+
+(await node.rpc.chain.getBalance({
91+
address: bobAddress.toString()
92+
}))!
93+
).to.deep.equal(3 /* share */);
94+
expect(
95+
+(await node.rpc.chain.getBalance({
96+
address: carolAddress.toString()
97+
}))!
98+
).to.deep.equal(2 /* share */);
99+
expect(
100+
+(await node.rpc.chain.getBalance({
101+
address: daveAddress.toString()
102+
}))!
103+
).to.deep.equal(1 /* share */);
82104
});
83105

84106
it("Mining a block with 3 transactions", async function() {
85-
await node.sdk.rpc.devel.stopSealing();
107+
await node.rpc.devel!.stopSealing();
86108
await node.sendPayTx({
87109
fee: 10,
88110
seq: 0
@@ -95,79 +117,116 @@ describe("Reward = 50, 1 miner", function() {
95117
fee: 15,
96118
seq: 2
97119
});
98-
await node.sdk.rpc.devel.startSealing();
120+
await node.rpc.devel!.startSealing();
99121

100122
const TOTAL_FEE = 10 + 10 + 15;
101123
const TOTAL_MIN_FEE = MIN_FEE_PAY * 3;
102124
expect(
103-
await node.sdk.rpc.chain.getBalance(faucetAddress)
104-
).to.deep.equal(FAUCET_INITIAL_CCS.minus(TOTAL_FEE));
105-
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
106-
new U64(Math.floor((TOTAL_MIN_FEE * 4) / 10) /* share */)
107-
.plus(TOTAL_FEE) // block author get the remaining fee
108-
.minus(Math.floor((TOTAL_MIN_FEE * 4) / 10))
109-
.minus(Math.floor((TOTAL_MIN_FEE * 3) / 10))
110-
.minus(Math.floor((TOTAL_MIN_FEE * 2) / 10))
111-
.minus(Math.floor((TOTAL_MIN_FEE * 1) / 10))
112-
.plus(BLOCK_REWARD)
125+
+(await node.rpc.chain.getBalance({
126+
address: faucetAddress.toString()
127+
}))!
128+
).to.deep.equal(FAUCET_INITIAL_CCS - TOTAL_FEE);
129+
expect(
130+
+(await node.rpc.chain.getBalance({
131+
address: aliceAddress.toString()
132+
}))!
133+
).to.equal(
134+
Number(Math.floor((TOTAL_MIN_FEE * 4) / 10) /* share */) +
135+
TOTAL_FEE - // block author get the remaining fee
136+
Math.floor((TOTAL_MIN_FEE * 4) / 10) -
137+
Math.floor((TOTAL_MIN_FEE * 3) / 10) -
138+
Math.floor((TOTAL_MIN_FEE * 2) / 10) -
139+
Math.floor((TOTAL_MIN_FEE * 1) / 10) +
140+
BLOCK_REWARD
113141
);
114-
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
115-
new U64(Math.floor((TOTAL_MIN_FEE * 3) / 10) /* share */)
142+
expect(
143+
+(await node.rpc.chain.getBalance({
144+
address: bobAddress.toString()
145+
}))!
146+
).to.deep.equal(
147+
Number(Math.floor((TOTAL_MIN_FEE * 3) / 10) /* share */)
116148
);
117-
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
118-
new U64(Math.floor((TOTAL_MIN_FEE * 2) / 10) /* share */)
149+
expect(
150+
+(await node.rpc.chain.getBalance({
151+
address: carolAddress.toString()
152+
}))!
153+
).to.deep.equal(
154+
Number(Math.floor((TOTAL_MIN_FEE * 2) / 10) /* share */)
119155
);
120-
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
121-
new U64(Math.floor((TOTAL_MIN_FEE * 1) / 10) /* share */)
156+
expect(
157+
+(await node.rpc.chain.getBalance({
158+
address: daveAddress.toString()
159+
}))!
160+
).to.deep.equal(
161+
Number(Math.floor((TOTAL_MIN_FEE * 1) / 10) /* share */)
122162
);
123163
});
124164

125165
it("Mining a block with a transaction that pays the author", async function() {
126166
await node.pay(aliceAddress, 100);
127167
expect(
128-
await node.sdk.rpc.chain.getBalance(faucetAddress)
129-
).to.deep.equal(
130-
FAUCET_INITIAL_CCS.minus(100 /* pay */).minus(10 /* fee */)
131-
);
132-
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
133-
new U64(100 /* pay */)
134-
.plus(Math.floor((10 * 4) / 10) /* share */)
135-
.plus(BLOCK_REWARD)
136-
);
137-
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
138-
new U64(Math.floor((10 * 3) / 10) /* share */)
139-
);
140-
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
141-
new U64(Math.floor((10 * 2) / 10) /* share */)
142-
);
143-
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
144-
new U64(Math.floor((10 * 1) / 10) /* share */)
168+
+(await node.rpc.chain.getBalance({
169+
address: faucetAddress.toString()
170+
}))!
171+
).to.equal(FAUCET_INITIAL_CCS + 100 /* pay */ - 10 /* fee */);
172+
expect(
173+
+(await node.rpc.chain.getBalance({
174+
address: aliceAddress.toString()
175+
}))!
176+
).to.equal(
177+
Number(
178+
100 /* pay */ +
179+
Math.floor((10 * 4) / 10) /* share */ +
180+
BLOCK_REWARD
181+
)
145182
);
183+
expect(
184+
+(await node.rpc.chain.getBalance({
185+
address: bobAddress.toString()
186+
}))!
187+
).to.equal(Number(Math.floor((10 * 3) / 10) /* share */));
188+
expect(
189+
+(await node.rpc.chain.getBalance({
190+
address: carolAddress.toString()
191+
}))!
192+
).to.equal(Number(Math.floor((10 * 2) / 10) /* share */));
193+
expect(
194+
+(await node.rpc.chain.getBalance({
195+
address: daveAddress.toString()
196+
}))!
197+
).to.equal(Number(Math.floor((10 * 1) / 10) /* share */));
146198
});
147199

148200
it("Mining a block with a transaction which author pays someone in", async function() {
149201
await node.sendPayTx({ fee: 10 });
150-
const faucetBalance = await node.sdk.rpc.chain.getBalance(
151-
faucetAddress
152-
);
153-
const aliceBalance = await node.sdk.rpc.chain.getBalance(aliceAddress);
154-
const bobBalance = await node.sdk.rpc.chain.getBalance(bobAddress);
155-
const carolBalance = await node.sdk.rpc.chain.getBalance(carolAddress);
156-
const daveBalance = await node.sdk.rpc.chain.getBalance(daveAddress);
157-
expect(faucetBalance).to.deep.equal(
158-
FAUCET_INITIAL_CCS.minus(10 /* fee */)
159-
);
160-
expect(aliceBalance).to.deep.equal(
161-
new U64(Math.floor((10 * 4) / 10) /* share */).plus(BLOCK_REWARD)
202+
const faucetBalance = +(await node.rpc.chain.getBalance({
203+
address: faucetAddress.toString()
204+
}))!;
205+
const aliceBalance = +(await node.rpc.chain.getBalance({
206+
address: aliceAddress.toString()
207+
}))!;
208+
const bobBalance = +(await node.rpc.chain.getBalance({
209+
address: bobAddress.toString()
210+
}))!;
211+
const carolBalance = +(await node.rpc.chain.getBalance({
212+
address: carolAddress.toString()
213+
}))!;
214+
const daveBalance = +(await node.rpc.chain.getBalance({
215+
address: daveAddress.toString()
216+
}))!;
217+
218+
expect(faucetBalance).to.equal(FAUCET_INITIAL_CCS - 10 /* fee */);
219+
expect(aliceBalance).to.equal(
220+
Number(Math.floor((10 * 4) / 10)) /* share */ + BLOCK_REWARD
162221
);
163-
expect(bobBalance).to.deep.equal(
164-
new U64(Math.floor((10 * 3) / 10) /* share */)
222+
expect(bobBalance).to.equal(
223+
Number(Math.floor((10 * 3) / 10) /* share */)
165224
);
166-
expect(carolBalance).to.deep.equal(
167-
new U64(Math.floor((10 * 2) / 10) /* share */)
225+
expect(carolBalance).to.equal(
226+
Number(Math.floor((10 * 2) / 10) /* share */)
168227
);
169-
expect(daveBalance).to.deep.equal(
170-
new U64(Math.floor((10 * 1) / 10) /* share */)
228+
expect(daveBalance).to.equal(
229+
Number(Math.floor((10 * 1) / 10) /* share */)
171230
);
172231

173232
const tx = await node.sdk.core
@@ -179,24 +238,36 @@ describe("Reward = 50, 1 miner", function() {
179238
await node.sdk.rpc.chain.sendSignedTransaction(tx);
180239

181240
expect(
182-
await node.sdk.rpc.chain.getBalance(faucetAddress)
183-
).to.deep.equal(faucetBalance.plus(20 /* pay */));
184-
expect(await node.sdk.rpc.chain.getBalance(aliceAddress)).to.deep.equal(
185-
aliceBalance
186-
.minus(20 /* pay */)
187-
.minus(10 /* fee */)
188-
.plus(Math.floor((10 * 4) / 10) /* share */)
189-
.plus(BLOCK_REWARD)
190-
);
191-
expect(await node.sdk.rpc.chain.getBalance(bobAddress)).to.deep.equal(
192-
bobBalance.plus(Math.floor((10 * 3) / 10))
193-
);
194-
expect(await node.sdk.rpc.chain.getBalance(carolAddress)).to.deep.equal(
195-
carolBalance.plus(Math.floor((10 * 2) / 10))
196-
);
197-
expect(await node.sdk.rpc.chain.getBalance(daveAddress)).to.deep.equal(
198-
daveBalance.plus(Math.floor((10 * 1) / 10))
241+
+(await node.rpc.chain.getBalance({
242+
address: faucetAddress.toString()
243+
}))!
244+
).to.deep.equal(faucetBalance + 20 /* pay */);
245+
expect(
246+
+(await node.rpc.chain.getBalance({
247+
address: aliceAddress.toString()
248+
}))!
249+
).to.deep.equal(
250+
aliceBalance -
251+
20 /* pay */ -
252+
10 /* fee */ +
253+
Math.floor((10 * 4) / 10) /* share */ +
254+
BLOCK_REWARD
199255
);
256+
expect(
257+
+(await node.rpc.chain.getBalance({
258+
address: bobAddress.toString()
259+
}))!
260+
).to.deep.equal(Number(bobBalance) + Math.floor((10 * 3) / 10));
261+
expect(
262+
+(await node.rpc.chain.getBalance({
263+
address: carolAddress.toString()
264+
}))!
265+
).to.deep.equal(Number(carolBalance) + Math.floor((10 * 2) / 10));
266+
expect(
267+
+(await node.rpc.chain.getBalance({
268+
address: daveAddress.toString()
269+
}))!
270+
).to.deep.equal(Number(daveBalance) + Math.floor((10 * 1) / 10));
200271
});
201272

202273
afterEach(async function() {

0 commit comments

Comments
 (0)