Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Conversation

@shamsartem
Copy link
Contributor

In this pull request I turned on noImplicitAny and strictNullChecks. I think these are important rules that could prevent us from some bugs in the future. I also did some accidental refactoring here and there.

Nothing set in stone - everything could be discussed and reverted if needed

There is stuff in the pull request that could be refactored further, but I decided to close this pull request as soon as typescript is satisfied. If we decide additional changes are required - I will do them in a separate pull request

@shamsartem shamsartem requested a review from coder11 May 10, 2022 09:19
Copy link
Contributor

@coder11 coder11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work!


expect(result.success).toBe(true);
const isSigCorrect = await customSig.verify(result.signature, data);
const isSigCorrect = await customSig.verify(result.signature as number[], data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just result.signature! ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is needed to satisfy typescript. Because it's a test and we are sure it's not null - it's ok to just use "as" keyword. In other cases compiler will complain now so we have something to think about and maybe check explicitly that it's not null if needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean use bang symbol

 const isSigCorrect = await customSig.verify(result.signature!, data);


const callAsSigRes = await callSig(peer, 'sig');
const callAsPeerIdRes = await callSig(peer, peer.getStatus().peerId);
const callAsPeerIdRes = await callSig(peer, peer.getStatus().peerId as string);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here and in other places with null checks


// act
await peer.start({ connectTo: addr });
await peer.start({ connectTo: new Multiaddr(nodes[0].multiaddr) });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should either use "AAA" pattern universally or not use it at all. At least in terms of pure unit tests.

IMO (esp, coming from backend / C# background) "AAA" thing is very neat. It forces you to think about the precise scope of the unit test.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw this test series can be written in table form. Seems like...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't heard about AAA before. In my personal opinion adding comments doesn't make anything clearer, I accidentally removed them. But with tests it's almost always this pattern anyways, but without explicit comments. We can discuss if it's easier for you to read, maybe. I would suggest regarding this question to do whatever you want - I don't think consistency matters here. Some tests could have the comments some test could be ok without them and we always can add or remove them later

if (peer) {
await peer.stop();
}
beforeAll(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want beforeEach and afterEach here so that tests don't interfere with each other

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used beforeAll just so the tests run a bit faster. These test should not interfere with each other anyways. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests connect to network and send particles. All this processing is happening inside the same peer. So in theory tests can interfere

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Will use beforeEach and afterEach just in case

};
};
};
export const MakeServiceCall =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To my taste the former is more explicit, thus easier to understand in a quick glance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always remove the syntax that is not required if it doesn't harm readability. If you sure you want this reversed I can do it. It's all purely a taste thing after all. We could even decide and have a eslint rule for that so we never discuss this again


return res;
constructor(
public id: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool. Did not know TS can do that :)

script: string;
signature: string;
data: Uint8Array;
signature?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will always be particle signature in future. It should be calculated from it's immutable part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make the signature not optional and retain the guaranties - it should be assigned in the constructor. If we can't do it now - I suggest we postpone it till later

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean for now the correct situation we are in is that we don't always have the signature so it's better if we can see it in types. I will add TODO for that, ok?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a TODO. Sounds good

@shamsartem shamsartem merged commit 5234ba2 into master May 12, 2022
@shamsartem shamsartem deleted the ts-refactor branch May 12, 2022 14:14
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants