Skip to content

Commit

Permalink
feat(tests): add tests for jams
Browse files Browse the repository at this point in the history
  • Loading branch information
lonerapier committed May 21, 2022
1 parent f1d3b2b commit 32378ac
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ var load = function (arg, _ethers, _signer) {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (typeof arg === "string") {
if (typeof arg === 'string') {
if ((0, ipfs_util_1.isCid)(arg)) {
arg = (0, ipfs_util_1.getIpfsJson)(arg);
}
else if (arg.split(".").pop() === "jams") {
else if (arg.split('.').pop() === 'jams') {
arg = (0, jams_js_1.jams)((0, fs_1.readFileSync)(arg));
}
else {
Expand Down
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { getIpfsJson, putIpfsJson, isCid } from './src/ipfs-util'
import { need } from './src/util'

export const load = async (arg, _ethers = undefined, _signer = undefined) => {
if (typeof arg === "string") {
if (typeof arg === 'string') {
if (isCid(arg)) {
arg = getIpfsJson(arg)
} else if (arg.split(".").pop() === "jams") {
} else if (arg.split('.').pop() === 'jams') {
arg = jams(readFileSync(arg))
} else {
arg = require(arg)
Expand Down
24 changes: 24 additions & 0 deletions test/data/weth_ropsten.dpack.jams
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
format dpack-1
network ropsten
types {
WETH9 {
typename WETH9
artifact {/ bafkreidsszpx34yqnshrtuszx7n77zxttk2s54kc2m5cftjutaumxe67fa }
}
}
objects {
weth9 {
objectname weth
address 0xc778417E063141139Fce010982780140Aa0cD5Ab
typename WETH9
artifact {/ bafkreidsszpx34yqnshrtuszx7n77zxttk2s54kc2m5cftjutaumxe67fa }
}
weth9 {
objectname weth9
address 0xc778417E063141139Fce010982780140Aa0cD5Ab
typename WETH9
artifact {/ bafkreidsszpx34yqnshrtuszx7n77zxttk2s54kc2m5cftjutaumxe67fa }
}
}
}
4 changes: 3 additions & 1 deletion test/dpack-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ before(async () => {

describe('end to end simple example', ()=>{
const packPath = path.join(__dirname, './data/weth_ropsten.dpack.json')
const jamsPath = path.join(__dirname, './data/weth_ropsten.dpack.jams')
let cidStr

it('create weth pack', async () => {
Expand Down Expand Up @@ -55,10 +56,11 @@ describe('end to end simple example', ()=>{
// another network. Packs can be loaded from a CID string, a file path string, or a json object.
const dappFromPack = await load(jsonObj, ethers, signer)
const dappFromPath = await load(packPath, ethers, signer)
const dappFromJams = await load(jamsPath, ethers, signer)
const dappFromCID = await load(cidStr, ethers, signer)

// All methods give the same pack
let packStrings = [JSON.stringify(dappFromPack), JSON.stringify(dappFromPath), JSON.stringify(dappFromCID)];
let packStrings = [JSON.stringify(dappFromPack), JSON.stringify(dappFromPath), JSON.stringify(dappFromJams), JSON.stringify(dappFromCID)];
want((new Set(packStrings)).size).to.equal(1)
})
});
Expand Down

0 comments on commit 32378ac

Please sign in to comment.