|
@@ -1,13 +1,13 @@
|
1
|
1
|
# solidity-test
|
2
|
2
|
[](https://badge.fury.io/js/solidity-test)
|
3
|
3
|
|
4
|
|
-A simple node module to aid smart contract development in testing contracts. Initially created due to the desire to modularize testing for `revert`s, now looking to expand into something more define.
|
|
4
|
+A simple node module to aid smart contract development in testing contracts. Initially created due to the desire to modularize testing for `revert`s, now looking to expand into something more definite.
|
5
|
5
|
|
6
|
6
|
# Quick Example
|
7
|
7
|
|
8
|
8
|
```javascript
|
9
|
9
|
const solidityTest = require('solidityTest');
|
10
|
|
-const solAssert = new solidityTest.solAssert();
|
|
10
|
+const solAssert = solidityTest.solAssert;
|
11
|
11
|
|
12
|
12
|
const notOwner = '0x00000000000000000000000000000000000';
|
13
|
13
|
|
|
@@ -24,3 +24,26 @@ it('reverts transaction', async () => {
|
24
|
24
|
})
|
25
|
25
|
|
26
|
26
|
```
|
|
27
|
+
|
|
28
|
+And, if perhaps testing for ownership, and wanting to be strict about the kind of error received:
|
|
29
|
+```javascript
|
|
30
|
+const solidityTest = require('solidityTest');
|
|
31
|
+const solAssert = solidityTest.solAssert;
|
|
32
|
+const errors = solidityTest.errors;
|
|
33
|
+
|
|
34
|
+const notOwner = '0x00000000000000000000000000000000000';
|
|
35
|
+
|
|
36
|
+//Within Mocha:
|
|
37
|
+
|
|
38
|
+it('reverts transaction', async () => {
|
|
39
|
+
|
|
40
|
+ //Passing an error string to revert will only pass when the error string is matched
|
|
41
|
+ await solAssert.revert(
|
|
42
|
+ async () => {
|
|
43
|
+ someContract.functionOnlyOwnerCanCall().send({from: notOwner});
|
|
44
|
+ }, errors.openzeppelin.ownable // which is: 'Ownable: caller is not the owner'
|
|
45
|
+ )
|
|
46
|
+
|
|
47
|
+})
|
|
48
|
+
|
|
49
|
+```
|