Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contract-library tries to find all contracts on Github even under NPM Link status #3

Open
benjamistan opened this issue Sep 6, 2021 · 1 comment

Comments

@benjamistan
Copy link

Expected Behavior

When trying to test new contracts using a local dev copy of contracts-library, the contracts-library repo should look locally if the HTTP call to find the json on Github fails.

Current Behavior

When trying to test a new GMTetherToken.sol contract using npm link, it appears that utils.js is still redirecting to Github to find the json and getting a 404.

Possible Solution

Check local before going to Github?

Steps to Reproduce

  1. Create new contract in this library using the standard steps
  2. Run npm link in your local contract-library folder
  3. Run npm link @xgm/contract-library in your local godmode-sample-project folder
  4. Run npx godmode install in your local godmode-sample-project-folder

Output

Installing protocols for GM...
/Users/Ben-XGM/gm/contract-library/dist/utils.js:27
                    throw error_codes_1.HTTPError(res.statusCode, `${url} ${res.statusCode} ${res.statusMessage}`);
                    ^

CustomError [HTTPError]: https://raw.githubusercontent.com/xGodMode/contract-library/main/build/protocols/Tether.json 404 Not Found
    at Object.HTTPError (/Users/Ben-XGM/gm/contract-library/node_modules/@xgm/error-codes/dist/index.js:23:12)
    at ClientRequest.<anonymous> (/Users/Ben-XGM/gm/contract-library/dist/utils.js:27:41)
    at Object.onceWrapper (events.js:422:26)
    at ClientRequest.emit (events.js:315:20)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:641:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:126:17)
    at TLSSocket.socketOnData (_http_client.js:509:22)
    at TLSSocket.emit (events.js:315:20)
    at addChunk (internal/streams/readable.js:309:12)
    at readableAddChunk (internal/streams/readable.js:284:9) {
  code: 'HTTP404',
  timestamp: 1630955568532,
  metadata: { statusCode: 404 }
}

Context (Environment)

I need to test local dev copies of contract-library without having to run npm publish each time I make changes.

@benjamistan
Copy link
Author

Looks like searching on Github is hardcoded here in /src/installer.ts

async function install(protocolName: string) {
    const protocolFilePath = path.join(OUTPUT_DIR, protocolName + '.json');
    const protocolUrl = `https://raw.githubusercontent.com/xGodMode/contract-library/main/build/protocols/${protocolName}.json`;
    const protocol = await handleRequest(protocolUrl, { json: true });
    await fs.promises.writeFile(
        protocolFilePath,
        JSON.stringify(protocol, null, 4)
    );
    console.log('Saved', protocolName, 'to', protocolFilePath);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant