Skip to content

Commit 8714e42

Browse files
authored
include alias in IContractInfo (#492)
* include alias in IContractInfo * lint * remove typo
1 parent 05b3b17 commit 8714e42

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

src/arc.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ export class Arc extends GraphNodeObserver {
3939
* a mapping of contrct names to contract addresses
4040
*/
4141
public contractInfos: IContractInfo[]
42-
public contracts: {[key: string]: any} = {} // a cache for the contracts
43-
public contractsR: {[key: string]: any} = {} // a cache for teh "read-only" contracts
42+
public contracts: { [key: string]: any } = {} // a cache for the contracts
43+
public contractsR: { [key: string]: any } = {} // a cache for teh "read-only" contracts
4444

4545
// accounts observed by ethBalance
46-
public blockHeaderSubscription: Subscription|undefined = undefined
47-
public observedAccounts: { [address: string]: {
46+
public blockHeaderSubscription: Subscription | undefined = undefined
47+
public observedAccounts: {
48+
[address: string]: {
4849
observable?: Observable<BN>
4950
observer?: Observer<BN>
5051
lastBalance?: string
@@ -125,6 +126,7 @@ export class Arc extends GraphNodeObserver {
125126
name
126127
version
127128
address
129+
alias
128130
}
129131
}`
130132
// const result = await this.getObservableList(query, itemMap, apolloQueryOptions).pipe(first()).toPromise()
@@ -204,11 +206,11 @@ export class Arc extends GraphNodeObserver {
204206
if (!this.observedAccounts[owner]) {
205207
this.observedAccounts[owner] = {
206208
subscriptionsCount: 1
207-
}
209+
}
208210
}
209211
if (this.observedAccounts[owner].observable) {
210-
this.observedAccounts[owner].subscriptionsCount += 1
211-
return this.observedAccounts[owner].observable as Observable<BN>
212+
this.observedAccounts[owner].subscriptionsCount += 1
213+
return this.observedAccounts[owner].observable as Observable<BN>
212214
}
213215

214216
const observable = Observable.create((observer: Observer<BN>) => {
@@ -225,7 +227,7 @@ export class Arc extends GraphNodeObserver {
225227

226228
// set up the blockheadersubscription if it does not exist yet
227229
if (!this.blockHeaderSubscription) {
228-
const subscribeToBlockHeaders = () => {
230+
const subscribeToBlockHeaders = () => {
229231
this.blockHeaderSubscription = this.web3Read.eth.subscribe('newBlockHeaders', async (err: Error) => {
230232
Object.keys(this.observedAccounts).forEach(async (addr) => {
231233
const accInfo = this.observedAccounts[addr]
@@ -294,10 +296,10 @@ export class Arc extends GraphNodeObserver {
294296

295297
public getContractInfoByName(name: string, version: string) {
296298
for (const contractInfo of this.contractInfos) {
297-
if (contractInfo.name === name && contractInfo.version === version) {
298-
return contractInfo
299-
}
299+
if (contractInfo.name === name && contractInfo.version === version) {
300+
return contractInfo
300301
}
302+
}
301303
if (!this.contractInfos) {
302304
throw Error(`no contract info was found - did you call "arc.setContractInfos(...)"?`)
303305
}
@@ -389,7 +391,7 @@ export class Arc extends GraphNodeObserver {
389391
if (web3.eth.accounts[0]) {
390392
observer.next(web3.eth.accounts[0].address)
391393
prevAccount = web3.eth.accounts[0].address
392-
} else if (web3.eth.defaultAccount ) {
394+
} else if (web3.eth.defaultAccount) {
393395
observer.next(web3.eth.defaultAccount)
394396
prevAccount = web3.eth.defaultAccount
395397
}
@@ -407,7 +409,7 @@ export class Arc extends GraphNodeObserver {
407409
}
408410
})
409411
}, interval)
410-
return() => clearTimeout(timeout)
412+
return () => clearTimeout(timeout)
411413
})
412414
}
413415

@@ -449,7 +451,7 @@ export class Arc extends GraphNodeObserver {
449451
* @param options an Object to save. This object must have title, url and desction defined
450452
* @return a Promise that resolves in the IPFS Hash where the file is saved
451453
*/
452-
public async saveIPFSData(options: { title?: string, url?: string, description?: string, tags?: string[]}):
454+
public async saveIPFSData(options: { title?: string, url?: string, description?: string, tags?: string[] }):
453455
Promise<string> {
454456
let ipfsDataToSave: object = {}
455457
if (options.title || options.url || options.description || options.tags !== undefined) {
@@ -486,4 +488,5 @@ export interface IContractInfo {
486488
version: string
487489
address: Address
488490
name: string
491+
alias: string
489492
}

test/arc.spec.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ describe('Arc ', () => {
181181
// these tests are a bit clumsy, because we have access to only a single node
182182

183183
// we now expect all read operations to fail, and all write operations to succeed
184-
const arcWrite = await newArc({ web3ProviderRead: 'http://does.not.exist'})
184+
const arcWrite = await newArc({ web3ProviderRead: 'http://does.not.exist' })
185185

186186
expect(arcWrite.ethBalance('0x90f8bf6a479f320ead074411a4b0e7944ea81111').pipe(first()).toPromise())
187187
.rejects.toThrow()
@@ -192,7 +192,7 @@ describe('Arc ', () => {
192192
.pipe(first()).toPromise())
193193
.rejects.toThrow()
194194
// we now expect all write operations to fail, and all read operations to succeed
195-
const arcRead = await newArc({ web3Provider: 'http://doesnotexist.com', web3ProviderRead: web3Provider})
195+
const arcRead = await newArc({ web3Provider: 'http://doesnotexist.com', web3ProviderRead: web3Provider })
196196
expect(await arcRead.ethBalance('0x90f8bf6a479f320ead074411a4b0e7944ea81111').pipe(first()).toPromise())
197197
.toEqual(new BN(0))
198198
})
@@ -222,4 +222,13 @@ describe('Arc ', () => {
222222
const abi = arc.getABI(undefined, 'Redeemer', REDEEMER_CONTRACT_VERSIONS[0])
223223
expect(abi[0].name).toEqual('redeem')
224224
})
225+
226+
it('scheme contractInfo should contain alias', async () => {
227+
const arc = await newArc()
228+
const schemeId = '0x405fC0EE23C7fcd0a41A864505Fe8c969ca3eF6A'
229+
230+
const contractInfo = arc.getContractInfo(schemeId)
231+
232+
expect(contractInfo.alias).toEqual("ContributionRewardExt")
233+
})
225234
})

test/utils.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { first } from 'rxjs/operators'
44
import { IContractInfo, IProposalCreateOptions, Proposal } from '../src'
55
import { Arc } from '../src/arc'
66
import { DAO } from '../src/dao'
7-
import { IProposalOutcome} from '../src/proposal'
7+
import { IProposalOutcome } from '../src/proposal'
88
import { Reputation } from '../src/reputation'
99
import { Address } from '../src/types'
1010

@@ -55,13 +55,13 @@ export interface ITestAddresses {
5555
executedProposalId: Address,
5656
queuedProposalId: Address,
5757
preBoostedProposalId: Address,
58-
[key: string]: Address|{ [key: string]: Address }
58+
[key: string]: Address | { [key: string]: Address }
5959
}
6060
}
6161

6262
export function getTestAddresses(arc: Arc, version: string = LATEST_ARC_VERSION): ITestAddresses {
6363
// const contractInfos = arc.contractInfos
64-
const migrationFile = path.resolve(`${require.resolve('@daostack/migration' )}/../migration.json`)
64+
const migrationFile = path.resolve(`${require.resolve('@daostack/migration')}/../migration.json`)
6565
const migration = require(migrationFile).private
6666
let UGenericScheme: string = ''
6767
try {
@@ -96,7 +96,7 @@ export async function getOptions(web3: any) {
9696
}
9797
}
9898

99-
export async function newArc(options: { [key: string]: any} = {}): Promise<Arc> {
99+
export async function newArc(options: { [key: string]: any } = {}): Promise<Arc> {
100100
const defaultOptions = {
101101
graphqlHttpProvider,
102102
graphqlWsProvider,
@@ -160,7 +160,7 @@ export async function createAProposal(
160160
if (!dao) {
161161
dao = await getTestDAO()
162162
}
163-
options = {
163+
options = {
164164
beneficiary: '0xffcf8fdee72ac11b5c542428b35eef5769c409f0',
165165
ethReward: toWei('300'),
166166
externalTokenAddress: undefined,
@@ -209,11 +209,11 @@ export async function voteToPassProposal(proposal: Proposal) {
209209
const accounts = arc.web3.eth.accounts.wallet
210210
// make sure the proposal is indexed
211211
await waitUntilTrue(async () => {
212-
const state = await proposal.state({ fetchPolicy: 'network-only'}).pipe(first()).toPromise()
212+
const state = await proposal.state({ fetchPolicy: 'network-only' }).pipe(first()).toPromise()
213213
return !!state
214214
})
215215

216-
for (let i = 0; i <= 3; i ++) {
216+
for (let i = 0; i <= 3; i++) {
217217
try {
218218
arc.setAccount(accounts[i].address)
219219
await proposal.vote(IProposalOutcome.Pass).send()
@@ -326,14 +326,15 @@ export async function firstResult(observable: Observable<any>) {
326326
return observable.pipe(first()).toPromise()
327327
}
328328

329-
export function getContractAddressesFromMigration(environment: 'private'|'rinkeby'|'mainnet'): IContractInfo[] {
329+
export function getContractAddressesFromMigration(environment: 'private' | 'rinkeby' | 'mainnet'): IContractInfo[] {
330330
const migration = require('@daostack/migration/migration.json')[environment]
331331
const contracts: IContractInfo[] = []
332-
for (const version of Object.keys( migration.base)) {
332+
for (const version of Object.keys(migration.base)) {
333333
for (const name of Object.keys(migration.base[version])) {
334334
contracts.push({
335335
address: migration.base[version][name].toLowerCase(),
336336
id: migration.base[version][name],
337+
alias: migration.base[version][name], // fake the data for tests
337338
name,
338339
version
339340
})

0 commit comments

Comments
 (0)