aiken-lang / stdlib

The Aiken Standard Library
https://aiken-lang.github.io/stdlib
Apache License 2.0
47 stars 26 forks source link

Value.add Has Unexpected Behavior When Subtracting #58

Closed logicalmechanism closed 1 year ago

logicalmechanism commented 1 year ago

The value.add function during subtraction returns incorrect results as shown in the example below.

Ubuntu 22.04.2 LTS aiken v1.0.10-alpha 85d82e5 stdlib 1.2

test adding_values_together() {
  let v =
    value.from_lovelace(123)
      |> value.add(#"acab", #"beef", 321)
      |> value.add(#"acab", #"beef", -1 * 321)
  v == value.from_lovelace(123)
}

This test fails when it should pass. The functionality should mirror the value.merge function, removing assets from a value when they are zero. As of right now, it returns a value with just the policy id and an empty dictionary.

  × adding_values_together failed
  help: ┍━ left ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┑
        │ (con string "{_ h\'\': {_ h\'\': 123 }, h\'ACAB\': {} }") │
        ┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┙

        should be equal to

        ┍━ right ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┑
        │ (con string "{_ h\'\': {_ h\'\': 123 } }") │
        ┕━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┙