-
Couldn't load subscription status.
- Fork 26
Turn on noImplicitAny and strictNullChecks #153
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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! ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) }); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
src/__test__/integration/avm.spec.ts
Outdated
| if (peer) { | ||
| await peer.stop(); | ||
| } | ||
| beforeAll(async () => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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