From 7b1bb1fef110c4371a9122e493ace0505e3e9f86 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Fri, 25 Mar 2022 15:45:33 +0100 Subject: [PATCH] Fix missing world account on emitted account volumes. --- pkg/ledger/ledger.go | 41 +++++++++++++++++++-------------------- pkg/ledger/ledger_test.go | 10 ++++++++++ 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/pkg/ledger/ledger.go b/pkg/ledger/ledger.go index a3f36413b..c6988402b 100644 --- a/pkg/ledger/ledger.go +++ b/pkg/ledger/ledger.go @@ -158,9 +158,6 @@ txLoop: } for addr := range rf { - if addr == "world" { - continue - } _, ok := aggregatedVolumes[addr] if !ok { @@ -177,25 +174,27 @@ txLoop: "output": 0, } } - expectedBalance := aggregatedVolumes[addr][asset]["input"] - aggregatedVolumes[addr][asset]["output"] + volumes["input"] - volumes["output"] - for _, contract := range contracts { - if contract.Match(addr) { - meta, err := l.store.GetMeta(ctx, "account", addr) - if err != nil { - return nil, nil, err - } - ok := contract.Expr.Eval(core.EvalContext{ - Variables: map[string]interface{}{ - "balance": float64(expectedBalance), - }, - Metadata: meta, - Asset: asset, - }) - if !ok { - commitError(NewTransactionCommitError(i, NewInsufficientFundError(asset))) - continue txLoop + if addr != "world" { + expectedBalance := aggregatedVolumes[addr][asset]["input"] - aggregatedVolumes[addr][asset]["output"] + volumes["input"] - volumes["output"] + for _, contract := range contracts { + if contract.Match(addr) { + meta, err := l.store.GetMeta(ctx, "account", addr) + if err != nil { + return nil, nil, err + } + ok := contract.Expr.Eval(core.EvalContext{ + Variables: map[string]interface{}{ + "balance": float64(expectedBalance), + }, + Metadata: meta, + Asset: asset, + }) + if !ok { + commitError(NewTransactionCommitError(i, NewInsufficientFundError(asset))) + continue txLoop + } + break } - break } } aggregatedVolumes[addr][asset]["input"] += volumes["input"] diff --git a/pkg/ledger/ledger_test.go b/pkg/ledger/ledger_test.go index 529e7d04e..7c532c7e4 100644 --- a/pkg/ledger/ledger_test.go +++ b/pkg/ledger/ledger_test.go @@ -297,6 +297,16 @@ func TestTransactionExpectedVolumes(t *testing.T) { } if !assert.EqualValues(t, volumes, Volumes{ + "world": map[string]map[string]int64{ + "USD": { + "input": 0, + "output": 100, + }, + "EUR": { + "input": 0, + "output": 200, + }, + }, "player": map[string]map[string]int64{ "USD": { "input": 100,