Skip to content

Commit d539e9e

Browse files
committed
tests: allow axfer of 0 amount to anyone
I believe this change would also support sending an axfer of 0 amount to yourself (opt in) whilst also including a close-out to yourself (close out) in a single axfer
1 parent cd6be5e commit d539e9e

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

data/transactions/logic/evalAppTxn_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@ func TestAppAxfer(t *testing.T) {
468468
"assert failed") // app account not opted in
469469

470470
ledger.NewAccount(appAddr(888), 10000) // plenty for fees
471+
472+
// It should be possible to send 0 amount of an asset (existing
473+
// or not) to any account but ourself. Regardless of being opted in
474+
test("global CurrentApplicationAddress; txn Accounts 1; int 0" + axfer + "int 1")
475+
holding, err := ledger.AssetHolding(appAddr(888), 77)
476+
require.ErrorContains(t, err, "no asset 77 for account")
477+
require.Equal(t, uint64(0), holding.Amount)
478+
471479
ledger.NewHolding(appAddr(888), 77, 3000, false)
472480
test("global CurrentApplicationAddress; int 77; asset_holding_get AssetBalance; assert; int 3000; ==;")
473481

data/transactions/logic/ledger_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -731,17 +731,20 @@ func (l *Ledger) axfer(from basics.Address, xfer transactions.AssetTransferTxnFi
731731
}
732732
fholding, ok := fbr.holdings[aid]
733733
if !ok {
734-
if from == to && amount == 0 {
735-
// opt in
736-
if params, exists := l.assets[aid]; exists {
737-
fbr.holdings[aid] = basics.AssetHolding{
738-
Frozen: params.DefaultFrozen,
734+
if amount == 0 {
735+
if from == to {
736+
// opt in
737+
if params, exists := l.assets[aid]; exists {
738+
fbr.holdings[aid] = basics.AssetHolding{
739+
Frozen: params.DefaultFrozen,
740+
}
741+
} else {
742+
return fmt.Errorf("Asset (%d) does not exist", aid)
739743
}
740-
return nil
741744
}
742-
return fmt.Errorf("Asset (%d) does not exist", aid)
745+
} else {
746+
return fmt.Errorf("Sender (%s) not opted in to %d", from, aid)
743747
}
744-
return fmt.Errorf("Sender (%s) not opted in to %d", from, aid)
745748
}
746749
if fholding.Frozen {
747750
return fmt.Errorf("Sender (%s) is frozen for %d", from, aid)

0 commit comments

Comments
 (0)