ConcourseOpen/DeFi-Pulse-Adapters

npm run test -- --project=_someProjectName fails because of run.js

W3stside opened this issue · 1 comments

Tests fail at npm run test due to run.js's: output = (await sdk.api.util.unwrap({balances: output, block: point.block})).output;

async function Run(runFunction, project, timeUnit = 'day', timeOffset = 0) {
    try {
      let timestamp;

      if(typeof timeUnit == 'number') {
        timestamp = timeUnit;
      } else {
        timestamp = moment().utcOffset(0).startOf(timeUnit).add(timeOffset, timeUnit).unix();
      }

      let point = await sdk.api.util.lookupBlock(timestamp);

      await sdk.api.util.resetEthCallCount();
      let output = await project[runFunction](point.timestamp, point.block);
      console.log('RUN before', output) // <----- this returns the normal expected data shape: { [tokenAddress: string]: BalanceAsString }
      if(runFunction == 'tvl') {
        output = (await sdk.api.util.toSymbols(output)).output;
        output = (await sdk.api.util.unwrap({balances: output, block: point.block})).output;
      }
      console.log('RUN after', output)
      let ethCallCount = await sdk.api.util.getEthCallCount();

      return {
        ...ethCallCount,
        ...point,
        output
      }

    } catch(error) {
      console.log(error);
    }
  }

the console log console.log('RUN after', output) returns:

RUN after {
  ETH: { balance: '2220.846437', id: 1027 },
  USDT: { balance: '605155.984481', id: 825 },
  TUSD: { balance: '10006.044458', id: 2563 },
  USDC: { balance: '3101071.305708', id: 3408 },
  PAX: { balance: '5093.068189', id: 3330 },
  GUSD: { balance: '142.37', id: 3306 },
...
}

which breaks inside test-run.js here:

_.each(projectRun.output, (value, symbol) => {
            let balance = BigNumber(value).toNumber();   // <----- "value" here is the object above e.g { balance: '2220', id: 1000 } 
            console.log(symbol, balance, value)
...

Obviously this fails as BigNumber({ balance: '2220.846437', id: 1027 }) breaks.
Btw, the log above console.log(RUN before, output) returns data as expected:
{
[tokenAddress: string]: string
}

Any ideas?
ok it's the unwrap function:
output = (await sdk.api.util.unwrap({balances: output, block: point.block})).output;

Which returns the object for each token symbol

closing as this was solved in master and not properly merged in my local branch