From 50547885606ba3e6cacb314d0682b3b22d270e79 Mon Sep 17 00:00:00 2001 From: Doug Kent Date: Mon, 6 Jul 2020 09:12:39 -0400 Subject: [PATCH 1/6] merge PR 477 from 1.0 --- src/plugins/genericPlugin/plugin.ts | 5 +++-- src/plugins/genericPlugin/proposal.ts | 6 +++++- test/proposal-genericscheme.spec.ts | 19 ++++++++++--------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/plugins/genericPlugin/plugin.ts b/src/plugins/genericPlugin/plugin.ts index f4187090..c51de2a2 100644 --- a/src/plugins/genericPlugin/plugin.ts +++ b/src/plugins/genericPlugin/plugin.ts @@ -1,3 +1,4 @@ +import BN from 'bn.js' import gql from 'graphql-tag' import { Address, @@ -27,7 +28,7 @@ export interface IGenericPluginState extends IPluginState { export interface IProposalCreateOptionsGS extends IProposalBaseCreateOptions { callData?: string - value?: number + value?: BN } export interface IInitParamsGS { @@ -43,7 +44,7 @@ export class GenericPlugin extends ProposalPlugin< IGenericPluginState, IGenericPluginProposalState, IProposalCreateOptionsGS -> { + > { public static fragment = { name: 'GenericpluginParams', fragment: gql` diff --git a/src/plugins/genericPlugin/proposal.ts b/src/plugins/genericPlugin/proposal.ts index 28130517..d7af9521 100644 --- a/src/plugins/genericPlugin/proposal.ts +++ b/src/plugins/genericPlugin/proposal.ts @@ -1,3 +1,4 @@ +import BN from 'bn.js' import gql from 'graphql-tag' import { from, Observable } from 'rxjs' import { concatMap } from 'rxjs/operators' @@ -25,6 +26,7 @@ export interface IGenericPluginProposalState extends IProposalState { callData: string executed: boolean returnValue: string + value: BN } export class GenericPluginProposal extends Proposal { @@ -38,6 +40,7 @@ export class GenericPluginProposal extends Proposal callData executed returnValue + value } } ` @@ -79,7 +82,8 @@ export class GenericPluginProposal extends Proposal callData: item.genericScheme.callData, contractToCall: item.genericScheme.contractToCall, executed: item.genericScheme.executed, - returnValue: item.genericScheme.returnValue + returnValue: item.genericScheme.returnValue, + value: item.genericScheme.value } } diff --git a/test/proposal-genericscheme.spec.ts b/test/proposal-genericscheme.spec.ts index d0346425..deb9896a 100644 --- a/test/proposal-genericscheme.spec.ts +++ b/test/proposal-genericscheme.spec.ts @@ -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) @@ -24,7 +24,7 @@ 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"`) @@ -32,23 +32,23 @@ describe('Proposal', () => { 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) @@ -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 From 12d323e8874d31dd29920fef0d75742e845e6f57 Mon Sep 17 00:00:00 2001 From: Doug Kent Date: Mon, 6 Jul 2020 10:32:14 -0400 Subject: [PATCH 2/6] fix text failure --- test/proposal-claim-reward.spec.ts | 32 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/test/proposal-claim-reward.spec.ts b/test/proposal-claim-reward.spec.ts index 470d588e..e8bbde8e 100644 --- a/test/proposal-claim-reward.spec.ts +++ b/test/proposal-claim-reward.spec.ts @@ -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' @@ -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({ @@ -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, @@ -141,25 +143,25 @@ 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]) @@ -167,10 +169,10 @@ describe('Claim rewards', () => { 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[] = [] @@ -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()) }) From ac5969c85e180efb2690c444462a40fb2274f9aa Mon Sep 17 00:00:00 2001 From: Doug Kent Date: Mon, 6 Jul 2020 11:23:25 -0400 Subject: [PATCH 3/6] fix test --- src/plugins/fundingRequest/plugin.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/fundingRequest/plugin.ts b/src/plugins/fundingRequest/plugin.ts index a11a6383..ed5b85c9 100644 --- a/src/plugins/fundingRequest/plugin.ts +++ b/src/plugins/fundingRequest/plugin.ts @@ -118,9 +118,9 @@ export class FundingRequest } return { - ...baseState, - pluginParams: fundingRequestParams - } + ...baseState, + pluginParams: fundingRequestParams + } } private static fragmentField: { name: string, fragment: DocumentNode } | undefined @@ -138,7 +138,7 @@ export class FundingRequest method: 'propose', args: [ options.beneficiary, - options.amount.toNumber(), + options.amount, options.descriptionHash || '' ] } @@ -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() From 87888972fa596a9292fe25811406d9e8d1c2fb3d Mon Sep 17 00:00:00 2001 From: Doug Kent Date: Mon, 6 Jul 2020 11:43:13 -0400 Subject: [PATCH 4/6] fix tests --- src/plugins/fundingRequest/plugin.ts | 2 +- src/plugins/genericPlugin/plugin.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/fundingRequest/plugin.ts b/src/plugins/fundingRequest/plugin.ts index ed5b85c9..92de1e08 100644 --- a/src/plugins/fundingRequest/plugin.ts +++ b/src/plugins/fundingRequest/plugin.ts @@ -138,7 +138,7 @@ export class FundingRequest method: 'propose', args: [ options.beneficiary, - options.amount, + options.amount.toString(), options.descriptionHash || '' ] } diff --git a/src/plugins/genericPlugin/plugin.ts b/src/plugins/genericPlugin/plugin.ts index c51de2a2..07466028 100644 --- a/src/plugins/genericPlugin/plugin.ts +++ b/src/plugins/genericPlugin/plugin.ts @@ -130,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] } } From 079c970964fe232c524db54562d88052ad5474fc Mon Sep 17 00:00:00 2001 From: Doug Kent Date: Mon, 6 Jul 2020 12:08:41 -0400 Subject: [PATCH 5/6] unit test --- src/plugins/genericPlugin/proposal.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/genericPlugin/proposal.ts b/src/plugins/genericPlugin/proposal.ts index d7af9521..acf3daf0 100644 --- a/src/plugins/genericPlugin/proposal.ts +++ b/src/plugins/genericPlugin/proposal.ts @@ -83,7 +83,7 @@ export class GenericPluginProposal extends Proposal contractToCall: item.genericScheme.contractToCall, executed: item.genericScheme.executed, returnValue: item.genericScheme.returnValue, - value: item.genericScheme.value + value: new BN(item.genericScheme.value) } } From 4a165e52ee2d9b3a20af66f5c7dab5dac56697f4 Mon Sep 17 00:00:00 2001 From: Doug Kent Date: Tue, 7 Jul 2020 08:57:23 -0400 Subject: [PATCH 6/6] bump version to .45 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index cf165cc7..f984aa02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc.js", - "version": "2.0.0-experimental.44", + "version": "2.0.0-experimental.45", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3cbdb2bf..1d7d74e9 100644 --- a/package.json +++ b/package.json @@ -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",