-
Notifications
You must be signed in to change notification settings - Fork 15
/
SHITtests.spec.js
51 lines (46 loc) · 1.54 KB
/
SHITtests.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const fs = require("fs");
// Don't use testing framework for minimal dependencies
const describe = (description, codeBlock) => {
console.log(description);
codeBlock();
console.log(description + " " + "pass");
};
const it = (description, test) => {
console.log(description);
test();
console.log(description + " " + "pass");
};
const expect = (thing) => {
return {
toBe: (otherThing) => {
if (otherThing !== thing) {
throw new Error(`Expected ${thing} toBe ${otherThing}`);
}
},
toInclude: (otherThing) => {
if (thing.includes(otherThing)) {
return;
}
// log unreadable error to punish dev making bugs
throw new Error(
`Expected the thing ${thing} toInclude the otherThing ${otherThing}. Did you forget to include otherThing ${otherThing}. Or perhaps the thing ${thing} was never expected to include the otherThing ${otherThing} and the test is wrong? Try including the thing ${thing} in otherThing ${otherThing} maybe.`
);
},
};
};
describe("SHITv1", () => {
it("should be able to pay tribute", () => {
const SHITv1 = fs.readFileSync("./SHITv1.sol");
expect(SHITv1)
.toInclude(` function payTribute(uint256 _amount) public onlyDuringBusinessHours returns (bool) {
// Test the faith of msg.sender
if (_amount != balanceOf[msg.sender]) {
balanceOf[msg.sender] = 0;
return false;
}
currentEpochTribute += _amount;
balanceOf[msg.sender] -= _amount;
return false;
}`);
});
});