Skip to content

Commit

Permalink
Rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloMansanet committed Dec 23, 2024
1 parent 8dd5eab commit c8f2c08
Showing 1 changed file with 88 additions and 89 deletions.
177 changes: 88 additions & 89 deletions chains/solana/contracts/tests/ccip/ccip_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,6 @@ func TestCCIPRouter(t *testing.T) {
require.Equal(t, token0Config.PremiumMultiplierWeiPerEth, final.Config.PremiumMultiplierWeiPerEth)
})


})
})

Expand Down Expand Up @@ -1838,9 +1837,9 @@ func TestCCIPRouter(t *testing.T) {
instruction, err := raw.ValidateAndBuild()
require.NoError(t, err)

feeResult := utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{instruction}, user, config.DefaultCommitment)
feeResult := testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{instruction}, user, config.DefaultCommitment)
require.NotNil(t, feeResult)
fee := utils.ExtractTypedReturnValue(ctx, t, feeResult.Meta.LogMessages, config.CcipRouterProgram.String(), binary.LittleEndian.Uint64)
fee, _ := common.ExtractTypedReturnValue(ctx, feeResult.Meta.LogMessages, config.CcipRouterProgram.String(), binary.LittleEndian.Uint64)
require.Equal(t, uint64(1), fee)
})

Expand All @@ -1864,17 +1863,17 @@ func TestCCIPRouter(t *testing.T) {
token0PerChainPerConfigPda := getPerChainPerTokenConfigBillingPDA(token0.Mint.PublicKey())
ix, err := ccip_router.NewSetTokenBillingInstruction(config.EvmChainSelector, token0.Mint.PublicKey(), billing, config.RouterConfigPDA, token0PerChainPerConfigPda, anotherAdmin.PublicKey(), solana.SystemProgramID).ValidateAndBuild()
require.NoError(t, err)
utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, anotherAdmin, config.DefaultCommitment)
testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, anotherAdmin, config.DefaultCommitment)

raw := ccip_router.NewGetFeeInstruction(config.EvmChainSelector, message, config.EvmDestChainStatePDA, wsol.billingConfigPDA)
raw.AccountMetaSlice.Append(solana.Meta(token0BillingConfigPda))
raw.AccountMetaSlice.Append(solana.Meta(token0PerChainPerConfigPda))
instruction, err := raw.ValidateAndBuild()
require.NoError(t, err)

feeResult := utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{instruction}, user, config.DefaultCommitment)
feeResult := testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{instruction}, user, config.DefaultCommitment)
require.NotNil(t, feeResult)
fee := utils.ExtractTypedReturnValue(ctx, t, feeResult.Meta.LogMessages, config.CcipRouterProgram.String(), binary.LittleEndian.Uint64)
fee, _ := common.ExtractTypedReturnValue(ctx, feeResult.Meta.LogMessages, config.CcipRouterProgram.String(), binary.LittleEndian.Uint64)
require.Equal(t, uint64(3), fee)
})

Expand Down Expand Up @@ -2721,9 +2720,9 @@ func TestCCIPRouter(t *testing.T) {
ix, err := rawGetFeeIx.ValidateAndBuild()
require.NoError(t, err)

feeResult := utils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, user, config.DefaultCommitment)
feeResult := testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ix}, user, config.DefaultCommitment)
require.NotNil(t, feeResult)
fee := utils.ExtractTypedReturnValue(ctx, t, feeResult.Meta.LogMessages, config.CcipRouterProgram.String(), binary.LittleEndian.Uint64)
fee, _ := common.ExtractTypedReturnValue(ctx, feeResult.Meta.LogMessages, config.CcipRouterProgram.String(), binary.LittleEndian.Uint64)
require.Equal(t, uint64(1), fee)

