Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
toblich committed Dec 19, 2024
1 parent 3b7bc05 commit 15721f0
Show file tree
Hide file tree
Showing 3 changed files with 374 additions and 3 deletions.
68 changes: 65 additions & 3 deletions chains/solana/contracts/tests/ccip/ccip_router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2918,19 +2918,81 @@ func TestCCIPRouter(t *testing.T) {
})

t.Run("When an non-admin user tries to withdraw funds from a billing token account, it fails", func(t *testing.T) {
ix, err := ccip_router.NewWithdrawBilledFundsInstruction(
true, // withdraw all
uint64(0), // amount
wsol.mint,
wsol.billingATA,
wsol.userATA, // send them to the user's account (just because, it could be any wallet)
wsol.program,
config.BillingSignerPDA,
config.RouterConfigPDA,
user.PublicKey(), // wrong user here
).ValidateAndBuild()
require.NoError(t, err)

utils.SendAndFailWith(ctx, t, solanaGoClient, []solana.Instruction{ix}, user, config.DefaultCommitment, []string{ccip_router.Unauthorized_CcipRouterError.String()})
})

t.Run("When withdrawing funds but sending them to the wrong token account, it fails", func(t *testing.T) {
ix, err := ccip_router.NewWithdrawBilledFundsInstruction(
true, // withdraw all
uint64(0), // amount
wsol.mint,
wsol.billingATA,
token2022.userATA, // wrong token account
wsol.program,
config.BillingSignerPDA,
config.RouterConfigPDA,
anotherAdmin.PublicKey(),
).ValidateAndBuild()
require.NoError(t, err)

utils.SendAndFailWith(ctx, t, solanaGoClient, []solana.Instruction{ix}, anotherAdmin, config.DefaultCommitment, []string{ccip_router.InvalidInputs_CcipRouterError.String()})
})

t.Run("When trying to withdraw more funds than what's available, it fails", func(t *testing.T) {
})
ix, err := ccip_router.NewWithdrawBilledFundsInstruction(
false, // withdraw all
getBalance(wsol.billingATA)+1, // amount (more than what's available)
wsol.mint,
wsol.billingATA,
wsol.userATA,
wsol.program,
config.BillingSignerPDA,
config.RouterConfigPDA,
anotherAdmin.PublicKey(),
).ValidateAndBuild()
require.NoError(t, err)

t.Run("When withdrawing funds from a billing token account that has no balance, it fails", func(t *testing.T) {
utils.SendAndFailWith(ctx, t, solanaGoClient, []solana.Instruction{ix}, anotherAdmin, config.DefaultCommitment, []string{ccip_router.InsufficientFunds_CcipRouterError.String()})
})

t.Run("When withdrawing a specific amount of funds, it succeeds", func(t *testing.T) {
funds := getBalance(token2022.billingATA)
require.Greater(t, funds, uint64(0))

initialUserBalance := getBalance(token2022.userATA)

amount := uint64(2)

ix, err := ccip_router.NewWithdrawBilledFundsInstruction(
false, // withdraw all
amount, // amount
token2022.mint,
token2022.billingATA,
token2022.userATA, // send them to the user's account (just because, it could be any wallet)
token2022.program,
config.BillingSignerPDA,
config.RouterConfigPDA,
anotherAdmin.PublicKey(),
).ValidateAndBuild()
require.NoError(t, err)

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

require.Equal(t, funds-amount, getBalance(token2022.billingATA)) // empty
require.Equal(t, amount, getBalance(token2022.userATA)-initialUserBalance) // increased by exact amount
})

t.Run("When withdrawing all funds, it succeeds", func(t *testing.T) {
Expand Down Expand Up @@ -2958,7 +3020,7 @@ func TestCCIPRouter(t *testing.T) {
require.Equal(t, funds, getBalance(wsol.userATA)-initialUserBalance) // increased by exact amount
})

t.Run("When withdrawing all funds but the accumulator account is already empty, it fails", func(t *testing.T) {
t.Run("When withdrawing all funds but the accumulator account is already empty (no balance), it fails", func(t *testing.T) {
funds := getBalance(wsol.billingATA)
require.Equal(t, uint64(0), funds)

Expand Down
277 changes: 277 additions & 0 deletions chains/solana/gobindings/ccip_router/WithdrawBilledFunds.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 15721f0

Please sign in to comment.