Skip to content

Commit 0bb58ee

Browse files
committed
Fix testhelper types
1 parent b43d5a3 commit 0bb58ee

File tree

2 files changed

+86
-16
lines changed

2 files changed

+86
-16
lines changed

test/src/helper/mock/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ export class Mock {
611611
new TendermintMessage({
612612
type: "proposalblock",
613613
view: message.view,
614+
priorityInfo: message.priorityInfo,
614615
message: RLP.encode([newHeader, block[1]]),
615616
signature: newSignature.r + newSignature.s
616617
})
@@ -623,8 +624,10 @@ export class Mock {
623624
this.sendTendermintMessage(
624625
new TendermintMessage({
625626
type: "requestproposal",
626-
height: message.voteStep.height,
627-
view: message.voteStep.view
627+
round: {
628+
height: message.voteStep.height,
629+
view: message.voteStep.view
630+
}
628631
})
629632
);
630633
}, 200);

test/src/helper/mock/tendermintMessage.ts

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ interface VoteStep {
4444
step: Step;
4545
}
4646

47+
interface SortitionRound {
48+
height: number;
49+
view: number;
50+
}
51+
52+
interface PriorityInfo {
53+
signerIdx: number;
54+
priority: H256;
55+
subUserIdx: number;
56+
numberOfElections: number;
57+
vrfProof: Buffer;
58+
}
59+
4760
export interface ConsensusMessage {
4861
type: "consensusmessage";
4962
messages: Array<{
@@ -59,14 +72,20 @@ export interface ConsensusMessage {
5972
export interface ProposalBlock {
6073
type: "proposalblock";
6174
signature: string;
75+
priorityInfo: PriorityInfo;
6276
view: number;
6377
message: Buffer;
6478
}
6579

80+
interface ProposalSummary {
81+
priorityInfo: PriorityInfo;
82+
blockHash: H256;
83+
}
84+
6685
export interface StepState {
6786
type: "stepstate";
6887
voteStep: VoteStep;
69-
proposal: H256 | null;
88+
proposal: ProposalSummary | null;
7089
lockView: number | null;
7190
knownVotes: Buffer;
7291
}
@@ -79,8 +98,7 @@ export interface RequestMessage {
7998

8099
export interface RequestProposal {
81100
type: "requestproposal";
82-
height: number;
83-
view: number;
101+
round: SortitionRound;
84102
}
85103

86104
type MessageBody =
@@ -124,8 +142,15 @@ export class TendermintMessage {
124142
message = {
125143
type: "proposalblock",
126144
signature: decoded[1].toString("hex"),
127-
view: readUIntRLP(decoded[2]),
128-
message: uncompressSync(decoded[3])
145+
priorityInfo: {
146+
signerIdx: readUIntRLP(decoded[2][0]),
147+
priority: new H256(decoded[2][1].toString("hex")),
148+
subUserIdx: readUIntRLP(decoded[2][2]),
149+
numberOfElections: readUIntRLP(decoded[2][3]),
150+
vrfProof: decoded[2][4]
151+
},
152+
view: readUIntRLP(decoded[3]),
153+
message: uncompressSync(decoded[4])
129154
};
130155
break;
131156
}
@@ -137,10 +162,20 @@ export class TendermintMessage {
137162
view: readUIntRLP(decoded[1][1]),
138163
step: readUIntRLP(decoded[1][2]) as Step
139164
},
140-
proposal: readOptionalRlp(
141-
decoded[2],
142-
buffer => new H256(buffer.toString("hex"))
143-
),
165+
proposal: readOptionalRlp(decoded[2], (buffer: any) => {
166+
return {
167+
priorityInfo: {
168+
signerIdx: readUIntRLP(buffer[0][0]),
169+
priority: new H256(
170+
buffer[0][1].toString("hex")
171+
),
172+
subUserIdx: readUIntRLP(buffer[0][2]),
173+
numberOfElections: readUIntRLP(buffer[0][3]),
174+
vrfProof: buffer[0][4]
175+
},
176+
blockHash: new H256(buffer[1].toString("hex"))
177+
};
178+
}),
144179
lockView: readOptionalRlp(decoded[3], readUIntRLP),
145180
knownVotes: decoded[4]
146181
};
@@ -161,8 +196,10 @@ export class TendermintMessage {
161196
case MessageType.MESSAGE_ID_REQUEST_PROPOSAL: {
162197
message = {
163198
type: "requestproposal",
164-
height: readUIntRLP(decoded[1]),
165-
view: readUIntRLP(decoded[2])
199+
round: {
200+
height: readUIntRLP(decoded[1][0]),
201+
view: readUIntRLP(decoded[1][1])
202+
}
166203
};
167204
break;
168205
}
@@ -210,6 +247,19 @@ export class TendermintMessage {
210247
return [
211248
MessageType.MESSAGE_ID_PROPOSAL_BLOCK,
212249
Buffer.from(this.body.signature, "hex"),
250+
[
251+
new U64(
252+
this.body.priorityInfo.signerIdx
253+
).toEncodeObject(),
254+
this.body.priorityInfo.priority.toEncodeObject(),
255+
new U64(
256+
this.body.priorityInfo.subUserIdx
257+
).toEncodeObject(),
258+
new U64(
259+
this.body.priorityInfo.numberOfElections
260+
).toEncodeObject(),
261+
this.body.priorityInfo.vrfProof
262+
],
213263
new U64(this.body.view).toEncodeObject(),
214264
compressSync(this.body.message)
215265
];
@@ -224,7 +274,22 @@ export class TendermintMessage {
224274
],
225275
this.body.proposal == null
226276
? []
227-
: [this.body.proposal.toEncodeObject()],
277+
: [
278+
[
279+
new U64(
280+
this.body.proposal.priorityInfo.signerIdx
281+
).toEncodeObject(),
282+
this.body.proposal.priorityInfo.priority.toEncodeObject(),
283+
new U64(
284+
this.body.proposal.priorityInfo.subUserIdx
285+
).toEncodeObject(),
286+
new U64(
287+
this.body.proposal.priorityInfo.numberOfElections
288+
).toEncodeObject(),
289+
this.body.proposal.priorityInfo.vrfProof
290+
],
291+
this.body.proposal.blockHash.toEncodeObject()
292+
],
228293
this.body.lockView == null
229294
? []
230295
: [new U64(this.body.lockView).toEncodeObject()],
@@ -245,8 +310,10 @@ export class TendermintMessage {
245310
case "requestproposal": {
246311
return [
247312
MessageType.MESSAGE_ID_REQUEST_PROPOSAL,
248-
new U64(this.body.height).toEncodeObject(),
249-
new U64(this.body.view).toEncodeObject()
313+
[
314+
new U64(this.body.round.height).toEncodeObject(),
315+
new U64(this.body.round.view).toEncodeObject()
316+
]
250317
];
251318
}
252319
}

0 commit comments

Comments
 (0)