11/* eslint-disable */
2- import { Artifact , Contract , SignatureTemplate , Transaction , Unlocker } from 'cashscript' ;
2+ import { Artifact , Contract , MockNetworkProvider , SignatureTemplate , Transaction , Unlocker } from 'cashscript' ;
33import p2pkhArtifact from '../fixture/p2pkh.artifact' ;
44import p2pkhArtifactJsonNotConst from '../fixture/p2pkh.json' with { type : 'json' } ;
55import announcementArtifact from '../fixture/announcement.artifact' ;
@@ -32,41 +32,48 @@ interface ManualArtifactType extends Artifact {
3232 ]
3333}
3434
35+ // Create a MockNetworkProvider for the tests
36+ const provider = new MockNetworkProvider ( ) ;
37+
3538// describe('P2PKH contract | single constructor input | single function (2 args)')
3639{
3740 // describe('Constructor arguments')
3841 {
3942 // it('should not give type errors when using correct constructor inputs')
40- new Contract ( p2pkhArtifact , [ alicePkh ] ) ;
41- new Contract ( p2pkhArtifact , [ binToHex ( alicePkh ) ] ) ;
43+ new Contract ( p2pkhArtifact , [ alicePkh ] , { provider } ) ;
44+ new Contract ( p2pkhArtifact , [ binToHex ( alicePkh ) ] , { provider } ) ;
4245
4346 // it('should give type errors when using empty constructor inputs')
4447 // @ts -expect-error
45- new Contract ( p2pkhArtifact , [ ] ) ;
48+ new Contract ( p2pkhArtifact , [ ] , { provider } ) ;
4649
4750 // it('should give type errors when using incorrect constructor input type')
4851 // @ts -expect-error
49- new Contract ( p2pkhArtifact , [ 1000n ] ) ;
52+ new Contract ( p2pkhArtifact , [ 1000n ] , { provider } ) ;
5053
5154 // it('should give type errors when using incorrect constructor input length')
5255 // @ts -expect-error
53- new Contract ( p2pkhArtifact , [ alicePkh , 1000n ] ) ;
56+ new Contract ( p2pkhArtifact , [ alicePkh , 1000n ] , { provider } ) ;
5457
5558 // it('should not perform type checking when cast to any')
56- new Contract ( p2pkhArtifact as any , [ alicePkh , 1000n ] ) ;
59+ new Contract ( p2pkhArtifact as any , [ alicePkh , 1000n ] , { provider } ) ;
5760
5861 // it('should not perform type checking when cannot infer type')
5962 // Note: would be very nice if it *could* infer the type from static json
60- new Contract ( p2pkhArtifactJsonNotConst , [ alicePkh , 1000n ] ) ;
63+ new Contract ( p2pkhArtifactJsonNotConst , [ alicePkh , 1000n ] , { provider } ) ;
6164
6265 // it('should perform type checking when manually specifying a type
6366 // @ts -expect-error
64- new Contract < ManualArtifactType > ( p2pkhArtifactJsonNotConst as any , [ alicePkh , 1000n ] ) ;
67+ new Contract < ManualArtifactType > ( p2pkhArtifactJsonNotConst as any , [ alicePkh , 1000n ] , { provider } ) ;
68+
69+ // it('requires a provider to be passed')
70+ // @ts -expect-error
71+ new Contract ( p2pkhArtifact , [ alicePkh ] ) ;
6572 }
6673
6774 // describe('Contract unlockers')
6875 {
69- const contract = new Contract ( p2pkhArtifact , [ alicePkh ] ) ;
76+ const contract = new Contract ( p2pkhArtifact , [ alicePkh ] , { provider } ) ;
7077
7178 // it('should not give type errors when using correct function inputs')
7279 contract . unlock . spend ( alicePub , new SignatureTemplate ( alicePriv ) ) ;
@@ -86,14 +93,14 @@ interface ManualArtifactType extends Artifact {
8693 contract . unlock . spend ( alicePub ) ;
8794
8895 // it('should not perform type checking when cast to any')
89- const contractAsAny = new Contract ( p2pkhArtifact as any , [ alicePkh , 1000n ] ) ;
96+ const contractAsAny = new Contract ( p2pkhArtifact as any , [ alicePkh , 1000n ] , { provider } ) ;
9097 contractAsAny . unlock . notAFunction ( ) ;
9198 contractAsAny . unlock . spend ( ) ;
9299 contractAsAny . unlock . spend ( 1000n , true ) ;
93100
94101 // it('should not perform type checking when cannot infer type')
95102 // Note: would be very nice if it *could* infer the type from static json
96- const contractFromUnknown = new Contract ( p2pkhArtifactJsonNotConst , [ alicePkh , 1000n ] ) ;
103+ const contractFromUnknown = new Contract ( p2pkhArtifactJsonNotConst , [ alicePkh , 1000n ] , { provider } ) ;
97104 contractFromUnknown . unlock . notAFunction ( ) ;
98105 contractFromUnknown . unlock . spend ( ) ;
99106 contractFromUnknown . unlock . spend ( 1000n , true ) ;
@@ -109,7 +116,7 @@ interface ManualArtifactType extends Artifact {
109116
110117 // describe('Contract functions')
111118 {
112- const contract = new Contract ( p2pkhArtifact , [ alicePkh ] ) ;
119+ const contract = new Contract ( p2pkhArtifact , [ alicePkh ] , { provider } ) ;
113120
114121 // it('should not give type errors when using correct function inputs')
115122 contract . functions . spend ( alicePub , new SignatureTemplate ( alicePriv ) ) . build ( ) ;
@@ -129,14 +136,14 @@ interface ManualArtifactType extends Artifact {
129136 contract . functions . spend ( alicePub ) ;
130137
131138 // it('should not perform type checking when cast to any')
132- const contractAsAny = new Contract ( p2pkhArtifact as any , [ alicePkh , 1000n ] ) ;
139+ const contractAsAny = new Contract ( p2pkhArtifact as any , [ alicePkh , 1000n ] , { provider } ) ;
133140 contractAsAny . functions . notAFunction ( ) . build ( ) ;
134141 contractAsAny . functions . spend ( ) ;
135142 contractAsAny . functions . spend ( 1000n , true ) ;
136143
137144 // it('should not perform type checking when cannot infer type')
138145 // Note: would be very nice if it *could* infer the type from static json
139- const contractFromUnknown = new Contract ( p2pkhArtifactJsonNotConst , [ alicePkh , 1000n ] ) ;
146+ const contractFromUnknown = new Contract ( p2pkhArtifactJsonNotConst , [ alicePkh , 1000n ] , { provider } ) ;
140147 contractFromUnknown . functions . notAFunction ( ) . build ( ) ;
141148 contractFromUnknown . functions . spend ( ) ;
142149 contractFromUnknown . functions . spend ( 1000n , true ) ;
@@ -152,7 +159,7 @@ interface ManualArtifactType extends Artifact {
152159
153160 // describe('Contract unlockers')
154161 {
155- const contract = new Contract ( p2pkhArtifact , [ alicePkh ] ) ;
162+ const contract = new Contract ( p2pkhArtifact , [ alicePkh ] , { provider } ) ;
156163
157164 // it('should not give type errors when using correct function inputs')
158165 contract . unlock . spend ( alicePub , new SignatureTemplate ( alicePriv ) ) . generateLockingBytecode ( ) ;
@@ -172,14 +179,14 @@ interface ManualArtifactType extends Artifact {
172179 contract . unlock . spend ( alicePub ) ;
173180
174181 // it('should not perform type checking when cast to any')
175- const contractAsAny = new Contract ( p2pkhArtifact as any , [ alicePkh , 1000n ] ) ;
182+ const contractAsAny = new Contract ( p2pkhArtifact as any , [ alicePkh , 1000n ] , { provider } ) ;
176183 contractAsAny . unlock . notAFunction ( ) . generateLockingBytecode ( ) ;
177184 contractAsAny . unlock . spend ( ) ;
178185 contractAsAny . unlock . spend ( 1000n , true ) ;
179186
180187 // it('should not perform type checking when cannot infer type')
181188 // Note: would be very nice if it *could* infer the type from static json
182- const contractFromUnknown = new Contract ( p2pkhArtifactJsonNotConst , [ alicePkh , 1000n ] ) ;
189+ const contractFromUnknown = new Contract ( p2pkhArtifactJsonNotConst , [ alicePkh , 1000n ] , { provider } ) ;
183190 contractFromUnknown . unlock . notAFunction ( ) . generateLockingBytecode ( ) ;
184191 contractFromUnknown . unlock . spend ( ) ;
185192 contractFromUnknown . unlock . spend ( 1000n , true ) ;
@@ -199,21 +206,21 @@ interface ManualArtifactType extends Artifact {
199206 // describe('Constructor arguments')
200207 {
201208 // it('should not give type errors when using correct constructor inputs')
202- new Contract ( announcementArtifact , [ ] ) ;
209+ new Contract ( announcementArtifact , [ ] , { provider } ) ;
203210
204211 // it('should give type errors when using incorrect constructor input length')
205212 // @ts -expect-error
206- new Contract ( announcementArtifact , [ 1000n ] ) ;
213+ new Contract ( announcementArtifact , [ 1000n ] , { provider } ) ;
207214
208215 // it('should give type errors when passing in completely incorrect type')
209216 // @ts -expect-error
210- new Contract ( announcementArtifact , 'hello' ) ;
217+ new Contract ( announcementArtifact , 'hello' , { provider } ) ;
211218 }
212219
213220 // describe('Contract unlockers')
214221 {
215222 // it('should not give type errors when using correct function inputs')
216- const contract = new Contract ( announcementArtifact , [ ] ) ;
223+ const contract = new Contract ( announcementArtifact , [ ] , { provider } ) ;
217224
218225 // it('should not give type errors when using correct function inputs')
219226 contract . unlock . announce ( ) ;
@@ -230,7 +237,7 @@ interface ManualArtifactType extends Artifact {
230237 // describe('Contract functions')
231238 {
232239 // it('should not give type errors when using correct function inputs')
233- const contract = new Contract ( announcementArtifact , [ ] ) ;
240+ const contract = new Contract ( announcementArtifact , [ ] , { provider } ) ;
234241
235242 // it('should not give type errors when using correct function inputs')
236243 contract . functions . announce ( ) ;
@@ -250,17 +257,17 @@ interface ManualArtifactType extends Artifact {
250257 // describe('Constructor arguments')
251258 {
252259 // it('should not give type errors when using correct constructor inputs')
253- new Contract ( hodlVaultArtifact , [ alicePub , binToHex ( oraclePub ) , 1000n , 1000n ] ) ;
260+ new Contract ( hodlVaultArtifact , [ alicePub , binToHex ( oraclePub ) , 1000n , 1000n ] , { provider } ) ;
254261
255262 // it('should give type errors when using too few constructor inputs')
256263 // @ts -expect-error
257- new Contract ( hodlVaultArtifact , [ alicePub , binToHex ( oraclePub ) ] ) ;
264+ new Contract ( hodlVaultArtifact , [ alicePub , binToHex ( oraclePub ) ] , { provider } ) ;
258265
259266 // it('should give type errors when using incorrect constructor input type')
260267 // @ts -expect-error
261- new Contract ( hodlVaultArtifact , [ alicePub , binToHex ( oraclePub ) , 1000n , 'hello' ] ) ;
268+ new Contract ( hodlVaultArtifact , [ alicePub , binToHex ( oraclePub ) , 1000n , 'hello' ] , { provider } ) ;
262269 // @ts -expect-error
263- new Contract ( hodlVaultArtifact , [ alicePub , binToHex ( oraclePub ) , true , 1000n ] ) ;
270+ new Contract ( hodlVaultArtifact , [ alicePub , binToHex ( oraclePub ) , true , 1000n ] , { provider } ) ;
264271 }
265272}
266273
@@ -270,12 +277,12 @@ interface ManualArtifactType extends Artifact {
270277 // describe('Constructor arguments')
271278 {
272279 // it('should not give type errors when using correct constructor inputs')
273- new Contract ( transferWithTimeoutArtifact , [ alicePub , bobPub , 100_000n ] ) ;
280+ new Contract ( transferWithTimeoutArtifact , [ alicePub , bobPub , 100_000n ] , { provider } ) ;
274281 }
275282
276283 // describe('Contract unlockers')
277284 {
278- const contract = new Contract ( transferWithTimeoutArtifact , [ alicePub , bobPub , 100_000n ] ) ;
285+ const contract = new Contract ( transferWithTimeoutArtifact , [ alicePub , bobPub , 100_000n ] , { provider } ) ;
279286
280287 // it('should not give type errors when using correct function inputs')
281288 contract . unlock . transfer ( new SignatureTemplate ( alicePriv ) ) ;
@@ -300,7 +307,7 @@ interface ManualArtifactType extends Artifact {
300307
301308 // describe('Contract functions')
302309 {
303- const contract = new Contract ( transferWithTimeoutArtifact , [ alicePub , bobPub , 100_000n ] ) ;
310+ const contract = new Contract ( transferWithTimeoutArtifact , [ alicePub , bobPub , 100_000n ] , { provider } ) ;
304311
305312 // it('should not give type errors when using correct function inputs')
306313 contract . functions . transfer ( new SignatureTemplate ( alicePriv ) ) ;
0 commit comments