1
- module . exports = function expectedExceptionPromise ( action , gasToUse ) {
2
- return new Promise ( function ( resolve , reject ) {
3
- try {
4
- resolve ( action ( ) ) ;
5
- } catch ( e ) {
6
- reject ( e ) ;
7
- }
8
- } )
9
- . then ( function ( txObj ) {
10
- return typeof txn === "string"
11
- ? web3 . eth . getTransactionReceiptMined ( txObj ) // regular tx hash
12
- : typeof txObj . receipt !== "undefined"
13
- ? txObj . receipt // truffle-contract function call
14
- : typeof txObj . transactionHash === "string"
15
- ? web3 . eth . getTransactionReceiptMined ( txObj . transactionHash ) // deployment
16
- : txObj ; // Unknown last case
17
- } )
18
- . then ( function ( receipt ) {
19
- console . log ( 'Receipt' , receipt ) ;
1
+ "use strict" ;
20
2
21
- // We are in Geth or the tx wrongly passed
22
- assert . equal ( receipt . gasUsed , gasToUse , "should have used all the gas" ) ;
23
- } )
24
- . catch ( function ( e ) {
25
- if ( ( e + "" ) . indexOf ( "invalid JUMP" ) > - 1 ||
26
- ( e + "" ) . indexOf ( "out of gas" ) > - 1 ||
27
- ( e + "" ) . indexOf ( "invalid opcode" ) > - 1 ) {
28
- // We are in TestRPC
29
- } else if ( ( e + "" ) . indexOf ( "please check your gas amount" ) > - 1 ) {
30
- // We are in Geth for a deployment
31
- } else {
32
- throw e ;
33
- }
34
- } ) ;
35
- } ;
3
+ /**
4
+ * @param {!Function.<!Promise> } action.
5
+ * @param {!Number | !string | !BigNumber } gasToUse.
6
+ * @returns {!Promise } which throws unless it hit a valid error.
7
+ */
8
+ module . exports = function expectedExceptionPromise ( action , gasToUse ) {
9
+ return new Promise ( function ( resolve , reject ) {
10
+ try {
11
+ resolve ( action ( ) ) ;
12
+ } catch ( e ) {
13
+ reject ( e ) ;
14
+ }
15
+ } )
16
+ . then ( function ( txObj ) {
17
+ return typeof txn === "string"
18
+ ? web3 . eth . getTransactionReceiptMined ( txObj ) // regular tx hash
19
+ : typeof txObj . receipt !== "undefined"
20
+ ? txObj . receipt // truffle-contract function call
21
+ : typeof txObj . transactionHash === "string"
22
+ ? web3 . eth . getTransactionReceiptMined ( txObj . transactionHash ) // deployment
23
+ : txObj ; // Unknown last case
24
+ } )
25
+ . then (
26
+ function ( receipt ) {
27
+ console . log ( "Receipt: " + receipt ) ;
28
+ // We are in Geth
29
+ if ( typeof receipt . status !== "undefined" ) {
30
+ // Byzantium
31
+ assert . include ( [ "0x0" , "0x00" ] , receipt . status , "should have reverted" ) ;
32
+ } else {
33
+ // Pre Byzantium
34
+ assert . equal ( receipt . gasUsed , gasToUse , "should have used all the gas" ) ;
35
+ }
36
+ } ,
37
+ function ( e ) {
38
+ if ( ( e + "" ) . indexOf ( "invalid JUMP" ) > - 1 ||
39
+ ( e + "" ) . indexOf ( "out of gas" ) > - 1 ||
40
+ ( e + "" ) . indexOf ( "invalid opcode" ) > - 1 ||
41
+ ( e + "" ) . indexOf ( "revert" ) > - 1 ) {
42
+ // We are in TestRPC
43
+ } else if ( ( e + "" ) . indexOf ( "please check your gas amount" ) > - 1 ) {
44
+ // We are in Geth for a deployment
45
+ } else {
46
+ throw e ;
47
+ }
48
+ }
49
+ ) ;
50
+ } ;
0 commit comments