0

I am writing some simple contract tests, and I want to check that account balances are updating appropriately.

There is currently no minus method on the Tez type. I attempted to add my own to the module, intending to make a PR if it worked - adding the following method to the Tez class in main.ts of archetype-ts-types...

minus(x: Tez): Tez {
    const result = this._content.minus(x.to_big_number())
    if (this._content.isLessThan(new BigNumber(0)) || this._content.isGreaterThan(new BigNumber("")))
          throw new Error("Invalid Tez value")
    return new Tez(result, "mutez")
  }

However I simply get the error "Property minus does not exist on type Tez".

Really I have two related questions -

  1. Why don't my updates to the types library in my local files flow through to my test script?
  2. Is this the right track or is there actually already a better way of doing this?

(I realise I can add "plus" to the other side of the assert equation, which is what I am doing for now, but it makes it easier to follow the meaning of the tests code having the minus option, so that would handy)

Help appreciated - thanks

1 Answer 1

0
  1. because Typescript is compiled to Js; what is executed is the precompiled Js; changing the source won't change the precompiled Js.
  2. you could use the to_big_number method:
const a = new Tez(10)
const b = new Tez(25)
const c = a.to_big_number().minus(b.to_big_number())
console.log(c.toNumber())

the above prints -15000000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.