From c5395d20e86be18ab1a473a919c83f16902fed1c Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Thu, 20 Apr 2023 14:52:40 +0200 Subject: [PATCH] feat: disallow empty accounts --- pkg/machine/internal/account.go | 4 ---- pkg/machine/machine_test.go | 31 ------------------------------- pkg/machine/vm/machine_test.go | 21 --------------------- 3 files changed, 56 deletions(-) diff --git a/pkg/machine/internal/account.go b/pkg/machine/internal/account.go index 43f0eb5fa..a535fac27 100644 --- a/pkg/machine/internal/account.go +++ b/pkg/machine/internal/account.go @@ -14,10 +14,6 @@ func (a AccountAddress) String() string { } func ParseAccountAddress(acc AccountAddress) error { - // TODO: handle properly in ledger v1.10 - if acc == "" { - return nil - } if !core.AccountRegexp.MatchString(string(acc)) { return fmt.Errorf("accounts should respect pattern %s", core.AccountPattern) } diff --git a/pkg/machine/machine_test.go b/pkg/machine/machine_test.go index ddbf92b8c..957f10952 100644 --- a/pkg/machine/machine_test.go +++ b/pkg/machine/machine_test.go @@ -116,37 +116,6 @@ var testCases = []testCase{ AccountMetadata: map[string]metadata.Metadata{}, }, }, - { - name: "use empty account", - script: ` - vars { - account $acc - } - - send [EUR 1] ( - source = @world - destination = @bob - ) - - send [EUR 1] ( - source = { - @bob - $acc - } - destination = @alice - )`, - vars: map[string]json.RawMessage{ - "acc": json.RawMessage(`""`), - }, - expectResult: Result{ - Postings: []core.Posting{ - core.NewPosting("world", "bob", "EUR", big.NewInt(1)), - core.NewPosting("bob", "alice", "EUR", big.NewInt(1)), - }, - Metadata: metadata.Metadata{}, - AccountMetadata: map[string]metadata.Metadata{}, - }, - }, { name: "using metadata", store: vm.StaticStore{ diff --git a/pkg/machine/vm/machine_test.go b/pkg/machine/vm/machine_test.go index b5327d558..fe675c83c 100644 --- a/pkg/machine/vm/machine_test.go +++ b/pkg/machine/vm/machine_test.go @@ -1360,27 +1360,6 @@ func TestVariablesParsing(t *testing.T) { })) }) - // TODO: handle properly in ledger v1.10 - t.Run("account empty string", func(t *testing.T) { - p, err := compiler.Compile(` - vars { - account $acc - } - set_tx_meta("account", $acc) - `) - require.NoError(t, err) - - m := NewMachine(*p) - - require.NoError(t, m.SetVars(map[string]internal.Value{ - "acc": internal.AccountAddress(""), - })) - - require.NoError(t, m.SetVarsFromJSON(map[string]json.RawMessage{ - "acc": json.RawMessage(`""`), - })) - }) - t.Run("monetary", func(t *testing.T) { p, err := compiler.Compile(` vars {