ipfs import unit tests in remix-url-resolver

pull/713/head
aniket-engg 4 years ago committed by Aniket
parent 2436b63a6d
commit d95b20d77b
  1. 2
      libs/remix-url-resolver/src/resolve.ts
  2. 2
      libs/remix-url-resolver/tests/example_1/greeter.sol
  3. 31
      libs/remix-url-resolver/tests/test.ts

@ -99,7 +99,7 @@ export class RemixURLResolver {
url = url.replace(/^ipfs:\/\/?/, 'ipfs/') url = url.replace(/^ipfs:\/\/?/, 'ipfs/')
//eslint-disable-next-line no-useless-catch //eslint-disable-next-line no-useless-catch
try { try {
const req = 'https://gateway.ipfs.io/' + url const req = 'https://ipfsgw.komputing.org/' + url
// If you don't find greeter.sol on ipfs gateway use local // If you don't find greeter.sol on ipfs gateway use local
// const req = 'http://localhost:8080/' + url // const req = 'http://localhost:8080/' + url
const response: AxiosResponse = await axios.get(req) const response: AxiosResponse = await axios.get(req)

@ -14,4 +14,4 @@ contract Greeter is Mortal {
function greet() public view returns (string memory) { function greet() public view returns (string memory) {
return greeting; return greeting;
} }
} }

@ -141,6 +141,37 @@ describe('testRunner', () => {
assert.deepEqual(results, expt) assert.deepEqual(results, expt)
}) })
}) })
// Test IPFS imports
describe('test getting IPFS imports', () => {
const urlResolver = new RemixURLResolver()
const fileName = 'ipfs://QmcuCKyokk9Z6f65ADAADNiS2R2xCjfRkv7mYBSWDwtA7M'
let results: object = {}
before(done => {
urlResolver.resolve(fileName)
.then((sources: object) => {
results = sources
done()
})
.catch((e: Error) => {
throw e
})
})
it('should have 3 items', () => {
assert.equal(Object.keys(results).length, 3)
})
it('should return contract content from raw github url', () => {
const content = fs.readFileSync(__dirname + '/example_1/greeter.sol', { encoding: 'utf8'})
const expt: object = {
content: content,
cleanUrl: 'ipfs/QmcuCKyokk9Z6f65ADAADNiS2R2xCjfRkv7mYBSWDwtA7M',
type: 'ipfs'
}
assert.deepEqual(results, expt)
})
})
}) })
}) })
}) })

Loading…
Cancel
Save