@@ -8,32 +8,17 @@ package e2etest
8
8
9
9
import (
10
10
"context"
11
- "encoding/hex"
12
- "fmt"
13
11
"io/ioutil"
14
- "math/big"
15
12
"os"
16
13
"testing"
17
14
"time"
18
15
19
16
"github.com/iotexproject/iotex-core/test/identityset"
20
17
21
- "github.com/pkg/errors"
22
- "github.com/stretchr/testify/assert"
23
- "github.com/stretchr/testify/require"
24
- "go.uber.org/zap"
25
-
26
- "github.com/iotexproject/iotex-address/address"
27
- "github.com/iotexproject/iotex-core/action"
28
18
"github.com/iotexproject/iotex-core/config"
29
- exp "github.com/iotexproject/iotex-core/explorer"
30
- "github.com/iotexproject/iotex-core/explorer/idl/explorer"
31
- "github.com/iotexproject/iotex-core/pkg/enc"
32
- "github.com/iotexproject/iotex-core/pkg/keypair"
33
- "github.com/iotexproject/iotex-core/pkg/log"
34
- "github.com/iotexproject/iotex-core/pkg/unit"
35
19
"github.com/iotexproject/iotex-core/server/itx"
36
20
"github.com/iotexproject/iotex-core/testutil"
21
+ "github.com/stretchr/testify/require"
37
22
)
38
23
39
24
func TestTwoChains (t * testing.T ) {
@@ -65,140 +50,14 @@ func TestTwoChains(t *testing.T) {
65
50
require .NoError (t , svr .Stop (ctx ))
66
51
}()
67
52
68
- sk1 , err := keypair .HexStringToPrivateKey (cfg .Chain .ProducerPrivKey )
69
- require .NoError (t , err )
70
- addr1 , err := address .FromBytes (sk1 .PublicKey ().Hash ())
71
- require .NoError (t , err )
72
- sk2 , err := keypair .HexStringToPrivateKey ("82a1556b2dbd0e3615e367edf5d3b90ce04346ec4d12ed71f67c70920ef9ac90" )
73
53
require .NoError (t , err )
74
- addr2 , err := address .FromBytes (sk2 .PublicKey ().Hash ())
75
- require .NoError (t , err )
76
-
77
- mainChainClient := exp .NewExplorerProxy (
78
- fmt .Sprintf ("http://127.0.0.1:%d" , svr .ChainService (cfg .Chain .ID ).Explorer ().Port ()),
79
- )
80
54
81
55
require .NoError (t , testutil .WaitUntil (time .Second , 20 * time .Second , func () (bool , error ) {
82
56
return svr .ChainService (2 ) != nil , nil
83
57
}))
84
58
85
- require .NoError (t , testutil .WaitUntil (time .Second , 10 * time .Second , func () (bool , error ) {
86
- balanceStr , err := mainChainClient .GetAddressBalance (addr1 .String ())
87
- if err != nil {
88
- return false , err
89
- }
90
- balance , ok := big .NewInt (0 ).SetString (balanceStr , 10 )
91
- if ! ok {
92
- return false , errors .New ("error when converting balance string to big int" )
93
- }
94
- if balance .Cmp (big .NewInt (0 ).Mul (big .NewInt (1 ), big .NewInt (unit .Iotx ))) < 0 {
95
- log .L ().Info ("Balance is not enough yet." , zap .String ("balance" , balance .String ()))
96
- return false , nil
97
- }
98
- log .L ().Info ("Balance is already enough." , zap .String ("balance" , balance .String ()))
99
- return true , nil
100
- }))
101
-
102
59
require .NoError (t , testutil .WaitUntil (time .Second , 20 * time .Second , func () (bool , error ) {
103
60
return svr .ChainService (2 ) != nil , nil
104
61
}))
105
62
106
- details , err := mainChainClient .GetAddressDetails (addr1 .String ())
107
- require .NoError (t , err )
108
- createDeposit := action .NewCreateDeposit (
109
- uint64 (details .Nonce )+ 1 ,
110
- 2 ,
111
- big .NewInt (0 ).Mul (big .NewInt (1 ), big .NewInt (unit .Iotx )),
112
- addr2 .String (),
113
- testutil .TestGasLimit ,
114
- big .NewInt (0 ),
115
- )
116
- bd := & action.EnvelopeBuilder {}
117
- elp := bd .SetAction (createDeposit ).
118
- SetNonce (uint64 (details .Nonce ) + 1 ).
119
- SetGasLimit (testutil .TestGasLimit ).Build ()
120
- selp , err := action .Sign (elp , sk1 )
121
- require .NoError (t , err )
122
-
123
- createRes , err := mainChainClient .CreateDeposit (explorer.CreateDepositRequest {
124
- Version : int64 (createDeposit .Version ()),
125
- Nonce : int64 (createDeposit .Nonce ()),
126
- ChainID : int64 (createDeposit .ChainID ()),
127
- SenderPubKey : createDeposit .SenderPublicKey ().HexString (),
128
- Recipient : createDeposit .Recipient (),
129
- Amount : createDeposit .Amount ().String (),
130
- Signature : hex .EncodeToString (selp .Signature ()),
131
- GasLimit : int64 (createDeposit .GasLimit ()),
132
- GasPrice : createDeposit .GasPrice ().String (),
133
- })
134
- require .NoError (t , err )
135
-
136
- require .NoError (t , testutil .WaitUntil (time .Second , 20 * time .Second , func () (bool , error ) {
137
- _ , err := mainChainClient .GetReceiptByExecutionID (createRes .Hash )
138
- return err == nil , nil
139
- }))
140
-
141
- cd1 , err := mainChainClient .GetCreateDeposit (createRes .Hash )
142
- require .NoError (t , err )
143
- cds , err := mainChainClient .GetCreateDepositsByAddress (addr1 .String (), 0 , 1 )
144
- require .NoError (t , err )
145
- require .Equal (t , 1 , len (cds ))
146
- assert .Equal (t , cd1 , cds [0 ])
147
-
148
- receipt , err := mainChainClient .GetReceiptByExecutionID (createRes .Hash )
149
- require .NoError (t , err )
150
- value , err := hex .DecodeString (receipt .ReturnValue )
151
- require .NoError (t , err )
152
- index := enc .MachineEndian .Uint64 (value )
153
-
154
- subChainClient := exp .NewExplorerProxy (
155
- fmt .Sprintf ("http://127.0.0.1:%d" , svr .ChainService (cfg .Chain .ID ).Explorer ().Port ()+ 1 ),
156
- )
157
-
158
- details , err = subChainClient .GetAddressDetails (addr2 .String ())
159
- var nonce uint64
160
- if err != nil {
161
- nonce = 1
162
- } else {
163
- nonce = uint64 (details .PendingNonce )
164
- }
165
- settleDeposit := action .NewSettleDeposit (
166
- nonce ,
167
- big .NewInt (0 ).Mul (big .NewInt (1 ), big .NewInt (unit .Iotx )),
168
- index ,
169
- addr2 .String (),
170
- testutil .TestGasLimit ,
171
- big .NewInt (0 ),
172
- )
173
- bd = & action.EnvelopeBuilder {}
174
- elp = bd .SetAction (settleDeposit ).
175
- SetNonce (nonce ).
176
- SetGasLimit (testutil .TestGasLimit ).Build ()
177
- selp , err = action .Sign (elp , sk1 )
178
- require .NoError (t , err )
179
-
180
- settleRes , err := subChainClient .SettleDeposit (explorer.SettleDepositRequest {
181
- Version : int64 (settleDeposit .Version ()),
182
- Nonce : int64 (settleDeposit .Nonce ()),
183
- SenderPubKey : settleDeposit .SenderPublicKey ().HexString (),
184
- Recipient : settleDeposit .Recipient (),
185
- Amount : settleDeposit .Amount ().String (),
186
- Index : int64 (index ),
187
- Signature : hex .EncodeToString (selp .Signature ()),
188
- GasLimit : int64 (settleDeposit .GasLimit ()),
189
- GasPrice : settleDeposit .GasPrice ().String (),
190
- })
191
- require .NoError (t , err )
192
-
193
- require .NoError (t , testutil .WaitUntil (time .Second , 20 * time .Second , func () (bool , error ) {
194
- sd , err := subChainClient .GetSettleDeposit (settleRes .Hash )
195
- return err == nil && sd .IsPending == false , nil
196
- }))
197
-
198
- sd1 , err := subChainClient .GetSettleDeposit (settleRes .Hash )
199
- require .NoError (t , err )
200
- sds , err := subChainClient .GetSettleDepositsByAddress (settleDeposit .Recipient (), 0 , 1 )
201
- require .NoError (t , err )
202
- require .Equal (t , 1 , len (sds ))
203
- assert .Equal (t , sd1 , sds [0 ])
204
63
}
0 commit comments