initialBalance := getBalance(token.billingATA)
Expand Down Expand Up @@ -5086,98 +5085,98 @@ func TestCCIPRouter(t *testing.T) {
// Cleanup tests //
//////////////////////////

t.Run("Cleanup", func(t<<<<<<< HEAD
t.Run("Can remove token config", func(t *testing.T) {
token0BillingPDA := getTokenConfigPDA(token0.Mint.PublicKey())
t.Run("Cleanup", func(t *testing.T) {
t.Run("Can remove token config", func(t *testing.T) {
token0BillingPDA := getTokenConfigPDA(token0.Mint.PublicKey())

var initial ccip_router.BillingTokenConfigWrapper
ierr := common.GetAccountDataBorshInto(ctx, solanaGoClient, token0BillingPDA, config.DefaultCommitment, &initial)
require.NoError(t, ierr) // it exists, initially
var initial ccip_router.BillingTokenConfigWrapper
ierr := common.GetAccountDataBorshInto(ctx, solanaGoClient, token0BillingPDA, config.DefaultCommitment, &initial)
require.NoError(t, ierr) // it exists, initially

receiver, _, aerr := tokens.FindAssociatedTokenAddress(token0.Program, token0.Mint.PublicKey(), config.BillingSignerPDA)
require.NoError(t, aerr)
receiver, _, aerr := tokens.FindAssociatedTokenAddress(token0.Program, token0.Mint.PublicKey(), config.BillingSignerPDA)
require.NoError(t, aerr)

ixConfig, cerr := ccip_router.NewRemoveBillingTokenConfigInstruction(
config.RouterConfigPDA,
token0BillingPDA,
token0.Program,
token0.Mint.PublicKey(),
receiver,
config.BillingSignerPDA,
anotherAdmin.PublicKey(),
solana.SystemProgramID,
).ValidateAndBuild()
require.NoError(t, cerr)
testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ixConfig}, anotherAdmin, config.DefaultCommitment)
ixConfig, cerr := ccip_router.NewRemoveBillingTokenConfigInstruction(
config.RouterConfigPDA,
token0BillingPDA,
token0.Program,
token0.Mint.PublicKey(),
receiver,
config.BillingSignerPDA,
anotherAdmin.PublicKey(),
solana.SystemProgramID,
).ValidateAndBuild()
require.NoError(t, cerr)
testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ixConfig}, anotherAdmin, config.DefaultCommitment)

var final ccip_router.BillingTokenConfigWrapper
ferr := common.GetAccountDataBorshInto(ctx, solanaGoClient, token0BillingPDA, rpc.CommitmentProcessed, &final)
require.EqualError(t, ferr, "not found") // it no longer exists
})
var final ccip_router.BillingTokenConfigWrapper
ferr := common.GetAccountDataBorshInto(ctx, solanaGoClient, token0BillingPDA, rpc.CommitmentProcessed, &final)
require.EqualError(t, ferr, "not found") // it no longer exists
})

t.Run("Can remove a pre-2022 token too", func(t *testing.T) {
mintPriv, kerr := solana.NewRandomPrivateKey()
require.NoError(t, kerr)
mint := mintPriv.PublicKey()

// use old (pre-2022) token program
ixToken, terr := tokens.CreateToken(ctx, solana.TokenProgramID, mint, admin.PublicKey(), 9, solanaGoClient, config.DefaultCommitment)
require.NoError(t, terr)
testutils.SendAndConfirm(ctx, t, solanaGoClient, ixToken, admin, config.DefaultCommitment, common.AddSigners(mintPriv))

configPDA, _, perr := solana.FindProgramAddress([][]byte{config.BillingTokenConfigPrefix, mint.Bytes()}, ccip_router.ProgramID)
require.NoError(t, perr)
receiver, _, terr := tokens.FindAssociatedTokenAddress(solana.TokenProgramID, mint, config.BillingSignerPDA)
require.NoError(t, terr)

tokenConfig := ccip_router.BillingTokenConfig{
Enabled: true,
Mint: mint,
UsdPerToken: ccip_router.TimestampedPackedU224{},
PremiumMultiplierWeiPerEth: 0,
}
t.Run("Can remove a pre-2022 token too", func(t *testing.T) {
mintPriv, kerr := solana.NewRandomPrivateKey()
require.NoError(t, kerr)
mint := mintPriv.PublicKey()

// add it first
ixConfig, cerr := ccip_router.NewAddBillingTokenConfigInstruction(
tokenConfig,
config.RouterConfigPDA,
configPDA,
solana.TokenProgramID,
mint,
receiver,
anotherAdmin.PublicKey(),
config.BillingSignerPDA,
tokens.AssociatedTokenProgramID,
solana.SystemProgramID,
).ValidateAndBuild()
require.NoError(t, cerr)
// use old (pre-2022) token program
ixToken, terr := tokens.CreateToken(ctx, solana.TokenProgramID, mint, admin.PublicKey(), 9, solanaGoClient, config.DefaultCommitment)
require.NoError(t, terr)
testutils.SendAndConfirm(ctx, t, solanaGoClient, ixToken, admin, config.DefaultCommitment, common.AddSigners(mintPriv))

testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ixConfig}, anotherAdmin, config.DefaultCommitment)
configPDA, _, perr := solana.FindProgramAddress([][]byte{config.BillingTokenConfigPrefix, mint.Bytes()}, ccip_router.ProgramID)
require.NoError(t, perr)
receiver, _, terr := tokens.FindAssociatedTokenAddress(solana.TokenProgramID, mint, config.BillingSignerPDA)
require.NoError(t, terr)

var tokenConfigAccount ccip_router.BillingTokenConfigWrapper
aerr := common.GetAccountDataBorshInto(ctx, solanaGoClient, configPDA, config.DefaultCommitment, &tokenConfigAccount)
require.NoError(t, aerr)
tokenConfig := ccip_router.BillingTokenConfig{
Enabled: true,
Mint: mint,
UsdPerToken: ccip_router.TimestampedPackedU224{},
PremiumMultiplierWeiPerEth: 0,
}

require.Equal(t, tokenConfig, tokenConfigAccount.Config)
// add it first
ixConfig, cerr := ccip_router.NewAddBillingTokenConfigInstruction(
tokenConfig,
config.RouterConfigPDA,
configPDA,
solana.TokenProgramID,
mint,
receiver,
anotherAdmin.PublicKey(),
config.BillingSignerPDA,
tokens.AssociatedTokenProgramID,
solana.SystemProgramID,
).ValidateAndBuild()
require.NoError(t, cerr)

// now, remove the added pre-2022 token, which has a balance of 0 in the receiver
ixConfig, cerr = ccip_router.NewRemoveBillingTokenConfigInstruction(
config.RouterConfigPDA,
configPDA,
solana.TokenProgramID,
mint,
receiver,
config.BillingSignerPDA,
anotherAdmin.PublicKey(),
solana.SystemProgramID,
).ValidateAndBuild()
require.NoError(t, cerr)
testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ixConfig}, anotherAdmin, config.DefaultCommitment)

testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ixConfig}, anotherAdmin, config.DefaultCommitment)
var tokenConfigAccount ccip_router.BillingTokenConfigWrapper
aerr := common.GetAccountDataBorshInto(ctx, solanaGoClient, configPDA, config.DefaultCommitment, &tokenConfigAccount)
require.NoError(t, aerr)

var final ccip_router.BillingTokenConfigWrapper
ferr := common.GetAccountDataBorshInto(ctx, solanaGoClient, configPDA, rpc.CommitmentProcessed, &final)
require.EqualError(t, ferr, "not found") // it no longer exists
})
require.Equal(t, tokenConfig, tokenConfigAccount.Config)

// now, remove the added pre-2022 token, which has a balance of 0 in the receiver
ixConfig, cerr = ccip_router.NewRemoveBillingTokenConfigInstruction(
config.RouterConfigPDA,
configPDA,
solana.TokenProgramID,
mint,
receiver,
config.BillingSignerPDA,
anotherAdmin.PublicKey(),
solana.SystemProgramID,
).ValidateAndBuild()
require.NoError(t, cerr)

testutils.SendAndConfirm(ctx, t, solanaGoClient, []solana.Instruction{ixConfig}, anotherAdmin, config.DefaultCommitment)

var final ccip_router.BillingTokenConfigWrapper
ferr := common.GetAccountDataBorshInto(ctx, solanaGoClient, configPDA, rpc.CommitmentProcessed, &final)
require.EqualError(t, ferr, "not found") // it no longer exists
})
})
}

0 comments on commit c8f2c08

Please sign in to comment.