Skip to content

merge PR 492 from 1.0 #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export class Arc extends GraphNodeObserver {

public get isInfuraProvider(): boolean {
return typeof this._web3Provider === 'string' &&
(this._web3Provider.includes('infura.io') ||
this._web3Provider.includes('xdai'))
(this._web3Provider.includes('infura.io') ||
this._web3Provider.includes('xdai'))
}

/**
Expand Down Expand Up @@ -214,6 +214,7 @@ export class Arc extends GraphNodeObserver {
name
version
address
alias
}
}
`
Expand Down Expand Up @@ -391,10 +392,11 @@ export class Arc extends GraphNodeObserver {
throw Error(`No contract with name ${name} and version ${version} is known`)
}

public getABI(opts: { address?: Address
abiName?: string
version?: string
}): any[] {
public getABI(opts: {
address?: Address
abiName?: string
version?: string
}): any[] {
if (Object.values(opts).filter((value) => value !== undefined).length === 0) {
throw Error('getABI needs at least one parameter passed')
}
Expand Down Expand Up @@ -607,4 +609,5 @@ export interface IContractInfo {
version: string
address: Address
name: string
alias: string
}
17 changes: 13 additions & 4 deletions test/arc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ describe('Arc ', () => {

it('arc.plugin() should work', async () => {
const arc = await newArc()
const nonUniquePlugin = await arc.plugin({where: { name: 'GenericScheme' }})
const uniquePlugin = await arc.plugin({where: { address: getTestScheme('GenericScheme') }}, true)
const nonUniquePlugin = await arc.plugin({ where: { name: 'GenericScheme' } })
const uniquePlugin = await arc.plugin({ where: { address: getTestScheme('GenericScheme') } }, true)

expect(nonUniquePlugin).toBeInstanceOf(Plugin)
expect(uniquePlugin).toBeInstanceOf(Plugin)
await expect(arc.plugin({where: { name: 'ContributionReward' }}, true)).rejects.toThrow()
await expect(arc.plugin({ where: { name: 'ContributionReward' } }, true)).rejects.toThrow()
})

it('arc.plugins() should work', async () => {
Expand All @@ -229,7 +229,7 @@ describe('Arc ', () => {
it('arc.getABI works', async () => {
const arc = await newArc()
await arc.fetchContractInfos()
const abi = arc.getABI({abiName: 'Redeemer', version: REDEEMER_CONTRACT_VERSIONS[0]})
const abi = arc.getABI({ abiName: 'Redeemer', version: REDEEMER_CONTRACT_VERSIONS[0] })
expect(abi[0].name).toEqual('redeem')
})

Expand Down Expand Up @@ -308,3 +308,12 @@ describe('Arc ', () => {
.toEqual(await signer.getAddress())
})
})

it('plugin contractInfo should contain alias', async () => {
const arc = await newArc()
const pluginId = '0x86072cbff48da3c1f01824a6761a03f105bcc697'

const contractInfo = arc.getContractInfo(pluginId)

expect(contractInfo.alias).toEqual("ContributionRewardExt")
})
7 changes: 4 additions & 3 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function getTestAddresses(version: string = LATEST_ARC_VERSION): ITestAdd
}

export function sleep(ms: number) {
return new Promise( (resolve) => setTimeout(resolve, ms) )
return new Promise((resolve) => setTimeout(resolve, ms))
}

export function getTestScheme(name: PluginName): Address {
Expand Down Expand Up @@ -271,16 +271,17 @@ export async function firstResult(observable: Observable<any>) {
return observable.pipe(first()).toPromise()
}

export function getContractAddressesFromMigration(environment: 'private'|'rinkeby'|'mainnet'): IContractInfo[] {
export function getContractAddressesFromMigration(environment: 'private' | 'rinkeby' | 'mainnet'): IContractInfo[] {
const migration = require('@daostack/migration-experimental/migration.json')[environment]
const contracts: IContractInfo[] = []
for (const version of Object.keys(migration.package)) {
for (const name of Object.keys(migration.package[version])) {
contracts.push({
address: migration.package[version][name].toLowerCase(),
id: migration.package[version][name],
alias: migration.package[version][name],
name,
version
version,
})
}
}
Expand Down