GPTScript / AiScript

A Minimal, Full-Stack, Tool-Assisted Language. Native to Browsers and Bun. Strictly & Strongly-Typed.
https://github.com/GPTScript/AiScript
Mozilla Public License 2.0
9 stars 1 forks source link

Test Case: should understand transitive conditions #46

Open coolaj86 opened 1 year ago

coolaj86 commented 1 year ago

If we assign one variable to another and test the new variables properties, we should know that the same applies to the previous variable:

    /**
     * @param {Object} opts
     * @param {Array<CoreUtxo>?} [opts.inputs]
     * @param {Number} [opts.satoshis]
     * @param {Number} [opts.now] - ms
     */
    function mustSelectInputs({ inputs, satoshis, now = Date.now() }) {
      if (inputs) {
        return inputs;
      }

      let fullTransfer = !satoshis;   <=== satoshis is assigned to fullTransfer, which is tested for truthy-ness
      if (fullTransfer) {
        let msg = `'satoshis' must be a positive number unless 'inputs' are specified`;
        let err = new Error(msg);
        throw err;
      }

      let coins = wallet.utxos();
      inputs = DashApi.selectOptimalUtxos(coins, satoshis);   <=== should know that satoshis is NOT undefined

      if (!inputs.length) {
        throw createInsufficientFundsError(coins, satoshis);
      }

      return inputs;
    }