1- import { PublicKey } from "@solana/web3.js" ;
1+ import { ComputeBudgetProgram , PublicKey } from "@solana/web3.js" ;
22import { assert } from "chai" ;
33import {
44 AutocratClient ,
@@ -21,6 +21,7 @@ export default function suite() {
2121 let treasuryUsdcAccount : PublicKey ;
2222
2323 const minRaise = new BN ( 1000_000000 ) ; // 1000 USDC
24+ const SLOTS_PER_DAY = 216_000n ; // (24 * 60 * 60 * 1000) / 400
2425
2526 before ( async function ( ) {
2627 autocratClient = this . autocratClient ;
@@ -61,11 +62,10 @@ export default function suite() {
6162 ] ) . rpc ( ) ;
6263 } ) ;
6364
64- it ( "completes launch successfully when minimum raise is met" , async function ( ) {
65+ it ( "completes launch successfully when minimum raise is met and time has passed " , async function ( ) {
6566 // Fund the launch with exactly minimum raise
6667 const userUsdcAccount = await this . createTokenAccount ( USDC , this . payer . publicKey ) ;
6768 const userTokenAccount = await this . createTokenAccount ( META , this . payer . publicKey ) ;
68- // await this.mintTo(USDC, userUsdcAccount, this.payer, minRaise.toNumber());
6969 await this . mintTo ( USDC , this . payer . publicKey , this . payer , minRaise . toNumber ( ) ) ;
7070
7171 await launchpadClient . fundIx (
@@ -75,6 +75,9 @@ export default function suite() {
7575 META
7676 ) . rpc ( ) ;
7777
78+ // Advance clock past 7 days
79+ await this . advanceBySlots ( SLOTS_PER_DAY * 7n ) ;
80+
7881 // Complete the launch
7982 await launchpadClient . completeLaunchIx ( launch , USDC , daoTreasury ) . rpc ( ) ;
8083
@@ -85,7 +88,39 @@ export default function suite() {
8588 assert . equal ( treasuryBalance . toString ( ) , minRaise . toString ( ) ) ;
8689 } ) ;
8790
88- it ( "moves to refunding state when minimum raise is not met" , async function ( ) {
91+ it ( "fails when launch period has not passed" , async function ( ) {
92+ // Fund the launch with exactly minimum raise
93+ const userUsdcAccount = await this . createTokenAccount ( USDC , this . payer . publicKey ) ;
94+ const userTokenAccount = await this . createTokenAccount ( META , this . payer . publicKey ) ;
95+ await this . mintTo ( USDC , this . payer . publicKey , this . payer , minRaise . toNumber ( ) ) ;
96+
97+ await launchpadClient . fundIx (
98+ launch ,
99+ minRaise ,
100+ USDC ,
101+ META
102+ ) . rpc ( ) ;
103+
104+ // Try to complete immediately (should fail)
105+ try {
106+ await launchpadClient . completeLaunchIx ( launch , USDC , daoTreasury ) . rpc ( ) ;
107+ assert . fail ( "Should have thrown error" ) ;
108+ } catch ( e ) {
109+ assert . include ( e . message , "LaunchPeriodNotOver" ) ;
110+ }
111+
112+ // Advance by 6 days (still not enough)
113+ await this . advanceBySlots ( SLOTS_PER_DAY * 3n ) ;
114+
115+ try {
116+ await launchpadClient . completeLaunchIx ( launch , USDC , daoTreasury ) . preInstructions ( [ ComputeBudgetProgram . setComputeUnitPrice ( { microLamports : 1 } ) ] ) . rpc ( ) ;
117+ assert . fail ( "Should have thrown error" ) ;
118+ } catch ( e ) {
119+ assert . include ( e . message , "LaunchPeriodNotOver" ) ;
120+ }
121+ } ) ;
122+
123+ it ( "moves to refunding state when minimum raise is not met after period" , async function ( ) {
89124 // Fund the launch with less than minimum raise
90125 const userUsdcAccount = await this . createTokenAccount ( USDC , this . payer . publicKey ) ;
91126 const userTokenAccount = await this . createTokenAccount ( META , this . payer . publicKey ) ;
@@ -99,6 +134,9 @@ export default function suite() {
99134 META
100135 ) . rpc ( ) ;
101136
137+ // Advance clock past 7 days
138+ await this . advanceBySlots ( SLOTS_PER_DAY * 7n ) ;
139+
102140 // Complete the launch
103141 await launchpadClient . completeLaunchIx ( launch , USDC , daoTreasury ) . rpc ( ) ;
104142
@@ -110,6 +148,9 @@ export default function suite() {
110148 } ) ;
111149
112150 it ( "fails when launch is not in live state" , async function ( ) {
151+ // Advance clock past 7 days
152+ await this . advanceBySlots ( SLOTS_PER_DAY * 7n ) ;
153+
113154 // Complete launch first time
114155 await launchpadClient . completeLaunchIx ( launch , USDC , daoTreasury ) . rpc ( ) ;
115156
0 commit comments