Add http call handle, add tests, add more typings

pull/7/head
Omkara 6 years ago
parent f438a3683b
commit 141bef406f
  1. 22
      remix-resolve/src/resolve.ts
  2. 32
      remix-resolve/tests/test.ts

@ -1,4 +1,4 @@
import axios from 'axios'
import axios, { AxiosResponse } from 'axios'
import { Api, ModuleProfile, API } from 'remix-plugin'
@ -45,7 +45,7 @@ export class RemixResolveApi implements API<RemixResolve> {
async handleGithubCall(root: string, filePath: string) {
try {
let req: string = 'https://api.github.com/repos/' + root + '/contents/' + filePath
const response = await axios.get(req)
const response: AxiosResponse = await axios.get(req)
return Buffer.from(response.data.content, 'base64').toString()
} catch(e) {
throw e
@ -56,17 +56,22 @@ export class RemixResolveApi implements API<RemixResolve> {
* @params url The url of the import statement
* @params cleanURL
*/
handleHttp(url: string, cleanURL: string) {
return
async handleHttp(url: string, _: string) {
try {
const response: AxiosResponse = await axios.get(url)
return response.data
} catch(e) {
throw e
}
}
/**
* Handle an import statement based on https
* @params url The url of the import statement
* @params cleanURL
*/
async handleHttps(url: string, cleanURL: string) {
async handleHttps(url: string, _: string) {
try {
const response = await axios.get(url)
const response: AxiosResponse = await axios.get(url)
return response.data
} catch(e) {
throw e
@ -86,15 +91,12 @@ export class RemixResolveApi implements API<RemixResolve> {
const req = 'https://gateway.ipfs.io/' + url
// If you don't find greeter.sol on ipfs gateway use local
// const req = 'http://localhost:8080/' + url
const response = await axios.get(req)
const response: AxiosResponse = await axios.get(req)
return response.data
} catch (e) {
throw e
}
}
handleLocal(root: string, filePath: string) {
return
}
getHandlers(): Handler[] {
return [
{

@ -61,7 +61,7 @@ describe('testRunner', () => {
throw e
})
})
it('Plugin should be added to app', () => {
assert.equal(typeof(app.calls[api.type].resolve), 'function')
})
@ -221,6 +221,36 @@ describe('testRunner', () => {
assert.deepEqual(results, expt)
})
})
// Test http imports
describe('test getting http imports', () => {
const remixResolve = new RemixResolveApi()
const fileName: string = 'http://gist.githubusercontent.com/roneilr/7901633d7c2f52957d22/raw/d9b9d54760f6e4f4cfbac4b321bee6a6983a1048/greeter.sol'
let results: object = {}
before(done => {
remixResolve.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 expt: object = {
content: 'contract mortal {\n /* Define variable owner of the type address*/\n address owner;\n\n /* this function is executed at initialization and sets the owner of the contract */\n function mortal() { owner = msg.sender; }\n\n /* Function to recover the funds on the contract */\n function kill() { if (msg.sender == owner) suicide(owner); }\n}\n\ncontract greeter is mortal {\n /* define variable greeting of the type string */\n string greeting;\n\n /* this runs when the contract is executed */\n function greeter(string _greeting) public {\n greeting = _greeting;\n }\n\n /* main function */\n function greet() constant returns (string) {\n return greeting;\n }\n}',
cleanURL: 'http://gist.githubusercontent.com/roneilr/7901633d7c2f52957d22/raw/d9b9d54760f6e4f4cfbac4b321bee6a6983a1048/greeter.sol',
type: 'http'
}
assert.deepEqual(results, expt)
})
})
})
})
})

Loading…
Cancel
Save