From e0d649f85e6f7e009969691221204295b7220a98 Mon Sep 17 00:00:00 2001 From: Doug Kent Date: Thu, 9 Aug 2018 11:46:21 -0400 Subject: [PATCH] add validation, bump version (#322) --- lib/wrappers/genesisProtocol.ts | 29 +++++++++++++++++++++++++++++ package.json | 2 +- test/genesisProtocol.ts | 18 ++++++++++++------ 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/lib/wrappers/genesisProtocol.ts b/lib/wrappers/genesisProtocol.ts index f68d8eeed..2e19c5a60 100644 --- a/lib/wrappers/genesisProtocol.ts +++ b/lib/wrappers/genesisProtocol.ts @@ -365,6 +365,10 @@ export class GenesisProtocolWrapper extends IntVoteInterfaceWrapper implements S throw new Error("proposalId is not defined"); } + if (!await this.validateRedemptionRequest(options.proposalId)) { + return new BigNumber(0); + } + this.logContractFunctionCall("GenesisProtocol.getRedeemableReputationProposer", options); return this.contract.getRedeemableReputationProposer(options.proposalId); @@ -387,6 +391,10 @@ export class GenesisProtocolWrapper extends IntVoteInterfaceWrapper implements S throw new Error("beneficiaryAddress is not defined"); } + if (!await this.validateRedemptionRequest(options.proposalId)) { + return new BigNumber(0); + } + this.logContractFunctionCall("GenesisProtocol.getRedeemableTokensVoter", options); return this.contract.getRedeemableTokensVoter( @@ -412,6 +420,10 @@ export class GenesisProtocolWrapper extends IntVoteInterfaceWrapper implements S throw new Error("beneficiaryAddress is not defined"); } + if (!await this.validateRedemptionRequest(options.proposalId)) { + return new BigNumber(0); + } + this.logContractFunctionCall("GenesisProtocol.getRedeemableReputationVoter", options); return this.contract.getRedeemableReputationVoter( @@ -436,6 +448,10 @@ export class GenesisProtocolWrapper extends IntVoteInterfaceWrapper implements S throw new Error("beneficiaryAddress is not defined"); } + if (!await this.validateRedemptionRequest(options.proposalId)) { + return new BigNumber(0); + } + this.logContractFunctionCall("GenesisProtocol.getRedeemableTokensStaker", options); return this.contract.getRedeemableTokensStaker( @@ -461,6 +477,10 @@ export class GenesisProtocolWrapper extends IntVoteInterfaceWrapper implements S throw new Error("beneficiaryAddress is not defined"); } + if (!await this.validateRedemptionRequest(options.proposalId)) { + return new BigNumber(0); + } + this.logContractFunctionCall("GenesisProtocol.getRedeemableTokensStakerBounty", options); return this.contract.getRedeemableTokensStakerBounty( @@ -486,6 +506,10 @@ export class GenesisProtocolWrapper extends IntVoteInterfaceWrapper implements S throw new Error("beneficiaryAddress is not defined"); } + if (!await this.validateRedemptionRequest(options.proposalId)) { + return new BigNumber(0); + } + this.logContractFunctionCall("GenesisProtocol.getRedeemableReputationStaker", options); return this.contract.getRedeemableReputationStaker( @@ -1087,6 +1111,11 @@ export class GenesisProtocolWrapper extends IntVoteInterfaceWrapper implements S winningVote: proposalArray[9].toNumber(), }; } + + private async validateRedemptionRequest(proposalId: Hash): Promise { + const proposalState = await this.getState({ proposalId }); + return ((proposalState === ProposalState.Executed) || (proposalState === ProposalState.Closed)); + } } /** diff --git a/package.json b/package.json index 776bef93a..2e864208a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/arc.js", - "version": "0.0.0-alpha.76", + "version": "0.0.0-alpha.77", "description": "A JavaScript library for interacting with @daostack/arc ethereum smart contracts", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/test/genesisProtocol.ts b/test/genesisProtocol.ts index b4ce609d6..ba6f0843e 100644 --- a/test/genesisProtocol.ts +++ b/test/genesisProtocol.ts @@ -571,10 +571,8 @@ describe("GenesisProtocol", () => { it("can call getRedeemableReputationProposer", async () => { const proposalId = await createProposal(); - const result = await genesisProtocol.getRedeemableReputationProposer({ - proposalId, - }); - assert(typeof result !== "undefined"); + const redeemable = await genesisProtocol.getRedeemableReputationProposer({ proposalId }); + assert.equal(web3.fromWei(redeemable).toNumber(), 0); }); it("can call getRedeemableTokensVoter", async () => { @@ -588,11 +586,19 @@ describe("GenesisProtocol", () => { it("can call getRedeemableReputationVoter", async () => { const proposalId = await createProposal(); - const result = await genesisProtocol.getRedeemableReputationVoter({ + let redeemable = await genesisProtocol.getRedeemableReputationVoter({ beneficiaryAddress: accounts[0], proposalId, }); - assert(typeof result !== "undefined"); + + assert.equal(web3.fromWei(redeemable).toNumber(), 0); + + await voteProposal(proposalId, 1); + + // should be executed now + redeemable = await genesisProtocol.getRedeemableReputationVoter({ proposalId, beneficiaryAddress: accounts[0] }); + assert.equal(web3.fromWei(redeemable).toNumber(), 18); + }); it("can call getRedeemableReputationStaker", async () => {