Skip to content

Commit

Permalink
Add test script
Browse files Browse the repository at this point in the history
  • Loading branch information
0xngmi committed Jun 23, 2021
1 parent 50f18b9 commit 0a0f602
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ This is a work in progress. The goal is to eventually handle historical data. De

If you have any suggestions, want to contribute or want to chat, please join [our discord](https://discord.gg/buPFYXzDDd) and drop a message.

## Testing adapters
```
node test.js projects/pangolin/index.js
```
35 changes: 35 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env node
const path = require("path");
require('dotenv').config();
const {default: computeTVL} = require("@defillama/sdk/build/computeTVL");
const { getCurrentBlocks } = require("@defillama/sdk/build//computeTVL/blocks");
const { humanizeNumber } = require("@defillama/sdk/build//computeTVL/humanizeNumber");


if (process.argv.length < 3) {
console.error(`Missing argument, you need to provide the filename of the adapter to test.
Eg: npx @defillama/sdk projects/myadapter.js`);
process.exit(1);
}
const passedFile = path.resolve(process.cwd(), process.argv[2]);

(async () => {
const moduleToTest = (await import(passedFile)).default;
let usdTvl;
if (moduleToTest.fetch) {
usdTvl = await moduleToTest.fetch();
} else if (moduleToTest.tvl) {
const { timestamp, ethereumBlock, chainBlocks } = await getCurrentBlocks();

let tvl = await moduleToTest.tvl(timestamp, ethereumBlock, chainBlocks);
if (typeof tvl !== "object") {
throw new Error("TVL returned is not a balances object");
}

usdTvl = (await computeTVL(tvl, "now", true)).usdTvl;
} else {
throw new Error("File must export either a property called tvl or one called fetch")
}
console.log("Total:", humanizeNumber(usdTvl));
process.exit(0);
})();

0 comments on commit 0a0f602

Please sign in to comment.