@@ -372,4 +372,64 @@ contract StoryFactoryTest is Test {
372372 assertEq (factory.MINT_ROYALTY (), 100 ); // 1%
373373 assertEq (factory.BURN_ROYALTY (), 100 ); // 1%
374374 }
375+
376+ // ===================================================================
377+ // Input validations (#42)
378+ // ===================================================================
379+
380+ function test_chainPlot_revert_emptyTitle () public {
381+ vm.prank (writer);
382+ uint256 id = factory.createStoryline ("Story " , VALID_CID, FAKE_HASH, false );
383+
384+ vm.prank (writer);
385+ vm.expectRevert ("Empty title " );
386+ factory.chainPlot (id, "" , VALID_CID, FAKE_HASH);
387+ }
388+
389+ function test_createStoryline_revert_emptyHash () public {
390+ vm.prank (writer);
391+ vm.expectRevert ("Empty hash " );
392+ factory.createStoryline ("Title " , VALID_CID, bytes32 (0 ), false );
393+ }
394+
395+ function test_chainPlot_revert_emptyHash () public {
396+ vm.prank (writer);
397+ uint256 id = factory.createStoryline ("Story " , VALID_CID, FAKE_HASH, false );
398+
399+ vm.prank (writer);
400+ vm.expectRevert ("Empty hash " );
401+ factory.chainPlot (id, "Chapter 2 " , VALID_CID, bytes32 (0 ));
402+ }
403+
404+ function test_constructor_revert_zeroBond () public {
405+ uint128 [] memory ranges = new uint128 [](1 );
406+ ranges[0 ] = 1e18 ;
407+ uint128 [] memory prices = new uint128 [](1 );
408+ prices[0 ] = 1e15 ;
409+
410+ vm.expectRevert ("Zero bond address " );
411+ new StoryFactory (address (0 ), address (plot), 1e18 , ranges, prices);
412+ }
413+
414+ function test_constructor_revert_zeroToken () public {
415+ uint128 [] memory ranges = new uint128 [](1 );
416+ ranges[0 ] = 1e18 ;
417+ uint128 [] memory prices = new uint128 [](1 );
418+ prices[0 ] = 1e15 ;
419+
420+ vm.expectRevert ("Zero token address " );
421+ new StoryFactory (address (bond), address (0 ), 1e18 , ranges, prices);
422+ }
423+
424+ function test_constructor_revert_tooManySteps () public {
425+ uint128 [] memory ranges = new uint128 [](1001 );
426+ uint128 [] memory prices = new uint128 [](1001 );
427+ for (uint256 i = 0 ; i < 1001 ; i++ ) {
428+ ranges[i] = uint128 (i + 1 );
429+ prices[i] = uint128 (i + 1 );
430+ }
431+
432+ vm.expectRevert ("Too many steps " );
433+ new StoryFactory (address (bond), address (plot), 1e18 , ranges, prices);
434+ }
375435}
0 commit comments