Skip to content

Commit 077b99e

Browse files
committed
chore(contract): added checks and some console.log to contract, test TODO done
1 parent 187b595 commit 077b99e

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

contracts/SinglePlayerCommit.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ contract SinglePlayerCommit is Ownable {
8888
address _oracle,
8989
address _token
9090
) public {
91+
console.log("Constructor called");
9192
// set up token interface
9293
token = IERC20(_token);
9394

@@ -170,8 +171,11 @@ contract SinglePlayerCommit is Ownable {
170171
uint256 _startTime,
171172
uint256 _stake
172173
) public returns (bool) {
174+
console.log("makeCommitment called");
175+
173176
require(!commitments[msg.sender].exists, "SPC::makeCommitment - msg.sender already has a commitment");
174177
require(allowedActivities[_activity].allowed, "SPC::makeCommitment - activity doesn't exist or isn't allowed");
178+
require(allowedActivities[_activity].measures.length >= _measureIndex+1, "SPC::makeCommitment - measure index out of bounds");
175179

176180
bytes32 measure = allowedActivities[_activity].measures[_measureIndex];
177181

test/SinglePlayerCommit.deploy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export function shouldDeployWithInitialParameters(): void {
66
it("has the 'biking' activity and it is allowed", async function () {
77
const activityKey: BytesLike = await this.singlePlayerCommit.activityList(0);
88
const _activityName: string = await this.singlePlayerCommit.getActivityName(activityKey);
9+
910

1011
const _activity = await this.singlePlayerCommit.allowedActivities(activityKey);
1112

test/SinglePlayerCommit.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//Setup
22
import chai from "chai";
33
import { ethers } from "@nomiclabs/buidler";
4-
import { BigNumberish, Signer, ContractFactory, Wallet } from "ethers";
5-
import { createFixtureLoader, deployMockContract, loadFixture, MockContract, MockProvider, solidity } from "ethereum-waffle";
4+
import { BigNumberish, Signer, ContractFactory} from "ethers";
5+
import { deployMockContract, MockContract, MockProvider, solidity } from "ethereum-waffle";
66

77
//Artifacts
88
import { SinglePlayerCommit } from "../typechain/SinglePlayerCommit";
@@ -15,6 +15,7 @@ import { userCanManageCommitments } from "./SinglePlayerCommit.user";
1515
import { ownerCanManageContract } from "./SinglePlayerCommit.owner";
1616

1717
chai.use(solidity);
18+
const bre = require("@nomiclabs/buidler");
1819

1920
setTimeout(async function () {
2021
describe("SinglePlayerCommit contract", async function () {

test/SinglePlayerCommit.user.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,19 @@ export function userCanManageCommitments(): void {
108108
const _amountToStake: BigNumber = utils.parseEther("50.0");
109109

110110
//Activity
111-
//TODO improve to revertedWith; now returns invalid opcode instead of error message
112-
_activity = 'LALALA';
111+
_activity = '0xb16dfc4a050ca7e77c1c5f443dc473a2f03ac722e25f721ab6333875f44984f2';
113112

114113
await expect(
115114
contractWithUser.makeCommitment(_activity, _measureIndex, _goal, _startTime, _amountToStake, _overrides),
116-
).to.be.reverted;
115+
).to.be.revertedWith("SPC::makeCommitment - activity doesn't exist or isn't allowed");
117116
_activity = await this.singlePlayerCommit.activityList(0);
118117

119118
//Measure
120-
//TODO improve to revertedWith; now returns invalid opcode instead of error message
121119
_measureIndex = 1;
122120

123121
await expect(
124122
contractWithUser.makeCommitment(_activity, _measureIndex, _goal, _startTime, _amountToStake, _overrides),
125-
).to.be.reverted;
123+
).to.be.revertedWith("SPC::makeCommitment - measure index out of bounds");
126124
_measureIndex = 0;
127125

128126
//Goal

0 commit comments

Comments
 (0)