11//
22// This script executes when you run 'yarn test'
33//
4- import { ethers , network } from "hardhat" ;
4+ import { network } from "hardhat" ;
55import { expect } from "chai" ;
6- import { FundingRecipient , CrowdFund } from "../typechain- types" ;
6+ import type { FundingRecipient , CrowdFund } from "../types/ethers-contracts/index.js " ;
77
88describe ( "🚩 Challenge: 📣 Crowdfunding App" , function ( ) {
9+ let ethers : Awaited < ReturnType < typeof network . create > > [ "ethers" ] ;
10+ let provider : Awaited < ReturnType < typeof network . create > > [ "provider" ] ;
11+
912 let fundingRecipient : FundingRecipient ;
1013 let crowdFundContract : CrowdFund ;
1114
15+ before ( async function ( ) {
16+ ( { ethers, provider } = await network . create ( ) ) ;
17+ } ) ;
18+
1219 describe ( "CrowdFund" , function ( ) {
1320 const contractAddress = process . env . CONTRACT_ADDRESS ;
1421
@@ -22,10 +29,10 @@ describe("🚩 Challenge: 📣 Crowdfunding App", function () {
2229
2330 const deployContracts = async ( ) => {
2431 const FundingRecipientFactory = await ethers . getContractFactory ( "FundingRecipient" ) ;
25- fundingRecipient = ( await FundingRecipientFactory . deploy ( ) ) as FundingRecipient ;
32+ fundingRecipient = ( await FundingRecipientFactory . deploy ( ) ) as unknown as FundingRecipient ;
2633
2734 const CrowdFundFactory = await ethers . getContractFactory ( contractArtifact ) ;
28- crowdFundContract = ( await CrowdFundFactory . deploy ( await fundingRecipient . getAddress ( ) ) ) as CrowdFund ;
35+ crowdFundContract = ( await CrowdFundFactory . deploy ( await fundingRecipient . getAddress ( ) ) ) as unknown as CrowdFund ;
2936 } ;
3037
3138 describe ( "Checkpoint 1: 🤝 Contributing 💵" , function ( ) {
@@ -139,7 +146,7 @@ describe("🚩 Challenge: 📣 Crowdfunding App", function () {
139146
140147 const writeStorageAt = async ( slot : bigint , value : string ) => {
141148 const slotHex = ethers . zeroPadValue ( ethers . toBeHex ( slot ) , 32 ) ;
142- await network . provider . send ( "hardhat_setStorageAt" , [ target , slotHex , value ] ) ;
149+ await provider . request ( { method : "hardhat_setStorageAt" , params : [ target , slotHex , value ] } ) ;
143150 } ;
144151
145152 const hexToBytes32 = ( hex : string ) => {
@@ -265,8 +272,8 @@ describe("🚩 Challenge: 📣 Crowdfunding App", function () {
265272 const t1 = await crowdFundContract . timeLeft ( ) ;
266273 expect ( Number ( t1 ) ) . to . be . greaterThan ( 0 ) ;
267274
268- await network . provider . send ( "evm_increaseTime" , [ 5 ] ) ;
269- await network . provider . send ( "evm_mine" ) ;
275+ await provider . request ( { method : "evm_increaseTime" , params : [ 5 ] } ) ;
276+ await provider . request ( { method : "evm_mine" } ) ;
270277
271278 const t2 = await crowdFundContract . timeLeft ( ) ;
272279 expect ( Number ( t2 ) ) . to . be . lessThan ( Number ( t1 ) ) ;
@@ -283,8 +290,8 @@ describe("🚩 Challenge: 📣 Crowdfunding App", function () {
283290 const amount = ethers . parseEther ( "1" ) ;
284291 await crowdFundContract . contribute ( { value : amount } ) ;
285292
286- await network . provider . send ( "evm_increaseTime" , [ 72 * 3600 ] ) ;
287- await network . provider . send ( "evm_mine" ) ;
293+ await provider . request ( { method : "evm_increaseTime" , params : [ 72 * 3600 ] } ) ;
294+ await provider . request ( { method : "evm_mine" } ) ;
288295
289296 const timeLeft2 = await crowdFundContract . timeLeft ( ) ;
290297 expect (
@@ -316,8 +323,8 @@ describe("🚩 Challenge: 📣 Crowdfunding App", function () {
316323 value : ethers . parseEther ( "0.001" ) ,
317324 } ) ;
318325
319- await network . provider . send ( "evm_increaseTime" , [ 72 * 3600 ] ) ;
320- await network . provider . send ( "evm_mine" ) ;
326+ await provider . request ( { method : "evm_increaseTime" , params : [ 72 * 3600 ] } ) ;
327+ await provider . request ( { method : "evm_mine" } ) ;
321328
322329 await crowdFundContract . execute ( ) ;
323330
0 commit comments