1414// You should have received a copy of the GNU Affero General Public License
1515// along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
17+ import * as chai from "chai" ;
1718import { expect } from "chai" ;
19+ import * as chaiAsPromised from "chai-as-promised" ;
1820import { H256 , PlatformAddress , U64 } from "codechain-primitives/lib" ;
1921import { blake256 } from "codechain-sdk/lib/utils" ;
2022import "mocha" ;
@@ -33,6 +35,8 @@ import CodeChain from "../helper/spawn";
3335
3436const RLP = require ( "rlp" ) ;
3537
38+ chai . use ( chaiAsPromised ) ;
39+
3640describe ( "ChangeParams" , function ( ) {
3741 const chain = `${ __dirname } /../scheme/solo-block-reward-50.json` ;
3842 let node : CodeChain ;
@@ -103,11 +107,7 @@ describe("ChangeParams", function() {
103107 expect ( await node . sdk . rpc . chain . containsTransaction ( hash ) ) . be . true ;
104108 }
105109
106- try {
107- await node . sendPayTx ( { fee : 10 } ) ;
108- } catch ( err ) {
109- expect ( err . message ) . contains ( "Too Low Fee" ) ;
110- }
110+ await expect ( node . sendPayTx ( { fee : 10 } ) ) . rejectedWith ( / T o o L o w F e e / ) ;
111111
112112 const params = await node . sdk . rpc . sendRpcRequest (
113113 "chain_getCommonParams" ,
@@ -161,12 +161,9 @@ describe("ChangeParams", function() {
161161 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
162162 fee : 10
163163 } ) ;
164- try {
165- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
166- expect . fail ( "The transaction must fail" ) ;
167- } catch ( err ) {
168- expect ( err . message ) . contains ( "network id" ) ;
169- }
164+ await expect ( node . sdk . rpc . chain . sendSignedTransaction ( tx ) ) . rejectedWith (
165+ / n e t w o r k i d /
166+ ) ;
170167 } ) ;
171168
172169 it ( "should keep default common params value" , async function ( ) {
@@ -240,11 +237,7 @@ describe("ChangeParams", function() {
240237 ) ;
241238 }
242239
243- try {
244- await node . sendPayTx ( { fee : 10 } ) ;
245- } catch ( err ) {
246- expect ( err . message ) . contains ( "Too Low Fee" ) ;
247- }
240+ await expect ( node . sendPayTx ( { fee : 10 } ) ) . rejectedWith ( / T o o L o w F e e / ) ;
248241 } ) ;
249242
250243 it ( "the parameter changed twice in the same block" , async function ( ) {
@@ -366,11 +359,7 @@ describe("ChangeParams", function() {
366359 const pay = await node . sendPayTx ( { fee : 5 } ) ;
367360 expect ( await node . sdk . rpc . chain . containsTransaction ( pay . hash ( ) ) ) . be
368361 . true ;
369- try {
370- await node . sendPayTx ( { fee : 4 } ) ;
371- } catch ( err ) {
372- expect ( err . message ) . contains ( "Too Low Fee" ) ;
373- }
362+ await expect ( node . sendPayTx ( { fee : 4 } ) ) . rejectedWith ( / T o o L o w F e e / ) ;
374363 } ) ;
375364
376365 it ( "cannot reuse the same signature" , async function ( ) {
@@ -492,11 +481,7 @@ describe("ChangeParams", function() {
492481 const pay = await node . sendPayTx ( { fee : 5 } ) ;
493482 expect ( await node . sdk . rpc . chain . containsTransaction ( pay . hash ( ) ) ) . be
494483 . true ;
495- try {
496- await node . sendPayTx ( { fee : 4 } ) ;
497- } catch ( err ) {
498- expect ( err . message ) . contains ( "Too Low Fee" ) ;
499- }
484+ await expect ( node . sendPayTx ( { fee : 4 } ) ) . rejectedWith ( / T o o L o w F e e / ) ;
500485 } ) ;
501486
502487 it ( "cannot change params with insufficient stakes" , async function ( ) {
@@ -700,11 +685,7 @@ describe("ChangeParams", function() {
700685 expect ( await node . sdk . rpc . chain . getTransaction ( hash ) ) . not . be . null ;
701686 }
702687
703- try {
704- await node . sendPayTx ( { fee : 10 } ) ;
705- } catch ( err ) {
706- expect ( err . message ) . contains ( "Too Low Fee" ) ;
707- }
688+ await expect ( node . sendPayTx ( { fee : 10 } ) ) . rejectedWith ( / T o o L o w F e e / ) ;
708689 } ) ;
709690
710691 describe ( "with stake parameters" , async function ( ) {
@@ -764,11 +745,9 @@ describe("ChangeParams", function() {
764745 . true ;
765746 }
766747
767- try {
768- await node . sendPayTx ( { fee : 10 } ) ;
769- } catch ( err ) {
770- expect ( err . message ) . contains ( "Too Low Fee" ) ;
771- }
748+ await expect ( node . sendPayTx ( { fee : 10 } ) ) . rejectedWith (
749+ / T o o L o w F e e /
750+ ) ;
772751
773752 const params = await node . sdk . rpc . sendRpcRequest (
774753 "chain_getCommonParams" ,
@@ -835,12 +814,9 @@ describe("ChangeParams", function() {
835814 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
836815 fee : 10
837816 } ) ;
838- try {
839- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
840- expect . fail ( "The transaction must fail" ) ;
841- } catch ( err ) {
842- expect ( err . message ) . contains ( "nomination expiration" ) ;
843- }
817+ await expect (
818+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
819+ ) . rejectedWith ( / n o m i n a t i o n e x p i r a t i o n / ) ;
844820 } ) ;
845821
846822 it ( "custody period cannot be zero" , async function ( ) {
@@ -901,12 +877,9 @@ describe("ChangeParams", function() {
901877 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
902878 fee : 10
903879 } ) ;
904- try {
905- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
906- expect . fail ( "The transaction must fail" ) ;
907- } catch ( err ) {
908- expect ( err . message ) . contains ( "custody period" ) ;
909- }
880+ await expect (
881+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
882+ ) . rejectedWith ( / c u s t o d y p e r i o d / ) ;
910883 } ) ;
911884
912885 it ( "release period cannot be zero" , async function ( ) {
@@ -967,12 +940,9 @@ describe("ChangeParams", function() {
967940 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
968941 fee : 10
969942 } ) ;
970- try {
971- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
972- expect . fail ( "The transaction must fail" ) ;
973- } catch ( err ) {
974- expect ( err . message ) . contains ( "release period" ) ;
975- }
943+ await expect (
944+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
945+ ) . rejectedWith ( / r e l e a s e p e r i o d / ) ;
976946 } ) ;
977947
978948 it ( "The maximum number of candidates cannot be equal to the minimum number of candidates" , async function ( ) {
@@ -1100,11 +1070,9 @@ describe("ChangeParams", function() {
11001070 . true ;
11011071 }
11021072
1103- try {
1104- await node . sendPayTx ( { fee : 10 } ) ;
1105- } catch ( err ) {
1106- expect ( err . message ) . contains ( "Too Low Fee" ) ;
1107- }
1073+ await expect ( node . sendPayTx ( { fee : 10 } ) ) . rejectedWith (
1074+ / T o o L o w F e e /
1075+ ) ;
11081076
11091077 const params = await node . sdk . rpc . sendRpcRequest (
11101078 "chain_getCommonParams" ,
@@ -1171,12 +1139,9 @@ describe("ChangeParams", function() {
11711139 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
11721140 fee : 10
11731141 } ) ;
1174- try {
1175- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
1176- expect . fail ( "The transaction must fail" ) ;
1177- } catch ( err ) {
1178- expect ( err . message ) . contains ( "nomination expiration" ) ;
1179- }
1142+ await expect (
1143+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
1144+ ) . rejectedWith ( / n o m i n a t i o n e x p i r a t i o n / ) ;
11801145 } ) ;
11811146
11821147 it ( "custody period cannot be zero" , async function ( ) {
@@ -1237,12 +1202,9 @@ describe("ChangeParams", function() {
12371202 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
12381203 fee : 10
12391204 } ) ;
1240- try {
1241- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
1242- expect . fail ( "The transaction must fail" ) ;
1243- } catch ( err ) {
1244- expect ( err . message ) . contains ( "custody period" ) ;
1245- }
1205+ await expect (
1206+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
1207+ ) . rejectedWith ( / c u s t o d y p e r i o d / ) ;
12461208 } ) ;
12471209
12481210 it ( "release period cannot be zero" , async function ( ) {
@@ -1303,12 +1265,9 @@ describe("ChangeParams", function() {
13031265 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
13041266 fee : 10
13051267 } ) ;
1306- try {
1307- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
1308- expect . fail ( "The transaction must fail" ) ;
1309- } catch ( err ) {
1310- expect ( err . message ) . contains ( "release period" ) ;
1311- }
1268+ await expect (
1269+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
1270+ ) . rejectedWith ( / r e l e a s e p e r i o d / ) ;
13121271 } ) ;
13131272
13141273 it ( "min deposit cannot be zero" , async function ( ) {
@@ -1369,12 +1328,9 @@ describe("ChangeParams", function() {
13691328 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
13701329 fee : 10
13711330 } ) ;
1372- try {
1373- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
1374- expect . fail ( "The transaction must fail" ) ;
1375- } catch ( err ) {
1376- expect ( err . message ) . contains ( "minimum deposit" ) ;
1377- }
1331+ await expect (
1332+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
1333+ ) . rejectedWith ( / m i n i m u m d e p o s i t / ) ;
13781334 } ) ;
13791335
13801336 it ( "delegation threshold cannot be zero" , async function ( ) {
@@ -1435,12 +1391,9 @@ describe("ChangeParams", function() {
14351391 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
14361392 fee : 10
14371393 } ) ;
1438- try {
1439- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
1440- expect . fail ( "The transaction must fail" ) ;
1441- } catch ( err ) {
1442- expect ( err . message ) . contains ( "delegation threshold" ) ;
1443- }
1394+ await expect (
1395+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
1396+ ) . rejectedWith ( / d e l e g a t i o n t h r e s h o l d / ) ;
14441397 } ) ;
14451398
14461399 it ( "min number of validators cannot be zero" , async function ( ) {
@@ -1501,12 +1454,9 @@ describe("ChangeParams", function() {
15011454 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
15021455 fee : 10
15031456 } ) ;
1504- try {
1505- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
1506- expect . fail ( "The transaction must fail" ) ;
1507- } catch ( err ) {
1508- expect ( err . message ) . contains ( "minimum number of validators" ) ;
1509- }
1457+ await expect (
1458+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
1459+ ) . rejectedWith ( / m i n i m u m n u m b e r o f v a l i d a t o r s / ) ;
15101460 } ) ;
15111461
15121462 it ( "max number of validators cannot be zero" , async function ( ) {
@@ -1567,12 +1517,9 @@ describe("ChangeParams", function() {
15671517 seq : await node . sdk . rpc . chain . getSeq ( faucetAddress ) ,
15681518 fee : 10
15691519 } ) ;
1570- try {
1571- await node . sdk . rpc . chain . sendSignedTransaction ( tx ) ;
1572- expect . fail ( "The transaction must fail" ) ;
1573- } catch ( err ) {
1574- expect ( err . message ) . contains ( "maximum number of validators" ) ;
1575- }
1520+ await expect (
1521+ node . sdk . rpc . chain . sendSignedTransaction ( tx )
1522+ ) . rejectedWith ( / m a x i m u m n u m b e r o f v a l i d a t o r s / ) ;
15761523 } ) ;
15771524
15781525 it ( "The maximum number of candidates cannot be equal to the minimum number of candidates" , async function ( ) {
0 commit comments