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 { expect } from "chai" ;
17+ import * as chai from "chai" ;
18+ import * as chaiAsPromised from "chai-as-promised" ;
19+ chai . use ( chaiAsPromised ) ;
1820import "mocha" ;
1921import {
2022 aliceAddress ,
@@ -26,10 +28,12 @@ import {
2628} from "../helper/constants" ;
2729import CodeChain from "../helper/spawn" ;
2830
31+ const expect = chai . expect ;
32+
2933describe ( "CreateShard" , function ( ) {
3034 let node : CodeChain ;
3135 before ( async function ( ) {
32- node = new CodeChain ( ) ;
36+ node = new CodeChain ( { argv : [ "--allow-create-shard" ] } ) ;
3337 await node . start ( ) ;
3438 } ) ;
3539
@@ -413,3 +417,43 @@ describe("CreateShard", function() {
413417 await node . clean ( ) ;
414418 } ) ;
415419} ) ;
420+
421+ describe ( "Cannot create shard without allow-create-shard flag" , function ( ) {
422+ let node : CodeChain ;
423+ before ( async function ( ) {
424+ node = new CodeChain ( ) ;
425+ await node . start ( ) ;
426+ } ) ;
427+
428+ it ( "Create 1 shard" , async function ( ) {
429+ const seq : number = ( await node . sdk . rpc . chain . getSeq ( faucetAddress ) ) ! ;
430+
431+ await node . sdk . rpc . chain . sendSignedTransaction (
432+ node . sdk . core
433+ . createPayTransaction ( { recipient : aliceAddress , quantity : 1 } )
434+ . sign ( { secret : faucetSecret , seq, fee : 10 } )
435+ ) ;
436+
437+ const tx = node . sdk . core
438+ . createCreateShardTransaction ( { users : [ aliceAddress ] } )
439+ . sign ( { secret : faucetSecret , seq : seq + 1 , fee : 10 } ) ;
440+ expect (
441+ await node . sdk . rpc . sendRpcRequest ( "chain_getShardIdByHash" , [
442+ tx . hash ( ) ,
443+ null
444+ ] )
445+ ) . be . null ;
446+ expect ( node . sdk . rpc . chain . sendSignedTransaction ( tx ) ) . be . rejected ;
447+ expect ( await node . sdk . rpc . chain . containTransaction ( tx . hash ( ) ) ) . be . false ;
448+ expect ( await node . sdk . rpc . chain . getTransaction ( tx . hash ( ) ) ) . be . null ;
449+ const afterShardId = await node . sdk . rpc . sendRpcRequest (
450+ "chain_getShardIdByHash" ,
451+ [ tx . hash ( ) , null ]
452+ ) ;
453+ expect ( afterShardId ) . be . null ;
454+ } ) ;
455+
456+ after ( async function ( ) {
457+ await node . clean ( ) ;
458+ } ) ;
459+ } ) ;
0 commit comments