Skip to content

Commit 8c2af51

Browse files
author
SeungMin Lee
committed
Remove the score from the tests
The tests was not updated when we changed the BlockSynMessage. We removed the unnecessary score from the tests and updated the tests.
1 parent 3baaad9 commit 8c2af51

15 files changed

+27
-113
lines changed

test/src/e2e.long/invalidBlockPropagation.helper.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ async function setup(): Promise<[Header, Block, Header]> {
5858
new H256(block0.transactionsRoot),
5959
new H256(block0.nextValidatorSetHash),
6060
new H256(block0.stateRoot),
61-
new U256(`${block0.score}`),
6261
block0.seal
6362
);
6463
const author1 = Address.fromString(block1.author);
@@ -71,7 +70,6 @@ async function setup(): Promise<[Header, Block, Header]> {
7170
new H256(block1.transactionsRoot),
7271
new H256(block1.nextValidatorSetHash),
7372
new H256(block1.stateRoot),
74-
new U256(2222222222222),
7573
block1.seal
7674
);
7775
const author3 = Address.fromString(block0.author);
@@ -84,7 +82,6 @@ async function setup(): Promise<[Header, Block, Header]> {
8482
new H256(block2.transactionsRoot),
8583
new H256(block2.nextValidatorSetHash),
8684
new H256(block2.stateRoot),
87-
new U256(33333333333333),
8885
block2.seal
8986
);
9087
return [header0, block1, header2];
@@ -120,14 +117,12 @@ async function testBody(
120117
ttransactionRoot?: H256;
121118
tstateRoot?: H256;
122119
tnextValidatorSetHash?: H256;
123-
tscore?: U256;
124120
tseal?: number[][];
125121
}
126122
) {
127123
const {
128124
tnumber,
129125
textraData,
130-
tscore,
131126
tparent,
132127
tauthor,
133128
ttransactionRoot,
@@ -137,7 +132,6 @@ async function testBody(
137132
} = params;
138133

139134
const bestHash = header2.hashing();
140-
const bestScore = header2.getScore();
141135

142136
const author4 = Address.fromString(block1.author);
143137
const header = new Header(
@@ -149,7 +143,6 @@ async function testBody(
149143
new H256(block1.transactionsRoot),
150144
new H256(block1.nextValidatorSetHash),
151145
new H256(block1.stateRoot),
152-
new U256(2222222222222),
153146
block1.seal
154147
);
155148

@@ -174,15 +167,13 @@ async function testBody(
174167
if (tnextValidatorSetHash != null) {
175168
header.setNextValidatorSetHash(tnextValidatorSetHash);
176169
}
177-
if (tscore != null) {
178-
header.setScore(tscore);
179-
}
180170
if (tseal != null) {
181171
header.setSeal(tseal);
182172
}
183173

184174
const genesis = mock.genesisHash;
185-
await mock.sendStatus(bestScore, bestHash, genesis);
175+
const seq = new U256(0);
176+
await mock.sendStatus(seq, bestHash, genesis);
186177
await mock.sendBlockHeaderResponse([
187178
header0.toEncodeObject(),
188179
header.toEncodeObject(),

test/src/e2e.long/invalidBlockPropagation8.test.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

test/src/e2e.long/invalidBlockPropagation9.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ const INVALID_SEAL = [Buffer.from("DEADBEEF")];
2121
const params = {
2222
tseal: INVALID_SEAL
2323
};
24-
createTestSuite(9, "OnChain invalid score seal propagation test", params);
24+
createTestSuite(9, "OnChain invalid seal propagation test", params);

test/src/e2e.long/onChainBlockValid.test.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ describe("Test onChain block communication", async function() {
7676
new H256(genesisBlock.transactionsRoot),
7777
new H256(genesisBlock.stateRoot),
7878
new H256(genesisBlock.nextValidatorSetHash),
79-
new U256(`${genesisBlock.score}`),
8079
genesisBlock.seal
8180
);
8281
const author2PlatformAddr = Address.fromString(block1.author);
@@ -89,7 +88,6 @@ describe("Test onChain block communication", async function() {
8988
new H256(block1.transactionsRoot),
9089
new H256(block1.stateRoot),
9190
new H256(block1.nextValidatorSetHash),
92-
new U256(2222222222222),
9391
block1.seal
9492
);
9593
const author3PlatformAddr = Address.fromString(block2.author);
@@ -102,7 +100,6 @@ describe("Test onChain block communication", async function() {
102100
new H256(block2.transactionsRoot),
103101
new H256(block2.stateRoot),
104102
new H256(block2.nextValidatorSetHash),
105-
new U256(33333333333333),
106103
block2.seal
107104
);
108105

@@ -137,8 +134,7 @@ describe("Test onChain block communication", async function() {
137134
header2.toEncodeObject()
138135
],
139136
[[], []],
140-
header2.hashing(),
141-
header2.getScore()
137+
header2.hashing()
142138
);
143139

144140
await mock.waitStatusMessage();

test/src/helper/mock/blockSyncMessage.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type BlockSyncMessageBody = IStatus | IRequest | IResponse;
3939

4040
interface IStatus {
4141
type: "status";
42-
totalScore: U256;
42+
seq: U256;
4343
bestHash: H256;
4444
genesisHash: H256;
4545
}
@@ -64,14 +64,12 @@ export class BlockSyncMessage {
6464
if (msgId === MessageType.MESSAGE_ID_STATUS) {
6565
Emitter.emit("status");
6666
const msg = decodedmsg[1];
67-
const totalScore = new U256(
68-
parseInt(msg[0].toString("hex"), 16) || 0
69-
);
67+
const seq = new U256(parseInt(msg[0].toString("hex"), 16) || 0);
7068
const bestHash = new H256(msg[1].toString("hex"));
7169
const genesisHash = new H256(msg[2].toString("hex"));
7270
return new BlockSyncMessage({
7371
type: "status",
74-
totalScore,
72+
seq,
7573
bestHash,
7674
genesisHash
7775
});
@@ -123,7 +121,7 @@ export class BlockSyncMessage {
123121
return [
124122
MessageType.MESSAGE_ID_STATUS,
125123
[
126-
this.body.totalScore.toEncodeObject(),
124+
this.body.seq.toEncodeObject(),
127125
this.body.bestHash.toEncodeObject(),
128126
this.body.genesisHash.toEncodeObject()
129127
]

test/src/helper/mock/cHeader.ts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ export class Header {
2929
const stateRoot = new H256(decodedmsg[2].toString("hex"));
3030
const transactionsRoot = new H256(decodedmsg[3].toString("hex"));
3131
const nextValidatorSetHash = new H256(decodedmsg[4].toString("hex"));
32-
const score = decodedmsg[5];
33-
const number = new U256(parseInt(decodedmsg[6].toString("hex"), 16));
34-
const timestamp = new U256(parseInt(decodedmsg[7].toString("hex"), 16));
35-
const extraData = decodedmsg[8];
32+
const number = new U256(parseInt(decodedmsg[5].toString("hex"), 16));
33+
const timestamp = new U256(parseInt(decodedmsg[6].toString("hex"), 16));
34+
const extraData = decodedmsg[7];
3635

3736
// Be careful of the order! Three roots have same types, so mistake on the order will not be catched by typechecker.
3837
const header = new Header(
@@ -44,11 +43,10 @@ export class Header {
4443
transactionsRoot,
4544
stateRoot,
4645
nextValidatorSetHash,
47-
score,
4846
[]
4947
);
5048

51-
for (let i = 9; i < decodedmsg.getLength(); i++) {
49+
for (let i = 8; i < decodedmsg.getLength(); i++) {
5250
header.seal.push(decodedmsg[i]);
5351
}
5452

@@ -62,7 +60,6 @@ export class Header {
6260
private transactionsRoot: H256;
6361
private stateRoot: H256;
6462
private nextValidatorSetHash: H256;
65-
private score: U256;
6663
private seal: number[][];
6764
private hash: null | H256;
6865
private bareHash: null | H256;
@@ -76,7 +73,6 @@ export class Header {
7673
transactionsRoot: H256,
7774
stateRoot: H256,
7875
nextValidatorSetHash: H256,
79-
score: U256,
8076
seal: number[][],
8177
hash?: H256,
8278
bareHash?: H256
@@ -89,7 +85,6 @@ export class Header {
8985
this.transactionsRoot = transactionsRoot;
9086
this.stateRoot = stateRoot;
9187
this.nextValidatorSetHash = nextValidatorSetHash;
92-
this.score = score;
9388
this.seal = seal;
9489
this.hash = hash == null ? this.hashing() : hash;
9590
this.bareHash = bareHash == null ? null : bareHash;
@@ -127,10 +122,6 @@ export class Header {
127122
this.nextValidatorSetHash = root;
128123
}
129124

130-
public setScore(score: U256) {
131-
this.score = score;
132-
}
133-
134125
public setSeal(seal: number[][]) {
135126
this.seal = seal;
136127
}
@@ -143,10 +134,6 @@ export class Header {
143134
return this.bareHash;
144135
}
145136

146-
public getScore(): U256 {
147-
return this.score;
148-
}
149-
150137
public default(): Header {
151138
return new Header(
152139
new H256(
@@ -159,9 +146,6 @@ export class Header {
159146
BLAKE_NULL_RLP,
160147
BLAKE_NULL_RLP,
161148
BLAKE_NULL_RLP,
162-
new U256(
163-
"0000000000000000000000000000000000000000000000000000000000000000"
164-
),
165149
[]
166150
);
167151
}
@@ -173,7 +157,6 @@ export class Header {
173157
this.stateRoot.toEncodeObject(),
174158
this.transactionsRoot.toEncodeObject(),
175159
this.nextValidatorSetHash.toEncodeObject(),
176-
this.score.toEncodeObject(),
177160
this.number.toEncodeObject(),
178161
this.timestamp.toEncodeObject(),
179162
this.extraData

test/src/helper/mock/example/send-block.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ async function sendBlock() {
2020
header2.toEncodeObject()
2121
],
2222
[[], []],
23-
header2.hashing(),
24-
header2.getScore()
23+
header2.hashing()
2524
);
2625

2726
await mock.end();

0 commit comments

Comments
 (0)