Skip to content

Commit

Permalink
Merge branch 'main' into cl33-15
Browse files Browse the repository at this point in the history
  • Loading branch information
b-gopalswami authored Dec 20, 2024
2 parents f086887 + 4e2de67 commit f64d626
Show file tree
Hide file tree
Showing 53 changed files with 1,714 additions and 1,622 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ pub fn wrap_native_sol<'info>(
signer_bump: u8,
) -> Result<()> {
require!(
// guarantee that if caller is a PDA it won't get garbage-collected
*from.owner == System::id() || from.get_lamports() > amount,
// guarantee that if caller is a PDA with data it won't get garbage-collected
from.data_is_empty() || from.get_lamports() > amount,
CcipRouterError::InsufficientLamports
);

Expand Down
1,072 changes: 539 additions & 533 deletions chains/solana/contracts/tests/ccip/ccip_router_test.go

Large diffs are not rendered by default.

104 changes: 53 additions & 51 deletions chains/solana/contracts/tests/ccip/tokenpool_test.go

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions chains/solana/contracts/tests/config/ccip_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/gagliardetto/solana-go"
"github.com/gagliardetto/solana-go/rpc"

"github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/utils"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common"
)

var (
Expand All @@ -33,7 +33,7 @@ var (

SolanaChainSelector uint64 = 15
EvmChainSelector uint64 = 21
EvmChainLE = utils.Uint64ToLE(EvmChainSelector)
EvmChainLE = common.Uint64ToLE(EvmChainSelector)

SolanaSourceChainStatePDA, _, _ = solana.FindProgramAddress([][]byte{[]byte("source_chain_state"), binary.LittleEndian.AppendUint64([]byte{}, SolanaChainSelector)}, CcipRouterProgram)
SolanaDestChainStatePDA, _, _ = solana.FindProgramAddress([][]byte{[]byte("dest_chain_state"), binary.LittleEndian.AppendUint64([]byte{}, SolanaChainSelector)}, CcipRouterProgram)
Expand All @@ -45,7 +45,7 @@ var (

MaxOracles = 16
OcrF uint8 = 5
ConfigDigest = utils.MakeRandom32ByteArray()
ConfigDigest = common.MakeRandom32ByteArray()
Empty24Byte = [24]byte{}
MaxSignersAndTransmitters = 16
)
41 changes: 0 additions & 41 deletions chains/solana/contracts/tests/config/config.go

This file was deleted.

15 changes: 8 additions & 7 deletions chains/solana/contracts/tests/lookuptable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ import (

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/utils"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/testutils"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common"
)

func TestSolanaLookupTables(t *testing.T) {
t.Parallel()

ctx := tests.Context(t)
url := utils.SetupLocalSolNode(t)
url := testutils.SetupLocalSolNode(t)
c := rpc.New(url)

sender, err := solana.NewRandomPrivateKey()
require.NoError(t, err)
utils.FundAccounts(ctx, []solana.PrivateKey{sender}, c, t)
testutils.FundAccounts(ctx, []solana.PrivateKey{sender}, c, t)

// transfer instructions
pubkeys := solana.PublicKeySlice{}
Expand All @@ -41,17 +42,17 @@ func TestSolanaLookupTables(t *testing.T) {
// create lookup table
slot, serr := c.GetSlot(ctx, rpc.CommitmentFinalized)
require.NoError(t, serr)
table, instruction, ierr := utils.NewCreateLookupTableInstruction(
table, instruction, ierr := common.NewCreateLookupTableInstruction(
sender.PublicKey(),
sender.PublicKey(),
slot,
)
require.NoError(t, ierr)
utils.SendAndConfirm(ctx, t, c, []solana.Instruction{instruction}, sender, rpc.CommitmentConfirmed)
testutils.SendAndConfirm(ctx, t, c, []solana.Instruction{instruction}, sender, rpc.CommitmentConfirmed)

// add entries to lookup table
utils.SendAndConfirm(ctx, t, c, []solana.Instruction{
utils.NewExtendLookupTableInstruction(
testutils.SendAndConfirm(ctx, t, c, []solana.Instruction{
common.NewExtendLookupTableInstruction(
table, sender.PublicKey(), sender.PublicKey(),
k,
),
Expand Down
73 changes: 37 additions & 36 deletions chains/solana/contracts/tests/mcms/mcm_multiple_multisigs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

"github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/config"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/utils"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/utils/eth"
mcmsUtils "github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/utils/mcms"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/contracts/tests/testutils"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/mcm"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/eth"
"github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/mcms"
)

func TestMcmMultipleMultisigs(t *testing.T) {
Expand All @@ -27,26 +28,26 @@ func TestMcmMultipleMultisigs(t *testing.T) {
admin, err := solana.NewRandomPrivateKey()
require.NoError(t, err)

solanaGoClient := utils.DeployAllPrograms(t, utils.PathToAnchorConfig, admin)
solanaGoClient := testutils.DeployAllPrograms(t, testutils.PathToAnchorConfig, admin)

// mcm multisig 1
testMsigName1, err := mcmsUtils.PadString32("test_mcm_instance_1")
testMsigName1, err := mcms.PadString32("test_mcm_instance_1")
require.NoError(t, err)
multisigConfigPDA1 := McmConfigAddress(testMsigName1)
rootMetadataPDA1 := RootMetadataAddress(testMsigName1)
expiringRootAndOpCountPDA1 := ExpiringRootAndOpCountAddress(testMsigName1)
configSignersPDA1 := McmConfigSignersAddress(testMsigName1)
multisigConfigPDA1 := mcms.McmConfigAddress(testMsigName1)
rootMetadataPDA1 := mcms.RootMetadataAddress(testMsigName1)
expiringRootAndOpCountPDA1 := mcms.ExpiringRootAndOpCountAddress(testMsigName1)
configSignersPDA1 := mcms.McmConfigSignersAddress(testMsigName1)

// mcm multisig 2
testMsigName2, err := mcmsUtils.PadString32("test_mcm_instance_2")
testMsigName2, err := mcms.PadString32("test_mcm_instance_2")
require.NoError(t, err)
multisigConfigPDA2 := McmConfigAddress(testMsigName2)
rootMetadataPDA2 := RootMetadataAddress(testMsigName2)
expiringRootAndOpCountPDA2 := ExpiringRootAndOpCountAddress(testMsigName2)
configSignersPDA2 := McmConfigSignersAddress(testMsigName2)
multisigConfigPDA2 := mcms.McmConfigAddress(testMsigName2)
rootMetadataPDA2 := mcms.RootMetadataAddress(testMsigName2)
expiringRootAndOpCountPDA2 := mcms.ExpiringRootAndOpCountAddress(testMsigName2)
configSignersPDA2 := mcms.McmConfigSignersAddress(testMsigName2)

t.Run("setup:funding", func(t *testing.T) {
utils.FundAccounts(ctx, []solana.PrivateKey{admin}, solanaGoClient, t)
testutils.FundAccounts(ctx, []solana.PrivateKey{admin}, solanaGoClient, t)
})

t.Run("setup:test_mcm_instance_1", func(t *testing.T) {
Expand Down Expand Up @@ -76,11 +77,11 @@ func TestMcmMultipleMultisigs(t *testing.T) {
expiringRootAndOpCountPDA1,
).ValidateAndBuild()
require.NoError(t, err)
utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)

// get config and validate
var configAccount mcm.MultisigConfig
err = utils.GetAccountDataBorshInto(ctx, solanaGoClient, multisigConfigPDA1, config.DefaultCommitment, &configAccount)
err = common.GetAccountDataBorshInto(ctx, solanaGoClient, multisigConfigPDA1, config.DefaultCommitment, &configAccount)
require.NoError(t, err, "failed to get account info")

require.Equal(t, config.TestChainID, configAccount.ChainId)
Expand All @@ -101,7 +102,7 @@ func TestMcmMultipleMultisigs(t *testing.T) {
groupQuorums := []uint8{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
groupParents := []uint8{0, 0, 0, 2, 0, 0, 0, 0, 0, 0}

mcmConfig, err := mcmsUtils.NewValidMcmConfig(
mcmConfig, err := mcms.NewValidMcmConfig(
testMsigName1,
signerPrivateKeys,
signerGroups,
Expand All @@ -116,7 +117,7 @@ func TestMcmMultipleMultisigs(t *testing.T) {
t.Run("mcm:set_config: preload signers on PDA", func(t *testing.T) {
ixs := make([]solana.Instruction, 0)

parsedTotalSigners, err := mcmsUtils.SafeToUint8(len(signerAddresses))
parsedTotalSigners, err := mcms.SafeToUint8(len(signerAddresses))
require.NoError(t, err)

initSignersIx, err := mcm.NewInitSignersInstruction(
Expand All @@ -131,7 +132,7 @@ func TestMcmMultipleMultisigs(t *testing.T) {
require.NoError(t, err)
ixs = append(ixs, initSignersIx)

appendSignersIxs, err := AppendSignersIxs(signerAddresses, testMsigName1, multisigConfigPDA1, configSignersPDA1, admin.PublicKey(), config.MaxAppendSignerBatchSize)
appendSignersIxs, err := mcms.AppendSignersIxs(signerAddresses, testMsigName1, multisigConfigPDA1, configSignersPDA1, admin.PublicKey(), config.MaxAppendSignerBatchSize)
require.NoError(t, err)
ixs = append(ixs, appendSignersIxs...)

Expand All @@ -145,11 +146,11 @@ func TestMcmMultipleMultisigs(t *testing.T) {
ixs = append(ixs, finalizeSignersIx)

for _, ix := range ixs {
utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
}

var cfgSignersAccount mcm.ConfigSigners
err = utils.GetAccountDataBorshInto(ctx, solanaGoClient, configSignersPDA1, config.DefaultCommitment, &cfgSignersAccount)
err = common.GetAccountDataBorshInto(ctx, solanaGoClient, configSignersPDA1, config.DefaultCommitment, &cfgSignersAccount)
require.NoError(t, err, "failed to get account info")

require.Equal(t, true, cfgSignersAccount.IsFinalized)
Expand All @@ -175,12 +176,12 @@ func TestMcmMultipleMultisigs(t *testing.T) {

require.NoError(t, err)

result := utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
result := testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
require.NotNil(t, result)

// get config and validate
var configAccount mcm.MultisigConfig
err = utils.GetAccountDataBorshInto(ctx, solanaGoClient, multisigConfigPDA1, config.DefaultCommitment, &configAccount)
err = common.GetAccountDataBorshInto(ctx, solanaGoClient, multisigConfigPDA1, config.DefaultCommitment, &configAccount)
require.NoError(t, err, "failed to get account info")

require.Equal(t, config.TestChainID, configAccount.ChainId)
Expand All @@ -195,7 +196,7 @@ func TestMcmMultipleMultisigs(t *testing.T) {
}

// pda closed after set_config
utils.AssertClosedAccount(ctx, t, solanaGoClient, configSignersPDA1, config.DefaultCommitment)
testutils.AssertClosedAccount(ctx, t, solanaGoClient, configSignersPDA1, config.DefaultCommitment)
})
})
})
Expand Down Expand Up @@ -225,11 +226,11 @@ func TestMcmMultipleMultisigs(t *testing.T) {
expiringRootAndOpCountPDA2,
).ValidateAndBuild()
require.NoError(t, err)
utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)

// get config and validate
var configAccount mcm.MultisigConfig
err = utils.GetAccountDataBorshInto(ctx, solanaGoClient, multisigConfigPDA2, config.DefaultCommitment, &configAccount)
err = common.GetAccountDataBorshInto(ctx, solanaGoClient, multisigConfigPDA2, config.DefaultCommitment, &configAccount)
require.NoError(t, err, "failed to get account info")

require.Equal(t, config.TestChainID, configAccount.ChainId)
Expand All @@ -249,7 +250,7 @@ func TestMcmMultipleMultisigs(t *testing.T) {
groupQuorums := []uint8{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
groupParents := []uint8{0, 0, 0, 2, 0, 0, 0, 0, 0, 0}

mcmConfig, err := mcmsUtils.NewValidMcmConfig(
mcmConfig, err := mcms.NewValidMcmConfig(
testMsigName2,
signerPrivateKeys,
signerGroups,
Expand All @@ -264,7 +265,7 @@ func TestMcmMultipleMultisigs(t *testing.T) {
t.Run("mcm:set_config: preload signers on PDA", func(t *testing.T) {
ixs := make([]solana.Instruction, 0)

parsedTotalSigners, err := mcmsUtils.SafeToUint8(len(signerAddresses))
parsedTotalSigners, err := mcms.SafeToUint8(len(signerAddresses))
require.NoError(t, err)

initSignersIx, err := mcm.NewInitSignersInstruction(
Expand All @@ -279,7 +280,7 @@ func TestMcmMultipleMultisigs(t *testing.T) {
require.NoError(t, err)
ixs = append(ixs, initSignersIx)

appendSignersIxs, err := AppendSignersIxs(signerAddresses, testMsigName2, multisigConfigPDA2, configSignersPDA2, admin.PublicKey(), config.MaxAppendSignerBatchSize)
appendSignersIxs, err := mcms.AppendSignersIxs(signerAddresses, testMsigName2, multisigConfigPDA2, configSignersPDA2, admin.PublicKey(), config.MaxAppendSignerBatchSize)
require.NoError(t, err)
ixs = append(ixs, appendSignersIxs...)

Expand All @@ -293,11 +294,11 @@ func TestMcmMultipleMultisigs(t *testing.T) {
ixs = append(ixs, finalizeSignersIx)

for _, ix := range ixs {
utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
}

var cfgSignersAccount mcm.ConfigSigners
err = utils.GetAccountDataBorshInto(ctx, solanaGoClient, configSignersPDA2, config.DefaultCommitment, &cfgSignersAccount)
err = common.GetAccountDataBorshInto(ctx, solanaGoClient, configSignersPDA2, config.DefaultCommitment, &cfgSignersAccount)
require.NoError(t, err, "failed to get account info")

require.Equal(t, true, cfgSignersAccount.IsFinalized)
Expand All @@ -323,7 +324,7 @@ func TestMcmMultipleMultisigs(t *testing.T) {

require.NoError(t, err)

result := utils.SendAndFailWith(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment, []string{"Error Code: " + "ConstraintSeeds"})
result := testutils.SendAndFailWith(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment, []string{"Error Code: " + "ConstraintSeeds"})
require.NotNil(t, result)
})

Expand All @@ -342,12 +343,12 @@ func TestMcmMultipleMultisigs(t *testing.T) {

require.NoError(t, err)

result := utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
result := testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, admin, config.DefaultCommitment)
require.NotNil(t, result)

// get config and validate
var configAccount mcm.MultisigConfig
err = utils.GetAccountDataBorshInto(ctx, solanaGoClient, multisigConfigPDA2, config.DefaultCommitment, &configAccount)
err = common.GetAccountDataBorshInto(ctx, solanaGoClient, multisigConfigPDA2, config.DefaultCommitment, &configAccount)
require.NoError(t, err, "failed to get account info")

require.Equal(t, config.TestChainID, configAccount.ChainId)
Expand All @@ -362,7 +363,7 @@ func TestMcmMultipleMultisigs(t *testing.T) {
}

// pda closed after set_config
utils.AssertClosedAccount(ctx, t, solanaGoClient, configSignersPDA2, config.DefaultCommitment)
testutils.AssertClosedAccount(ctx, t, solanaGoClient, configSignersPDA2, config.DefaultCommitment)
})
})
})
Expand Down
Loading

0 comments on commit f64d626

Please sign in to comment.