Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevmatos committed Apr 22, 2020
1 parent 36f565c commit 39dd196
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion raiden-ts/src/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export function packMessage(message: Message) {
encode(message.fee_schedule.flat, 32),
encode(message.fee_schedule.proportional, 32),
rlpEncode(message.fee_schedule.imbalance_penalty ?? '0x'),
encode(message.timestamp.substr(0, 19), 19),
encode(message.timestamp, 19),
]),
) as HexString; // variable size of fee_schedule.imbalance_penalty rlpEncoding, when not null
}
Expand Down
9 changes: 7 additions & 2 deletions raiden-ts/src/path/epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ const PathError = t.readonly(
}),
);

// returns a ISO string truncated at the integer second resolution
function makeTimestamp(time?: Date): string {
return (time ?? new Date()).toISOString().substr(0, 19);
}

const makeIOU = (
sender: Address,
receiver: Address,
Expand Down Expand Up @@ -103,7 +108,7 @@ const signIOU$ = (iou: IOU, signer: Signer): Observable<Signed<IOU>> =>

const makeAndSignLastIOURequest$ = (sender: Address, receiver: Address, signer: Signer) =>
defer(() => {
const timestamp = new Date().toISOString().split('.')[0],
const timestamp = makeTimestamp(),
message = concat([sender, receiver, toUtf8Bytes(timestamp)]);
return from(signer.signMessage(message) as Promise<Signature>).pipe(
map((signature) => ({ sender, receiver, timestamp, signature })),
Expand Down Expand Up @@ -495,7 +500,7 @@ export const pfsFeeUpdateEpic = (
channel_identifier: bigNumberify(channel.id) as UInt<32>,
},
updating_participant: address,
timestamp: new Date().toISOString().substr(0, 23) + '000',
timestamp: makeTimestamp(),
fee_schedule: {
cap_fees: true,
imbalance_penalty: null,
Expand Down
4 changes: 2 additions & 2 deletions raiden-ts/tests/unit/messages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ describe('sign/verify, pack & encode/decode ', () => {
channel_identifier: bigNumberify(1338) as UInt<32>,
},
updating_participant: '0x14791697260E4c9A71f18484C9f997B308e59325' as Address,
timestamp: new Date(0).toISOString().substr(0, 23) + '000',
timestamp: new Date(0).toISOString().substr(0, 19),
fee_schedule: {
cap_fees: true,
imbalance_penalty: null,
Expand All @@ -548,7 +548,7 @@ describe('sign/verify, pack & encode/decode ', () => {

const encoded = encodeJsonMessage(signed);
expect(encoded).toBe(
'{"type":"PFSFeeUpdate","canonical_identifier":{"chain_identifier":"337","token_network_address":"0xe82ae5475589b828D3644e1B56546F93cD27d1a4","channel_identifier":"1338"},"updating_participant":"0x14791697260E4c9A71f18484C9f997B308e59325","timestamp":"1970-01-01T00:00:00.000000","fee_schedule":{"cap_fees":true,"imbalance_penalty":null,"proportional":"0","flat":"0"},"signature":"0x444213b2b0a3e390b0e288ebb92cc219e1177ff8359d51517cc894643b3fdbc56da603289a967bacf42c2dcc0ba1cc98425e4524e4eca86023c776a284c2a71f1c"}',
'{"type":"PFSFeeUpdate","canonical_identifier":{"chain_identifier":"337","token_network_address":"0xe82ae5475589b828D3644e1B56546F93cD27d1a4","channel_identifier":"1338"},"updating_participant":"0x14791697260E4c9A71f18484C9f997B308e59325","timestamp":"1970-01-01T00:00:00","fee_schedule":{"cap_fees":true,"imbalance_penalty":null,"proportional":"0","flat":"0"},"signature":"0x444213b2b0a3e390b0e288ebb92cc219e1177ff8359d51517cc894643b3fdbc56da603289a967bacf42c2dcc0ba1cc98425e4524e4eca86023c776a284c2a71f1c"}',
);

const decoded = decodeJsonMessage(encoded);
Expand Down
4 changes: 3 additions & 1 deletion raiden-ts/tests/unit/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ describe('data', () => {
expect(() => encode(bigNumberify(65537), 2)).toThrowError('too large');
expect(() => encode('0x01', 2)).toThrowError(ErrorCodes.DTA_ARRAY_LENGTH_DIFFRENCE);
// @ts-ignore // TODO: replace with @ts-expect-error ts@^3.9
expect(() => encode(null, 2)).toThrowError('data is not');
expect(() => encode(null, 2)).toThrowError(
'Passed data is not a HEX string nor integer array',
);
});

test('losslessParse', () => {
Expand Down

0 comments on commit 39dd196

Please sign in to comment.