diff --git a/pkg/machine/vm/machine.go b/pkg/machine/vm/machine.go index d699aa599..0666e113e 100644 --- a/pkg/machine/vm/machine.go +++ b/pkg/machine/vm/machine.go @@ -504,8 +504,13 @@ func (m *Machine) ResolveBalances() (chan BalanceRequest, error) { } return } + if account, ok := (*account).(core.AccountAddress); ok { - m.Balances[account] = make(map[core.Asset]*core.MonetaryInt) + + if _, ok := m.Balances[account]; !ok { + m.Balances[account] = make(map[core.Asset]*core.MonetaryInt) + } + // for every asset, send request for addr := range neededAssets { mon, ok := m.getResource(addr) diff --git a/pkg/machine/vm/machine_test.go b/pkg/machine/vm/machine_test.go index 456ba81fc..dea3d8701 100644 --- a/pkg/machine/vm/machine_test.go +++ b/pkg/machine/vm/machine_test.go @@ -1929,3 +1929,37 @@ func TestSendWithArithmetic(t *testing.T) { test(t, tc) }) } + +func TestUseDifferentAssetsWithSameSourceAccount(t *testing.T) { + tc := NewTestCase() + tc.compile(t, `vars { + account $a_account +} +send [A 100] ( + source = $a_account allowing unbounded overdraft + destination = @account1 +) +send [B 100] ( + source = @world + destination = @account2 +)`) + tc.setBalance("account1", "A", 100) + tc.setBalance("account2", "B", 100) + tc.setVarsFromJSON(t, `{"a_account": "world"}`) + tc.expected = CaseResult{ + Printed: []core.Value{}, + Postings: []Posting{{ + Source: "world", + Destination: "account1", + Amount: core.NewMonetaryInt(100), + Asset: "A", + }, { + Source: "world", + Destination: "account2", + Amount: core.NewMonetaryInt(100), + Asset: "B", + }}, + ExitCode: EXIT_OK, + } + test(t, tc) +}