Skip to content

Commit d389060

Browse files
committed
test(bdd commitment): continued on testing user interaction with contract
1 parent 16b8e1c commit d389060

File tree

2 files changed

+50
-31
lines changed

2 files changed

+50
-31
lines changed
Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,57 @@
1+
import { ethers } from "@nomiclabs/buidler";
12
import { expect } from "chai";
3+
import { MockProvider } from "ethereum-waffle";
24
import { Wallet, utils } from "ethers";
35
import { BytesLike } from "ethers/lib/utils";
46
import { SinglePlayerCommit } from "../typechain/SinglePlayerCommit";
57

6-
export function shouldManageCommitments(wallet: Wallet, walletTo: Wallet): void {
8+
export function shouldManageCommitments(provider: MockProvider): void {
9+
const [contractWallet, userWallet] = provider.getWallets();
710

8-
it("allows the user to deposit for staking", async function () {
9-
// const _activity = "biking";
10-
// const _measureIndex = await this.singlePlayerCommit.measureList(0);
11-
console.log(await walletTo.getBalance());
12-
const _amount = utils.parseEther("1.0");
13-
let contractWithSigner = await this.singlePlayerCommit.connect(walletTo);
14-
console.log("Connected to contract")
15-
let output = await contractWithSigner.deposit(_amount);
16-
console.log(output)
11+
context('user can', function () {
12+
it("deposit funds for staking", async function () {
13+
const contract = this.singlePlayerCommit;
1714

18-
expect(1).to.equal(1);
19-
});
15+
const contractWithUser = await contract.connect(userWallet);
16+
console.log("Connected to contract with wallet: " + userWallet.address)
17+
18+
const _amountToDeposit = utils.parseEther("1.0");
19+
const _overrides = {
20+
gasLimit: 100000,
21+
};
22+
23+
//TODO Error: revert Mock on the method is not initialized
24+
expect(await contractWithUser.deposit(_amountToDeposit, _overrides)).to.equal(true);
25+
console.log('deposited funds')
26+
27+
const _committerBalance = await contract.committerBalance.call();
28+
console.log(_committerBalance);
29+
30+
expect(_committerBalance).to.equal(_amountToDeposit)
31+
expect('_deposit').to.be.calledOnContract(contract);
32+
expect('_changeCommitterBalance').to.be.calledOnContract(contract);
33+
});
2034

21-
it.skip("allows users with sufficient staked funds to stake on a commitment of biking 50 kms", async function () {
22-
// const _activity = "biking";
23-
// const _measureIndex = await this.singlePlayerCommit.measureList(0);
24-
console.log(await walletTo.getBalance());
25-
const _activity = await this.singlePlayerCommit.activityList(0);
26-
const _measureIndex = 0
27-
const _goal = 50;
28-
const _startTime = Date.now();
29-
const _stake = 10;
30-
let contractWithSigner = await this.singlePlayerCommit.connect(walletTo);
31-
let output = await contractWithSigner.makeCommitment(_activity, _measureIndex, _goal, _startTime, _stake);
32-
console.log(output)
33-
34-
expect(1).to.equal(1);
35+
it.skip('withdraw deposited funds', async function () {
36+
expect(1).to.equal(1);
37+
});
38+
39+
it.skip("make a commitment of biking 50 kms against stake with deposited funds", async function () {
40+
// const _activity = "biking";
41+
// const _measureIndex = await this.singlePlayerCommit.measureList(0);
42+
const contractWithSigner = await this.singlePlayerCommit.connect(userWallet);
43+
44+
console.log(await userWallet.getBalance());
45+
const _activity = await this.singlePlayerCommit.activityList(0);
46+
const _measureIndex = 0
47+
const _goal = 50;
48+
const _startTime = Date.now();
49+
const _stake = 10;
50+
await contractWithSigner.makeCommitment(_activity, _measureIndex, _goal, _startTime, _stake);
51+
52+
expect(1).to.equal(1);
53+
});
3554
});
3655

56+
3757
}

test/SinglePlayerCommit.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import { shouldManageCommitments } from './SinglePlayerCommit.commitment';
1313
chai.use(solidity);
1414

1515
setTimeout(async function () {
16-
const [wallet, walletTo] = new MockProvider().getWallets();
17-
1816
describe("SinglePlayerCommit contract", function () {
19-
17+
const provider: MockProvider = new MockProvider()
18+
const [wallet, walletTo] = provider.getWallets();
2019
const activity: string = "biking";
2120
const measures: string[] = ["km"];
2221
const ranges: BigNumberish[][] = [[2, 1024]];
@@ -40,8 +39,8 @@ setTimeout(async function () {
4039
shouldDeployWithInitialParameters();
4140
});
4241

43-
describe("Commitments can be managed", function() {
44-
shouldManageCommitments(wallet, walletTo);
42+
describe("Commitments can be managed", function () {
43+
shouldManageCommitments(provider);
4544
});
4645
});
4746

0 commit comments

Comments
 (0)