Browse Source

Edits and corrections to README.md, placing errors.js in index.js module

Luiserebii 6 months ago
parent
commit
a9f4dbb624
Signed by: Luiserebii <luis@serebii.io> GPG Key ID: 3B7E2D68E27CBBCF
3 changed files with 29 additions and 4 deletions
  1. 25
    2
      README.md
  2. 3
    1
      index.js
  3. 1
    1
      sol-assert.js

+ 25
- 2
README.md View File

@@ -1,13 +1,13 @@
1 1
 # solidity-test
2 2
 [![npm version](https://badge.fury.io/js/solidity-test.svg)](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
+```

+ 3
- 1
index.js View File

@@ -11,9 +11,11 @@
11 11
 
12 12
 
13 13
 const solAssert = require('./sol-assert');
14
+const errors = require('./errors');
14 15
 
15 16
 module.exports = {
16 17
 
17
-  'solAssert': solAssert
18
+  'solAssert': solAssert,
19
+  'errors': errors
18 20
 
19 21
 }

+ 1
- 1
sol-assert.js View File

@@ -15,7 +15,7 @@ class SolAssert {
15 15
 
16 16
   //Simply function to test for Solidity revert errors; optionally takes an "expectedErr" which simply looks for a string within
17 17
   //This function has limits, however; if a function can potentially return two or more reverts, we can't quite test for each of them through expectedErr and apply if/and/or logic
18
-  async revert(run, expectedErr = null) {
18
+  static async revert(run, expectedErr = null) {
19 19
     let err;
20 20
     try {
21 21
       await run();

Loading…
Cancel
Save