@@ -5,48 +5,30 @@ Module that runs up as a user
5
5
/* eslint-disable no-await-in-loop */
6
6
/* eslint no-constant-condition: ["error", { "checkLoops": false } ] */
7
7
8
- import logger from 'common-files/utils/logger.mjs' ;
8
+ // import logger from 'common-files/utils/logger.mjs';
9
9
import config from 'config' ;
10
- import inquirer from 'inquirer' ;
11
10
import Nf3 from '../../../../cli/lib/nf3.mjs' ;
12
- import waitForSufficientBalance from './utils.mjs' ;
11
+ import { waitForSufficientBalance , retrieveL2Balance } from './utils.mjs' ;
13
12
14
13
const {
15
14
zkpMnemonic,
16
- userEthereumSigningKey ,
15
+ user1EthereumSigningKey ,
17
16
optimistWsUrl,
18
17
web3WsUrl,
19
18
clientBaseUrl,
20
19
optimistBaseUrl,
21
20
TRANSACTIONS_PER_BLOCK ,
22
21
} = config ;
23
22
24
- /**
25
- Asks CLI questions
26
- */
27
- async function promptUser ( ) {
28
- return new Promise ( resolve => {
29
- setTimeout ( function ( ) {
30
- resolve ( true ) ;
31
- } , 10000 ) ;
32
- resolve (
33
- inquirer . prompt ( [
34
- {
35
- name : 'isContinue' ,
36
- type : 'confirm' ,
37
- message : 'Continue the test' ,
38
- default : true ,
39
- } ,
40
- ] ) ,
41
- ) ;
42
- } ) ;
43
- }
23
+ const TEST_LENGTH = 1 ;
24
+ const recipientPkd = process . env . RECIPIENT_PKD . split ( ',' ) ;
44
25
45
26
/**
46
27
Does the preliminary setup and starts listening on the websocket
47
28
*/
48
29
async function localTest ( ) {
49
- logger . info ( 'Starting local test...' ) ;
30
+ // logger.info('Starting local test...');
31
+ console . log ( 'Starting local test...' ) ;
50
32
51
33
const tokenType = 'ERC20' ;
52
34
const value = 1 ;
@@ -56,46 +38,39 @@ async function localTest() {
56
38
optimistBaseUrl ,
57
39
optimistWsUrl ,
58
40
web3WsUrl ,
59
- userEthereumSigningKey ,
41
+ user1EthereumSigningKey ,
60
42
) ;
61
43
62
44
await nf3 . init ( zkpMnemonic ) ;
63
- if ( await nf3 . healthcheck ( 'client' ) ) logger . info ( 'Healthcheck passed' ) ;
45
+ if ( await nf3 . healthcheck ( 'client' ) ) console . log ( 'Healthcheck passed' ) ;
64
46
else throw new Error ( 'Healthcheck failed' ) ;
65
47
66
- const ercAddress = await nf3 . getContractAddress ( 'ERC20Mock' ) ; // TODO use proper mock contracts
67
- const startBalance = await nf3 . getLayer2Balances ( ) ;
68
-
48
+ const ercAddress = await nf3 . getContractAddress ( 'ERC20Mock1' ) ;
49
+ const startBalance = await retrieveL2Balance ( nf3 ) ;
69
50
console . log ( 'HERE startBalance' , startBalance ) ;
70
51
71
52
// To start with create a block of deposits such that, we do a transfer in the next block
72
53
for ( let i = 0 ; i < TRANSACTIONS_PER_BLOCK ; i ++ ) {
73
54
await nf3 . deposit ( ercAddress , tokenType , value , tokenId ) ;
74
55
}
75
56
76
- while ( true ) {
77
- const { isContinue } = await promptUser ( ) ;
78
- if ( isContinue ) {
79
- for ( let j = 0 ; j < TRANSACTIONS_PER_BLOCK ; j ++ ) {
80
- // ensure there is sufficient balance for transfer.
81
- // this function relies on a prior deposit of
82
- // similar value being made
83
- await waitForSufficientBalance ( nf3 , value ) ;
84
- await nf3 . transfer ( false , ercAddress , tokenType , value , tokenId , nf3 . zkpKeys . pkd ) ;
85
- await new Promise ( resolve => setTimeout ( resolve , 20000 ) ) ;
86
- }
87
- } else break ;
57
+ for ( let i = 0 ; i < TEST_LENGTH ; i ++ ) {
58
+ await waitForSufficientBalance ( nf3 , value ) ;
59
+ await nf3 . transfer ( false , ercAddress , tokenType , value , tokenId , recipientPkd ) ;
60
+ await nf3 . deposit ( ercAddress , tokenType , value , tokenId ) ;
61
+ await new Promise ( resolve => setTimeout ( resolve , 20000 ) ) ;
88
62
}
89
63
90
- const endBalance = await nf3 . getLayer2Balances ( ) ;
64
+ const endBalance = await retrieveL2Balance ( nf3 ) ;
91
65
console . log ( 'HERE endBalance' , endBalance ) ;
92
66
93
- if ( Object . keys ( startBalance ) . length >= Object . keys ( endBalance ) . length ) {
94
- logger . warn ( 'The test failed because the L2 balance has not increased' ) ;
67
+ if ( endBalance - startBalance === 2 * value ) {
68
+ console . log ( 'Test passed' ) ;
69
+ nf3 . close ( ) ;
70
+ } else {
71
+ console . log ( 'The test failed because the L2 balance has not increased' ) ;
95
72
process . exit ( 1 ) ;
96
73
}
97
- logger . info ( 'Test passed' ) ;
98
- nf3 . close ( ) ;
99
74
}
100
75
101
76
localTest ( ) ;
0 commit comments