Skip to content

merge PR 477 from 1.0 #508

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 6 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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daostack/arc.js",
"version": "2.0.0-experimental.44",
"version": "2.0.0-experimental.45",
"description": "",
"keywords": [],
"main": "dist/lib/index.js",
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/fundingRequest/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ export class FundingRequest
}

return {
...baseState,
pluginParams: fundingRequestParams
}
...baseState,
pluginParams: fundingRequestParams
}
}

private static fragmentField: { name: string, fragment: DocumentNode } | undefined
Expand All @@ -138,7 +138,7 @@ export class FundingRequest
method: 'propose',
args: [
options.beneficiary,
options.amount.toNumber(),
options.amount.toString(),
Copy link
Contributor

Choose a reason for hiding this comment

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

this plugin is not supported in alchemy yet. so why update that ?
@jellegerbrandy is that needed for Common ?

Copy link
Contributor Author

@dkent600 dkent600 Jul 7, 2020

Choose a reason for hiding this comment

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

the change is needed in any case. without it we would have a bug by casting a BN to a number, assuming the BN in this case can easily overflow a number.

However, just to note: I don't think this change was absolutely needed for this particular PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is good 👍

options.descriptionHash || ''
]
}
Expand All @@ -157,7 +157,7 @@ export class FundingRequest
if (err.message.match(/funding is not allowed yet/)) {
const state = await this.fetchState()
const dao = state.dao.entity
const joinAndQuit = (await dao.plugin({where: {name: 'JoinAndQuit'}}))
const joinAndQuit = (await dao.plugin({ where: { name: 'JoinAndQuit' } }))
const joinAndQuitState = await joinAndQuit.fetchState() as IJoinAndQuitState
const deadline = joinAndQuitState.pluginParams.fundingGoalDeadline
const now = new Date()
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/genericPlugin/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BN from 'bn.js'
import gql from 'graphql-tag'
import {
Address,
Expand Down Expand Up @@ -27,7 +28,7 @@ export interface IGenericPluginState extends IPluginState {

export interface IProposalCreateOptionsGS extends IProposalBaseCreateOptions {
callData?: string
value?: number
value?: BN
}

export interface IInitParamsGS {
Expand All @@ -43,7 +44,7 @@ export class GenericPlugin extends ProposalPlugin<
IGenericPluginState,
IGenericPluginProposalState,
IProposalCreateOptionsGS
> {
> {
Copy link
Contributor

Choose a reason for hiding this comment

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

why additiional space is here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was generated by my editor. I'm not sure what rules it is following, but the change makes sense by aligning the bracket with the lines above. Looks clean and harmless enough to me.

public static fragment = {
name: 'GenericpluginParams',
fragment: gql`
Expand Down Expand Up @@ -129,7 +130,7 @@ export class GenericPlugin extends ProposalPlugin<
return {
contract: this.context.getContract(options.plugin as string),
method: 'proposeCall',
args: [options.callData, options.value, options.descriptionHash]
args: [options.callData, options.value.toString(), options.descriptionHash]
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/plugins/genericPlugin/proposal.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import BN from 'bn.js'
import gql from 'graphql-tag'
import { from, Observable } from 'rxjs'
import { concatMap } from 'rxjs/operators'
Expand Down Expand Up @@ -25,6 +26,7 @@ export interface IGenericPluginProposalState extends IProposalState {
callData: string
executed: boolean
returnValue: string
value: BN
}

export class GenericPluginProposal extends Proposal<IGenericPluginProposalState> {
Expand All @@ -38,6 +40,7 @@ export class GenericPluginProposal extends Proposal<IGenericPluginProposalState>
callData
executed
returnValue
value
}
}
`
Expand Down Expand Up @@ -79,7 +82,8 @@ export class GenericPluginProposal extends Proposal<IGenericPluginProposalState>
callData: item.genericScheme.callData,
contractToCall: item.genericScheme.contractToCall,
executed: item.genericScheme.executed,
returnValue: item.genericScheme.returnValue
returnValue: item.genericScheme.returnValue,
value: new BN(item.genericScheme.value)
}
}

Expand Down
32 changes: 17 additions & 15 deletions test/proposal-claim-reward.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { first } from 'rxjs/operators'
import { Arc, DAO, IProposalOutcome, IProposalStage, IProposalState, IProposalCreateOptionsCR, LATEST_ARC_VERSION, GenericPlugin, GenericPluginProposal, IGenericPluginProposalState } from '../src'

import BN from 'bn.js'
import { createAProposal, firstResult, getTestAddresses, getTestDAO, ITestAddresses, newArc,
toWei, voteToPassProposal, waitUntilTrue, createCRProposal, getTestScheme } from './utils'
import {
createAProposal, firstResult, getTestAddresses, getTestDAO, ITestAddresses, newArc,
toWei, voteToPassProposal, waitUntilTrue, createCRProposal, getTestScheme
} from './utils'
import { BigNumber } from 'ethers/utils'
import { ethers } from 'ethers'
import { ContributionRewardProposal } from '../src'
Expand All @@ -29,7 +31,7 @@ describe('Claim rewards', () => {
const states: IProposalState[] = []
const lastState = () => states[states.length - 1]

if(!arc.web3) throw new Error("Web3 provider not set")
if (!arc.web3) throw new Error("Web3 provider not set")

// make sure that the DAO has enough Ether to pay for the reward
await arc.web3.getSigner().sendTransaction({
Expand Down Expand Up @@ -98,7 +100,7 @@ describe('Claim rewards', () => {

const gen = arc.GENToken()
await gen.transfer(dao.id, externalTokenReward).send()
const daoBalance = await firstResult(arc.GENToken().balanceOf(dao.id))
const daoBalance = await firstResult(arc.GENToken().balanceOf(dao.id))
expect(Number(daoBalance.toString())).toBeGreaterThanOrEqual(Number(externalTokenReward.toString()))
const options: IProposalCreateOptionsCR = {
beneficiary,
Expand Down Expand Up @@ -141,36 +143,36 @@ describe('Claim rewards', () => {
})

it('redeemRewards should also work for expired proposals', async () => {
const proposal = new ContributionRewardProposal(arc, testAddresses.queuedProposalId)
await proposal.redeemRewards().send()
const proposal = new ContributionRewardProposal(arc, testAddresses.queuedProposalId)
await proposal.redeemRewards().send()
})

it('works with non-CR proposal', async () => {

testAddresses = getTestAddresses()
const genericSchemes = await arc.plugins({where: {name: 'GenericScheme' }}).pipe(first()).toPromise()
const genericSchemes = await arc.plugins({ where: { name: 'GenericScheme' } }).pipe(first()).toPromise()
const genericScheme = genericSchemes[0] as GenericPlugin
const genericSchemeState = await genericScheme.state({}).pipe(first()).toPromise()

dao = new DAO(arc, genericSchemeState.dao.id)
dao = new DAO(arc, genericSchemeState.dao.id)

const beneficiary = await arc.getAccount().pipe(first()).toPromise()
const stakeAmount = new BN(123456789)
await arc.GENToken().transfer(dao.id, stakeAmount).send()
const actionMockABI = arc.getABI({abiName: 'ActionMock', version: LATEST_ARC_VERSION})
const actionMockABI = arc.getABI({ abiName: 'ActionMock', version: LATEST_ARC_VERSION })

if(!arc.web3) throw new Error("Web3 provider not set")
if (!arc.web3) throw new Error("Web3 provider not set")

const callData = new ethers.utils.Interface(actionMockABI).functions.test2.encode([dao.id])

const tx = await genericScheme.createProposal({
callData,
dao: dao.id,
plugin: genericSchemeState.address,
value: 0
value: new BN("0")
}).send()

if(!tx.result) throw new Error('Response yielded no result')
if (!tx.result) throw new Error('Response yielded no result')

const proposal = new GenericPluginProposal(arc, tx.result.id)
const proposalStates: IGenericPluginProposalState[] = []
Expand Down Expand Up @@ -203,11 +205,11 @@ describe('Claim rewards', () => {
return lastState() && lastState().stage === IProposalStage.Executed
})

if(!beneficiary) throw new Error("Beneficiary not set")
if (!beneficiary) throw new Error("Beneficiary not set")

const prevBalance = await firstResult(arc.GENToken().balanceOf(beneficiary))
const prevBalance = await firstResult(arc.GENToken().balanceOf(beneficiary))
await proposal.redeemRewards(beneficiary).send()
const newBalance = await firstResult(arc.GENToken().balanceOf(beneficiary))
const newBalance = await firstResult(arc.GENToken().balanceOf(beneficiary))
expect(newBalance.sub(prevBalance).toString()).toEqual(stakeAmount.toString())

})
Expand Down
19 changes: 10 additions & 9 deletions test/proposal-genericscheme.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
GenericPlugin,
GenericPluginProposal,
LATEST_ARC_VERSION
} from '../src'
import { newArc, voteToPassProposal, waitUntilTrue, getTestScheme } from './utils'
} from '../src'
import { newArc, voteToPassProposal, waitUntilTrue, getTestScheme, BN } from './utils'
import { ethers } from 'ethers'

jest.setTimeout(60000)
Expand All @@ -24,31 +24,31 @@ describe('Proposal', () => {
})

it('Check proposal state is correct', async () => {
const daos = await arc.daos({where: { name: 'Nectar DAO'}}).pipe(first()).toPromise()
const daos = await arc.daos({ where: { name: 'Nectar DAO' } }).pipe(first()).toPromise()
const dao = daos[0]
if (dao === undefined) {
throw Error(`Could not find "Nectar DAO"`)
}
const states: IProposalState[] = []
const lastState = (): IProposalState => states[states.length - 1]

const actionMockABI = arc.getABI({abiName: 'ActionMock', version: LATEST_ARC_VERSION})
const actionMockABI = arc.getABI({ abiName: 'ActionMock', version: LATEST_ARC_VERSION })

if(!arc.web3) throw new Error('Web3 provider not set')
if (!arc.web3) throw new Error('Web3 provider not set')

const callData = new ethers.utils.Interface(actionMockABI).functions.test2.encode([dao.id])

const plugins = await dao.plugins({ where: {name: 'GenericScheme' }}).pipe(first()).toPromise() as GenericPlugin[]
const plugins = await dao.plugins({ where: { name: 'GenericScheme' } }).pipe(first()).toPromise() as GenericPlugin[]
const genericScheme = plugins[0]

const tx = await genericScheme.createProposal({
dao: dao.id,
callData,
value: 0,
value: new BN('1'),
plugin: getTestScheme('GenericScheme')
}).send()

if(!tx.result) throw new Error('Create proposal yielded no result')
if (!tx.result) throw new Error('Create proposal yielded no result')

const proposal = new GenericPluginProposal(arc, tx.result.id)

Expand All @@ -64,7 +64,8 @@ describe('Proposal', () => {
expect(lastState()).toMatchObject({
callData,
executed: false,
returnValue: null
returnValue: null,
value: new BN('1')
})

// accept the proposal by voting the hell out of it
Expand Down