Skip to content

Commit

Permalink
Fix missing world account on emitted account volumes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Mar 28, 2022
1 parent a479d5b commit 7b1bb1f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
41 changes: 20 additions & 21 deletions pkg/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ txLoop:
}

for addr := range rf {
if addr == "world" {
continue
}

_, ok := aggregatedVolumes[addr]
if !ok {
Expand All @@ -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"]
Expand Down
10 changes: 10 additions & 0 deletions pkg/ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 7b1bb1f

Please sign in to comment.