Skip to content

Commit

Permalink
add validation, bump version (#322)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkent600 authored Aug 9, 2018
1 parent 1cb3367 commit e0d649f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
29 changes: 29 additions & 0 deletions lib/wrappers/genesisProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -1087,6 +1111,11 @@ export class GenesisProtocolWrapper extends IntVoteInterfaceWrapper implements S
winningVote: proposalArray[9].toNumber(),
};
}

private async validateRedemptionRequest(proposalId: Hash): Promise<boolean> {
const proposalState = await this.getState({ proposalId });
return ((proposalState === ProposalState.Executed) || (proposalState === ProposalState.Closed));
}
}

/**
Expand Down
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": "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",
Expand Down
18 changes: 12 additions & 6 deletions test/genesisProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down

0 comments on commit e0d649f

Please sign in to comment.