Skip to content

Commit

Permalink
services/horizon: Add integration test for claimable balance sponsors…
Browse files Browse the repository at this point in the history
…hip change (#5308)
  • Loading branch information
urvisavla authored May 10, 2024
1 parent 64cb187 commit c65b5b7
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions services/horizon/internal/integration/sponsorship_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,63 @@ func TestSponsorships(t *testing.T) {
tt.Equalf(needed, actual, "effect %s not found enough", expectedType)
}
})

t.Run("ClaimableBalanceTransferSponsorship", func(t *testing.T) {
keys, accounts := itest.CreateAccounts(3, "150")
sponsorPair1, sponsor1 := keys[0], accounts[0]
sponsoreePair, _ := keys[1], accounts[1]
sponsorPair2, sponsor2 := keys[2], accounts[2]

// Create a claimable balance
op := &txnbuild.CreateClaimableBalance{
SourceAccount: sponsor1.GetAccountID(),
Destinations: []txnbuild.Claimant{
txnbuild.NewClaimant(sponsorPair1.Address(), nil),
txnbuild.NewClaimant(sponsoreePair.Address(), nil),
},
Amount: "10",
Asset: txnbuild.NativeAsset{},
}

_, err := itest.SubmitOperations(sponsor1, sponsorPair1, op)
tt.NoError(err)

balances, err := client.ClaimableBalances(sdk.ClaimableBalanceRequest{})
tt.NoError(err)

// Verify the sponsor
claims := balances.Embedded.Records
tt.Len(claims, 1)
balance := claims[0]
tt.Equal(sponsorPair1.Address(), balance.Sponsor)

// Transfer sponsorship
ops := []txnbuild.Operation{
&txnbuild.BeginSponsoringFutureReserves{
SourceAccount: sponsor2.GetAccountID(),
SponsoredID: sponsorPair1.Address(),
},
&txnbuild.RevokeSponsorship{
SponsorshipType: txnbuild.RevokeSponsorshipTypeClaimableBalance,
SourceAccount: sponsor1.GetAccountID(),
ClaimableBalance: &claims[0].BalanceID,
},
&txnbuild.EndSponsoringFutureReserves{SourceAccount: sponsor1.GetAccountID()},
}

_, err = itest.SubmitMultiSigOperations(sponsor2, []*keypair.Full{sponsorPair1, sponsorPair2}, ops...)
tt.NoError(err)

balances, err = client.ClaimableBalances(sdk.ClaimableBalanceRequest{})
tt.NoError(err)

// Verify sponsorship transfer
claims = balances.Embedded.Records
tt.Len(claims, 1)
balance = claims[0]
tt.Equal(sponsorPair2.Address(), balance.Sponsor)

})
}

// Sandwiches a set of operations between a Begin/End reserve sponsorship.
Expand Down

0 comments on commit c65b5b7

Please sign in to comment.