Skip to content

Commit

Permalink
feat: disallow empty accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag authored and flemzord committed May 12, 2023
1 parent 05c7cff commit c5395d2
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 56 deletions.
4 changes: 0 additions & 4 deletions pkg/machine/internal/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
31 changes: 0 additions & 31 deletions pkg/machine/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
21 changes: 0 additions & 21 deletions pkg/machine/vm/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c5395d2

Please sign in to comment.