1
1
import { BigNumber } from '@ethersproject/bignumber' ;
2
+ import { hexlify } from '@ethersproject/bytes' ;
2
3
3
- import { fAccount , fAssets , fNetworks } from '@fixtures' ;
4
+ import { fAccount , fAccounts , fAssets , fNetworks } from '@fixtures' ;
4
5
import { ITxStatus , ITxType } from '@types' ;
5
6
6
7
import { makeTxConfig , makeTxReceipt , possibleSolution } from './helpers' ;
7
8
import { ITxFaucetResult } from './types' ;
8
9
9
- const exampleTXResult = {
10
+ const exampleTXResultV1 = {
10
11
chainId : 3 ,
11
12
data : '0x' ,
12
13
from : '0xa500B2427458D12Ef70dd7b1E031ef99d1cc09f7' ,
@@ -19,6 +20,20 @@ const exampleTXResult = {
19
20
value : '1'
20
21
} as ITxFaucetResult ;
21
22
23
+ const exampleTXResultV2 = {
24
+ chainId : 3 ,
25
+ data : '0x' ,
26
+ from : '0xa500B2427458D12Ef70dd7b1E031ef99d1cc09f7' ,
27
+ gasLimit : '21000' ,
28
+ maxFeePerGas : '1000000000' ,
29
+ maxPriorityFeePerGas : '1000000000' ,
30
+ hash : '0x5049c0847681402db2c303847f2f66ac7f3a6caf63119b676374d5781b8d11e9' ,
31
+ network : 'ropsten' ,
32
+ nonce : 39 ,
33
+ to : fAccount . address ,
34
+ value : '1'
35
+ } as ITxFaucetResult ;
36
+
22
37
describe ( 'Faucet helpers' , ( ) => {
23
38
describe ( 'Captcha solution regex' , ( ) => {
24
39
test ( 'AbC0 should be a valid solution' , ( ) => {
@@ -31,9 +46,15 @@ describe('Faucet helpers', () => {
31
46
32
47
describe ( 'makeTxConfig' , ( ) => {
33
48
const getContactByAddressAndNetworkId = jest . fn ( ) ;
34
- test ( 'returns expected value' , async ( ) => {
49
+ test ( 'returns expected value for type 1 tx ' , async ( ) => {
35
50
expect (
36
- makeTxConfig ( exampleTXResult , fNetworks , fAssets , getContactByAddressAndNetworkId )
51
+ makeTxConfig (
52
+ exampleTXResultV1 ,
53
+ fNetworks ,
54
+ fAssets ,
55
+ fAccounts ,
56
+ getContactByAddressAndNetworkId
57
+ )
37
58
) . toEqual ( {
38
59
amount : '0.000000000000000001' ,
39
60
asset : fAssets [ 1 ] ,
@@ -44,11 +65,43 @@ describe('Faucet helpers', () => {
44
65
chainId : 3 ,
45
66
data : '0x' ,
46
67
from : '0xa500B2427458D12Ef70dd7b1E031ef99d1cc09f7' ,
47
- gasLimit : ' 21000' ,
48
- gasPrice : ' 1000000000' ,
49
- nonce : '39' ,
68
+ gasLimit : hexlify ( 21000 ) ,
69
+ gasPrice : hexlify ( 1000000000 ) ,
70
+ nonce : hexlify ( 39 ) ,
50
71
to : fAccount . address ,
51
- value : '1'
72
+ type : 0 ,
73
+ value : hexlify ( 1 )
74
+ } ,
75
+ receiverAddress : fAccount . address ,
76
+ senderAccount : undefined
77
+ } ) ;
78
+ } ) ;
79
+ test ( 'returns expected value for type 2 tx' , async ( ) => {
80
+ expect (
81
+ makeTxConfig (
82
+ exampleTXResultV2 ,
83
+ fNetworks ,
84
+ fAssets ,
85
+ fAccounts ,
86
+ getContactByAddressAndNetworkId
87
+ )
88
+ ) . toEqual ( {
89
+ amount : '0.000000000000000001' ,
90
+ asset : fAssets [ 1 ] ,
91
+ baseAsset : fAssets [ 1 ] ,
92
+ from : '0xa500B2427458D12Ef70dd7b1E031ef99d1cc09f7' ,
93
+ networkId : 'Ropsten' ,
94
+ rawTransaction : {
95
+ chainId : 3 ,
96
+ data : '0x' ,
97
+ from : '0xa500B2427458D12Ef70dd7b1E031ef99d1cc09f7' ,
98
+ gasLimit : hexlify ( 21000 ) ,
99
+ maxFeePerGas : hexlify ( 1000000000 ) ,
100
+ maxPriorityFeePerGas : hexlify ( 1000000000 ) ,
101
+ type : 2 ,
102
+ nonce : hexlify ( 39 ) ,
103
+ to : fAccount . address ,
104
+ value : hexlify ( 1 )
52
105
} ,
53
106
receiverAddress : fAccount . address ,
54
107
senderAccount : undefined
@@ -57,8 +110,17 @@ describe('Faucet helpers', () => {
57
110
} ) ;
58
111
59
112
describe ( 'makeTxReceipt' , ( ) => {
60
- test ( 'returns expected value' , async ( ) => {
61
- expect ( makeTxReceipt ( exampleTXResult , fNetworks , fAssets ) ) . toEqual ( {
113
+ const getContactByAddressAndNetworkId = jest . fn ( ) ;
114
+
115
+ test ( 'returns expected value for type 1 tx' , async ( ) => {
116
+ const txConfig = makeTxConfig (
117
+ exampleTXResultV1 ,
118
+ fNetworks ,
119
+ fAssets ,
120
+ fAccounts ,
121
+ getContactByAddressAndNetworkId
122
+ ) ;
123
+ expect ( makeTxReceipt ( exampleTXResultV1 , txConfig ) ) . toEqual ( {
62
124
amount : '0.000000000000000001' ,
63
125
asset : fAssets [ 1 ] ,
64
126
baseAsset : fAssets [ 1 ] ,
@@ -70,6 +132,39 @@ describe('Faucet helpers', () => {
70
132
nonce : BigNumber . from ( 39 ) ,
71
133
receiverAddress : fAccount . address ,
72
134
status : ITxStatus . PENDING ,
135
+ blockNumber : 0 ,
136
+ timestamp : 0 ,
137
+ metadata : undefined ,
138
+ to : fAccount . address ,
139
+ txType : ITxType . FAUCET ,
140
+ value : BigNumber . from ( '1' )
141
+ } ) ;
142
+ } ) ;
143
+ test ( 'returns expected value for type 2 tx' , async ( ) => {
144
+ const txConfig = makeTxConfig (
145
+ exampleTXResultV2 ,
146
+ fNetworks ,
147
+ fAssets ,
148
+ fAccounts ,
149
+ getContactByAddressAndNetworkId
150
+ ) ;
151
+ expect ( makeTxReceipt ( exampleTXResultV2 , txConfig ) ) . toEqual ( {
152
+ amount : '0.000000000000000001' ,
153
+ asset : fAssets [ 1 ] ,
154
+ baseAsset : fAssets [ 1 ] ,
155
+ data : '0x' ,
156
+ from : '0xa500B2427458D12Ef70dd7b1E031ef99d1cc09f7' ,
157
+ gasLimit : BigNumber . from ( 21000 ) ,
158
+ maxFeePerGas : BigNumber . from ( 1000000000 ) ,
159
+ maxPriorityFeePerGas : BigNumber . from ( 1000000000 ) ,
160
+ type : 2 ,
161
+ hash : '0x5049c0847681402db2c303847f2f66ac7f3a6caf63119b676374d5781b8d11e9' ,
162
+ nonce : BigNumber . from ( 39 ) ,
163
+ receiverAddress : fAccount . address ,
164
+ status : ITxStatus . PENDING ,
165
+ blockNumber : 0 ,
166
+ timestamp : 0 ,
167
+ metadata : undefined ,
73
168
to : fAccount . address ,
74
169
txType : ITxType . FAUCET ,
75
170
value : BigNumber . from ( '1' )
0 commit comments