1
1
# Table of Contents
2
+
3
+ - [ Init] ( #init )
4
+ - [ Emulator] ( #emulator )
5
+ - [ start] ( #emulator.start )
6
+ - [ stop] ( #emulator.stop )
2
7
- [ Accounts] ( #accounts )
3
- - [ getAccountAddress] ( #getaccountaddressname )
8
+ - [ getAccountAddress] ( #getaccountaddressname )
4
9
- [ Contracts] ( #contracts )
5
- - [ deployContractByName] ( #deploycontractbynameprops )
6
- - [ deployContract] ( #deploycontractbynameprops )
7
- - [ getContractAddress] ( #getcontractaddressname-usedefaults--false )
10
+ - [ deployContractByName] ( #deploycontractbynameprops )
11
+ - [ deployContract] ( #deploycontractbynameprops )
12
+ - [ getContractAddress] ( #getcontractaddressname-usedefaults--false )
8
13
- [ Cadence Code Templates] ( #cadence-code-templates )
9
- - [ getTemplate] ( #gettemplatefile-addressmap---byaddress--false )
10
- - [ getContractCode] ( #getcontractcodename-addressmap---service--false )
11
- - [ getTransactionCode] ( #gettransactioncodename-addressmap---service--false )
12
- - [ getScriptCode] ( #getscriptcodename-addressmap---service--false )
14
+ - [ getTemplate] ( #gettemplatefile-addressmap---byaddress--false )
15
+ - [ getContractCode] ( #getcontractcodename-addressmap---service--false )
16
+ - [ getTransactionCode] ( #gettransactioncodename-addressmap---service--false )
17
+ - [ getScriptCode] ( #getscriptcodename-addressmap---service--false )
13
18
- [ Send and Execute] ( #send-and-execute )
14
- - [ sendTransaction] ( #sendtransactionprops )
15
- - [ executeScript] ( #executescriptprops )
19
+ - [ sendTransaction] ( #sendtransactionprops )
20
+ - [ executeScript] ( #executescriptprops )
16
21
- [ FlowToken] ( #flowtoken )
17
- - [ getFlowBalance] ( #getflowbalanceaddress )
18
- - [ mintFlow] ( #mintflowrecipient-amount )
19
-
22
+ - [ getFlowBalance] ( #getflowbalanceaddress )
23
+ - [ mintFlow] ( #mintflowrecipient-amount )
24
+
20
25
---
21
26
27
+ ## Init
28
+
29
+ ### init(basePath, port)
30
+
31
+ Initializes framework variables and specifies port to use for HTTP and grpc access.
32
+ ` port ` is set to 8080 by default. grpc port is calculated to ` 3569 + (port - 8080) ` to allow multiple instances
33
+ of emulator to be run in parallel
34
+
35
+ - ` basePath ` - path to the folder, with Cadence template files
36
+ - ` port ` - http port to use for access node
37
+
38
+ ``` javascript
39
+ import path from " path" ;
40
+ import { init } from " js-testing-framework" ;
41
+
42
+ describe (" test setup" , () => {
43
+ beforeEach (async (done ) => {
44
+ const basePath = path .resolve (__dirname , " ../cadence" );
45
+ init (basePath);
46
+
47
+ // alternatively you can pass specific port
48
+ // init(basePath, 8085)
49
+
50
+ done ();
51
+ });
52
+ });
53
+ ```
54
+
55
+ ## Emulator
56
+
57
+ ### emulator.start
58
+
59
+ Starts emulator on specified port.
60
+
61
+ - ` port ` - number representing a port to use for access API
62
+ - ` logging ` - whether log messages from emulator shall be added to the output
63
+
64
+ ### emulator.stop
65
+
66
+ Stops emulator instance.
67
+
68
+ ``` javascript
69
+ describe (" test setup" , () => {
70
+ // Instantiate emulator and path to Cadence files
71
+ beforeEach (async (done ) => {
72
+ const basePath = path .resolve (__dirname , " ../cadence" );
73
+ const port = 8080 ;
74
+ init (basePath, port);
75
+ await emulator .start (port, false );
76
+ done ();
77
+ });
78
+
79
+ // Stop emulator, so it could be restarted
80
+ afterEach (async (done ) => {
81
+ await emulator .stop ();
82
+ done ();
83
+ });
84
+ });
85
+ ```
86
+
22
87
## Accounts
23
88
24
89
### getAccountAddress(name)
@@ -29,7 +94,7 @@ Next time when you call this method, it will grab exactly the same account. This
29
94
and then use them throughout your code, without worrying that accounts match or trying to store/handle specific addresses.
30
95
31
96
``` javascript
32
- import { getAccountAddress } from " flow-js-testing/dist " ;
97
+ import { getAccountAddress } from " flow-js-testing" ;
33
98
34
99
const main = async () => {
35
100
const Alice = await getAccountAddress (" Alice" );
@@ -58,7 +123,7 @@ Usage:
58
123
59
124
``` javascript
60
125
import path from " path" ;
61
- import { init , deployContractByName } from " flow-js-testing/dist " ;
126
+ import { init , deployContractByName } from " flow-js-testing" ;
62
127
63
128
const main = async () => {
64
129
init (path .resolve (__dirname , " ../cadence" ));
@@ -93,7 +158,7 @@ Usage:
93
158
94
159
``` javascript
95
160
import path from " path" ;
96
- import { deployContract } from " flow-js-testing/dist " ;
161
+ import { deployContract } from " flow-js-testing" ;
97
162
98
163
const main = async () => {
99
164
init (path .resolve (__dirname , " ../cadence" ));
@@ -133,7 +198,7 @@ Returns address of the account, where contract is currently deployed.
133
198
> Though if you don't pass second argument, you can override contracts deployed by default.
134
199
135
200
``` javascript
136
- import { getContractAddress } from " flow-js-testing/dist " ;
201
+ import { getContractAddress } from " flow-js-testing" ;
137
202
138
203
const main = async () => {
139
204
const contract = await getContractAddress (" HelloWorld" );
@@ -157,7 +222,7 @@ Returns Cadence template as string with addresses replaced using addressMap
157
222
158
223
``` javascript
159
224
import path from " path" ;
160
- import { init , getTemplate } from " flow-js-testing/dist " ;
225
+ import { init , getTemplate } from " flow-js-testing" ;
161
226
162
227
const main = async () => {
163
228
init (path .resolve (__dirname , " ../cadence" ));
@@ -178,7 +243,7 @@ Returns Cadence template from file with `name` in `_basepath/contracts` folder
178
243
179
244
``` javascript
180
245
import path from " path" ;
181
- import { init , getContractCode } from " flow-js-testing/dist " ;
246
+ import { init , getContractCode } from " flow-js-testing" ;
182
247
183
248
const main = async () => {
184
249
init (path .resolve (__dirname , " ../cadence" ));
@@ -206,7 +271,7 @@ Returns Cadence template from file with `name` in `_basepath/transactions` folde
206
271
207
272
``` javascript
208
273
import path from " path" ;
209
- import { init , getTransactionCode } from " flow-js-testing/dist " ;
274
+ import { init , getTransactionCode } from " flow-js-testing" ;
210
275
211
276
const main = async () => {
212
277
init (path .resolve (__dirname , " ../cadence" ));
@@ -235,7 +300,7 @@ Returns Cadence template from file with `name` in `_basepath/scripts` folder
235
300
236
301
``` javascript
237
302
import path from " path" ;
238
- import { init , getScriptCode } from " flow-js-testing/dist " ;
303
+ import { init , getScriptCode } from " flow-js-testing" ;
239
304
240
305
const main = async () => {
241
306
init (path .resolve (__dirname , " ../cadence" ));
@@ -259,12 +324,7 @@ If you don't have any contract dependencies, you can use those methods without s
259
324
260
325
``` javascript
261
326
import path from " path" ;
262
- import {
263
- init ,
264
- getContractCode ,
265
- getTransactionCode ,
266
- getScriptCode ,
267
- } from " flow-js-testing/dist" ;
327
+ import { init , getContractCode , getTransactionCode , getScriptCode } from " flow-js-testing" ;
268
328
269
329
const main = async () => {
270
330
init (path .resolve (__dirname , " ../cadence" ));
@@ -296,7 +356,7 @@ Usage:
296
356
297
357
``` javascript
298
358
import { Int , UFix64 } from " @onflow/types" ;
299
- import { deployContract } from " flow-js-testing/dist " ;
359
+ import { deployContract } from " flow-js-testing" ;
300
360
301
361
const main = async () => {
302
362
// Get signers adresses
@@ -349,7 +409,7 @@ Props object accepts following fields:
349
409
350
410
``` javascript
351
411
import { Int , UFix64 } from " @onflow/types" ;
352
- import { deployContract } from " flow-js-testing/dist " ;
412
+ import { deployContract } from " flow-js-testing" ;
353
413
354
414
const main = async () => {
355
415
// Read or create script code
@@ -396,7 +456,7 @@ Returns current FlowToken balance of account specified by address
396
456
Usage:
397
457
398
458
``` javascript
399
- import { getFlowBalance } from " flow-js-testing/dist " ;
459
+ import { getFlowBalance } from " flow-js-testing" ;
400
460
401
461
const main = async () => {
402
462
const Alice = await getAccountAddress (" Alice" );
@@ -420,7 +480,7 @@ Sends transaction to mint specified amount of FlowToken and send it to recipient
420
480
- ` amount ` - amount to mint and send
421
481
422
482
``` javascript
423
- import { mintFlow } from " flow-js-testing/dist " ;
483
+ import { mintFlow } from " flow-js-testing" ;
424
484
425
485
const main = async () => {
426
486
const Alice = await getAccountAddress (" Alice" );
@@ -434,4 +494,4 @@ const main = async () => {
434
494
};
435
495
436
496
main ();
437
- ```
497
+ ```
0 commit comments