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

Commit ddef678

Browse files
committed
Fix line lengths, unify dataunion address validation messages.
1 parent 1db5b30 commit ddef678

File tree

8 files changed

+39
-34
lines changed

8 files changed

+39
-34
lines changed

src/Config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ export type StrictStreamrClientOptions = {
4848
}
4949
}
5050

51-
export type StreamrClientOptions = Partial<Omit<StrictStreamrClientOptions, 'dataUnion'> & { dataUnion: Partial<StrictStreamrClientOptions['dataUnion']>}>
51+
export type StreamrClientOptions = Partial<Omit<StrictStreamrClientOptions, 'dataUnion'> & {
52+
dataUnion: Partial<StrictStreamrClientOptions['dataUnion']>
53+
}>
5254

5355
const { ControlMessage } = ControlLayer
5456
const { StreamMessage } = MessageLayer
@@ -87,7 +89,9 @@ export default function ClientConfig(opts: StreamrClientOptions = {}) {
8789
tokenAddress: '0x0Cf0Ee63788A0849fE5297F3407f701E122cC023',
8890
dataUnion: {
8991
minimumWithdrawTokenWei: '1000000', // Threshold value set in AMB configs, smallest token amount to pass over the bridge
90-
freeWithdraw: false, // if someone else pays for the gas when transporting the withdraw tx to mainnet; otherwise the client does the transport as self-service and pays the mainnet gas costs
92+
// if someone else pays for the gas when transporting the withdraw tx to mainnet;
93+
// otherwise the client does the transport as self-service and pays the mainnet gas costs
94+
freeWithdraw: false,
9195
factoryMainnetAddress: '0x7d55f9981d4E10A193314E001b96f72FCc901e40',
9296
factorySidechainAddress: '0x1b55587Beea0b5Bc96Bb2ADa56bD692870522e9f',
9397
templateMainnetAddress: '0x5FE790E3751dd775Cb92e9086Acd34a2adeB8C7b',

src/Connection.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ export default class Connection extends EventEmitter {
314314

315315
constructor(options = {}, debug?: Debug.Debugger) {
316316
super()
317-
this._debug = (debug !== undefined) ? debug.extend(counterId(this.constructor.name)) : Debug(`StreamrClient::${counterId(this.constructor.name)}`)
317+
this._debug = debug !== undefined
318+
? debug.extend(counterId(this.constructor.name))
319+
: Debug(`StreamrClient::${counterId(this.constructor.name)}`)
318320

319321
this.options = options
320322
this.options.autoConnect = !!this.options.autoConnect

src/dataunion/Contracts.ts

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ import { StreamrClient } from '../StreamrClient'
1414

1515
const log = debug('StreamrClient::DataUnion')
1616

17+
function validateAddress(name: string, address: EthereumAddress) {
18+
if (!isAddress(address)) {
19+
throw new Error(`${name} is ${address ? 'not a valid Ethereum address' : 'missing'}`)
20+
}
21+
}
22+
1723
export class Contracts {
1824

1925
ethereum: StreamrEthereum
@@ -41,13 +47,8 @@ export class Contracts {
4147
}
4248

4349
getDataUnionMainnetAddress(dataUnionName: string, deployerAddress: EthereumAddress) {
44-
if (!isAddress(this.factoryMainnetAddress)) {
45-
throw new Error('StreamrClient factoryMainnetAddress configuration is ' + (this.factoryMainnetAddress ? 'not a valid Ethereum address' : 'missing'))
46-
}
47-
48-
if (!isAddress(this.templateMainnetAddress)) {
49-
throw new Error('StreamrClient templateMainnetAddress configuration is ' + (this.templateMainnetAddress ? 'not a valid Ethereum address' : 'missing'))
50-
}
50+
validateAddress('StreamrClient factoryMainnetAddress', this.factoryMainnetAddress)
51+
validateAddress('StreamrClient templateMainnetAddress', this.templateMainnetAddress)
5152
// This magic hex comes from https://github.com/streamr-dev/data-union-solidity/blob/master/contracts/CloneLib.sol#L19
5253
const codeHash = keccak256(`0x3d602d80600a3d3981f3363d3d373d3d3d363d73${this.templateMainnetAddress.slice(2)}5af43d82803e903d91602b57fd5bf3`)
5354
const salt = keccak256(defaultAbiCoder.encode(['string', 'address'], [dataUnionName, deployerAddress]))
@@ -61,24 +62,18 @@ export class Contracts {
6162
}
6263

6364
getDataUnionSidechainAddress(mainnetAddress: EthereumAddress) {
64-
if (!isAddress(this.factorySidechainAddress)) {
65-
throw new Error('StreamrClient factorySidechainAddress configuration is ' + (this.factorySidechainAddress ? 'not a valid Ethereum address' : 'missing'))
66-
}
67-
68-
if (!isAddress(this.templateSidechainAddress)) {
69-
throw new Error('StreamrClient templateSidechainAddress configuration is ' + (this.templateSidechainAddress ? 'not a valid Ethereum address' : 'missing'))
70-
}
65+
validateAddress('StreamrClient factorySidechainAddress', this.factorySidechainAddress)
66+
validateAddress('StreamrClient templateSidechainAddress', this.templateSidechainAddress)
7167
// This magic hex comes from https://github.com/streamr-dev/data-union-solidity/blob/master/contracts/CloneLib.sol#L19
72-
const codeHash = keccak256(`0x3d602d80600a3d3981f3363d3d373d3d3d363d73${this.templateSidechainAddress.slice(2)}5af43d82803e903d91602b57fd5bf3`)
68+
const code = `0x3d602d80600a3d3981f3363d3d373d3d3d363d73${this.templateSidechainAddress.slice(2)}5af43d82803e903d91602b57fd5bf3`
69+
const codeHash = keccak256(code)
7370
return getCreate2Address(this.factorySidechainAddress, hexZeroPad(mainnetAddress, 32), codeHash)
7471
}
7572

7673
getMainnetContractReadOnly(contractAddress: EthereumAddress) {
77-
if (isAddress(contractAddress)) {
78-
const provider = this.ethereum.getMainnetProvider()
79-
return new Contract(contractAddress, dataUnionMainnetABI, provider)
80-
}
81-
throw new Error(`${contractAddress} was not a good Ethereum address`)
74+
validateAddress('contractAddress', contractAddress)
75+
const provider = this.ethereum.getMainnetProvider()
76+
return new Contract(contractAddress, dataUnionMainnetABI, provider)
8277
}
8378

8479
getMainnetContract(contractAddress: EthereumAddress) {
@@ -298,12 +293,12 @@ export class Contracts {
298293
throw new Error(`Mainnet data union "${duName}" contract ${duMainnetAddress} already exists!`)
299294
}
300295

301-
if (!isAddress(this.factoryMainnetAddress)) {
302-
throw new Error('StreamrClient has invalid factoryMainnetAddress configuration.')
303-
}
296+
validateAddress('StreamrClient factoryMainnetAddress', this.factoryMainnetAddress)
304297

305298
if (await mainnetProvider.getCode(this.factoryMainnetAddress) === '0x') {
306-
throw new Error(`Data union factory contract not found at ${this.factoryMainnetAddress}, check StreamrClient.options.dataUnion.factoryMainnetAddress!`)
299+
throw new Error(
300+
`Data union factory contract not found at ${this.factoryMainnetAddress}, check StreamrClient.options.dataUnion.factoryMainnetAddress!`
301+
)
307302
}
308303

309304
const factoryMainnet = new Contract(this.factoryMainnetAddress!, factoryMainnetABI, mainnetWallet)

src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ export * from './dataunion/DataUnion'
1313
export * from './rest/authFetch'
1414
export * from './types'
1515

16-
// TODO should export these to support StreamMessageAsObject: export { StreamMessageType, ContentType, EncryptionType, SignatureType } from 'streamr-client-protocol/dist/src/protocol/message_layer/StreamMessage'
16+
// TODO should export these to support StreamMessageAsObject:
17+
// export {
18+
// StreamMessageType, ContentType, EncryptionType, SignatureType
19+
// } from 'streamr-client-protocol/dist/src/protocol/message_layer/StreamMessage'
1720
export { BigNumber } from '@ethersproject/bignumber'
1821
export { ConnectionInfo } from '@ethersproject/web'
1922
export { Contract } from '@ethersproject/contracts'

test/benchmarks/publish.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
const { format } = require('util')
2-
32
const { Benchmark } = require('benchmark')
43

54
// eslint-disable-next-line import/no-unresolved
65
const StreamrClient = require('../../dist')
76
const config = require('../integration/config')
87

9-
console.log('StreamrClient', { StreamrClient })
10-
118
/* eslint-disable no-console */
129

1310
let count = 100000 // pedantic: use large initial number so payload size is similar

test/benchmarks/subscribe.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const { format } = require('util')
2-
32
const { Benchmark } = require('benchmark')
43

54
// eslint-disable-next-line import/no-unresolved

test/integration/dataunion/signature.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ describe('DataUnion signature', () => {
6767
const isValid3 = await sidechainContract.signatureIsValid(memberWallet.address, member2Wallet.address, '3000000000000000', signature3)
6868
log(`Signature for all tokens ${memberWallet.address} -> ${member2Wallet.address}: ${signature}, checked ${isValid ? 'OK' : '!!!BROKEN!!!'}`)
6969
log(`Signature for 1 token ${memberWallet.address} -> ${member2Wallet.address}: ${signature2}, checked ${isValid2 ? 'OK' : '!!!BROKEN!!!'}`)
70+
// eslint-disable-next-line max-len
7071
log(`Signature for 0.003 tokens ${memberWallet.address} -> ${member2Wallet.address}: ${signature3}, checked ${isValid3 ? 'OK' : '!!!BROKEN!!!'}`)
7172
log(`sidechainDU(${sidechainContract.address}) token bal ${await tokenSidechain.balanceOf(sidechainContract.address)}`)
7273

7374
expect(isValid).toBe(true)
7475
expect(isValid2).toBe(true)
7576
expect(isValid3).toBe(true)
7677
}, 100000)
77-
7878
})

test/integration/dataunion/stats.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ describe('DataUnion stats', () => {
5656
}, 150000)
5757

5858
it('member stats', async () => {
59-
const memberStats = await Promise.all(activeMemberAddressList.concat([inactiveMember]).map((m) => queryClient.getDataUnion(dataUnion.getAddress()).getMemberStats(m)))
59+
const memberStats = await Promise.all(
60+
activeMemberAddressList
61+
.concat([inactiveMember])
62+
.map((m) => queryClient.getDataUnion(dataUnion.getAddress()).getMemberStats(m))
63+
)
64+
6065
const ZERO = BigNumber.from(0)
6166
expect(memberStats).toMatchObject([{
6267
status: MemberStatus.ACTIVE,

0 commit comments

Comments
 (0)