Skip to content

Commit

Permalink
fix: mapping ignore destinations accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Apr 17, 2023
1 parent 991b720 commit 32fde57
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
36 changes: 36 additions & 0 deletions pkg/ledger/execute_script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,42 @@ func TestCompilationError(t *testing.T) {
})
}

func TestMappingIgnoreDestinations(t *testing.T) {
runOnLedger(func(l *ledger.Ledger) {
script := core.ScriptData{
Script: core.Script{
Plain: `
send [USD/2 1100] (
source = @A allowing overdraft up to [USD/2 1100]
destination = @B
)`,
},
}
_, err := l.ExecuteScript(context.Background(), false, script)
require.NoError(t, err)

_, err = l.ExecuteTxsData(context.Background(), false, core.TransactionData{
Postings: []core.Posting{{
Source: "B",
Destination: "A",
Amount: core.NewMonetaryInt(100),
Asset: "USD/2",
}},
})
require.NoError(t, err)

_, err = l.ExecuteTxsData(context.Background(), false, core.TransactionData{
Postings: []core.Posting{{
Source: "B",
Destination: "A",
Amount: core.NewMonetaryInt(0),
Asset: "USD/2",
}},
})
require.NoError(t, err)
})
}

func TestSend(t *testing.T) {
runOnLedger(func(l *ledger.Ledger) {
t.Run("nominal", func(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/ledger/execute_txsdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (l *Ledger) ExecuteTxsData(ctx context.Context, preview bool, txsData ...co
if account == core.WORLD {
continue
}
if volume.Balance().Gte(txVolumeAggr.PreCommitVolumes[account][asset].Balance()) {
continue
}

for _, contract := range contracts {
if contract.Match(account) {
Expand Down

0 comments on commit 32fde57

Please sign in to comment.