diff --git a/remix-resolve/src/resolve.ts b/remix-resolve/src/resolve.ts index ca1da57ce2..ed67db69ba 100644 --- a/remix-resolve/src/resolve.ts +++ b/remix-resolve/src/resolve.ts @@ -1,19 +1,5 @@ import axios, { AxiosResponse } from 'axios' -import { Api, ModuleProfile, API } from 'remix-plugin' - -export interface RemixResolve extends Api { - type: 'remix-resolve' - events: {} - resolve: Function -} - -export const RemixResolveProfile: ModuleProfile = { - type: 'remix-resolve', - methods: ['resolve'] -} - - export interface Imported { content: string; cleanURL: string; @@ -30,9 +16,7 @@ interface Handler { handle(match: any): any; } -export class RemixResolveApi implements API { - public readonly type = 'remix-resolve' - +export class RemixResolve { private previouslyHandled: PreviouslyHandledImports constructor() { this.previouslyHandled = {} diff --git a/remix-resolve/tests/test.ts b/remix-resolve/tests/test.ts index 3deab4fc7e..54afd22096 100644 --- a/remix-resolve/tests/test.ts +++ b/remix-resolve/tests/test.ts @@ -1,123 +1,13 @@ -import { RemixResolve, RemixResolveApi } from '../src' +import { RemixResolve } from '../src' import * as fs from 'fs' import * as path from 'path' import * as assert from 'assert' -import { AppManager, PluginProfile } from 'remix-plugin' - -const RemixResolveProfile: PluginProfile = { - type: 'remix-resolve', - methods: ['resolve'], - url: '' -} -interface IAppManager { - modules: { - remixResolve: RemixResolve - }, - plugins: {} -} describe('testRunner', () => { - describe('# RemixResolveApi.resolve()', () => { - // AppManager tests - describe('* test with AppManager', () => { - describe('test example_1 [local imports]', () => { - let app: AppManager - let api: RemixResolveApi - - const fileName = '../remix-resolve/tests/example_1/greeter.sol' - let results: object = {} - - before(done => { - api = new RemixResolveApi() - app = new AppManager({ - modules: [{ json: RemixResolveProfile, api }] - }) - - function handleLocal(pathString: string, filePath: string) { - // if no relative/absolute path given then search in node_modules folder - if (pathString && pathString.indexOf('.') !== 0 && pathString.indexOf('/') !== 0) { - // return handleNodeModulesImport(pathString, filePath, pathString) - return - } else { - const o = { encoding: 'UTF-8' } - const p = pathString ? path.resolve(pathString, filePath) : path.resolve(pathString, filePath) - const content = fs.readFileSync(p, o) - return content - } - } - const localFSHandler = [ - { - type: 'local', - match: (url: string) => { return /(^(?!(?:http:\/\/)|(?:https:\/\/)?(?:www.)?(?:github.com)))(^\/*[\w+-_/]*\/)*?(\w+\.sol)/g.exec(url) }, - handle: (match: Array) => { return handleLocal(match[2], match[3]) } - } - ] - app['modules'][api.type].api.resolve(fileName, localFSHandler) - .then((sources: object) => { - results = sources - done() - }) - .catch((e: Error) => { - throw e - }) - }) - - it('Plugin should be added to app', () => { - assert.equal(typeof(app.calls[api.type].resolve), 'function') - }) - it('should return contract content of given local path', () => { - const expt = { - content: 'pragma solidity ^0.5.0;\nimport "./mortal.sol";\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 constructor(string memory _greeting) public {\n greeting = _greeting;\n }\n\n /* Main function */\n function greet() public view returns (string memory) {\n return greeting;\n }\n}\n', - cleanURL: '../remix-resolve/tests/example_1/greeter.sol', - type: 'local' - } - assert.deepEqual(results, expt) - }) - }) - // test IPFShandle - describe('test getting IPFS files', function() { - let app: AppManager - let api: RemixResolveApi - - const fileName: string = 'ipfs://QmeKtwMBqz5Ac7oL8SyTD96mccEzw9X9d39jLb2kgnBYbn' - let results: object - - before((done) => { - try { - api = new RemixResolveApi() - app = new AppManager({ - modules: [{ json: RemixResolveProfile, api }] - }) - - app['modules'][api.type].api.resolve(fileName) - .then((sources: object) => { - results = sources - done() - }) - .catch((e: Error) => { - throw e - }) - } catch(e) { - throw e - } - }) - - it('should have 3 items', () => { - assert.equal(Object.keys(results).length, 3) - }) - it('should return contract content of given IPFS path', () => { - const expt = { - content: 'pragma solidity ^0.5.0;\nimport "./mortal.sol";\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 constructor(string memory _greeting) public {\n greeting = _greeting;\n }\n\n /* Main function */\n function greet() public view returns (string memory) {\n return greeting;\n }\n}\n', - cleanURL: 'ipfs://QmeKtwMBqz5Ac7oL8SyTD96mccEzw9X9d39jLb2kgnBYbn', - type: 'ipfs' - } - assert.deepEqual(results, expt) - }) - }) - }) + describe('# RemixResolve.resolve()', () => { describe('* test without AppManager', () => { describe('test example_1 [local imports]', () => { - const remixResolve = new RemixResolveApi() + const remixResolve = new RemixResolve() const fileName: string = '../remix-resolve/tests/example_1/greeter.sol' let results: object = {} @@ -165,7 +55,7 @@ describe('testRunner', () => { }) // Test github import describe('test getting github imports', () => { - const remixResolve = new RemixResolveApi() + const remixResolve = new RemixResolve() const fileName: string = 'github.com/ethereum/populus/docs/assets/Greeter.sol' let results: object = {} @@ -194,7 +84,7 @@ describe('testRunner', () => { }) // Test https imports describe('test getting https imports', () => { - const remixResolve = new RemixResolveApi() + const remixResolve = new RemixResolve() const fileName: string = 'https://gist.githubusercontent.com/roneilr/7901633d7c2f52957d22/raw/d9b9d54760f6e4f4cfbac4b321bee6a6983a1048/greeter.sol' let results: object = {} @@ -224,7 +114,7 @@ describe('testRunner', () => { // Test http imports describe('test getting http imports', () => { - const remixResolve = new RemixResolveApi() + const remixResolve = new RemixResolve() const fileName: string = 'http://gist.githubusercontent.com/roneilr/7901633d7c2f52957d22/raw/d9b9d54760f6e4f4cfbac4b321bee6a6983a1048/greeter.sol' let results: object = {}