Skip to content

Commit

Permalink
initialize recipient subaccount with random balance
Browse files Browse the repository at this point in the history
  • Loading branch information
tqin7 committed Nov 27, 2023
1 parent 529524b commit d651b44
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions protocol/x/sending/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ import (

func TestMsgCreateTransfer(t *testing.T) {
tests := map[string]struct {
/* Setup */
// Initial balance of sender subaccount.
senderInitialBalance uint64

// Whether recipient subaccount exists.
recipientDoesNotExist bool

// Sender subaccount ID.
senderSubaccountId satypes.SubaccountId

Expand Down Expand Up @@ -72,8 +76,9 @@ func TestMsgCreateTransfer(t *testing.T) {
},
// Transfer to a non-existent subaccount will create that subaccount and succeed.
"Success: transfer from Alice subaccount to non-existent subaccount": {
senderInitialBalance: 10_000_000,
senderSubaccountId: constants.Alice_Num0,
senderInitialBalance: 10_000_000,
recipientDoesNotExist: true,
senderSubaccountId: constants.Alice_Num0,
recipientSubaccountId: satypes.SubaccountId{
Owner: constants.BobAccAddress.String(),
Number: 104,
Expand Down Expand Up @@ -141,6 +146,23 @@ func TestMsgCreateTransfer(t *testing.T) {
},
},
}
if !tc.recipientDoesNotExist {
genesisState.Subaccounts = append(
genesisState.Subaccounts,
satypes.Subaccount{
Id: &tc.recipientSubaccountId,
AssetPositions: []*satypes.AssetPosition{
{
AssetId: constants.Usdc.Id,
Index: 0,
Quantums: dtypes.NewIntFromUint64(
rand.NewRand().Uint64(),
),
},
},
},
)
}
},
)
return genesis
Expand Down

0 comments on commit d651b44

Please sign in to comment.