diff --git a/contracts/generated/contract_reader_interface/Initialize.go b/contracts/generated/contract_reader_interface/Initialize.go index ee6fa51f8..03e13f579 100644 --- a/contracts/generated/contract_reader_interface/Initialize.go +++ b/contracts/generated/contract_reader_interface/Initialize.go @@ -15,9 +15,9 @@ type Initialize struct { TestIdx *uint64 Value *uint64 - // [0] = [WRITE] data + // [0] = [WRITE, SIGNER] signer // - // [1] = [WRITE, SIGNER] signer + // [1] = [WRITE] data // // [2] = [] systemProgram ag_solanago.AccountMetaSlice `bin:"-" borsh_skip:"true"` @@ -43,25 +43,25 @@ func (inst *Initialize) SetValue(value uint64) *Initialize { return inst } -// SetDataAccount sets the "data" account. -func (inst *Initialize) SetDataAccount(data ag_solanago.PublicKey) *Initialize { - inst.AccountMetaSlice[0] = ag_solanago.Meta(data).WRITE() +// SetSignerAccount sets the "signer" account. +func (inst *Initialize) SetSignerAccount(signer ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[0] = ag_solanago.Meta(signer).WRITE().SIGNER() return inst } -// GetDataAccount gets the "data" account. -func (inst *Initialize) GetDataAccount() *ag_solanago.AccountMeta { +// GetSignerAccount gets the "signer" account. +func (inst *Initialize) GetSignerAccount() *ag_solanago.AccountMeta { return inst.AccountMetaSlice[0] } -// SetSignerAccount sets the "signer" account. -func (inst *Initialize) SetSignerAccount(signer ag_solanago.PublicKey) *Initialize { - inst.AccountMetaSlice[1] = ag_solanago.Meta(signer).WRITE().SIGNER() +// SetDataAccount sets the "data" account. +func (inst *Initialize) SetDataAccount(data ag_solanago.PublicKey) *Initialize { + inst.AccountMetaSlice[1] = ag_solanago.Meta(data).WRITE() return inst } -// GetSignerAccount gets the "signer" account. -func (inst *Initialize) GetSignerAccount() *ag_solanago.AccountMeta { +// GetDataAccount gets the "data" account. +func (inst *Initialize) GetDataAccount() *ag_solanago.AccountMeta { return inst.AccountMetaSlice[1] } @@ -107,10 +107,10 @@ func (inst *Initialize) Validate() error { // Check whether all (required) accounts are set: { if inst.AccountMetaSlice[0] == nil { - return errors.New("accounts.Data is not set") + return errors.New("accounts.Signer is not set") } if inst.AccountMetaSlice[1] == nil { - return errors.New("accounts.Signer is not set") + return errors.New("accounts.Data is not set") } if inst.AccountMetaSlice[2] == nil { return errors.New("accounts.SystemProgram is not set") @@ -135,8 +135,8 @@ func (inst *Initialize) EncodeToTree(parent ag_treeout.Branches) { // Accounts of the instruction: instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { - accountsBranch.Child(ag_format.Meta(" data", inst.AccountMetaSlice[0])) - accountsBranch.Child(ag_format.Meta(" signer", inst.AccountMetaSlice[1])) + accountsBranch.Child(ag_format.Meta(" signer", inst.AccountMetaSlice[0])) + accountsBranch.Child(ag_format.Meta(" data", inst.AccountMetaSlice[1])) accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice[2])) }) }) @@ -176,13 +176,13 @@ func NewInitializeInstruction( testIdx uint64, value uint64, // Accounts: - data ag_solanago.PublicKey, signer ag_solanago.PublicKey, + data ag_solanago.PublicKey, systemProgram ag_solanago.PublicKey) *Initialize { return NewInitializeInstructionBuilder(). SetTestIdx(testIdx). SetValue(value). - SetDataAccount(data). SetSignerAccount(signer). + SetDataAccount(data). SetSystemProgramAccount(systemProgram) } diff --git a/contracts/programs/contract-reader-interface/src/lib.rs b/contracts/programs/contract-reader-interface/src/lib.rs index b02b68888..51c06a33e 100644 --- a/contracts/programs/contract-reader-interface/src/lib.rs +++ b/contracts/programs/contract-reader-interface/src/lib.rs @@ -35,6 +35,9 @@ pub mod contract_reader_interface { #[derive(Accounts)] #[instruction(test_idx: u64)] pub struct Initialize<'info> { + #[account(mut)] + pub signer: Signer<'info>, + // derived test PDA #[account( init, @@ -44,9 +47,6 @@ pub struct Initialize<'info> { bump)] pub data: Account<'info, DataAccount>, - #[account(mut)] - pub signer: Signer<'info>, - pub system_program: Program<'info, System>, } diff --git a/integration-tests/relayinterface/chain_components_test.go b/integration-tests/relayinterface/chain_components_test.go index 4346fa930..173d3fb65 100644 --- a/integration-tests/relayinterface/chain_components_test.go +++ b/integration-tests/relayinterface/chain_components_test.go @@ -6,9 +6,6 @@ package relayinterface import ( "context" "encoding/binary" - "fmt" - "io" - "log" "os" "path/filepath" "sync" @@ -18,11 +15,11 @@ import ( "github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go/rpc" "github.com/gagliardetto/solana-go/rpc/ws" - "github.com/gagliardetto/solana-go/text" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" - "github.com/test-go/testify/mock" "github.com/smartcontractkit/chainlink-common/pkg/codec" + commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" "github.com/smartcontractkit/chainlink-common/pkg/logger" commontestutils "github.com/smartcontractkit/chainlink-common/pkg/loop/testutils" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" @@ -310,6 +307,7 @@ func (h *helper) Init(t *testing.T) { solanautils.FundAccounts(t, []solana.PrivateKey{privateKey}, h.rpcClient) cfg := config.NewDefault() + cfg.Chain.TxRetentionTimeout = commonconfig.MustNewDuration(10 * time.Minute) solanaClient, err := client.NewClient(h.rpcURL, cfg, 5*time.Second, nil) require.NoError(t, err) @@ -319,14 +317,14 @@ func (h *helper) Init(t *testing.T) { mkey := keyMocks.NewSimpleKeystore(t) mkey.On("Sign", mock.Anything, privateKey.PublicKey().String(), mock.Anything).Return(func(_ context.Context, _ string, data []byte) []byte { sig, _ := privateKey.Sign(data) - verifySignature(privateKey.PublicKey(), sig[:], data) - fmt.Printf("Signed for %s: %x\n", privateKey.PublicKey().String(), sig) return sig[:] }, nil) lggr := logger.Test(t) txm := txm.NewTxm("localnet", loader, nil, cfg, mkey, lggr) - txm.Start(tests.Context(t)) + err = txm.Start(tests.Context(t)) + require.NoError(t, err) + h.txm = txm pubkey, err := solana.PublicKeyFromBase58(programPubKey) @@ -336,16 +334,6 @@ func (h *helper) Init(t *testing.T) { h.programID = pubkey } -func verifySignature(publicKey solana.PublicKey, signature []byte, message []byte) bool { - valid := publicKey.Verify(message, solana.SignatureFromBytes(signature)) - if valid { - log.Printf("Signature is valid for public key: %s\n", publicKey.String()) - } else { - log.Printf("Signature is invalid for public key: %s\n", publicKey.String()) - } - return valid -} - func (h *helper) RPCClient() *chainreader.RPCClientWrapper { return &chainreader.RPCClientWrapper{Client: h.rpcClient} } @@ -404,13 +392,7 @@ func (h *helper) CreateAccount(t *testing.T, it SolanaChainComponentsInterfaceTe pubKey, _, err := solana.FindProgramAddress([][]byte{[]byte("data"), bts}, h.programID) require.NoError(t, err) - // Getting the default localnet private key - privateKey, err := solana.PrivateKeyFromBase58(solclient.DefaultPrivateKeysSolValidator[1]) - require.NoError(t, err) - - h.runInitialize(t, it, nonce, value, pubKey, func(key solana.PublicKey) *solana.PrivateKey { - return &privateKey - }, privateKey.PublicKey()) + h.runInitialize(t, it, nonce, value) return pubKey } @@ -420,9 +402,6 @@ func (h *helper) runInitialize( it SolanaChainComponentsInterfaceTester[*testing.T], nonce uint64, value uint64, - data solana.PublicKey, - signerFunc func(key solana.PublicKey) *solana.PrivateKey, - payer solana.PublicKey, ) { t.Helper() @@ -436,82 +415,7 @@ func (h *helper) runInitialize( buf := make([]byte, 8) binary.LittleEndian.PutUint64(buf, nonce*value) - data, _, err := solana.FindProgramAddress( - [][]byte{ - []byte("data"), // Seed 1 - buf, // Seed 2 (test_idx) - }, - solana.MustPublicKeyFromBase58(programPubKey), // The program ID - ) - require.NoError(t, err) - - fmt.Printf("Derived PDA in test: %s\n", data.String()) - SubmitTransactionToCW(t, &it, cw, "initialize", args, types.BoundContract{Name: AnyContractName, Address: h.programID.String()}, types.Finalized) - - // inst, err := contract.NewInitializeInstruction(nonce*value, value, data, payer, solana.SystemProgramID).ValidateAndBuild() - // require.NoError(t, err) - - // h.sendInstruction(t, inst, signerFunc, payer) -} - -func (h *helper) sendInstruction( - t *testing.T, - inst *contract.Instruction, - signerFunc func(key solana.PublicKey) *solana.PrivateKey, - payer solana.PublicKey, -) { - t.Helper() - - ctx := tests.Context(t) - - recent, err := h.rpcClient.GetLatestBlockhash(ctx, rpc.CommitmentFinalized) - require.NoError(t, err) - - tx, err := solana.NewTransaction( - []solana.Instruction{ - inst, - }, - recent.Value.Blockhash, - solana.TransactionPayer(payer), - ) - require.NoError(t, err) - - _, err = tx.EncodeTree(text.NewTreeEncoder(io.Discard, "Initialize")) - require.NoError(t, err) - - _, err = tx.Sign(signerFunc) - require.NoError(t, err) - - sig, err := h.rpcClient.SendTransactionWithOpts( - ctx, tx, - rpc.TransactionOpts{ - PreflightCommitment: rpc.CommitmentConfirmed, - }, - ) - require.NoError(t, err) - - h.waitForTX(t, sig, rpc.CommitmentFinalized) -} - -func (h *helper) waitForTX(t *testing.T, sig solana.Signature, commitment rpc.CommitmentType) { - t.Helper() - - sub, err := h.wsClient.SignatureSubscribe( - sig, - commitment, - ) - require.NoError(t, err) - - defer sub.Unsubscribe() - - res, err := sub.Recv() - require.NoError(t, err) - - if res.Value.Err != nil { - t.Logf("transaction confirmation failed: %v", res.Value.Err) - t.FailNow() - } } const programPubKey = "6AfuXF6HapDUhQfE4nQG9C1SGtA1YjP3icaJyRfU4RyE" diff --git a/pkg/solana/txm/txm.go b/pkg/solana/txm/txm.go index 06729ca63..c87089060 100644 --- a/pkg/solana/txm/txm.go +++ b/pkg/solana/txm/txm.go @@ -253,24 +253,10 @@ func (txm *Txm) buildTx(ctx context.Context, msg pendingTx, retryCount int) (sol if err != nil { return solanaGo.Transaction{}, fmt.Errorf("error in Sign: %w", err) } - fmt.Printf("Transaction Message (hex): %x\n", txMsg) - var finalSig [64]byte copy(finalSig[:], sigBytes) newTx.Signatures = append(newTx.Signatures, finalSig) - for i, sig := range newTx.Signatures { - fmt.Printf("Signature[%d]: %x\n", i, sig) - } - - for i, account := range newTx.Message.AccountKeys { - writable, err := newTx.Message.IsWritable(account) - if err != nil { - return solanaGo.Transaction{}, fmt.Errorf("error in IsWritable: %w", err) - } - fmt.Printf("Account[%d]: %s (Signer: %v, Writable: %v)\n", i, account, newTx.Message.IsSigner(account), writable) - } - return newTx, nil }