From 39dd196b3443d41f2f5a7016f3d66b7bc5cd4287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Vitor=20de=20Lima=20Matos?= Date: Mon, 20 Apr 2020 12:29:54 -0300 Subject: [PATCH] PR review --- raiden-ts/src/messages/utils.ts | 2 +- raiden-ts/src/path/epics.ts | 9 +++++++-- raiden-ts/tests/unit/messages.spec.ts | 4 ++-- raiden-ts/tests/unit/utils.spec.ts | 4 +++- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/raiden-ts/src/messages/utils.ts b/raiden-ts/src/messages/utils.ts index a5f2d73eee..c3dd3f9822 100644 --- a/raiden-ts/src/messages/utils.ts +++ b/raiden-ts/src/messages/utils.ts @@ -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 } diff --git a/raiden-ts/src/path/epics.ts b/raiden-ts/src/path/epics.ts index 3a7448737c..07f174cf68 100644 --- a/raiden-ts/src/path/epics.ts +++ b/raiden-ts/src/path/epics.ts @@ -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, @@ -103,7 +108,7 @@ const signIOU$ = (iou: IOU, signer: Signer): Observable> => 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).pipe( map((signature) => ({ sender, receiver, timestamp, signature })), @@ -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, diff --git a/raiden-ts/tests/unit/messages.spec.ts b/raiden-ts/tests/unit/messages.spec.ts index de7be0748e..990fb3d183 100644 --- a/raiden-ts/tests/unit/messages.spec.ts +++ b/raiden-ts/tests/unit/messages.spec.ts @@ -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, @@ -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); diff --git a/raiden-ts/tests/unit/utils.spec.ts b/raiden-ts/tests/unit/utils.spec.ts index 1045b9636b..ed076afc0c 100644 --- a/raiden-ts/tests/unit/utils.spec.ts +++ b/raiden-ts/tests/unit/utils.spec.ts @@ -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', () => {