Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Conversation

@teogeb
Copy link
Contributor

@teogeb teogeb commented Mar 16, 2021

Convert most of tests to TypeScript.

Copy link
Contributor

@timoxley timoxley left a comment

Choose a reason for hiding this comment

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

Looking good

}

export async function getAddressFromOptions({ ethereum, privateKey } = {}) {
export async function getAddressFromOptions({ ethereum, privateKey }: { ethereum?: EthereumConfig, privateKey?: any} = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably get something like this into Config.ts then use the same types across the app e.g. here and Signer:

type PrivateKeyAuth = {
    privateKey: string
    ethereum?: never,
    apiKey?: never,
}

type ProviderAuth = {
    ethereum: ExternalProvider | JsonRpcFetchFunc
    privateKey?: never,
    apiKey?: never,
}

/**
 * deprecated: Please create an ethereum identity.
 */
type APIKeyAuth = {
    apiKey: string
    privateKey?: never,
    ethereum?: never,
}

type AnonymousAuth = {
    privateKey?: never,
    apiKey?: never,
    ethereum?: never,
}

type Authenticated = PrivateKeyAuth | ProviderAuth | APIKeyAuth
type AuthOptions =  Authenticated | AnonymousAuth

Maybe for another PR, your call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. It would be great if e.g. ts-toolbelt would have a good helper for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah it might, worth looking into

streamId: stream.id,
last: published.length,
})
}, () => {})
Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, this shouldn't be required.

I also notice that resendSubscribe's last param is actually mislabeled as onMessage when it should be onFinally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed type Subscriptions.add, Subscriptions.subscribe and Subscriptions.resendSubscribe to MaybeAsync<(err?: any) => void>

return new Stream(null, {
// eslint-disable-next-line class-methods-use-this
async getStream() {
return new Stream(null as any, {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems weird

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did a small change to the implementation and now there is less casting and disabled warnings.

Copy link
Contributor

Choose a reason for hiding this comment

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

excellent

}
}
// publisherId is the hash of 'username'
// @ts-expect-error
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's not too much effort maybe add additional comment after // @ts-expect-error explaining what it's erroring on? Might make these more likely to get fixed if the comment gives a clue as to what's wrong at a glance.

e.g.

 // @ts-expect-error additional commenting

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'll make another PR where most of these will be fixed, and the rest commented.

Copy link
Contributor

@timoxley timoxley left a comment

Choose a reason for hiding this comment

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

👍 Let's get this merged asap.

import config from './config'
import { Stream } from '../../src/stream'
import { Subscription } from '../../src'
import { PublishRequest } from 'streamr-client-protocol/dist/src/protocol/control_layer'
Copy link
Contributor

Choose a reason for hiding this comment

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

blegh, ideally shouldn't have dist/src in any import, I'd consider that stuff "private".

For now you might have to grab it like this:

import { ControlLayer } from 'streamr-client-protocol'
const { PublishRequest } = ControlLayer

But if we update protocol to 8.0.0 you should be able to do this as of streamr-dev/streamr-client-protocol-js#53:

import { PublishRequest } from 'streamr-client-protocol'

describeRepeats('GapFill with resends', () => {
let expectErrors = 0 // check no errors by default
let publishTestMessages: (n?: number, opts?: any) => Promise<[message: any, request: any][]>
let publishTestMessages: ReturnType<typeof getPublishTestMessages>
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@teogeb teogeb merged commit 7c0b343 into master Mar 18, 2021
@teogeb teogeb deleted the tests-to-typescript branch March 18, 2021 22:59
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