@@ -10,7 +10,10 @@ import (
10
10
"testing"
11
11
"time"
12
12
13
+ "github.com/go-resty/resty/v2"
14
+
13
15
"github.com/avast/retry-go/v4"
16
+ "github.com/block-vision/sui-go-sdk/models"
14
17
sui_sdk "github.com/block-vision/sui-go-sdk/sui"
15
18
chainsel "github.com/smartcontractkit/chain-selectors"
16
19
"github.com/smartcontractkit/chainlink-testing-framework/framework"
@@ -108,16 +111,17 @@ func (p *CTFChainProvider) Initialize(_ context.Context) (chain.BlockChain, erro
108
111
}
109
112
110
113
// Start the CTF Container
111
- url , client := p .startContainer (chainID , deployerSigner )
114
+ url , faucetUrl , client := p .startContainer (chainID , deployerSigner )
112
115
113
116
// Construct the chain
114
117
p .chain = & sui.Chain {
115
118
ChainMetadata : sui.ChainMetadata {
116
119
Selector : p .selector ,
117
120
},
118
- Client : client ,
119
- Signer : deployerSigner ,
120
- URL : url ,
121
+ Client : client ,
122
+ Signer : deployerSigner ,
123
+ URL : url ,
124
+ FaucetURL : faucetUrl ,
121
125
// TODO: Implement ConfirmTransaction when available
122
126
}
123
127
@@ -144,11 +148,11 @@ func (p *CTFChainProvider) BlockChain() chain.BlockChain {
144
148
// It returns the URL of the Sui node and the client to interact with it.
145
149
func (p * CTFChainProvider ) startContainer (
146
150
chainID string , account sui.SuiSigner ,
147
- ) (string , sui_sdk.ISuiAPI ) {
151
+ ) (string , string , sui_sdk.ISuiAPI ) {
148
152
var (
149
- attempts = uint (10 )
150
- url string
151
- containerName string
153
+ attempts = uint (10 )
154
+ url string
155
+ fauceturl string
152
156
)
153
157
154
158
// initialize the docker network used by CTF
@@ -161,6 +165,7 @@ func (p *CTFChainProvider) startContainer(
161
165
162
166
type containerResult struct {
163
167
url string
168
+ faucetPort string
164
169
containerName string
165
170
}
166
171
@@ -204,13 +209,15 @@ func (p *CTFChainProvider) startContainer(
204
209
if rerr != nil {
205
210
// Return the ports to freeport to avoid leaking them during retries
206
211
freeport .Return ([]int {port , faucetPort })
212
+
207
213
return containerResult {}, rerr
208
214
}
209
215
210
216
testcontainers .CleanupContainer (p .t , output .Container )
211
217
212
218
return containerResult {
213
- url : output .Nodes [0 ].ExternalHTTPUrl + "/v1" ,
219
+ url : output .Nodes [0 ].ExternalHTTPUrl ,
220
+ faucetPort : input .FaucetPort ,
214
221
containerName : output .ContainerName ,
215
222
}, nil
216
223
},
@@ -225,7 +232,7 @@ func (p *CTFChainProvider) startContainer(
225
232
require .NoError (p .t , err , "Failed to start CTF Sui container after %d attempts" , attempts )
226
233
227
234
url = result .url
228
- containerName = result .containerName
235
+ fauceturl = fmt . Sprintf ( "http://%s:%s" , "127.0.0.1" , result .faucetPort )
229
236
230
237
client := sui_sdk .NewSuiClient (url )
231
238
@@ -240,14 +247,24 @@ func (p *CTFChainProvider) startContainer(
240
247
}
241
248
require .True (p .t , ready , "Sui network not ready" )
242
249
243
- dc , err := framework . NewDockerClient ( )
250
+ err = fundAccount ( fauceturl , address )
244
251
require .NoError (p .t , err )
245
252
246
- _ , err = dc .ExecContainer (containerName , []string {
247
- "sui" , "client" , "faucet" ,
248
- "--address" , address ,
249
- })
250
- require .NoError (p .t , err )
253
+ return url , fauceturl , client
254
+ }
251
255
252
- return url , client
256
+ func fundAccount (url string , address string ) error {
257
+ r := resty .New ().SetBaseURL (url )
258
+ b := & models.FaucetRequest {
259
+ FixedAmountRequest : & models.FaucetFixedAmountRequest {
260
+ Recipient : address ,
261
+ },
262
+ }
263
+ resp , err := r .R ().SetBody (b ).SetHeader ("Content-Type" , "application/json" ).Post ("/gas" )
264
+ if err != nil {
265
+ return err
266
+ }
267
+ framework .L .Info ().Any ("Resp" , resp ).Msg ("Address is funded!" )
268
+
269
+ return nil
253
270
}
0 commit comments