@@ -6,9 +6,6 @@ package relayinterface
6
6
import (
7
7
"context"
8
8
"encoding/binary"
9
- "fmt"
10
- "io"
11
- "log"
12
9
"os"
13
10
"path/filepath"
14
11
"sync"
@@ -18,11 +15,11 @@ import (
18
15
"github.com/gagliardetto/solana-go"
19
16
"github.com/gagliardetto/solana-go/rpc"
20
17
"github.com/gagliardetto/solana-go/rpc/ws"
21
- "github.com/gagliardetto/solana-go/text"
22
18
"github.com/stretchr/testify/require"
23
19
"github.com/test-go/testify/mock"
24
20
25
21
"github.com/smartcontractkit/chainlink-common/pkg/codec"
22
+ commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
26
23
"github.com/smartcontractkit/chainlink-common/pkg/logger"
27
24
commontestutils "github.com/smartcontractkit/chainlink-common/pkg/loop/testutils"
28
25
"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
@@ -310,6 +307,7 @@ func (h *helper) Init(t *testing.T) {
310
307
solanautils .FundAccounts (t , []solana.PrivateKey {privateKey }, h .rpcClient )
311
308
312
309
cfg := config .NewDefault ()
310
+ cfg .Chain .TxRetentionTimeout = commonconfig .MustNewDuration (10 * time .Minute )
313
311
solanaClient , err := client .NewClient (h .rpcURL , cfg , 5 * time .Second , nil )
314
312
require .NoError (t , err )
315
313
@@ -319,8 +317,6 @@ func (h *helper) Init(t *testing.T) {
319
317
mkey := keyMocks .NewSimpleKeystore (t )
320
318
mkey .On ("Sign" , mock .Anything , privateKey .PublicKey ().String (), mock .Anything ).Return (func (_ context.Context , _ string , data []byte ) []byte {
321
319
sig , _ := privateKey .Sign (data )
322
- verifySignature (privateKey .PublicKey (), sig [:], data )
323
- fmt .Printf ("Signed for %s: %x\n " , privateKey .PublicKey ().String (), sig )
324
320
return sig [:]
325
321
}, nil )
326
322
lggr := logger .Test (t )
@@ -336,16 +332,6 @@ func (h *helper) Init(t *testing.T) {
336
332
h .programID = pubkey
337
333
}
338
334
339
- func verifySignature (publicKey solana.PublicKey , signature []byte , message []byte ) bool {
340
- valid := publicKey .Verify (message , solana .SignatureFromBytes (signature ))
341
- if valid {
342
- log .Printf ("Signature is valid for public key: %s\n " , publicKey .String ())
343
- } else {
344
- log .Printf ("Signature is invalid for public key: %s\n " , publicKey .String ())
345
- }
346
- return valid
347
- }
348
-
349
335
func (h * helper ) RPCClient () * chainreader.RPCClientWrapper {
350
336
return & chainreader.RPCClientWrapper {Client : h .rpcClient }
351
337
}
@@ -404,13 +390,7 @@ func (h *helper) CreateAccount(t *testing.T, it SolanaChainComponentsInterfaceTe
404
390
pubKey , _ , err := solana .FindProgramAddress ([][]byte {[]byte ("data" ), bts }, h .programID )
405
391
require .NoError (t , err )
406
392
407
- // Getting the default localnet private key
408
- privateKey , err := solana .PrivateKeyFromBase58 (solclient .DefaultPrivateKeysSolValidator [1 ])
409
- require .NoError (t , err )
410
-
411
- h .runInitialize (t , it , nonce , value , pubKey , func (key solana.PublicKey ) * solana.PrivateKey {
412
- return & privateKey
413
- }, privateKey .PublicKey ())
393
+ h .runInitialize (t , it , nonce , value )
414
394
415
395
return pubKey
416
396
}
@@ -420,9 +400,6 @@ func (h *helper) runInitialize(
420
400
it SolanaChainComponentsInterfaceTester [* testing.T ],
421
401
nonce uint64 ,
422
402
value uint64 ,
423
- data solana.PublicKey ,
424
- signerFunc func (key solana.PublicKey ) * solana.PrivateKey ,
425
- payer solana.PublicKey ,
426
403
) {
427
404
t .Helper ()
428
405
@@ -436,82 +413,7 @@ func (h *helper) runInitialize(
436
413
buf := make ([]byte , 8 )
437
414
binary .LittleEndian .PutUint64 (buf , nonce * value )
438
415
439
- data , _ , err := solana .FindProgramAddress (
440
- [][]byte {
441
- []byte ("data" ), // Seed 1
442
- buf , // Seed 2 (test_idx)
443
- },
444
- solana .MustPublicKeyFromBase58 (programPubKey ), // The program ID
445
- )
446
- require .NoError (t , err )
447
-
448
- fmt .Printf ("Derived PDA in test: %s\n " , data .String ())
449
-
450
416
SubmitTransactionToCW (t , & it , cw , "initialize" , args , types.BoundContract {Name : AnyContractName , Address : h .programID .String ()}, types .Finalized )
451
-
452
- // inst, err := contract.NewInitializeInstruction(nonce*value, value, data, payer, solana.SystemProgramID).ValidateAndBuild()
453
- // require.NoError(t, err)
454
-
455
- // h.sendInstruction(t, inst, signerFunc, payer)
456
- }
457
-
458
- func (h * helper ) sendInstruction (
459
- t * testing.T ,
460
- inst * contract.Instruction ,
461
- signerFunc func (key solana.PublicKey ) * solana.PrivateKey ,
462
- payer solana.PublicKey ,
463
- ) {
464
- t .Helper ()
465
-
466
- ctx := tests .Context (t )
467
-
468
- recent , err := h .rpcClient .GetLatestBlockhash (ctx , rpc .CommitmentFinalized )
469
- require .NoError (t , err )
470
-
471
- tx , err := solana .NewTransaction (
472
- []solana.Instruction {
473
- inst ,
474
- },
475
- recent .Value .Blockhash ,
476
- solana .TransactionPayer (payer ),
477
- )
478
- require .NoError (t , err )
479
-
480
- _ , err = tx .EncodeTree (text .NewTreeEncoder (io .Discard , "Initialize" ))
481
- require .NoError (t , err )
482
-
483
- _ , err = tx .Sign (signerFunc )
484
- require .NoError (t , err )
485
-
486
- sig , err := h .rpcClient .SendTransactionWithOpts (
487
- ctx , tx ,
488
- rpc.TransactionOpts {
489
- PreflightCommitment : rpc .CommitmentConfirmed ,
490
- },
491
- )
492
- require .NoError (t , err )
493
-
494
- h .waitForTX (t , sig , rpc .CommitmentFinalized )
495
- }
496
-
497
- func (h * helper ) waitForTX (t * testing.T , sig solana.Signature , commitment rpc.CommitmentType ) {
498
- t .Helper ()
499
-
500
- sub , err := h .wsClient .SignatureSubscribe (
501
- sig ,
502
- commitment ,
503
- )
504
- require .NoError (t , err )
505
-
506
- defer sub .Unsubscribe ()
507
-
508
- res , err := sub .Recv ()
509
- require .NoError (t , err )
510
-
511
- if res .Value .Err != nil {
512
- t .Logf ("transaction confirmation failed: %v" , res .Value .Err )
513
- t .FailNow ()
514
- }
515
417
}
516
418
517
419
const programPubKey = "6AfuXF6HapDUhQfE4nQG9C1SGtA1YjP3icaJyRfU4RyE"
0 commit comments